patchelf icon indicating copy to clipboard operation
patchelf copied to clipboard

Compute program header flags in rewriteSectionsLibrary

Open cgzones opened this issue 2 years ago • 2 comments

Instead of using fixed flags of RW for the new program header, holding the replaced sections, check if the write or execute flags is required by any accompanying section.

If many sections are going to be replaced a more strict method would be to split them up and add up-to 4 new program headers if necessary: read-only, read-write, read-execute, read-write-execute.

p.s.: also the harded flags for executables seems suspicious: https://github.com/NixOS/patchelf/blob/e37f892b12ff900ab5e733f688548c87cd14ef02/src/patchelf.cc#L562 Maybe that should be wri(phdr.p_flags, rdi(phdrs.at(splitIndex).p_flags));?

p.p.s: Should these lines convert the read data https://github.com/NixOS/patchelf/blob/e37f892b12ff900ab5e733f688548c87cd14ef02/src/patchelf.cc#L558-L560 e.g.


 wri(phdr.p_offset, rdi(phdrs.at(splitIndex).p_offset) - splitShift - shift); 
 wri(phdr.p_paddr, rdi(phdrs.at(splitIndex).p_paddr) - splitShift - shift); 
 wri(phdr.p_vaddr, rdi(phdrs.at(splitIndex).p_vaddr) - splitShift - shift);

?

cgzones avatar Feb 22 '23 19:02 cgzones

cc @brenoguim

Mic92 avatar Feb 24 '23 13:02 Mic92

also the harded flags for executables seems suspicious:

Since these flags are not being tracked, RW is the "works for all". I don't think we ever move executable sessions (because they are usually progbits) so we never needed.

Should these lines convert the read data

I think so. I would expect things to break drastically if endianess is not respected. Do you know if we have tests for that?

brenoguim avatar Feb 24 '23 21:02 brenoguim