Skip to contentSkip to conversation

32 bit userland on G5

DISCUSSION Johannes Berg 3 participants 11 messages Jun 13, 2006 – Jun 14, 2006

lore
Share & tools
lore
#0 lore raw

Hi,

Since apparently the G5 honours no-execute permissions, shouldn't the 64 bit kernel set the READ_IMPLIES_EXEC personality flag for 32-bit userland?

The memory being execute-protected is causing a mono bug
(http://bugzilla.ximian.com/show_bug.cgi?id=77028) but I'm not sure where the correct fix would be, currently the kernel doesn't seem to be behaving exactly the same on G4 and G5.

johannes

#1 lore raw
Quoted 3 lines · Johannes Berg

Since apparently the G5 honours no-execute permissions, shouldn't the 64 bit kernel set the READ_IMPLIES_EXEC personality flag for 32-bit userland?

Why? Just because older hardware wasn't capable of enforcing the permissions, that doesn't mean that we shouldn't enforce them now.

Signature · 1 line
dwmw2
#2 lore raw
Quoted 2 lines · David Woodhouse

Why? Just because older hardware wasn't capable of enforcing the permissions, that doesn't mean that we shouldn't enforce them now.

Yeah, I was just thinking that there are programs relying on that and if they run in the 32-bit compat mode they might rightfully do so... Dunno.

johannes

#3 lore raw
Quoted 2 lines · Johannes Berg

Yeah, I was just thinking that there are programs relying on that and if they run in the 32-bit compat mode they might rightfully do so... Dunno.

Nah. It isn't a valid assumption; just as it isn't valid to assume that your stack will _always_ be at about 0xbfffffff.

Signature · 1 line
dwmw2
#4 lore raw
Quoted 2 lines · David Woodhouse

Nah. It isn't a valid assumption; just as it isn't valid to assume that your stack will _always_ be at about 0xbfffffff.

Ok.

Just curious though: Why does READ_IMPLIES_EXEC exist at all then?

johannes

#9 lore raw
In reply to Johannes Berg
Quoted 3 lines · Johannes Berg

Since apparently the G5 honours no-execute permissions, shouldn't the 64 bit kernel set the READ_IMPLIES_EXEC personality flag for 32-bit userland?

The elf_read_implies_exec() macro in include/asm-powerpc/elf.h achieves the same effect, I believe.

Paul.

#5 lore raw
In reply to David Woodhouse
Quoted 2 lines · David Woodhouse

Why? Just because older hardware wasn't capable of enforcing the permissions, that doesn't mean that we shouldn't enforce them now.

Historically the PPC32 ELF ABI has used an executable PLT, containing instructions constructed at runtime, located next to the BSS, and without the corresponding program header entry indicating execute permission. Alan Modra devised a new way of doing the PLT which doesn't require it to be executable, but of course it is only used in programs that have been built since the new method went into the toolchain (in fact all of the .o files being linked have to have been compiled with the new method in order for it to be used).

So if you are absolutely sure that every program you will ever want to run on your kernel has been built with an up-to-date toolchain, you can turn on enforcement of execute permissions for 32-bit processes. It would be a "courageous" step (in the Yes Minister sense :) for a distro to do it, IMHO.

Paul.

#6 lore raw
Quoted 8 lines · Paul Mackerras

Historically the PPC32 ELF ABI has used an executable PLT, containing instructions constructed at runtime, located next to the BSS, and without the corresponding program header entry indicating execute permission. Alan Modra devised a new way of doing the PLT which doesn't require it to be executable, but of course it is only used in programs that have been built since the new method went into the toolchain (in fact all of the .o files being linked have to have been compiled with the new method in order for it to be used).

'Historical' being until about 4 years ago, around the time of
http://ecos.sourceware.org/ml/binutils/2002-05/msg00097.html ?

Quoted 5 lines

So if you are absolutely sure that every program you will ever want to run on your kernel has been built with an up-to-date toolchain, you can turn on enforcement of execute permissions for 32-bit processes. It would be a "courageous" step (in the Yes Minister sense :) for a distro to do it, IMHO.

We already did it in Fedora. We don't default to READ_IMPLIES_EXEC for 32-bit processes on the 64-bit kernel.

Signature · 1 line
dwmw2
#7 lore raw
Quoted 2 lines · David Woodhouse

'Historical' being until about 4 years ago, around the time of
http://ecos.sourceware.org/ml/binutils/2002-05/msg00097.html ?

That's not the one I was talking about; that appears to be about marking the GOT and PLT as executable in the ELF file. That may be enough in fact to allow us to turn off read-implies-exec, though.

Quoted 2 lines

We already did it in Fedora. We don't default to READ_IMPLIES_EXEC for 32-bit processes on the 64-bit kernel.

By patching include/asm-powerpc/elf.h?

Paul.

#8 lore raw
Quoted 4 lines · Paul Mackerras
Quoted 2 lines

We already did it in Fedora. We don't default to READ_IMPLIES_EXEC for 32-bit processes on the 64-bit kernel.

By patching include/asm-powerpc/elf.h?

By patching fs/binfmt_elf.c -- it's part of the exec-shield patch.
http://cvs.fedora.redhat.com/viewcvs/devel/kernel/linux-2.6-execshield.patch?rev=1.20&view=auto

shinybook /home/dwmw2 $ cat foo.c
int foo[2] = { 0x3860005a, 0x4e800020 };
int main(void)

{
        int (*foofn)(void) = (void *)foo;
        int f = foofn();
        printf("%x\n", f);
}

shinybook /home/dwmw2 $ ./foo
5a
shinybook /home/dwmw2 $ scp foo pmac: ; ssh pmac
foo 100% 9996 9.8KB/s
00:00
Last login: Wed Jun 14 00:58:26 2006 from shinybook-bcm.infradead.org pmac /home/dwmw2 $ ./foo
Segmentation fault
pmac /home/dwmw2 $ setarch ppc -X ./foo
5a

Signature · 1 line
dwmw2
#10 lore raw
In reply to Paul Mackerras
Quoted 2 lines · Paul Mackerras

The elf_read_implies_exec() macro in include/asm-powerpc/elf.h achieves the same effect, I believe.

Even for mprotect()? It doesn't look like it does.

johannes