Skip to content

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

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
hdthky opened this issue Mar 25, 2022 · 3 comments
Assignees
Labels
bug Something isn't working priority-low
Milestone

Comments

@hdthky
Copy link

hdthky commented Mar 25, 2022

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.

@michaelrsweet michaelrsweet self-assigned this Mar 25, 2022
@michaelrsweet michaelrsweet added bug Something isn't working priority-low labels Mar 25, 2022
@michaelrsweet michaelrsweet added this to the Stable milestone Mar 25, 2022
@michaelrsweet
Copy link
Owner

Denial of service perhaps, information disclosure unlikely.

@hdthky
Copy link
Author

hdthky commented Mar 25, 2022

Maybe I misrepresent it, I just wanted to say it's possible.

@michaelrsweet
Copy link
Owner

Needed to update prev pointer in linked list:

[master 614fcba] Fix potential use-after-free in blocks/paragraphs (Issue #484)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working priority-low
Projects
None yet
Development

No branches or pull requests

2 participants