Skip to contentSkip to conversation

is_loadable_phdr

DISCUSSION Brad Plant 2 participants 3 messages Jan 28, 2010

lore
Share & tools
lore

Brad Plant

author
#0 lore raw

Hi,

I'm attempting to boot the latest mainline kernel patched with PaX. The PaX patch marks some segments as read-only (R--) which is resulting in these segments not being loaded due to is_loadable_phdr returning zero for read-only segments:

int elf_phdr_is_loadable(struct elf_binary *elf, const elf_phdr * phdr)

{
	uint64_t p_type = elf_uval(elf, phdr, p_type);
	uint64_t p_flags = elf_uval(elf, phdr, p_flags);

	return ((p_type == PT_LOAD) && (p_flags & (PF_W | PF_X)) != 0);
}

I'm trying to get an understanding of why a segment has to be writeable or executable for xen to load it. Does anyone know why this is so?

Also, is it likely that this behaviour could be changed? My understanding is that it's perfectly valid to have an ELF kernel with read-only segments in it. Attempting to use an image with a read-only segment leads to the kernel failing to boot with weird and hard to debug crashes.

Cheers,

Brad

_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xensource.com/xen-devel

#1 lore raw
Quoted 7 lines · Brad Plant

I'm trying to get an understanding of why a segment has to be writeable or executable for xen to load it. Does anyone know why this is so?

Also, is it likely that this behaviour could be changed? My understanding is that it's perfectly valid to have an ELF kernel with read-only segments in it. Attempting to use an image with a read-only segment leads to the kernel failing to boot with weird and hard to debug crashes.

Yes, we can change that. Send a patch for it.

-- Keir

author
#2 lore raw
Quoted 11 lines · On Thu, 28 Jan 2010 21:14:14 +0000 Keir Fraser <[email protected]>…
Quoted 7 lines · Brad Plant

I'm trying to get an understanding of why a segment has to be writeable or executable for xen to load it. Does anyone know why this is so?

Also, is it likely that this behaviour could be changed? My understanding is that it's perfectly valid to have an ELF kernel with read-only segments in it. Attempting to use an image with a read-only segment leads to the kernel failing to boot with weird and hard to debug crashes.

Yes, we can change that. Send a patch for it.

So there's no reason not loading read-only segments then?

I've attached a patch that'll change elf_phdr_is_loadable's behaviour. It just adds PF_R into the mix. I don't know if this will cause some unwanted side effects. Unfortunately there'll be some very unhappy people if I go rebooting an entire physical machine at the moment.

Cheers,

Brad

common/libelf/libelf-tools.c renamed from common/libelf/libelf-tools.c.orig +1 -1
@@ -235,7 +235,7 @@ int elf_phdr_is_loadable(struct elf_bina
     uint64_t p_type = elf_uval(elf, phdr, p_type);
     uint64_t p_flags = elf_uval(elf, phdr, p_flags);
 
-    return ((p_type == PT_LOAD) && (p_flags & (PF_W | PF_X)) != 0);
+    return ((p_type == PT_LOAD) && (p_flags & (PF_R | PF_W | PF_X)) != 0);
 }
 
 /*

_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xensource.com/xen-devel