Skip to content
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

Corrupted ELF generated without any modification #970

Closed
weimingzha0 opened this issue Sep 20, 2023 · 5 comments
Closed

Corrupted ELF generated without any modification #970

weimingzha0 opened this issue Sep 20, 2023 · 5 comments
Assignees

Comments

@weimingzha0
Copy link

weimingzha0 commented Sep 20, 2023

Describe the bug
I tried to rename a symbol in libcudart.so, but the resulting shared lib is corrupted.
Even without changing anything, the new lib is corrupted.

readelf -sw new_lib.so shows something like:

   164: 00000000000548e0   517 FUNC    GLOBAL DEFAULT   13 cudaMalloc3D@@<corrupt>
   194: 000000000005bd70   478 FUNC    GLOBAL DEFAULT   13 cudaMallocFromPoolAsync_ptsz@@<corrupt>

To Reproduce
Steps to reproduce the behavior:

import lief

lib_name='/usr/local/cuda-12.2/targets/x86_64-linux/lib/libcudart.so.12'
lib=lief.parse(lib_name)
sym = lib.get_dynamic_symbol('cudaMalloc')
# sym.name='xxxxMalloc' 
lib.write('/tmp/patched.so')

Then run readelf:
readelf -św /tmp/patched.so

Environment (please complete the following information):

  • System and Version :Ubuntu 18]
  • Target format (ELF)
  • LIEF commit version: 0.13.2-2d9855fc (I also tried C++ version by building from latest source)
@romainthomas
Copy link
Member

@weimingzha0 this issue is incomplete and does not contain enough information to reproduce the error:

but the resulting shared lib is corrupted.

Corrupted: crash? missing symbol?

Steps to reproduce the behavior:
lib_name='/usr/local/cuda-12.2/targets/x86_64-linux/lib/libcudart.so.12'

You didn't attach the library isn't?

Please re-open an issue with all the details and the information needed to reproduce the error.

Thank you

@romainthomas romainthomas added the Incomplete The issue is incomplete to be addressed label Sep 23, 2023
@weimingzha0
Copy link
Author

Sorry for no providing enough info to reproduce.

If I run readelf on the original, unmodified .so :

readelf -sW /usr/lib/libcudart.so.12 |grep cudaMalloc@
   219: 0000000000052230   421 FUNC    GLOBAL DEFAULT   13 cudaMalloc@@libcudart.so.12

If I run the same command on generated .so file (just parse and write):

readelf -sW /tmp/patched.so |grep cudaMalloc@
   219: 0000000000053230   421 FUNC    GLOBAL DEFAULT   13 cudaMalloc@@<corrupt>

You can see the "" after "@@"

If I use "nm"

 nm -D /tmp/patched.so
nm: /tmp/patched.so: .gnu.version_d invalid entry
nm: /tmp/patched.so: no symbols

@weimingzha0
Copy link
Author

I'm attaching the files
libs.zip

@weimingzha0 weimingzha0 changed the title Corrupted ELF generated with symbol renaming Corrupted ELF generated without any modification Sep 28, 2023
@weimingzha0
Copy link
Author

@romainthomas I don't have permission to reopen it. Please let me know if anything else is needed to reproduce it

@romainthomas
Copy link
Member

Thank you @weimingzha0 for the new details. I confirm the bug and I'm going to address it quickly.

@romainthomas romainthomas reopened this Sep 29, 2023
@romainthomas romainthomas added bug ELF Builder and removed Incomplete The issue is incomplete to be addressed labels Sep 29, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants