NetBSD-Bugs archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

Re: toolchain/52675: crunching binaries improperly removes PaX notes



The following reply was made to PR toolchain/52675; it has been noted by GNATS.

From: Valery Ushakov <uwe%stderr.spb.ru@localhost>
To: gnats-bugs%NetBSD.org@localhost
Cc: 
Subject: Re: toolchain/52675: crunching binaries improperly removes PaX notes
Date: Mon, 11 Feb 2019 03:24:24 +0300

 On Mon, Oct 30, 2017 at 12:15:00 +0000, martin%NetBSD.org@localhost wrote:
 
 > The space in between has been zeroed, but this breaks note parsing
 > semantics (i.e. in arm vs. earm binaries getting their machine_arch
 > wrong).
 
 I wonder if instead of fixing objcopy we can do what we want of it
 manually with something like the following:
 
 Manually create a stub ELF note with namesz 0 that has the same total
 size as the PaX note and then use --update-section to replace the PaX
 note with the stub.
 
 
 fake-note.bin:
 .if ${TARGET_ENDIANNESS} == "1234"
 	printf '\0\0\0\0''\010\0\0\0''\0\0\0\0''\0\0\0\0''\0\0\0\0' > $@
 .else
 	printf '\0\0\0\0''\0\0\0\010''\0\0\0\0''\0\0\0\0''\0\0\0\0' > $@
 .endif
 
 ${PROG}.strip:
 	...
 	objcopy ... --update-section .note.netbsd.pax=fake-note.bin ...
 
 
 I get the following from readelf for the output of objcopy for a
 simple test binary:
 
 Displaying notes found at file offset 0x0000012c with length 0x00000018:
   Owner                 Data size       Description
   NetBSD                0x00000004      IDENT 899001800 (8.99.18)
 
 Displaying notes found at file offset 0x00000144 with length 0x00000014:
   Owner                 Data size       Description
   (NONE)               0x00000008       Unknown note type: (0x00000000)
 
 Displaying notes found at file offset 0x00000158 with length 0x00000020:
   Owner                 Data size       Description
   NetBSD                0x00000009      MARCH <earmv7hf>
 
 
 Verbose DIAGNOSTIC code still complains about the stub (it complains
 about ~everything), but doesn't get out of sync now and reads the
 MARCH note fine it seems:
 
   ./x.out: Unknown elf note type 0 (unknown tag): [namesz=0, descsz=8 name=]
 
 
 The note with namesz=0 and namesz=1 and name="" are reserved by the
 standard.
 
 If that's a problem we may instead just use a different name/type, we
 only need to make sure the size is the same and that our elf loader
 ignores that name/type.  E.g.
 
    0: namesz = 7
    4: descsz = 0
    8:   type = 3    # not currently in use
    c:   name = NetB
   10:          SD\0\0
   14:
 
 The section (well, the section header) ".note.netbsd.pax" is still
 there, but it shouldn't affect anything.  We can also tweak the name
 with e.g. --rename-section .note.netbsd.pax=.note.netbsd.xxx
 
 -uwe
 


Home | Main Index | Thread Index | Old Index