linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] um: Fix overlapping ELF segments when statically linked
@ 2020-03-05 18:39 David Gow
  2020-03-10 21:24 ` Brendan Higgins
  0 siblings, 1 reply; 3+ messages in thread
From: David Gow @ 2020-03-05 18:39 UTC (permalink / raw)
  To: Jeff Dike, Richard Weinberger, Anton Ivanov
  Cc: brendanhiggins, trishalfonso, linux-um, linux-kernel, 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.

Signed-off-by: David Gow <davidgow@google.com>
---
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(-)

diff --git a/arch/um/kernel/uml.lds.S b/arch/um/kernel/uml.lds.S
index 9f21443be2c9..3b6dab3d4501 100644
--- a/arch/um/kernel/uml.lds.S
+++ b/arch/um/kernel/uml.lds.S
@@ -19,10 +19,10 @@ SECTIONS
   __binary_start = START;
 
   . = START + SIZEOF_HEADERS;
+  . = ALIGN(PAGE_SIZE);
 
   _text = .;
   INIT_TEXT_SECTION(0)
-  . = ALIGN(PAGE_SIZE);
 
   .text      :
   {
-- 
2.25.0.265.gbab2e86ba0-goog


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH] um: Fix overlapping ELF segments when statically linked
  2020-03-05 18:39 [PATCH] um: Fix overlapping ELF segments when statically linked David Gow
@ 2020-03-10 21:24 ` Brendan Higgins
  2020-03-29 21:38   ` Richard Weinberger
  0 siblings, 1 reply; 3+ messages in thread
From: Brendan Higgins @ 2020-03-10 21:24 UTC (permalink / raw)
  To: David Gow
  Cc: Jeff Dike, Richard Weinberger, Anton Ivanov, Patricia Alfonso,
	linux-um, Linux Kernel Mailing List

On Thu, Mar 5, 2020 at 10:39 AM David Gow <davidgow@google.com> wrote:
>
> 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.
>
> Signed-off-by: David Gow <davidgow@google.com>

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.)

Reviewed-by: Brendan Higgins <brendanhiggins@google.com>

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] um: Fix overlapping ELF segments when statically linked
  2020-03-10 21:24 ` Brendan Higgins
@ 2020-03-29 21:38   ` Richard Weinberger
  0 siblings, 0 replies; 3+ messages in thread
From: Richard Weinberger @ 2020-03-29 21:38 UTC (permalink / raw)
  To: Brendan Higgins
  Cc: David Gow, Patricia Alfonso, Richard Weinberger, Jeff Dike,
	linux-um, Linux Kernel Mailing List, Anton Ivanov

On Tue, Mar 10, 2020 at 10:24 PM Brendan Higgins
<brendanhiggins@google.com> wrote:
>
> On Thu, Mar 5, 2020 at 10:39 AM David Gow <davidgow@google.com> wrote:
> >
> > 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.
> >
> > Signed-off-by: David Gow <davidgow@google.com>
>
> 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.)
>
> Reviewed-by: Brendan Higgins <brendanhiggins@google.com>

Applied, thanks!

-- 
Thanks,
//richard

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2020-03-29 21:39 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-03-05 18:39 [PATCH] um: Fix overlapping ELF segments when statically linked David Gow
2020-03-10 21:24 ` Brendan Higgins
2020-03-29 21:38   ` Richard Weinberger

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).