-
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
elf: Detect if Elf is PIE #5126
base: master
Are you sure you want to change the base?
Conversation
It is not sufficient to determine whether Elf is ET_DYN or not to be a dynamic library in bcc_elf_is_shared_obj() function, because the executable Elf of the PIE type is also ET_DYN. For example, on fedora 40, /usr/bin/bash is PIE: $ readelf -h /usr/bin/bash ELF Header: ... Type: DYN (Position-Independent Executable file) ... bcc_elf_is_shared_obj() should not return 'true' for /usr/bin/bash. This commit add a function bcc_elf_is_pie(), maybe we can provide API in bcc_elf.h. Signed-off-by: Rong Tao <[email protected]>
There is a test failure:
could you take a look? Searching internet, I found the following link: |
In src/cc/usdt/usdt_args.cc::get_global_address() call bcc_elf_is_shared_obj(). bcc uses Ubuntu 20.04 as the CI/CD environment on github. The test ELF program will be compiled as PIE. After that, bcc_elf_is_shared_obj() will skip PIE, causing the py_test_usdt3 test to fail. Similarly, it will be compiled as PIE on Debian-like OS, such as Ubuntu, and compiled as EXEC on Fedora-like OS such as RHEL. Signed-off-by: Rong Tao <[email protected]>
Thanks for your reply, Song. I think i just found the ISSUE: In src/cc/usdt/usdt_args.cc::get_global_address() call bcc_elf_is_shared_obj(). bcc uses Ubuntu 20.04 as the CI/CD environment on github. The test ELF program will be compiled as PIE. After that, bcc_elf_is_shared_obj() will skip PIE, causing the py_test_usdt3 test to fail. Similarly, it will be compiled as PIE on Debian-like systems and as EXEC on Fedora-like systems. On Fedora 40 Start 30: py_test_usdt3
30/37 Test #30: py_test_usdt3 .................... Passed 2.30 sec On Debian12 Start 2: py_test_usdt3
30/37 Test #2: py_test_usdt3 ....................***Failed 67.42 sec |
It is not sufficient to determine whether Elf is ET_DYN or not to be a dynamic library in bcc_elf_is_shared_obj() function, because the executable Elf of the PIE type is also ET_DYN.
For example, on fedora 40, /usr/bin/bash is PIE:
bcc_elf_is_shared_obj() should not return 'true' for /usr/bin/bash.
This commit add a function bcc_elf_is_pie(), maybe we can provide API in bcc_elf.h.