Coder Social home page Coder Social logo

Comments (11)

adevress avatar adevress commented on June 1, 2024

This is not only a false positive.

It seems that patchelf corrupt binary under powerpc64 :

$ ./ls: /nix/store/eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee-glibc-2.21-powerpc64-unknown-linux-gnu/lib/ld64.so.1: bad ELF interpreter: Aucun fichier ou dossier de ce type

# patchelf to set the interpreter to a valid value
~/scratch/workspace/patchelf/src/patchelf --set-interpreter /gpfs/[.....]/nix/store/ng8p3bpwxlwp8dslv31dndkk4wrg79bp-bootstrap-tools/lib/ld-2.21.so ls

# retry execution
./ls
Processus arrêté

# valgrind trace 
 valgrind --tool=memcheck ./ls
==27375== Memcheck, a memory error detector
==27375== Copyright (C) 2002-2012, and GNU GPL'd, by Julian Seward et al.
==27375== Using Valgrind-3.8.1 and LibVEX; rerun with -h for copyright info
==27375== Command: ./ls
==27375== 
Inconsistency detected by ld.so: rtld.c: 1141: dl_main: Assertion `_rtld_local._dl_rtld_map.l_libname' failed!
==27375== 
==27375== HEAP SUMMARY:


from patchelf.

adevress avatar adevress commented on June 1, 2024

Anyone has seen something similar this before ?

from patchelf.

adevress avatar adevress commented on June 1, 2024

I add you a little over trace on this when using only native system tools

# copy ls in current directory
cp /bin/ls ./
# use it
./ls 
# -> works with normal listing
# use patch elf to print interpreter
 ~/scratch/workspace/patchelf/src/patchelf --print-interpreter --debug  ./ls
/lib64/ld64.so.1
# list again
./ls 
# works
# now modify the interpreter with exactly the same value than before
 ~/scratch/workspace/patchelf/src/patchelf --set-interpreter /lib64/ld64.so.1 --debug  ./ls
patching ELF file `ls'
replacing section `.interp' with size 17
this is an executable
using replaced section `.interp'
last replaced is 1
looking at section `.interp'
first reserved offset/addr is 0x214/0x10000214
first page is 0x10000000
needed space is 536
needed space is 592
needed pages is 1
changing alignment of program header 2 from 65536 to 4096
changing alignment of program header 3 from 65536 to 4096
clearing first 4060 bytes
rewriting section `.interp' from offset 0x1200 (size 17) to offset 0x238 (size 17)
rewriting symbol table section 5

# now let's try to use ls again
./ls
# crash : Process stopped
# let's try to use the buggy ls into valgrind
valgrind --tool=memcheck ./ls
==7562== Memcheck, a memory error detector
==7562== Copyright (C) 2002-2012, and GNU GPL'd, by Julian Seward et al.
==7562== Using Valgrind-3.8.1 and LibVEX; rerun with -h for copyright info
==7562== Command: ./ls
==7562== 
==7562== 
==7562== Process terminating with default action of signal 11 (SIGSEGV): dumping core
==7562==  Access not within mapped region at address 0x0
==7562==    at 0x8082267C9C: dl_main (in /lib64/ld-2.12.so)
==7562==    by 0x80822811F7: _dl_sysdep_start (in /lib64/ld-2.12.so)
==7562==    by 0x8082265E43: _dl_start_final (in /lib64/ld-2.12.so)
==7562==    by 0x808226612B: _dl_start (in /lib64/ld-2.12.so)
==7562==    by 0x80822654EF: _start (in /lib64/ld-2.12.so)
==7562==  If you believe this happened as a result of a stack
==7562==  overflow in your program's main thread (unlikely but
==7562==  possible), you can try to increase the size of the
==7562==  main thread stack using the --main-stacksize= flag.
==7562==  The main thread stack size used in this run was 10485760.
==7562== 

from patchelf.

adevress avatar adevress commented on June 1, 2024

From the previous trace, it --set-interpreter seems to be broken for powerpc64.

from patchelf.

vcunat avatar vcunat commented on June 1, 2024

I see the code does try to be correct with endian issues, but has it ever been tested on a big-endian HW? There could be a bug in the handling (or introduced since last testing).

from patchelf.

adevress avatar adevress commented on June 1, 2024

From the previous trace,

Here you have :
The readelf output before patching

http://pastebin.com/6V0gc6Wk

The readelf output after patching

http://pastebin.com/G65vnemV

and here is the diff between both.

http://pastebin.com/XaQTACx7

from patchelf.

adevress avatar adevress commented on June 1, 2024

@vcunat

Notes in the project says it has been tested on powerpc 32 bits which is big endian. But I do'nt think any tests has been executed on powerpc64.

from patchelf.

adevress avatar adevress commented on June 1, 2024

I just did the same test than before but using 32-bits ELF binaries. It works perfectly on PPC 32 bits.

The problem is triggered only in PPC 64 bits.

from patchelf.

adevress avatar adevress commented on June 1, 2024

I found the issue.

Powerpc64 kernels can have a page size up to 65K.
This is the case here.

The Patchelf should use sysconf(_SC_PAGE_SIZE) when available to detect the kernel page size.

I'm going to make a patch for this.

from patchelf.

adevress avatar adevress commented on June 1, 2024

Patch provided with #54

from patchelf.

adevress avatar adevress commented on June 1, 2024

Solved with #54

from patchelf.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.