[prev in list] [next in list] [prev in thread] [next in thread] 

List:       openembedded-core
Subject:    [OE-core][PATCH] patchelf: Fix e2fsprogs ELF corruption
From:       "Joshua Watt" <JPEWhacker () gmail ! com>
Date:       2023-07-31 20:26:38
Message-ID: 20230731202638.2291210-1-JPEWhacker () gmail ! com
[Download RAW message or body]

Content-Transfer-Encoding: 8bit

Patchelf has a nasty bug where calling --set-interpreter repeatedly
on the same program will eventually corrupt the program headers in a way
that causes a segmentation fault when the loader attempts to load the
program. In most cases, we don't reach this limit, but for recipes that
make multiple links to the same program with different names (e.g.
e2fsprogs-native), this limit can be reached, corrupting the program.

This doesn't fix the underlying issue as it is complicated, but instead
prevents the interpreter program from being re-written if it hasn't
changed (which is for the best anyway as each call would make the
program larger).

Signed-off-by: Joshua Watt <JPEWhacker@gmail.com>
---
 ...thing-if-interpreter-has-not-changed.patch | 38 +++++++++++++++++++
 .../patchelf/patchelf_0.18.0.bb               |  4 +-
 2 files changed, 41 insertions(+), 1 deletion(-)
 create mode 100644 meta/recipes-devtools/patchelf/patchelf/0001-Do-nothing-if-interpreter-has-not-changed.patch


diff --git a/meta/recipes-devtools/patchelf/patchelf/0001-Do-nothing-if-interpreter-has-not-changed.patch \
b/meta/recipes-devtools/patchelf/patchelf/0001-Do-nothing-if-interpreter-has-not-changed.patch
 new file mode 100644
index 00000000000..0183d212259
--- /dev/null
+++ b/meta/recipes-devtools/patchelf/patchelf/0001-Do-nothing-if-interpreter-has-not-changed.patch
 @@ -0,0 +1,38 @@
+From 09d182d9dfde5d68c4481edfa1bb77453b111380 Mon Sep 17 00:00:00 2001
+From: Joshua Watt <JPEWhacker@gmail.com>
+Date: Mon, 31 Jul 2023 13:15:27 -0600
+Subject: [PATCH] Do nothing if interpreter has not changed
+
+If there is not change to the interpreter, don't make any modifications
+to the file. This is more efficient than requiring programs to check
+before changing, and also prevents thrashing of the ELF file, since
+changing the interpreter repeatedly will keep growing the ELF file each
+time, even if it's the same value.
+
+This is particularly helpful where the same binary is symlinked or
+hardlinked with multiple names and has patchelf run on it.
+
+Signed-off-by: Joshua Watt <JPEWhacker@gmail.com>
+Upstream-Status: Submitted [https://github.com/NixOS/patchelf/pull/512]
+---
+ src/patchelf.cc | 4 ++++
+ 1 file changed, 4 insertions(+)
+
+diff --git a/src/patchelf.cc b/src/patchelf.cc
+index 82b4b46..bc40026 100644
+--- a/src/patchelf.cc
++++ b/src/patchelf.cc
+@@ -1454,6 +1454,10 @@ void ElfFile<ElfFileParamNames>::modifySoname(sonameMode op, \
const std::string & + template<ElfFileParams>
+ void ElfFile<ElfFileParamNames>::setInterpreter(const std::string & newInterpreter)
+ {
++    if (getInterpreter() == newInterpreter) {
++        return;
++    }
++
+     std::string & section = replaceSection(".interp", newInterpreter.size() + 1);
+     setSubstr(section, 0, newInterpreter + '\0');
+     changed = true;
+-- 
+2.33.0
+
diff --git a/meta/recipes-devtools/patchelf/patchelf_0.18.0.bb \
b/meta/recipes-devtools/patchelf/patchelf_0.18.0.bb index e8bc2ff83dd..3aec0030cf4 \
                100644
--- a/meta/recipes-devtools/patchelf/patchelf_0.18.0.bb
+++ b/meta/recipes-devtools/patchelf/patchelf_0.18.0.bb
@@ -4,7 +4,9 @@ HOMEPAGE = "https://github.com/NixOS/patchelf"
 
 LICENSE = "GPL-3.0-only"
 
-SRC_URI = "git://github.com/NixOS/patchelf;protocol=https;branch=master"
+SRC_URI = "git://github.com/NixOS/patchelf;protocol=https;branch=master \
+           file://0001-Do-nothing-if-interpreter-has-not-changed.patch \
+           "
 SRCREV = "99c24238981b7b1084313aca8f5c493bb46f302c"
 
 S = "${WORKDIR}/git"
-- 
2.33.0



-=-=-=-=-=-=-=-=-=-=-=-
Links: You receive all messages sent to this group.
View/Reply Online (#185169): https://lists.openembedded.org/g/openembedded-core/message/185169
Mute This Topic: https://lists.openembedded.org/mt/100470204/4454766
Group Owner: openembedded-core+owner@lists.openembedded.org
Unsubscribe: https://lists.openembedded.org/g/openembedded-core/unsub [openembedded-core@marc.info]
-=-=-=-=-=-=-=-=-=-=-=-



[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic