]> git.ipfire.org Git - thirdparty/valgrind.git/commitdiff
Bug 290061 - pie elf always loaded at 0x108000
authorPaul Floyd <pjfloyd@wanadoo.fr>
Sun, 19 May 2024 09:55:30 +0000 (11:55 +0200)
committerPaul Floyd <pjfloyd@wanadoo.fr>
Thu, 10 Apr 2025 18:55:09 +0000 (20:55 +0200)
Initial patch from Amir Szekely <kichik@gmail.com

.gitignore
NEWS
coregrind/m_ume/elf.c
none/tests/Makefile.am
none/tests/bug290061.c [new file with mode: 0644]
none/tests/bug290061.stderr.exp [new file with mode: 0644]
none/tests/bug290061.vgtest [new file with mode: 0644]

index f58e91dd839237f7c15f18fed5961e9d91701ab5..43b5d9b6bad16d6f1d635084ab10d0e140392bf6 100644 (file)
 /none/tests/blockfault
 /none/tests/bug129866
 /none/tests/bug234814
+/none/tests/bug290061
 /none/tests/bug491394
 /none/tests/bug492678
 /none/tests/closeall
diff --git a/NEWS b/NEWS
index ee501aef698785ad547bd8b0d6b5f6aac4958f9c..98270e95e62fd6c9ee71e8c1afcdf72ee67bb846 100644 (file)
--- a/NEWS
+++ b/NEWS
@@ -32,6 +32,7 @@ bugzilla (https://bugs.kde.org/enter_bug.cgi?product=valgrind) rather
 than mailing the developers (or mailing lists) directly -- bugs that
 are not entered into bugzilla tend to get forgotten about or ignored.
 
+290061  pie elf always loaded at 0x108000
 396415  Valgrind is not looking up $ORIGIN rpath of shebang programs
 420682  io_pgetevents is not supported
 469782  Valgrind does not support zstd-compressed debug sections
index bad7e5ee6b4cb9ceea9e02a5feb5d99b0b192935..67d3139d29b191d57177928c3d5e3e2d00e00052 100644 (file)
@@ -513,8 +513,8 @@ Bool VG_(match_ELF)(const void *hdr, SizeT len)
      required.  mapelf() returns the address just beyond the end of
      the furthest-along mapping it creates.  The executable is mapped
      starting at EBASE, which is usually read from it (eg, 0x8048000
-     etc) except if it's a PIE, in which case I'm not sure what
-     happens.
+     etc) except if it's a PIE, in which case aspacem is queried for
+     the first adequately sized segement.
 
      The returned address is recorded in info->brkbase as the start
      point of the brk (data) segment, as it is traditional to place
@@ -566,10 +566,8 @@ Int VG_(load_ELF)(Int fd, const HChar* name, /*MOD*/ExeInfo* info)
       return VKI_ENOEXEC;
 
    /* The kernel maps position-independent executables at TASK_SIZE*2/3;
-      duplicate this behavior as close as we can. */
+      for us it's good enough to just load it somewhere with enough free space. */
    if (e->e.e_type == ET_DYN && ebase == 0) {
-      ebase = VG_PGROUNDDN(info->exe_base 
-                           + (info->exe_end - info->exe_base) * 2 / 3);
       /* We really don't want to load PIEs at zero or too close.  It
          works, but it's unrobust (NULL pointer reads and writes
          become legit, which is really bad) and causes problems for
@@ -582,13 +580,19 @@ Int VG_(load_ELF)(Int fd, const HChar* name, /*MOD*/ExeInfo* info)
       /* Later .. on mips64 we can't use 0x108000, because mapelf will
          fail. */
 #     if defined(VGP_mips64_linux)
+      ebase = VG_PGROUNDDN(info->exe_base
+                           + (info->exe_end - info->exe_base) * 2 / 3);
       if (ebase < 0x100000)
          ebase = 0x100000;
 #     else
-      vg_assert(VKI_PAGE_SIZE >= 4096); /* stay sane */
-      ESZ(Addr) hacky_load_address = 0x100000 + 8 * VKI_PAGE_SIZE;
-      if (ebase < hacky_load_address)
-         ebase = hacky_load_address;
+      Bool ok = False;
+      ebase = VG_(am_get_advisory_client_simple)( 0, e->p->p_filesz, &ok );
+
+      if (!ok) {
+         VG_(printf)( "Cannot find segment large enough to contain %llx bytes\n", (ULong)e->p->p_filesz );
+         return VKI_ENOMEM;
+      }
+
 #     endif
 
 #     if defined(VGO_solaris)
index d119c74a1da295f48b0b0ae68f5a87384f42f58c..8bd4b9bf281f8ba5c1d2a2361380524cef18675c 100644 (file)
@@ -106,6 +106,7 @@ EXTRA_DIST = \
        bitfield1.stderr.exp bitfield1.vgtest \
        bug129866.vgtest bug129866.stderr.exp bug129866.stdout.exp \
        bug234814.vgtest bug234814.stderr.exp bug234814.stdout.exp \
+       bug290061.vgtest bug290061.stderr.exp \
        bug491394.vgtest bug491394.stderr.exp \
        bug492678.vgtest bug492678.stderr.exp \
        closeall.stderr.exp closeall.vgtest \
@@ -273,7 +274,9 @@ check_PROGRAMS = \
        args \
        async-sigs \
        bitfield1 \
-       bug129866 bug234814 bug492678\
+       bug129866 bug234814 \
+       bug290061 \
+       bug492678 \
        closeall coolo_strlen \
        discard exec-sigmask execve faultstatus fcntl_setown \
        fdleak_cmsg fdleak_creat fdleak_dup fdleak_dup2 \
@@ -371,6 +374,7 @@ AM_CXXFLAGS += $(AM_FLAG_M3264_PRI)
 
 # Extra stuff for C tests
 ansi_CFLAGS            = $(AM_CFLAGS) -ansi
+bug290061_CFLAGS       = ${AM_CFLAGS} -pie
 bug491394_LDADD                = -lc
 bug491394_LDFLAGS      = -nostdlib -static
 bug491394_CFLAGS       = ${AM_CFLAGS} -Os
diff --git a/none/tests/bug290061.c b/none/tests/bug290061.c
new file mode 100644 (file)
index 0000000..40d847e
--- /dev/null
@@ -0,0 +1,5 @@
+static char meh[3000000]; // ~3mb
+int main(void)
+{
+}
+
diff --git a/none/tests/bug290061.stderr.exp b/none/tests/bug290061.stderr.exp
new file mode 100644 (file)
index 0000000..e69de29
diff --git a/none/tests/bug290061.vgtest b/none/tests/bug290061.vgtest
new file mode 100644 (file)
index 0000000..ab6217a
--- /dev/null
@@ -0,0 +1,3 @@
+prereq: ! ../../tests/arch_test mips64
+prog: bug290061
+vgopts: -q