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-based buffer overflow in CxadbmfPlayer::__bmf_convert_stream() #85

Closed
fcambus opened this issue Aug 6, 2019 · 1 comment
Closed

Comments

@fcambus
Copy link
Contributor

fcambus commented Aug 6, 2019

Hi,

While fuzzing AdPlug with American Fuzzy Lop, I found a heap-based buffer overflow in CxadbmfPlayer::__bmf_convert_stream(), in src/bmf.cpp L430.

Attaching a reproducer (gzipped so GitHub accepts it): test01.bmf.gz

=================================================================
==6298==ERROR: AddressSanitizer: heap-buffer-overflow on address 0x63000000f8dd at pc 0x0000004c6aaf bp 0x7ffd579ffc90 sp 0x7ffd579ff440
WRITE of size 6 at 0x63000000f8dd thread T0
    #0 0x4c6aae in __asan_memset (/home/fcambus/reps/adplay+0x4c6aae)
    #1 0x7face9bf1bdd in CxadbmfPlayer::__bmf_convert_stream(unsigned char*, int) /home/fcambus/adplug/src/bmf.cpp:430:5
    #2 0x7face9bf1a0a in CxadbmfPlayer::xadplayer_load() /home/fcambus/adplug/src/bmf.cpp:189:12
    #3 0x7face9d5d88a in CxadPlayer::load(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, CFileProvider const&) /home/fcambus/adplug/src/xad.cpp:93:8
    #4 0x7face9bdf1d5 in CAdPlug::factory(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, Copl*, CPlayers const&, CFileProvider const&) /home/fcambus/adplug/src/adplug.cpp:169:10
    #5 0x4fcd62 in play(char const*, Player*, int) /home/fcambus/adplay-unix/src/adplay.cc:309:11
    #6 0x4fbaf4 in main /home/fcambus/adplay-unix/src/adplay.cc:544:5
    #7 0x7face941d09a in __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x2409a)
    #8 0x41f759 in _start (/home/fcambus/reps/adplay+0x41f759)

0x63000000f8dd is located 6061 bytes to the right of 56624-byte region [0x630000000400,0x63000000e130)
allocated by thread T0 here:
    #0 0x4f67e2 in operator new(unsigned long) (/home/fcambus/reps/adplay+0x4f67e2)
    #1 0x7face9bf0157 in CxadbmfPlayer::factory(Copl*) /home/fcambus/adplug/src/bmf.cpp:78:10
    #2 0x7face9bdf11d in CAdPlug::factory(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, Copl*, CPlayers const&, CFileProvider const&) /home/fcambus/adplug/src/adplug.cpp:168:10
    #3 0x4fcd62 in play(char const*, Player*, int) /home/fcambus/adplay-unix/src/adplay.cc:309:11
    #4 0x4fbaf4 in main /home/fcambus/adplay-unix/src/adplay.cc:544:5
    #5 0x7face941d09a in __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x2409a)

SUMMARY: AddressSanitizer: heap-buffer-overflow (/home/fcambus/reps/adplay+0x4c6aae) in __asan_memset
Shadow bytes around the buggy address:
  0x0c607fff9ec0: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
  0x0c607fff9ed0: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
  0x0c607fff9ee0: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
  0x0c607fff9ef0: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
  0x0c607fff9f00: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
=>0x0c607fff9f10: fa fa fa fa fa fa fa fa fa fa fa[fa]fa fa fa fa
  0x0c607fff9f20: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
  0x0c607fff9f30: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
  0x0c607fff9f40: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
  0x0c607fff9f50: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
  0x0c607fff9f60: 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
==6298==ABORTING
@fcambus
Copy link
Contributor Author

fcambus commented Aug 6, 2019

This issue has been assigned CVE-2019-14690.

miller-alex added a commit to miller-alex/adplug that referenced this issue Apr 3, 2020
While fuzzing AdPlug with American Fuzzy Lop, Frederic Cambus
found several memory issues and reported them on github. Hook
up the reproducers he provided as test cases in stresstest.cpp.
This includes tests for the following github issues:

* Issue adplug#85 ("Heap-based buffer overflow in
  CxadbmfPlayer::__bmf_convert_stream()")
* Issue adplug#86 ("Heap-based buffer overflow in CdtmLoader::load()")
* Issue adplug#87 ("Heap-based buffer overflow in CmkjPlayer::load()")
* Issue adplug#88 ("Multiple heap-based buffer overflows in Ca2mLoader::load()")
* Issue adplug#89 ("Multiple heap-based buffer overflows in CradLoader::load()")
* Issue adplug#90 ("Multiple heap-based buffer overflows in CmtkLoader::load()")
* Issue adplug#91 ("Double free in Cu6mPlayer::~Cu6mPlayer()")

Co-authored-by: Frederic Cambus <fred@statdns.com>
Bug: adplug#85
Bug: adplug#86
Bug: adplug#87
Bug: adplug#88
Bug: adplug#89
Bug: adplug#90
Bug: adplug#91
miller-alex added a commit to miller-alex/adplug that referenced this issue Apr 3, 2020
There are no checks validating the integrity of .bmf files
in the methods CxadbmfPlayer::xadplayer_load() and
CxadbmfPlayer::__bmf_convert_stream() used to load them.
A broken or malicious .bmf file can easily cause invalid
memory accesses.

This commit addresses the following issues:
* Add checks whether the input buffer has enough data available
  before accessing it in many places. Abort loading otherwise.
* Replace unlimited strcpy for instrument names with code that
  doesn't overflow the destination buffer.
* Check index when loading instrument data in BMF0_9B files.
* Fail loading if number of streams encoded in version BMF0_9B
  files exceeds the maximum.
* Don't overflow buffer if stream is too long.

This fixes CVE-2019-14690.

Fixes: adplug#85
Fixes: adplug#93
Malvineous pushed a commit that referenced this issue May 11, 2020
While fuzzing AdPlug with American Fuzzy Lop, Frederic Cambus
found several memory issues and reported them on github. Hook
up the reproducers he provided as test cases in stresstest.cpp.
This includes tests for the following github issues:

* Issue #85 ("Heap-based buffer overflow in
  CxadbmfPlayer::__bmf_convert_stream()")
* Issue #86 ("Heap-based buffer overflow in CdtmLoader::load()")
* Issue #87 ("Heap-based buffer overflow in CmkjPlayer::load()")
* Issue #88 ("Multiple heap-based buffer overflows in Ca2mLoader::load()")
* Issue #89 ("Multiple heap-based buffer overflows in CradLoader::load()")
* Issue #90 ("Multiple heap-based buffer overflows in CmtkLoader::load()")
* Issue #91 ("Double free in Cu6mPlayer::~Cu6mPlayer()")

Co-authored-by: Frederic Cambus <fred@statdns.com>
Bug: #85
Bug: #86
Bug: #87
Bug: #88
Bug: #89
Bug: #90
Bug: #91
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants