DhavalKapil / libdheap

A shared (dynamic) library that can be transparently injected into different processes to detect memory corruption in glibc heap
MIT License
167 stars 29 forks source link

undefined symbol error #2

Closed combab0 closed 7 years ago

combab0 commented 7 years ago

I have no idea what is the matter :(

root@real:~/source/libdheap# LD_PRELOAD=/root/source/libdheap/libdheap.so ./double_free 
./double_free: symbol lookup error: /root/source/libdheap/libdheap.so: undefined symbol: get_begin_canary
root@real:~/source/libdheap# LD_PRELOAD=/root/source/libdheap/libdheap.so /bin/ls
/bin/ls: symbol lookup error: /root/source/libdheap/libdheap.so: undefined symbol: get_begin_canary
ghost commented 7 years ago

get_begin_canary and get_end_canary in src/canary.c have to be static inline instead of inline. This will fix this issue for you.

DhavalKapil commented 7 years ago

Thank you @0x64616E69656C! Could you please clarify the reasoning behind it?

DhavalKapil commented 7 years ago

@hdarwin I just made the changes, can you test it again?

ghost commented 7 years ago

@DhavalKapil See https://gcc.gnu.org/onlinedocs/gcc/Inline.html last section for reference:

When an inline function is not static, then the compiler must assume that there may be calls from other source files; since a global symbol can be defined only once in any program, the function must not be defined in the other source files, so the calls therein cannot be integrated. Therefore, a non-static inline function is always compiled on its own in the usual fashion.

objdump -d libdheap.so |grep get_
0000000000001490 <get_padded_size@plt>:
    1490:       ff 25 82 2b 20 00       jmpq   *0x202b82(%rip)        # 204018 <get_padded_size@@Base+0x2025f5>
00000000000014d0 <get_begin_canary@plt>:
    14d0:       ff 25 62 2b 20 00       jmpq   *0x202b62(%rip)        # 204038 <get_begin_canary>
00000000000017c0 <get_end_canary@plt>:
    17c0:       ff 25 ea 29 20 00       jmpq   *0x2029ea(%rip)        # 2041b0 <get_end_canary>
0000000000001a23 <get_padded_size>:
    1af6:       e8 d5 f9 ff ff          callq  14d0 <get_begin_canary@plt>
    1b10:       e8 ab fc ff ff          callq  17c0 <get_end_canary@plt>
    1b42:       e8 89 f9 ff ff          callq  14d0 <get_begin_canary@plt>
    1b83:       e8 38 fc ff ff          callq  17c0 <get_end_canary@plt>
    279b:       e8 f0 ec ff ff          callq  1490 <get_padded_size@plt>
DhavalKapil commented 7 years ago

Thank you @0x64616E69656C again! I get it now.