This is the mail archive of the binutils@sourceware.org mailing list for the binutils project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[PATCH] elf: Try not pointing empty PT_LOAD segment's offset past EOF


Hi,

Strip sometimes leaves file offset of empty PT_LOAD segment pointing
past end of file as observed on Ubuntu 19.10's gzip binary. This is
traditionally considered a non-issue as loaders tolerated that, but
WSL1's ELF loader does not run the gzip binary [1] due to this offset.

I have opened a bug [2] in bugzilla, but I was advised to send the
patch here, too.

Please consider accepting the patch. I believe this does not cause any
regression and it fixes ELF loading on WSL.

Thanks,
Balint

[1] https://github.com/microsoft/WSL/issues/4461
[2] https://sourceware.org/bugzilla/show_bug.cgi?id=25237
From 547345d59b5a1e682c0cb7dc7f3f29ec8c113122 Mon Sep 17 00:00:00 2001
From: Balint Reczey <balint.reczey@canonical.com>
Date: Fri, 29 Nov 2019 23:58:00 +0100
Subject: [PATCH] elf: Try not pointing empty PT_LOAD segment's offset past EOF

While this did not cause problems in the past, it crashes WSL's ELF loader.

https://launchpad.net/bugs/1843479
---
 bfd/elf.c | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)

diff --git a/bfd/elf.c b/bfd/elf.c
index 1aa2603ee8..e1a9a02eec 100644
--- a/bfd/elf.c
+++ b/bfd/elf.c
@@ -5752,7 +5752,12 @@ assign_file_positions_for_load_sections (bfd *abfd,
 	  || (p->p_type == PT_NOTE && bfd_get_format (abfd) == bfd_core))
 	{
 	  if (!m->includes_filehdr && !m->includes_phdrs)
-	    p->p_offset = off;
+	    if (no_contents)
+	      /* Try avoiding pointing past the EOF with this empty segment's
+		 p_offset. */
+	      p->p_offset = p->p_offset % maxpagesize;
+	    else
+	      p->p_offset = off;
 	  else
 	    {
 	      file_ptr adjust;
-- 
2.17.1


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]