Bug 1468471 - There is heap buffer overflow in function ole_init of catdoc.
There is heap buffer overflow in function ole_init of catdoc.
Status: NEW
Product: Fedora
Classification: Fedora
Component: catdoc (Show other bugs)
27
x86_64 Linux
unspecified Severity urgent
: ---
: ---
Assigned To: Adel Gadllah
Fedora Extras Quality Assurance
: Reopened
Depends On:
Blocks:
  Show dependency treegraph
 
Reported: 2017-07-07 04:07 EDT by owl337
Modified: 2017-08-15 05:15 EDT (History)
6 users (show)

See Also:
Fixed In Version:
Doc Type: If docs needed, set a value
Doc Text:
Story Points: ---
Clone Of:
Environment:
Last Closed: 2017-07-12 11:07:06 EDT
Type: Bug
Regression: ---
Mount Type: ---
Documentation: ---
CRM:
Verified Versions:
Category: ---
oVirt Team: ---
RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: ---


Attachments (Terms of Use)
Triggered by "./catdoc $POC" (56.91 KB, application/x-rar)
2017-07-07 04:07 EDT, owl337
no flags Details
this is file format of POC (88.78 KB, application/x-ole-storage)
2017-07-08 05:31 EDT, owl337
no flags Details

  None (edit)
Description owl337 2017-07-07 04:07:38 EDT
Created attachment 1295211 [details]
Triggered by  "./catdoc $POC"

Description of problem:

At ole.c:150:
 if(fread(tmpBuf+MSAT_ORIG_SIZE+(sectorSize-4)*i,
                                                 1, sectorSize, newfile) != sectorSize) {

A short value at 0x1e of the file is assigned the power of sectorSize as follows:

long int sectorSize
sectorSize = 1<<getshort(oleBuf,0x1e);

If sectorSize is less than 4 and i is large enough, the input can override MSAT_ORIG_SIZE (436) so that fread writes data to tmpBuf before the contents cause heap underflow.

Version-Release number of selected component (if applicable):

<= latest version

How reproducible:

./catdoc $POC

Steps to Reproduce:

The ASAN debugging information is as follows:

=================================================================
==8489==ERROR: AddressSanitizer: heap-buffer-overflow on address 0x616000001e7e at pc 0x48ffd8 bp 0x7ffdf50b19d0 sp 0x7ffdf50b19c8
READ of size 1 at 0x616000001e7e thread T0
==8489==WARNING: Trying to symbolize code, but external symbolizer is not initialized!
    #0 0x48ffd7 (/home/company/collafl/testcases/catdoc-0.95/install/bin/catdoc_asan+0x48ffd7)
    #1 0x490de3 (/home/company/collafl/testcases/catdoc-0.95/install/bin/catdoc_asan+0x490de3)
    #2 0x482189 (/home/company/collafl/testcases/catdoc-0.95/install/bin/catdoc_asan+0x482189)
    #3 0x47de9e (/home/company/collafl/testcases/catdoc-0.95/install/bin/catdoc_asan+0x47de9e)
    #4 0x7f9658881a3f (/lib/x86_64-linux-gnu/libc.so.6+0x20a3f)
    #5 0x47c838 (/home/company/collafl/testcases/catdoc-0.95/install/bin/catdoc_asan+0x47c838)

0x616000001e7e is located 2 bytes to the left of 582-byte region [0x616000001e80,0x6160000020c6)
allocated by thread T0 here:
    #0 0x466943 (/home/company/collafl/testcases/catdoc-0.95/install/bin/catdoc_asan+0x466943)
    #1 0x490c57 (/home/company/collafl/testcases/catdoc-0.95/install/bin/catdoc_asan+0x490c57)
    #2 0x482189 (/home/company/collafl/testcases/catdoc-0.95/install/bin/catdoc_asan+0x482189)
    #3 0x47de9e (/home/company/collafl/testcases/catdoc-0.95/install/bin/catdoc_asan+0x47de9e)
    #4 0x7f9658881a3f (/lib/x86_64-linux-gnu/libc.so.6+0x20a3f)

SUMMARY: AddressSanitizer: heap-buffer-overflow ??:0 ??
Shadow bytes around the buggy address:
  0x0c2c7fff8370: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
  0x0c2c7fff8380: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
  0x0c2c7fff8390: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
  0x0c2c7fff83a0: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
  0x0c2c7fff83b0: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
=>0x0c2c7fff83c0: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa[fa]
  0x0c2c7fff83d0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
  0x0c2c7fff83e0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
  0x0c2c7fff83f0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
  0x0c2c7fff8400: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
  0x0c2c7fff8410: 00 00 00 00 00 00 00 00 06 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
  ASan internal:         fe
==8489==ABORTING

The gdb debug info is as follows:

#0  0x00007ffff7a43428 in __GI_raise (sig=sig@entry=0x6) at ../sysdeps/unix/sysv/linux/raise.c:54
#1  0x00007ffff7a4502a in __GI_abort () at abort.c:89
#2  0x00007ffff7a857ea in __libc_message (do_abort=do_abort@entry=0x2, fmt=fmt@entry=0x7ffff7b9e2e0 "*** Error in `%s': %s: 0x%s ***\n")
    at ../sysdeps/posix/libc_fatal.c:175
#3  0x00007ffff7a91ae8 in malloc_printerr (ar_ptr=0x0, ptr=<optimized out>, str=0x7ffff7b9e308 "munmap_chunk(): invalid pointer", 
    action=<optimized out>) at malloc.c:5004
#4  munmap_chunk (p=<optimized out>) at malloc.c:2840
#5  __GI___libc_free (mem=<optimized out>) at malloc.c:2961
#6  0x0000000000406400 in ole_init (f=0x68dc80, buffer=0x7fffffffdd40, bufSize=0x8) at ole.c:178
#7  0x00000000004028de in analyze_format (f=0x68dc80) at analyze.c:58
#8  0x0000000000401b6a in main (argc=0x2, argv=0x7fffffffdf28) at catdoc.c:180
#9  0x00007ffff7a2e830 in __libc_start_main (main=0x401526 <main>, argc=0x2, argv=0x7fffffffdf28, init=<optimized out>, 
    fini=<optimized out>, rtld_fini=<optimized out>, stack_end=0x7fffffffdf18) at ../csu/libc-start.c:291
#10 0x0000000000401459 in _start ()


Actual results:

crash

Expected results:

crash

Additional info:

This vulnerability is detected by team OWL337, with our custom fuzzer collAFL. Please contact ganshuitao@gmail.com  and chaoz@tsinghua.edu.cn if you need more info about the team, the tool or the vulnerability.
Comment 1 Robert Scheck 2017-07-07 15:10:23 EDT
Did you also send this bug report to the upstream developers of catdoc?
May I kindly ask you to provide the reproducer in an open format (thus
not *.rar)?
Comment 2 owl337 2017-07-08 05:31 EDT
Created attachment 1295476 [details]
this is file format of POC
Comment 3 Agostino Sarubbo 2017-07-12 03:31:56 EDT
Please also check: https://catdocbugs.neocities.org/

Feel free to check by yourself if it is not a duplicate.
Comment 6 Jan Kurik 2017-08-15 05:15:13 EDT
This bug appears to have been reported against 'rawhide' during the Fedora 27 development cycle.
Changing version to '27'.

Note You need to log in before you can comment on or make changes to this bug.