View Issue Details

IDProjectCategoryView StatusLast Update
0000638fileGeneralpublic2025-03-29 15:17
Reporterpbrook Assigned Tochristos  
PrioritynormalSeveritycrashReproducibilityalways
Status resolvedResolutionfixed 
Product Version5.46 
Fixed in VersionHEAD 
Summary0000638: Buffer overrun parsing ELF PT_INTERP
DescriptionBuffer overrun leading to a crash when parsing ELF files with a large
PT_INTERP segment.
Steps To Reproduce$ file crash.elf
*** buffer overflow detected ***: terminated
Aborted
Additional InformationLooks like this was probably introduced by commit 9109a696f3289ba00eaa222fd432755ec4287e28

I observed this when installing a Yocto SDK, where binaries are built
with large amounts of padding in PT_INTERP to allow later patching
(the install script also happens to use file).

Example ELF file and Patch to fix the bug attached
TagsNo tags attached.

Activities

pbrook

2025-03-28 01:45

reporter  

elf-crash.patch (466 bytes)   
diff --git a/src/readelf.c b/src/readelf.c
index fed85efe..5c557522 100644
--- a/src/readelf.c
+++ b/src/readelf.c
@@ -1827,7 +1827,7 @@ dophn_exec(struct magic_set *ms, int clazz, int swap, int fd, off_t off,
 				continue;
 			if (bufsize && nbuf[0]) {
 				nbuf[bufsize - 1] = '\0';
-				memcpy(interp, nbuf, CAST(size_t, bufsize));
+				strlcpy(interp, RCAST(char *, nbuf), sizeof(interp));
 			} else
 				strlcpy(interp, "*empty*", sizeof(interp));
 			break;
elf-crash.patch (466 bytes)   
crash.elf (27,304 bytes)

cbiedl

2025-03-28 12:11

reporter   ~0004196

As also mentioned in the Debian bug report at <https://bugs.debian.org/1101470>, this was likely already fixed upstream, "PR/579: net147: Fix stack overrun."

christos

2025-03-29 15:17

manager   ~0004197

fixed, thanks!

Issue History

Date Modified Username Field Change
2025-03-28 01:45 pbrook New Issue
2025-03-28 01:45 pbrook File Added: elf-crash.patch
2025-03-28 01:45 pbrook File Added: crash.elf
2025-03-28 12:11 cbiedl Note Added: 0004196
2025-03-29 15:16 christos Assigned To => christos
2025-03-29 15:16 christos Status new => assigned
2025-03-29 15:17 christos Status assigned => resolved
2025-03-29 15:17 christos Resolution open => fixed
2025-03-29 15:17 christos Fixed in Version => HEAD
2025-03-29 15:17 christos Note Added: 0004197