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 #1009

Closed
3 tasks done
SmileBugs opened this issue Mar 2, 2018 · 5 comments
Closed
3 tasks done

heap-buffer-overflow #1009

SmileBugs opened this issue Mar 2, 2018 · 5 comments

Comments

@SmileBugs
Copy link

Prerequisites

  • I have written a descriptive issue title
  • I have verified that I am using the latest version of ImageMagick
  • I have searched open and closed issues to ensure it has not already been reported

Description

Version: ImageMagick 7.0.7-22 Q16 i686 2018-02-08 http://www.imagemagick.org
Copyright: © 1999-2018 ImageMagick Studio LLC
License: http://www.imagemagick.org/script/license.php
Features: Cipher DPC HDRI Modules OpenMP
Delegates (built-in): bzlib djvu fftw flif fontconfig fpx freetype jbig jng jp2 jpeg lcms ltdl openexr pangocairo png raw tiff webp wmf x xml zlib

ASAN OUTPUT

root@v22017125319057172:~# identify -verbose ./poc
=================================================================
==11603==ERROR: AddressSanitizer: heap-buffer-overflow on address 0xb3e0459f at pc 0xb3f17327 bp 0xbfc4c008 sp 0xbfc4bff8
READ of size 1 at 0xb3e0459f thread T0
    #0 0xb3f17326 in IsWEBPImageLossless coders/webp.c:184
    #1 0xb3f17326 in ReadWEBPImage coders/webp.c:299
    #2 0xb6322c0a in ReadImage MagickCore/constitute.c:497
    #3 0xb63260b4 in ReadImages MagickCore/constitute.c:866
    #4 0xb5c40700 in IdentifyImageCommand MagickWand/identify.c:321
    #5 0xb5d1314d in MagickCommandGenesis MagickWand/mogrify.c:183
    #6 0x80499d0 in MagickMain utilities/magick.c:149
    #7 0x804907a in main utilities/magick.c:180
    #8 0xb581c636 in __libc_start_main (/lib/i386-linux-gnu/libc.so.6+0x18636)
    #9 0x80490fb  (/usr/bin/magick+0x80490fb)

0xb3e0459f is located 3 bytes to the right of 12-byte region [0xb3e04590,0xb3e0459c)
allocated by thread T0 here:
    #0 0xb722adee in malloc (/usr/lib/i386-linux-gnu/libasan.so.2+0x96dee)
    #1 0xb667a092 in AcquireMagickMemory MagickCore/memory.c:468

SUMMARY: AddressSanitizer: heap-buffer-overflow coders/webp.c:184 IsWEBPImageLossless
Shadow bytes around the buggy address:
  0x367c0860: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
  0x367c0870: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
  0x367c0880: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
  0x367c0890: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
  0x367c08a0: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
=>0x367c08b0: fa fa 00[04]fa fa 00 00 fa fa 00 01 fa fa fd fd
  0x367c08c0: fa fa fd fd fa fa 00 00 fa fa 00 03 fa fa 05 fa
  0x367c08d0: fa fa 05 fa fa fa 00 00 fa fa 05 fa fa fa fd fa
  0x367c08e0: fa fa 05 fa fa fa 00 00 fa fa 07 fa fa fa 00 00
  0x367c08f0: fa fa 02 fa fa fa 00 00 fa fa 03 fa fa fa 00 00
  0x367c0900: 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
==11603==ABORTING

POC

poc.zip

System Configuration

System Configuration
ImageMagick version: 7.0.7-22
Environment (Operating system, version and so on): ubuntu-16.04.3-server-i386
Additional information:

Found by: Wang Yan

@urban-warrior
Copy link
Contributor

We get expected results with ImageMagick 7.0.7-24, the current release:

$ identify -verbose ./poc
identify: corrupt image `./poc' @ error/webp.c/ReadWEBPImage/.

@SmileBugs
Copy link
Author

root@v22017125319057172:/opt# identify -version && identify -verbose ./poc 
Version: ImageMagick 7.0.7-24 Q16 i686 2018-03-05 http://www.imagemagick.org
Copyright: © 1999-2018 ImageMagick Studio LLC
License: http://www.imagemagick.org/script/license.php
Features: Cipher DPC HDRI Modules OpenMP 
Delegates (built-in): bzlib djvu fftw flif fontconfig fpx freetype jbig jng jp2 jpeg lcms ltdl openexr pangocairo png raw tiff webp wmf x xml zlib
=================================================================
==11686==ERROR: AddressSanitizer: heap-buffer-overflow on address 0xb3e0455f at pc 0xb3f2852d bp 0xbf8cca78 sp 0xbf8cca68
READ of size 1 at 0xb3e0455f thread T0
    #0 0xb3f2852c in IsWEBPImageLossless coders/webp.c:184
    #1 0xb3f2852c in ReadWEBPImage coders/webp.c:299
    #2 0xb633c112 in ReadImage MagickCore/constitute.c:497
    #3 0xb633f8b8 in ReadImages MagickCore/constitute.c:867
    #4 0xb5c55980 in IdentifyImageCommand MagickWand/identify.c:321
    #5 0xb5d2a9dd in MagickCommandGenesis MagickWand/mogrify.c:183
    #6 0x8049a2e in MagickMain utilities/magick.c:149
    #7 0x804907a in main utilities/magick.c:180
    #8 0xb582e636 in __libc_start_main (/lib/i386-linux-gnu/libc.so.6+0x18636)
    #9 0x80490fb  (/usr/bin/magick+0x80490fb)

0xb3e0455f is located 3 bytes to the right of 12-byte region [0xb3e04550,0xb3e0455c)
allocated by thread T0 here:
    #0 0xb7254dee in malloc (/usr/lib/i386-linux-gnu/libasan.so.2+0x96dee)
    #1 0xb669c082 in AcquireMagickMemory MagickCore/memory.c:468

SUMMARY: AddressSanitizer: heap-buffer-overflow coders/webp.c:184 IsWEBPImageLossless
Shadow bytes around the buggy address:
  0x367c0850: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
  0x367c0860: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
  0x367c0870: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
  0x367c0880: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
  0x367c0890: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
=>0x367c08a0: fa fa fa fa fa fa fa fa fa fa 00[04]fa fa 00 00
  0x367c08b0: fa fa 00 01 fa fa 06 fa fa fa fd fd fa fa fd fd
  0x367c08c0: fa fa fd fa fa fa 00 00 fa fa 00 03 fa fa 05 fa
  0x367c08d0: fa fa 05 fa fa fa 00 00 fa fa 05 fa fa fa fd fa
  0x367c08e0: fa fa 05 fa fa fa 00 00 fa fa 07 fa fa fa 00 00
  0x367c08f0: fa fa 02 fa fa fa 00 00 fa fa 03 fa fa fa 00 00
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
==11686==ABORTING

@urban-warrior
Copy link
Contributor

Thanks for the problem report. We can reproduce it and will have a patch to fix it in GIT master branch @ https://github.com/ImageMagick/ImageMagick later today. The patch will be available in the beta releases of ImageMagick @ https://www.imagemagick.org/download/beta/ by sometime tomorrow.

@nohmask
Copy link

nohmask commented Apr 2, 2018

This was assigned CVE-2018-9135.

@SmileBugs
Copy link
Author

credit: zxsoft security team.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

3 participants