A heap-based buffer overflow bug was found in advzip.
Brought to you by:
amadvance
Hello,
I found a heap-based overflow bug in advzip. It happened when someone give a crafted input and may allow a remote attacker to cause unspecified impact including denial-of-service attack.
Actually it looks like CVE-2018-1056(https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=889270). The ASAN report is as below.
liwc@ubuntu:~/advancecomp_bak$ ./advzip -l poc
=================================================================
==117600==ERROR: AddressSanitizer: heap-buffer-overflow on address 0x60800000bffe at pc 0x000000409de9 bp 0x7fff4b0dbb90 sp 0x7fff4b0dbb80
READ of size 1 at 0x60800000bffe thread T0
#0 0x409de8 in le_uint32_read lib/endianrw.h:172
#1 0x412803 in zip::open() /home/liwc/advancecomp_bak/zip.cc:860
#2 0x404e44 in list_single(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, bool) /home/liwc/advancecomp_bak/rezip.cc:122
#3 0x405ee9 in list_all(int, char**, bool) /home/liwc/advancecomp_bak/rezip.cc:261
#4 0x408994 in process(int, char**) /home/liwc/advancecomp_bak/rezip.cc:613
#5 0x408ced in main /home/liwc/advancecomp_bak/rezip.cc:623
#6 0x7f306ce4d82f in __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x2082f)
#7 0x404108 in _start (/home/liwc/advancecomp_bak/advzip+0x404108)
0x60800000bffe is located 0 bytes to the right of 94-byte region [0x60800000bfa0,0x60800000bffe)
allocated by thread T0 here:
#0 0x7f306dd56662 in malloc (/usr/lib/x86_64-linux-gnu/libasan.so.2+0x98662)
#1 0x41b437 in data_alloc(unsigned int) /home/liwc/advancecomp_bak/data.cc:51
#2 0x40a379 in cent_read(_IO_FILE*, unsigned int, unsigned char*&, unsigned int&) /home/liwc/advancecomp_bak/zip.cc:113
#3 0x41276a in zip::open() /home/liwc/advancecomp_bak/zip.cc:846
#4 0x404e44 in list_single(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, bool) /home/liwc/advancecomp_bak/rezip.cc:122
#5 0x405ee9 in list_all(int, char**, bool) /home/liwc/advancecomp_bak/rezip.cc:261
#6 0x408994 in process(int, char**) /home/liwc/advancecomp_bak/rezip.cc:613
#7 0x408ced in main /home/liwc/advancecomp_bak/rezip.cc:623
#8 0x7f306ce4d82f in __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x2082f)
SUMMARY: AddressSanitizer: heap-buffer-overflow lib/endianrw.h:172 le_uint32_read
Shadow bytes around the buggy address:
0x0c107fff97a0: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
0x0c107fff97b0: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
0x0c107fff97c0: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
0x0c107fff97d0: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
0x0c107fff97e0: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
=>0x0c107fff97f0: fa fa fa fa 00 00 00 00 00 00 00 00 00 00 00[06]
0x0c107fff9800: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
0x0c107fff9810: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
0x0c107fff9820: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
0x0c107fff9830: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
0x0c107fff9840: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
Shadow byte legend (one shadow byte represents 8 application bytes):
Addressable: 00
Partially addressable: 01 02 03 04 05 06 07
Heap left redzone: fa
Heap right redzone: fb
Freed heap region: fd
Stack left redzone: f1
Stack mid redzone: f2
Stack right redzone: f3
Stack partial redzone: f4
Stack after return: f5
Stack use after scope: f8
Global redzone: f9
Global init order: f6
Poisoned by user: f7
Container overflow: fc
Array cookie: ac
Intra object redzone: bb
ASan internal: fe
==117600==ABORTING
Here is the function le_uint_read:
static inline unsigned le_uint32_read(const void* ptr)
{
#ifdef USE_LSB
return cpu_uint32_read(ptr);
#else
const unsigned char* ptr8 = (const unsigned char*)ptr;
return (unsigned)ptr8[0] | (unsigned)ptr8[1] << 8 | (unsigned)ptr8[2] << 16 | (unsigned)ptr8[3] << 24; <-
#endif
}
I built the lastest commit (fcf71a8) advancecomp with gcc & asan, we can reproduce it with the poc I attached.
The command line is ./advzip -l poc.