-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
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
child.cpp: validate_cmd: Support symbolic links in environment variables #2708
child.cpp: validate_cmd: Support symbolic links in environment variables #2708
Conversation
@danobi Seems all is well. please review. thanks. |
8f2d0d8
to
71533ac
Compare
Can we create a test for this? |
Is this necessary? This PR only solves the error when /usr/bin/sleep and /bin/sleep are the same executable file. How should this situation be deployed in the CICD environment?
This problem may not exist in different environments (including CICD), so I suggest not to add a test case. What do you think? @viktormalik Or we can create a TEST(childproc, multi_exe_link_match)
{
// Create /usr/sbin/sleep -> /usr/bin/sleep
// Test bpftrace -e '...' sleep 5
} However, i still think it's not necessary to add this test case. |
71533ac
to
e79ff58
Compare
I just force push a modification. There may be worse cases like
So instead of using |
On some systems /bin is a symbolic link to /usr/bin (/bin -> /usr/bin), When using the '-c' parameter to specify the executable program in the environment variable, the problem of "multiple binary files matching" occurs, for example: $ sudo bpftrace -e 'kprobe:do_nanosleep { printf("%d sleeping\n", pid); }' -c 'sleep 5' ERROR: Failed to fork child: path 'sleep' must refer to a unique binary but matched 2 binaries Debugging the bpftrace program through gdb can also be verified: (gdb) p valid_executable_paths $9 = std::vector of length 2, capacity 2 = {"/bin/ls", "/usr/bin/ls"} Another situation is: $ realpath /usr/bin/ping /bin/ping /usr/sbin/ping /sbin/ping /usr/bin/ping /usr/bin/ping /usr/bin/ping /usr/bin/ping $ sudo bpftrace -e 'kprobe:do_nanosleep { printf("%d sleeping\n", pid); }' -c 'ping -c 4 0' ERROR: Failed to fork child: path 'ping' must refer to a unique binary but matched 4 binaries This commit fixes this problem. See also v1[0], v2[1]. [0] bpftrace#2682 [1] bpftrace#2689 Signed-off-by: Rong Tao <[email protected]>
e79ff58
to
e24713e
Compare
The fix looks good to me. But I agree with Viktor -- test here would be good. But rather than depend on CI environment (which is not reliable like you mention), we could create a tempdir and then populate it with a an executable shell script and some symlinks to it. I think that should be reliable. |
I have a question, shall we add a test example in C, such as the following code in tests/child.cpp: TEST(childproc, match_multi_exe)
{
char path[] = "rootfs/";
// make temp rootfs directory
// make /usr/bin/ under rootfs
// create tmp shell script "sleep.sh" (with x permission)
// create link: /bin -> /usr/bin
// put the rootfs/usr/bin and rootfs/bin to env
// THEN, test sleep.sh
} right? I'm not sure if my idea is accurate, if not, please give me some advice. thanks. |
Yeah that looks right to me |
OK, I'll try it. |
@danobi @viktormalik I just add test
|
8615546
to
3145b82
Compare
3145b82
to
5d46e6f
Compare
$ sudo ./tests/bpftrace_test --gtest_filter=childproc.multi_exec_match Note: Google Test filter = childproc.multi_exec_match [==========] Running 1 test from 1 test suite. [----------] Global test environment set-up. [----------] 1 test from childproc [ RUN ] childproc.multi_exec_match [ OK ] childproc.multi_exec_match (10 ms) [----------] 1 test from childproc (10 ms total) [----------] Global test environment tear-down [==========] 1 test from 1 test suite ran. (10 ms total) [ PASSED ] 1 test. Signed-off-by: Rong Tao <[email protected]>
5d46e6f
to
dad5a49
Compare
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.
thanks for iterating on this!
On some systems /bin is a symbolic link to /usr/bin (/bin -> /usr/bin), When using the '-c' parameter to specify the executable program in the environment variable, the problem of "multiple binary files matching" occurs, for example:
Debugging the bpftrace program through gdb can also be verified:
This commit fixes the issue. The v1[0] will cause CICD busybox error.
[0] #2689