diff options
| author | Richard Purdie <richard.purdie@linuxfoundation.org> | 2023-01-10 14:10:28 +0000 |
|---|---|---|
| committer | Richard Purdie <richard.purdie@linuxfoundation.org> | 2023-01-10 14:18:36 +0000 |
| commit | 44e148d6160f1205bdafd902f8ab9771d7181b43 (patch) | |
| tree | d1fd4ae047dcff2bd6908f5c2925a71c63d06a95 /meta | |
| parent | 654380885a167fb11d3918dd737ff02ce8716a71 (diff) | |
| download | poky-44e148d6160f1205bdafd902f8ab9771d7181b43.tar.gz | |
patchelf: Add fix submitted upstream for uninative segfaults
The new uninative tarball is segfaulting in quilt (the underlying
patch binary). We see errors in dmesg like:
(patch): Uhuuh, elf segment at 0000000000400000 requested but the memory is mapped already
This patch submitted to patchelf upstream looks like an appropriate fix
for that.
(From OE-Core rev: cccd4bcaf381c2729adc000381bd89906003e72a)
Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
Diffstat (limited to 'meta')
| -rw-r--r-- | meta/recipes-devtools/patchelf/patchelf/8d2cb4f9ab8d564904c292099a022ffb3cccd52d.patch | 104 | ||||
| -rw-r--r-- | meta/recipes-devtools/patchelf/patchelf_0.17.0.bb | 1 |
2 files changed, 105 insertions, 0 deletions
diff --git a/meta/recipes-devtools/patchelf/patchelf/8d2cb4f9ab8d564904c292099a022ffb3cccd52d.patch b/meta/recipes-devtools/patchelf/patchelf/8d2cb4f9ab8d564904c292099a022ffb3cccd52d.patch new file mode 100644 index 0000000000..6296f0e44b --- /dev/null +++ b/meta/recipes-devtools/patchelf/patchelf/8d2cb4f9ab8d564904c292099a022ffb3cccd52d.patch | |||
| @@ -0,0 +1,104 @@ | |||
| 1 | From 8d2cb4f9ab8d564904c292099a022ffb3cccd52d Mon Sep 17 00:00:00 2001 | ||
| 2 | From: Jason <otherjason@nodomain.com> | ||
| 3 | Date: Fri, 2 Dec 2022 10:01:41 -0500 | ||
| 4 | Subject: [PATCH] Fix bug in file shifting that could cause conflicting PT_LOAD | ||
| 5 | segments | ||
| 6 | |||
| 7 | When a section in the file needs to be enlarged (e.g. to accommodate | ||
| 8 | setting a larger RPATH), shiftFile() is used to shift all content | ||
| 9 | following the growing section to a later position in the file. | ||
| 10 | |||
| 11 | Commit 109b771f53ee3d37ede8c0f165665605183c0975 introduced logic to | ||
| 12 | ensure that, after the segment split, no sections span multiple | ||
| 13 | segments. This is done by sliding the portion of the segment after the | ||
| 14 | split point later in the file, then adding a new PT_LOAD segment that | ||
| 15 | contains the preceding data plus the extra room that is being added. The | ||
| 16 | existing implementation does this by simply adding | ||
| 17 | `extraPages*getPageSize()` bytes to the number of bytes ahead of the | ||
| 18 | split point in the segment. | ||
| 19 | |||
| 20 | However, this approach can result in two PT_LOAD segments that overlap | ||
| 21 | when page boundaries are taken into account. As an example, this PT_LOAD | ||
| 22 | section (taken from a Python 3.10 binary): | ||
| 23 | |||
| 24 | LOAD 0x0000000000000000 0x0000000000400000 0x0000000000400000 | ||
| 25 | 0x0000000000000948 0x0000000000000948 R E 0x200000 | ||
| 26 | |||
| 27 | is split into the following two sections: | ||
| 28 | |||
| 29 | LOAD 0x0000000000000000 0x00000000003ff000 0x00000000003ff000 | ||
| 30 | 0x0000000000001594 0x0000000000001594 R E 0x1000 | ||
| 31 | LOAD 0x0000000000001594 0x0000000000400594 0x0000000000400594 | ||
| 32 | 0x00000000000003b4 0x00000000000003b4 R E 0x1000 | ||
| 33 | |||
| 34 | Note that the two PT_LOAD sections both contain the memory page at | ||
| 35 | address 0x400000. The Linux kernel's ELF loader (at least as of v4.18) | ||
| 36 | does not accept this as a valid ELF executable, triggering a segfault | ||
| 37 | with si_code=SI_KERNEL immediately when the binary is executed. | ||
| 38 | |||
| 39 | The fix here is to set the length of the segment that comes before the | ||
| 40 | split point more carefully; instead of adding `extraPages*getPageSize()` | ||
| 41 | bytes to the portion of the segment that came before the split, the | ||
| 42 | actual number of padding bytes that were needed (before rounding up to | ||
| 43 | the next multiple of the page size) are used. This avoids the overlap | ||
| 44 | in the PT_LOAD segments and makes the output files executable again. | ||
| 45 | --- | ||
| 46 | src/patchelf.cc | 10 ++++++---- | ||
| 47 | src/patchelf.h | 2 +- | ||
| 48 | 2 files changed, 7 insertions(+), 5 deletions(-) | ||
| 49 | |||
| 50 | Upstream-Status: Submitted [https://github.com/NixOS/patchelf/pull/447] | ||
| 51 | Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org> | ||
| 52 | |||
| 53 | Index: git/src/patchelf.cc | ||
| 54 | =================================================================== | ||
| 55 | --- git.orig/src/patchelf.cc | ||
| 56 | +++ git/src/patchelf.cc | ||
| 57 | @@ -432,7 +432,7 @@ static uint64_t roundUp(uint64_t n, uint | ||
| 58 | |||
| 59 | |||
| 60 | template<ElfFileParams> | ||
| 61 | -void ElfFile<ElfFileParamNames>::shiftFile(unsigned int extraPages, size_t startOffset) | ||
| 62 | +void ElfFile<ElfFileParamNames>::shiftFile(unsigned int extraPages, size_t startOffset, size_t extraBytes) | ||
| 63 | { | ||
| 64 | assert(startOffset >= sizeof(Elf_Ehdr)); | ||
| 65 | |||
| 66 | @@ -508,7 +508,7 @@ void ElfFile<ElfFileParamNames>::shiftFi | ||
| 67 | wri(phdr.p_offset, phdrs.at(splitIndex).p_offset - splitShift - shift); | ||
| 68 | wri(phdr.p_paddr, phdrs.at(splitIndex).p_paddr - splitShift - shift); | ||
| 69 | wri(phdr.p_vaddr, phdrs.at(splitIndex).p_vaddr - splitShift - shift); | ||
| 70 | - wri(phdr.p_filesz, wri(phdr.p_memsz, splitShift + shift)); | ||
| 71 | + wri(phdr.p_filesz, wri(phdr.p_memsz, splitShift + extraBytes)); | ||
| 72 | wri(phdr.p_flags, PF_R | PF_W); | ||
| 73 | wri(phdr.p_align, getPageSize()); | ||
| 74 | } | ||
| 75 | @@ -898,12 +898,14 @@ void ElfFile<ElfFileParamNames>::rewrite | ||
| 76 | neededSpace += sizeof(Elf_Phdr); | ||
| 77 | debug("needed space is %d\n", neededSpace); | ||
| 78 | |||
| 79 | - unsigned int neededPages = roundUp(neededSpace - startOffset, getPageSize()) / getPageSize(); | ||
| 80 | + /* Calculate how many bytes are needed out of the additional pages. */ | ||
| 81 | + size_t extraSpace = neededSpace - startOffset; | ||
| 82 | + unsigned int neededPages = roundUp(extraSpace, getPageSize()) / getPageSize(); | ||
| 83 | debug("needed pages is %d\n", neededPages); | ||
| 84 | if (neededPages * getPageSize() > firstPage) | ||
| 85 | error("virtual address space underrun!"); | ||
| 86 | |||
| 87 | - shiftFile(neededPages, startOffset); | ||
| 88 | + shiftFile(neededPages, startOffset, extraSpace); | ||
| 89 | |||
| 90 | firstPage -= neededPages * getPageSize(); | ||
| 91 | startOffset += neededPages * getPageSize(); | ||
| 92 | Index: git/src/patchelf.h | ||
| 93 | =================================================================== | ||
| 94 | --- git.orig/src/patchelf.h | ||
| 95 | +++ git/src/patchelf.h | ||
| 96 | @@ -77,7 +77,7 @@ private: | ||
| 97 | |||
| 98 | void sortShdrs(); | ||
| 99 | |||
| 100 | - void shiftFile(unsigned int extraPages, size_t sizeOffset); | ||
| 101 | + void shiftFile(unsigned int extraPages, size_t sizeOffset, size_t extraBytes); | ||
| 102 | |||
| 103 | std::string getSectionName(const Elf_Shdr & shdr) const; | ||
| 104 | |||
diff --git a/meta/recipes-devtools/patchelf/patchelf_0.17.0.bb b/meta/recipes-devtools/patchelf/patchelf_0.17.0.bb index 5faee923bf..b32abc7b87 100644 --- a/meta/recipes-devtools/patchelf/patchelf_0.17.0.bb +++ b/meta/recipes-devtools/patchelf/patchelf_0.17.0.bb | |||
| @@ -5,6 +5,7 @@ HOMEPAGE = "https://github.com/NixOS/patchelf" | |||
| 5 | LICENSE = "GPL-3.0-only" | 5 | LICENSE = "GPL-3.0-only" |
| 6 | 6 | ||
| 7 | SRC_URI = "git://github.com/NixOS/patchelf;protocol=https;branch=master \ | 7 | SRC_URI = "git://github.com/NixOS/patchelf;protocol=https;branch=master \ |
| 8 | file://8d2cb4f9ab8d564904c292099a022ffb3cccd52d.patch \ | ||
| 8 | " | 9 | " |
| 9 | SRCREV = "ad0265668f12eff59027259345fed4b0f315336a" | 10 | SRCREV = "ad0265668f12eff59027259345fed4b0f315336a" |
| 10 | 11 | ||
