-
Notifications
You must be signed in to change notification settings - Fork 3.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
clang: check header ownership #4928
Conversation
int ret; | ||
if ((ret = stat(f, &buffer)) == 0) { | ||
if (buffer.st_uid != uid) { | ||
std::cout << "ERROR: header file ownership unexpected: " << std::string(f) << "\n"; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit: is it useful to also print out the expected uid
and the one in the file: st_uid
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this is close enough: says this filename has this type of error. End-user should likely see this and run ls -l
. There's related codepaths that can error with no such hint, which is pretty hard to debug, which is why I put a big clue in. :-)
Do we need to check the ld cache ownership too? https://github.com/iovisor/bcc/blob/master/src/cc/bcc_proc.c#L400 |
Thanks, although the ld cache is only in /etc, right? /etc should already be locked down, so we wouldn't need to check. If unprivileged users can create files in /etc, I imagine there's a ton of other issues. |
I'm afraid this is not fixed yet. The example above fails only because it does not contain the include/linux/kconfig.h file.
|
file_exists_and_ownedby() returns -1 when the file exists but its ownership is unexpected, which is very misleading since anything non zero is interpreted as true and a function with such a name is expected to return a boolean. So currently all this does, is write a warning message, and continues as if nothing is wrong. Make file_exists_and_ownedby() returns false when the ownership is wrong and have get_proc_kheaders() fails when this happen. Also have all the *exists* functions return bool to avoid such issues in the future. Signed-off-by: Jerome Marchand <jmarchan@redhat.com>
file_exists_and_ownedby() returns -1 when the file exists but its ownership is unexpected, which is very misleading since anything non zero is interpreted as true and a function with such a name is expected to return a boolean. So currently all this does, is write a warning message, and continues as if nothing is wrong. Make file_exists_and_ownedby() returns false when the ownership is wrong and have get_proc_kheaders() fails when this happen. Also have all the *exists* functions return bool to avoid such issues in the future. Signed-off-by: Jerome Marchand <jmarchan@redhat.com>
file_exists_and_ownedby() returns -1 when the file exists but its ownership is unexpected, which is very misleading since anything non zero is interpreted as true and a function with such a name is expected to return a boolean. So currently all this does, is write a warning message, and continues as if nothing is wrong. Make file_exists_and_ownedby() returns false when the ownership is wrong and have get_proc_kheaders() fails when this happen. Also have all the *exists* functions return bool to avoid such issues in the future. Signed-off-by: Jerome Marchand <jmarchan@redhat.com>
file_exists_and_ownedby() returns -1 when the file exists but its ownership is unexpected, which is very misleading since anything non zero is interpreted as true and a function with such a name is expected to return a boolean. So currently all this does, is write a warning message, and continues as if nothing is wrong. Make file_exists_and_ownedby() returns false when the ownership is wrong and have get_proc_kheaders() fails when this happen. Also have all the *exists* functions return bool to avoid such issues in the future. Signed-off-by: Jerome Marchand <jmarchan@redhat.com>
file_exists_and_ownedby() returns -1 when the file exists but its ownership is unexpected, which is very misleading since anything non zero is interpreted as true and a function with such a name is expected to return a boolean. So currently all this does, is write a warning message, and continues as if nothing is wrong. Make file_exists_and_ownedby() returns false when the ownership is wrong and have get_proc_kheaders() fails when this happen. Also have all the *exists* functions return bool to avoid such issues in the future. Signed-off-by: Jerome Marchand <jmarchan@redhat.com>
Example testing with a brendan-owned /tmp/kheaders file (note the "ERROR:" message): ~/bcc/build$ sudo /usr/share/bcc/tools/biosnoop ERROR: header file ownership unexpected: /tmp/kheaders-5.15.47-internal <built-in>:1:10: fatal error: './include/linux/kconfig.h' file not found #include "./include/linux/kconfig.h" ^~~~~~~~~~~~~~~~~~~~~~~~~~~ 1 error generated. Traceback (most recent call last): File "/usr/share/bcc/tools/biosnoop", line 335, in <module> b = BPF(text=bpf_text) File "/usr/lib/python3/dist-packages/bcc-0.1.5+6cd27218-py3.10.egg/bcc/__init__.py", line 479, in __init__ Exception: Failed to compile BPF module <text> ~/bcc/build$ ls -lhd /tmp/kheaders-5.15.47-internal drwxrwxr-x 2 brendan dev 4.0K Mar 6 02:50 /tmp/kheaders-5.15.47-internal No error when chown'd back to root.
…sor#4985) file_exists_and_ownedby() returns -1 when the file exists but its ownership is unexpected, which is very misleading since anything non zero is interpreted as true and a function with such a name is expected to return a boolean. So currently all this does, is write a warning message, and continues as if nothing is wrong. Make file_exists_and_ownedby() returns false when the ownership is wrong and have get_proc_kheaders() fails when this happen. Also have all the *exists* functions return bool to avoid such issues in the future. Signed-off-by: Jerome Marchand <jmarchan@redhat.com>
Example testing with a brendan-owned /tmp/kheaders file (note the "ERROR:" message):
No error when chown'd back to root.