Skip to contentSkip to conversation

um: Fix overlapping ELF segments when statically linked

PATCH Applied David Gow 3 participants 3 messages Mar 5, 2020 – Mar 29, 2020 User-mode Linux (UML)

lore
Share & tools
lore

David Gow

author
#0 lore raw

PATCH 1/1 um: Fix overlapping ELF segments when statically linked

When statically linked, the .text section in UML kernels is not page aligned, causing it to share a page with the executable headers. As .text and the executable headers have different permissions, this causes the kernel to wish to map the same page twice (once as headers with r-- permissions, once as .text with r-x permissions), causing a segfault, and a nasty message printed to the host kernel's dmesg:

"Uhuuh, elf segment at 0000000060000000 requested but the memory is mapped already"

By aligning the .text to a page boundary (as in the dynamically linked version in dyn.lds.S), there is no such overlap, and the kernel runs correctly.

---
I'm not 100% sure what triggered this -- possibly a change to the host kernel on my machine -- as I'm able to reproduce the issue as far back as in 4.4, but it seems to be reproducible easily on my machine with defconfig + CONFIG_STATIC_LINK=y.

 arch/um/kernel/uml.lds.S | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
arch/um/kernel/uml.lds.S +1 -1
index 9f21443be2c9..3b6dab3d4501 100644
@@ -19,10 +19,10 @@ SECTIONS
   __binary_start = START;
 
   . = START + SIZEOF_HEADERS;
+  . = ALIGN(PAGE_SIZE);
 
   _text = .;
   INIT_TEXT_SECTION(0)
-  . = ALIGN(PAGE_SIZE);
 
   .text      :
   {
Signature · 1 line
2.25.0.265.gbab2e86ba0-goog
Reviewed-by on v1 1/1
#1 lore raw
Quoted 8 lines · David Gow

When statically linked, the .text section in UML kernels is not page aligned, causing it to share a page with the executable headers. As .text and the executable headers have different permissions, this causes the kernel to wish to map the same page twice (once as headers with r-- permissions, once as .text with r-x permissions), causing a segfault, and a nasty message printed to the host kernel's dmesg:

Quoted 8 lines

"Uhuuh, elf segment at 0000000060000000 requested but the memory is mapped already"

By aligning the .text to a page boundary (as in the dynamically linked version in dyn.lds.S), there is no such overlap, and the kernel runs correctly.

I can confirm that I am seeing this problem as well. (I know we run the same Linux distro; nevertheless, this is a real problem for some population of users.)

#2 lore raw
Quoted 17 lines · Brendan Higgins
Quoted 15 lines · David Gow

When statically linked, the .text section in UML kernels is not page aligned, causing it to share a page with the executable headers. As .text and the executable headers have different permissions, this causes the kernel to wish to map the same page twice (once as headers with r-- permissions, once as .text with r-x permissions), causing a segfault, and a nasty message printed to the host kernel's dmesg:

"Uhuuh, elf segment at 0000000060000000 requested but the memory is mapped already"

By aligning the .text to a page boundary (as in the dynamically linked version in dyn.lds.S), there is no such overlap, and the kernel runs correctly.

Quoted 7 lines
Quoted 1 line

I can confirm that I am seeing this problem as well. (I know we run the same Linux distro; nevertheless, this is a real problem for some population of users.)

Applied, thanks!

Signature · 7 lines
Thanks,
//richard

_______________________________________________
linux-um mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-um