Gentoo Websites Logo
Go to: Gentoo Home Documentation Forums Lists Bugs Planet Store Wiki Get Gentoo!
Bug 567954 - app-misc/pax-utils: dumpelf: segfault ELF file with corrupt section headers
Summary: app-misc/pax-utils: dumpelf: segfault ELF file with corrupt section headers
Status: RESOLVED FIXED
Alias: None
Product: Gentoo Linux
Classification: Unclassified
Component: Current packages (show other bugs)
Hardware: AMD64 Linux
: Normal normal
Assignee: SpanKY
URL:
Whiteboard:
Keywords:
: 568026 (view as bug list)
Depends on:
Blocks:
 
Reported: 2015-12-11 03:10 UTC by Brian 'geeknik' Carpenter
Modified: 2015-12-12 22:46 UTC (History)
0 users

See Also:
Package list:
Runtime testing required: ---


Attachments
Crashing test case (test00-min.gz,54 bytes, application/x-gzip)
2015-12-11 03:10 UTC, Brian 'geeknik' Carpenter
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Brian 'geeknik' Carpenter 2015-12-11 03:10:27 UTC
I compiled dumpelf 1.1.3 from git source ~ 5 hours ago and started in with American Fuzzy Lop. The following ELF file causes a segfault in dumpelf at dumpelf.c:108.



Reproducible: Always

Steps to Reproduce:
1. Compile from git source
2. dumpelf test00-min
3. Crash.
Actual Results:  
Program received signal SIGSEGV, Segmentation fault.
0x00000000004032ee in dumpelf (file_cnt=0, filename=<optimized out>)
    at dumpelf.c:108
108			DUMP_SHDRS(32)
(gdb) bt
#0  0x00000000004032ee in dumpelf (file_cnt=0, filename=<optimized out>)
    at dumpelf.c:108
#1  parseargs (argv=0x7fffffffe328, argc=2) at dumpelf.c:381
#2  main (argc=2, argv=0x7fffffffe328) at dumpelf.c:390

$ valgrind -q ~/pax-utils/dumpelf test00-min
dumpelf: test00-min: Invalid program header info (3)
#include <elf.h>

/*
 * ELF dump of 'test00-min'
 *     156 (0x9C) bytes
 */

Elf32_Dyn dumpedelf_dyn_0[];
struct {
	Elf32_Ehdr ehdr;
	Elf32_Phdr phdrs[12336];
	Elf32_Shdr shdrs[3];
	Elf32_Dyn *dyns;
} dumpedelf_0 = {

.ehdr = {
	.e_ident = { /* (EI_NIDENT bytes) */
		/* [0] EI_MAG:        */ 0x7F,'E','L','F',
		/* [4] EI_CLASS:      */ 1 , /* (ELFCLASS32) */
		/* [5] EI_DATA:       */ 1 , /* (ELFDATA2LSB) */
		/* [6] EI_VERSION:    */ 1 , /* (EV_CURRENT) */
		/* [7] EI_OSABI:      */ 48 , /* (UNKNOWN_TYPE) */
		/* [8] EI_ABIVERSION: */ 48 ,
		/* [9] EI_PAD:        */ 0x30 /* x 7 bytes */
	},
	.e_type      = 12336      , /* (UNKNOWN_TYPE) */
	.e_machine   = 12336      , /* (UNKNOWN_TYPE) */
	.e_version   = 808464432  ,
	.e_entry     = 0x30303030 ,
	.e_phoff     = 808464432  , /* (bytes into file) */
	.e_shoff     = 36         , /* (bytes into file) */
	.e_flags     = 0x30303030 ,
	.e_ehsize    = 12336      , /* (bytes) */
	.e_phentsize = 12336      , /* (bytes) */
	.e_phnum     = 12336      , /* (program headers) */
	.e_shentsize = 40         , /* (bytes) */
	.e_shnum     = 3          , /* (section headers) */
	.e_shstrndx  = 12336     
},

.phdrs = {
 /* no program headers ! */ },

.shdrs = {
==100430== Invalid read of size 4
==100430==    at 0x4032EE: dumpelf (dumpelf.c:108)
==100430==    by 0x4032EE: parseargs (dumpelf.c:381)
==100430==    by 0x4032EE: main (dumpelf.c:390)
==100430==  Address 0x409a7b4 is not stack'd, malloc'd or (recently) free'd
==100430== 
==100430== 
==100430== Process terminating with default action of signal 11 (SIGSEGV)
==100430==  Access not within mapped region at address 0x409A7B4
==100430==    at 0x4032EE: dumpelf (dumpelf.c:108)
==100430==    by 0x4032EE: parseargs (dumpelf.c:381)
==100430==    by 0x4032EE: main (dumpelf.c:390)
==100430==  If you believe this happened as a result of a stack
==100430==  overflow in your program's main thread (unlikely but
==100430==  possible), you can try to increase the size of the
==100430==  main thread stack using the --main-stacksize= flag.
==100430==  The main thread stack size used in this run was 8388608.
Segmentation fault

Expected Results:  
No crash.

Compiled on Debian 8.2 (x86_64) with afl-gcc and gcc v4.9.2.
Comment 1 Brian 'geeknik' Carpenter 2015-12-11 03:10:51 UTC
Created attachment 418956 [details]
Crashing test case
Comment 2 SpanKY gentoo-dev 2015-12-12 18:13:28 UTC
seems to be fixed w/1.1.4 already
Comment 3 Brian 'geeknik' Carpenter 2015-12-12 19:06:50 UTC
I'm still seeing a crash in dumpelf (pax-utils-git: v1.1.4-1-g335e3c3) with the attached crash test. Can you point to where this was fixed? Thanks.
Comment 4 SpanKY gentoo-dev 2015-12-12 21:09:20 UTC
sorry, i thought you attached the ELF rather than compressing it, so i was running the tools on the compressed file.  dumpelf in latest git still crashes.
Comment 5 SpanKY gentoo-dev 2015-12-12 21:32:02 UTC
dumpelf crashes are not critical as this is really just a dev/hacking tool.
i'm not aware of anyone using it for any real work.  scanelf is way more interesting of a target.
Comment 6 SpanKY gentoo-dev 2015-12-12 21:36:43 UTC
*** Bug 568026 has been marked as a duplicate of this bug. ***