Skip to content
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

Heap buffer overflow via TNEFVersion #86

Closed
jasperla opened this issue Jan 30, 2021 · 1 comment · Fixed by #88
Closed

Heap buffer overflow via TNEFVersion #86

jasperla opened this issue Jan 30, 2021 · 1 comment · Fixed by #88

Comments

@jasperla
Copy link

jasperla commented Jan 30, 2021

A heap buffer overflow can be triggered as of ecc9d87 with crafted input, despite ytnef recognizing that the provided input file is not valid:

ERROR: Checksum mismatch. Data corruption?:

However when built with ASAN we see that SwapWord attempts to read invalid memory before said error message can be printed:

=================================================================
==2699631==ERROR: AddressSanitizer: heap-buffer-overflow on address 0x602000000032 at pc 0x000000498907 bp 0x7fffffffdf50 sp 0x7fffffffd718
READ of size 2 at 0x602000000032 thread T0
    #0 0x498906 in __asan_memcpy (/home/kali/ytnef/asan/bin/ytnef+0x498906)
    #1 0x7ffff7f51e90 in SwapWord /home/kali/ytnef/lib/ytnef.c:155:26
    #2 0x7ffff7f51e90 in TNEFVersion /home/kali/ytnef/lib/ytnef.c:343:11
    #3 0x7ffff7f68243 in TNEFParse /home/kali/ytnef/lib/ytnef.c:1220:15
    #4 0x7ffff7f664d9 in TNEFParseFile /home/kali/ytnef/lib/ytnef.c:1077:10
    #5 0x4c975c in main /home/kali/ytnef/ytnef/main.c:140:9
    #6 0x7ffff7bf9d09 in __libc_start_main csu/../csu/libc-start.c:308:16
    #7 0x41f439 in _start (/home/kali/ytnef/asan/bin/ytnef+0x41f439)

0x602000000032 is located 1 bytes to the right of 1-byte region [0x602000000030,0x602000000031)
allocated by thread T0 here:
    #0 0x499622 in calloc (/home/kali/ytnef/asan/bin/ytnef+0x499622)
    #1 0x7ffff7f676d9 in TNEFParse /home/kali/ytnef/lib/ytnef.c:1190:12
    #2 0x7ffff7f664d9 in TNEFParseFile /home/kali/ytnef/lib/ytnef.c:1077:10
    #3 0x4c975c in main /home/kali/ytnef/ytnef/main.c:140:9
    #4 0x7ffff7bf9d09 in __libc_start_main csu/../csu/libc-start.c:308:16

SUMMARY: AddressSanitizer: heap-buffer-overflow (/home/kali/ytnef/asan/bin/ytnef+0x498906) in __asan_memcpy
Shadow bytes around the buggy address:
  0x0c047fff7fb0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
  0x0c047fff7fc0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
  0x0c047fff7fd0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
  0x0c047fff7fe0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
  0x0c047fff7ff0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
=>0x0c047fff8000: fa fa fd fa fa fa[01]fa fa fa fa fa fa fa fa fa
  0x0c047fff8010: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
  0x0c047fff8020: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
  0x0c047fff8030: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
  0x0c047fff8040: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
  0x0c047fff8050: 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
==2699631==ABORTING

I have attached a minimal reproducer of this crash: heap.zip

ohwgiles added a commit to ohwgiles/ytnef that referenced this issue Jan 31, 2021
A corrupted version field size can cause TNEFVersion to access outside
of allocated memory. Check the version is the expected size and raise
an error if not.

Resolves: Yeraze#86
Reported-by: jasperla
@carnil
Copy link

carnil commented Feb 10, 2021

This issue was assigned CVE-2021-3404

@Yeraze Yeraze closed this as completed in #88 Mar 5, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants