Skip to content

AddressSanitizer: heap-buffer-overflow in function parse_paragraph at ps-pdf.cxx:5203 #484

Closed
@hdthky

Description

@hdthky

Description

Whilst experimenting with htmldoc, built from commit 0bef12c, we are able to induce a vulnerability at htmldoc/htmldoc/ps-pdf.cxx:5203 in function parse_paragraph , using a harness compiled from htmldoc/htmldoc.cxx.

Because there is no bounds checking, a heap-based out-of-bound read will be triggered when the software encounters a malformed file, result in information disclosure or denial of service.

Environment

Ubuntu 20.04

gcc 10.3.0 with ASAN

Proof of Concept

The POC is: poc_heap_overflow7

The command is: ./htmldoc --webpage -t pdf -f /dev/null poc_heap_overflow7

The ASAN report is:

=================================================================
==9833==ERROR: AddressSanitizer: heap-use-after-free on address 0x6080000005d0 at pc 0x5555555d65cd bp 0x7fffffffa220 sp 0x7fffffffa210
READ of size 4 at 0x6080000005d0 thread T0
    #0 0x5555555d65cc in parse_paragraph /work/htmldoc/htmldoc/ps-pdf.cxx:5203
    #1 0x5555555f526e in parse_doc /work/htmldoc/htmldoc/ps-pdf.cxx:4572
    #2 0x5555555f1976 in parse_doc /work/htmldoc/htmldoc/ps-pdf.cxx:4273
    #3 0x5555555f4f23 in parse_doc /work/htmldoc/htmldoc/ps-pdf.cxx:4537
    #4 0x555555604d71 in pspdf_export /work/htmldoc/htmldoc/ps-pdf.cxx:803
    #5 0x55555559f764 in main /work/htmldoc/htmldoc/htmldoc.cxx:1291
    #6 0x7ffff6b620b2 in __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x270b2)
    #7 0x55555559fbcd in _start (/work/htmldoc/htmldoc/htmldoc+0x4bbcd)

0x6080000005d0 is located 48 bytes inside of 96-byte region [0x6080000005a0,0x608000000600)
freed by thread T0 here:
    #0 0x7ffff769b8f7 in __interceptor_free ../../../../src/libsanitizer/asan/asan_malloc_linux.cpp:127
    #1 0x5555555d4b91 in parse_paragraph /work/htmldoc/htmldoc/ps-pdf.cxx:4881

previously allocated by thread T0 here:
    #0 0x7ffff769be17 in __interceptor_calloc ../../../../src/libsanitizer/asan/asan_malloc_linux.cpp:154
    #1 0x5555555d0470 in flatten_tree /work/htmldoc/htmldoc/ps-pdf.cxx:9585

SUMMARY: AddressSanitizer: heap-use-after-free /work/htmldoc/htmldoc/ps-pdf.cxx:5203 in parse_paragraph
Shadow bytes around the buggy address:
  0x0c107fff8060: fa fa fa fa 00 00 00 00 00 00 00 00 00 00 00 00
  0x0c107fff8070: fa fa fa fa 00 00 00 00 00 00 00 00 00 00 00 00
  0x0c107fff8080: fa fa fa fa 00 00 00 00 00 00 00 00 00 00 00 00
  0x0c107fff8090: fa fa fa fa 00 00 00 00 00 00 00 00 00 00 00 00
  0x0c107fff80a0: fa fa fa fa 00 00 00 00 00 00 00 00 00 00 00 00
=>0x0c107fff80b0: fa fa fa fa fd fd fd fd fd fd[fd]fd fd fd fd fd
  0x0c107fff80c0: fa fa fa fa 00 00 00 00 00 00 00 00 00 00 00 00
  0x0c107fff80d0: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
  0x0c107fff80e0: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
  0x0c107fff80f0: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
  0x0c107fff8100: 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
  Freed heap region:       fd
  Stack left redzone:      f1
  Stack mid redzone:       f2
  Stack right redzone:     f3
  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
  Left alloca redzone:     ca
  Right alloca redzone:    cb
  Shadow gap:              cc
==9833==ABORTING

Impact

This vulnerability is capable of inducing information disclosure or denial of service.

Metadata

Metadata

Assignees

Labels

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions