[PATCH] elf: Check ldconfig property segment bounds [BZ #34954]

skyman wftw skyman-wftw@hotmail.com
Mon Nov 9 13:56:47 GMT 2026


readelflib.c process_elf_file() does not validate p_offset or p_filesz
for PT_GNU_PROPERTY segments before constructing a pointer into the
mapped file contents.  A shared library with a PT_GNU_PROPERTY segment
whose p_offset exceeds the file size causes ldconfig to SIGSEGV.

Add a range check before the note pointer is constructed.  The check
uses subtraction (file_length - p_offset) to avoid overflow from
computing p_offset + p_filesz.  An out-of-range segment is skipped,
consistent with how the existing code already skips property segments
with incorrect alignment.

Tested on x86_64-linux-gnu (glibc 2.39):
- PoC with p_offset=0x100000000000: cleanly skipped, no crash
- Normal libraries (libc.so.6, libcuda.so.1): SONAME parsed correctly

Signed-off-by: skyman wftw <kamariishereka03041992@outlook.com>
---
 elf/readelflib.c | 5 +++++
 1 file changed, 5 insertions(+)

diff --git a/elf/readelflib.c b/elf/readelflib.c
index XXXXXXX..XXXXXXX 100644
--- a/elf/readelflib.c
+++ b/elf/readelflib.c
@@ -115,6 +115,11 @@
 	     notes with incorrect alignment.  */
 	  if (segment->p_align == (__ELF_NATIVE_CLASS / 8))
 	    {
+	      /* Skip property segments whose file range is out of bounds.  */
+	      if (segment->p_offset > file_length
+		  || segment->p_filesz > file_length - segment->p_offset)
+		break;
+
 	      const ElfW(Nhdr) *note = (const void *) (file_contents
 						       + segment->p_offset);
 	      const ElfW(Addr) size = segment->p_filesz;


More information about the Libc-alpha mailing list