LIEF
LIEF copied to clipboard
LIEF 0.10.1 : 04_ELF_hooking broken - cos function does not exist in output lib.so.6 file
Describe the bug Cross-referenced from tutorial issue 4 When running the 04_ELF_hooking example, make run, I get a SegFault.
make run
unset LD_LIBRARY_PATH
./do_math.bin 2
cos(2) = -0.416147
python3 insert_hook.py
Hook inserted at VA: 0x38d000
Change cos!34b70 -> cos!38d0d0
LD_LIBRARY_PATH=. ./do_math.bin 2
Segmentation fault (core dumped)
make: *** [Makefile:17: run] Error 139
Looking more closely at the generated so file, the hook function code does not exist in the output ./lib.so.6 file:
%> nm -gD ./libm.so.6 | egrep -w 'cos'
000000000038d0d0 i cos
%> gdb -batch -ex 'file ./libm.so.6' -ex 'disassemble cos'
warning: Loadable section ".note.gnu.build-id" outside of ELF segments
warning: Loadable section ".note.ABI-tag" outside of ELF segments
No function contains specified address.
- python3.6
- LIEF 0.10.1
- Ubuntu 18.10
- gcc 8.3.0
To Reproduce Steps to reproduce the behavior:
-
git clone https://github.com/lief-project/tutorials.git
-
cd tutorials/04_ELF_hooking
-
make all
-
make run
I had to make a few minor changes to get baseline to work:
- changed the Makefile to invoke python3
- change insert_hook.py to point to my system's libm.so.6
- changed insert_hook.py to print(f"Change...") line to use .format with parameters, rather than inline
Expected behavior I expected that the cos function would exist in the ./libm.so.6 file at the offset specified by the example.
Environment (please complete the following information):
- System and Version : Ubuntu 18.10
- Target format : ELF
- LIEF commit version: 0.10.1
Additional context n/a
Looks like related to Issue #339
Ack,
I think it's strongly related to the underlying version of libm.so
The crash here was likely due to that system's libm.so exposed cos
as GNU_IFUNC
symbol: https://github.com/lief-project/LIEF/pull/890.