Re: [PROPOSAL/PATCH] Remove PT_GNU_STACK support before 2.6.11

From: PaweÅ Sikora
Date: Sun Feb 06 2005 - 13:10:46 EST


On Sunday 06 of February 2005 13:47, you wrote:
> On Sun, Feb 06, 2005 at 01:03:11PM +0100, Pawel Sikora wrote:
> > On Sunday 06 of February 2005 12:36, you wrote:
> > > Worse is that even when the program has trampolines and has
> > > PT_GNU_STACK header with an E bit on the stack it still won't get an
> > > executable heap by default (this is what broke grub)
> > > (...)
> > > My proposal is to turn this all off at least for 2.6.11.
> >
> > My proposal is to recompile broken software with cflags +=
> > -Wa,--noexecstack
>
> By how do you detect broken software? There doesn't seem to be any
> fool proof way other than a extensive test on a NX capable system
> with correct kernel.

[1] glibc-2.3.4 kill buggy bins at the load time.
(please look into: elf/dl-load.c, elf/dl-support.c, elf/rtld.c)
This works on i386/PaX systems too (hardware NX isn't required).

[2] `readelf -Wl |grep GNU_STACK` shows RWE ;-)

Please look at this quick example.

# gcc tmp1.c tmp2-invalid.S -o tmp -s
# readelf -Wl tmp

(...)
GNU_STACK 0x000000 0x00000000 0x00000000 0x00000 0x00000 RWE 0x4
^ execstack?
PAX_FLAGS 0x000000 0x00000000 0x00000000 0x00000 0x00000 0x4
(...)

Now, let's add section note to the asm. file and rebuild.

# gcc tmp1.c tmp2-valid.S -o tmp -s
# readelf -Wl tmp

(...)
GNU_STACK 0x000000 0x00000000 0x00000000 0x00000 0x00000 RW 0x4
PAX_FLAGS 0x000000 0x00000000 0x00000000 0x00000 0x00000 0x4
(...)

The execstack req. disappeard (~99% of broken sources).
I get the same effect with fixed cflags and invalid source.

# gcc tmp1.c tmp2-invalid.S -o tmp -s -Wa,--noexecstack
# readelf -Wl tmp

(...)
GNU_STACK 0x000000 0x00000000 0x00000000 0x00000 0x00000 RW 0x4
PAX_FLAGS 0x000000 0x00000000 0x00000000 0x00000 0x00000 0x4
(...)

I known several apps that really need executable data/stack (eg. jvm, xorg).
The rest of RWE-marked binaries have IMHO buggy sources.

> It would be fine if there was a compile time error or something,
> but there isn't.

IMHO the `as` should warn about missed (.note.GNU-stack) section.

Regards,
PaweÅ.

--
/* Copyright (C) 2003, SCO, Inc. This is valuable Intellectual Property. */

#define say(x) lie(x)
extern void test();

int main(int argc, char** argv)
{
test();
return 0;
}
.text
.global test
test:
ret
.end
.section .note.GNU-stack,"",@progbits; .previous
.text
.global test
test:
ret
.end