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 in input-bmp.ci:456 #55

Closed
puppet-meteor opened this issue Oct 15, 2018 · 1 comment
Closed

heap buffer overflow in input-bmp.ci:456 #55

puppet-meteor opened this issue Oct 15, 2018 · 1 comment

Comments

@puppet-meteor
Copy link

There is a heap buffer overflow in input-bmp.ci:456 at sam2p 0.49.4. A crafted input will lead to denial of service attack.

Steps to Reproduce:

#./sam2p POC_4 EPS: /dev/null

POC File: https://github.com/puppet-meteor/sam2p_POC/blob/master/POC_4

Information from addresssanitizer:

This is sam2p 0.49.4.
Available Loaders: PS PDF JAI PNG JPEG TIFF PNM BMP GIF LBM XPM PCX TGA.
Available Appliers: XWD Meta Empty BMP PNG TIFF6 TIFF6-JAI JPEG-JAI JPEG PNM GIF89a+LZW XPM PSL1C PSL23+PDF PSL2+PDF-JAI P-TrOpBb.
=================================================================
==6273==ERROR: AddressSanitizer: heap-buffer-overflow on address 0x7fbc13401124 at pc 0x0000004280d4 bp 0x7ffc91c5d970 sp 0x7ffc91c5d960
WRITE of size 1 at 0x7fbc13401124 thread T0
    #0 0x4280d3 in ReadImage /home/puppet/target/sam2p-gdb/input-bmp.ci:456
    #1 0x4280d3 in bmp_load_image(_IO_FILE*) /home/puppet/target/sam2p-gdb/input-bmp.ci:206
    #2 0x42823c in in_bmp_reader /home/puppet/target/sam2p-gdb/in_bmp.cpp:23
    #3 0x478f1b in Image::load(Image::Loader::UFD*, SimBuffer::Flat const&, char const*) /home/puppet/target/sam2p-gdb/image.cpp:1427
    #4 0x403a96 in run_sam2p_engine(Files::FILEW&, Files::FILEW&, char const* const*, bool) /home/puppet/target/sam2p-gdb/sam2p_main.cpp:1024
    #5 0x40264f in main /home/puppet/target/sam2p-gdb/sam2p_main.cpp:1117
    #6 0x7fbc6dbfb82f in __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x2082f)
    #7 0x402f98 in _start (/usr/local/bin/sam2p+0x402f98)

0x7fbc13401124 is located 0 bytes to the right of 108992804-byte region [0x7fbc0cc0f800,0x7fbc13401124)
allocated by thread T0 here:
    #0 0x7fbc6e03d602 in malloc (/usr/lib/x86_64-linux-gnu/libasan.so.2+0x98602)
    #1 0x41f2aa in emulate_cc_new /home/puppet/target/sam2p-gdb/c_lgcc.cpp:35
    #2 0x41f2aa in operator new[](unsigned long) /home/puppet/target/sam2p-gdb/c_lgcc.cpp:55
    #3 0x42777e in ReadImage /home/puppet/target/sam2p-gdb/input-bmp.ci:445
    #4 0x42777e in bmp_load_image(_IO_FILE*) /home/puppet/target/sam2p-gdb/input-bmp.ci:206
    #5 0x42823c in in_bmp_reader /home/puppet/target/sam2p-gdb/in_bmp.cpp:23
    #6 0x478f1b in Image::load(Image::Loader::UFD*, SimBuffer::Flat const&, char const*) /home/puppet/target/sam2p-gdb/image.cpp:1427
    #7 0x403a96 in run_sam2p_engine(Files::FILEW&, Files::FILEW&, char const* const*, bool) /home/puppet/target/sam2p-gdb/sam2p_main.cpp:1024
    #8 0x40264f in main /home/puppet/target/sam2p-gdb/sam2p_main.cpp:1117
    #9 0x7fbc6dbfb82f in __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x2082f)

SUMMARY: AddressSanitizer: heap-buffer-overflow /home/puppet/target/sam2p-gdb/input-bmp.ci:456 ReadImage
Shadow bytes around the buggy address:
  0x0ff8026781d0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
  0x0ff8026781e0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
  0x0ff8026781f0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
  0x0ff802678200: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
  0x0ff802678210: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
=>0x0ff802678220: 00 00 00 00[04]fa fa fa fa fa fa fa fa fa fa fa
  0x0ff802678230: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
  0x0ff802678240: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
  0x0ff802678250: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
  0x0ff802678260: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
  0x0ff802678270: 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
  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
  Container overflow:      fc
  Array cookie:            ac
  Intra object redzone:    bb
  ASan internal:           fe
==6273==ABORTING

found by puppet@zju.edu.cn from NESA Lab in Zhejiang University.

@pts
Copy link
Owner

pts commented Oct 15, 2018

Thank you for reporting this! I'm not able to reproduce this bug with the latest sam2p HEAD (d2656be), so I'm closing this issue now. Feel free to report more issues, but please check that you have d2656be or later checked out.

$ ./sam2p.asan POC_4 EPS: /dev/null
This is sam2p 0.49.4.
Available Loaders: PS PDF JAI PNG JPEG TIFF PNM BMP GIF LBM XPM PCX TGA.
Available Appliers: XWD Meta Empty BMP PNG TIFF6 TIFF6-JAI JPEG-JAI JPEG PNM GIF89a+LZW XPM PSL1C PSL23+PDF PSL2+PDF-JAI P-TrOpBb.
sam2p.asan: Error: BMP: Image too large.

@pts pts closed this as completed Oct 15, 2018
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

No branches or pull requests

2 participants