LIEF icon indicating copy to clipboard operation
LIEF copied to clipboard

LIEF 0.10.1 : 04_ELF_hooking broken - cos function does not exist in output lib.so.6 file

Open pdreiter opened this issue 5 years ago • 2 comments

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

pdreiter avatar Feb 04 '20 21:02 pdreiter

Looks like related to Issue #339

pdreiter avatar Feb 13 '20 20:02 pdreiter

Ack, I think it's strongly related to the underlying version of libm.so

romainthomas avatar Feb 18 '20 07:02 romainthomas

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.

navytux avatar Apr 06 '23 14:04 navytux