This service will be undergoing maintenance at 00:00 UTC, 2017-10-23 It is expected to last about 30 minutes
Bug 1466411 - There is a heap based buffer overflow in libsass
There is a heap based buffer overflow in libsass
Status: NEW
Product: Fedora
Classification: Fedora
Component: libsass (Show other bugs)
27
Unspecified Unspecified
unspecified Severity urgent
: ---
: ---
Assigned To: Aurelien Bompard
Fedora Extras Quality Assurance
: Reopened
Depends On:
Blocks:
  Show dependency treegraph
 
Reported: 2017-06-29 10:18 EDT by owl337
Modified: 2017-08-15 05:11 EDT (History)
2 users (show)

See Also:
Fixed In Version:
Doc Type: If docs needed, set a value
Doc Text:
Story Points: ---
Clone Of:
Environment:
Last Closed: 2017-07-11 07:11:59 EDT
Type: Bug
Regression: ---
Mount Type: ---
Documentation: ---
CRM:
Verified Versions:
Category: ---
oVirt Team: ---
RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: ---


Attachments (Terms of Use)
./sassc POC1 (166 bytes, application/x-rar)
2017-06-29 10:18 EDT, owl337
no flags Details

  None (edit)
Description owl337 2017-06-29 10:18:45 EDT
Created attachment 1292899 [details]
./sassc POC1

Description of problem:

The security bug was trigged by function  json_mkstream() at line libsass/src/sass_context.cpp:91.

Version-Release number of selected component (if applicable):

 <= latest

How reproducible:

 ./sassc POC1


Steps to Reproduce:

The debugging information is as follows:

$ ./sassc POC1

=================================================================
==91395==ERROR: AddressSanitizer: heap-buffer-overflow on address 0x61d00001f315 at pc 0x0000004a7ce3 bp 0x7ffce9b5ca00 sp 0x7ffce9b5c1b8
READ of size 78 at 0x61d00001f315 thread T0
    #0 0x4a7ce2  (/home/icy/real/sassc-master-asan/sassc-master/install/bin/sassc+0x4a7ce2)
    #1 0x7fd357425036  (/home/icy/libsass/install/lib/libsass.so.1+0x22c036)
    #2 0x7fd3572b0407  (/home/icy/libsass/install/lib/libsass.so.1+0xb7407)
    #3 0x7fd3572b0fa6  (/home/icy/libsass/install/lib/libsass.so.1+0xb7fa6)
    #4 0x7fd357425878  (/home/icy/libsass/install/lib/libsass.so.1+0x22c878)
    #5 0x7fd357425c58  (/home/icy/libsass/install/lib/libsass.so.1+0x22cc58)
    #6 0x4ddfb5  (/home/icy/real/sassc-master-asan/sassc-master/install/bin/sassc+0x4ddfb5)
    #7 0x4debd5  (/home/icy/real/sassc-master-asan/sassc-master/install/bin/sassc+0x4debd5)
    #8 0x7fd355f84a3f  (/lib/x86_64-linux-gnu/libc.so.6+0x20a3f)
    #9 0x4364f8  (/home/icy/real/sassc-master-asan/sassc-master/install/bin/sassc+0x4364f8)

0x61d00001f315 is located 0 bytes to the right of 2197-byte region [0x61d00001ea80,0x61d00001f315)
allocated by thread T0 here:
    #0 0x4bd4c2  (/home/icy/real/sassc-master-asan/sassc-master/install/bin/sassc+0x4bd4c2)
    #1 0x7fd3573442a3  (/home/icy/libsass/install/lib/libsass.so.1+0x14b2a3)

Shadow bytes around the buggy address:
  0x0c3a7fffbe10: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
  0x0c3a7fffbe20: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
  0x0c3a7fffbe30: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
  0x0c3a7fffbe40: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
  0x0c3a7fffbe50: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
=>0x0c3a7fffbe60: 00 00[05]fa fa fa fa fa fa fa fa fa fa fa fa fa
  0x0c3a7fffbe70: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
  0x0c3a7fffbe80: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
  0x0c3a7fffbe90: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
  0x0c3a7fffbea0: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
  0x0c3a7fffbeb0: 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
  Left alloca redzone:     ca
  Right alloca redzone:    cb
==91395==ABORTING

The GDB debugging information is as follows:

(gdb)set args POC1
(gdb) r
The program being debugged has been started already.
Start it from the beginning? (y or n) y
Starting program: /home/icy/real/sassc-master-asan/sassc-master/install/bin/sassc POC1
[Thread debugging using libthread_db enabled]
Using host libthread_db library "/lib/x86_64-linux-gnu/libthread_db.so.1".
...
(gdb) 
91	        msg_stream << ">> " << std::string(line_beg + move_in, line_end - shorten) << "\n";
(gdb) n
Program received signal SIGSEGV, Segmentation fault.
0xffffffffcc4d7750 in ?? ()
(gdb) c
Continuing.
ASAN:SIGSEGV
=================================================================
==93440==ERROR: AddressSanitizer: SEGV on unknown address 0xffffffffcc4d7750 (pc 0xffffffffcc4d7750 bp 0x7fffffffde20 sp 0x7fffffffd598 T0)

Program received signal SIGSEGV, Segmentation fault.
0x00007ffff6a78cf9 in ?? () from /lib/x86_64-linux-gnu/libgcc_s.so.1
(gdb) bt
#0  0x00007ffff6a78cf9 in ?? () from /lib/x86_64-linux-gnu/libgcc_s.so.1
#1  0x00007ffff6a7a618 in _Unwind_Backtrace () from /lib/x86_64-linux-gnu/libgcc_s.so.1
#2  0x00000000004dc815 in __sanitizer::BufferedStackTrace::SlowUnwindStackWithContext(unsigned long, void*, unsigned long) ()
#3  0x00000000004c16e4 in __asan::ReportSIGSEGV(char const*, __asan::SignalContext const&) ()
#4  0x00000000004bfc7d in __asan::AsanOnSIGSEGV(int, void*, void*) ()
#5  <signal handler called>
#6  0xffffffffcc4d7750 in ?? ()
#7  0x00000000004a7ce3 in memcpy ()
#8  0x00007ffff7b61037 in std::char_traits<char>::copy (__n=78, 
    __s2=0x61d00001f2e6 "{\335gn: {y {\335gn: {y {\335gn: {y {\335gn: {y {\335gn& y ", <incomplete sequence \335>, __s1=<optimized out>) at /usr/include/c++/5/bits/char_traits.h:290
#9  std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >::_S_copy (__n=78, 
    __s=0x61d00001f2e6 "{\335gn: {y {\335gn: {y {\335gn: {y {\335gn: {y {\335gn& y ", <incomplete sequence \335>, __d=<optimized out>) at /usr/include/c++/5/bits/basic_string.h:299
#10 std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >::_S_copy_chars (
    __k2=<optimized out>, 
    __k1=0x61d00001f2e6 "{\335gn: {y {\335gn: {y {\335gn: {y {\335gn: {y {\335gn& y ", <incomplete sequence \335>, __p=<optimized out>) at /usr/include/c++/5/bits/basic_string.h:342
#11 std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >::_M_construct<char*> (
---Type <return> to continue, or q <return> to quit---
    this=0x7fffffffdf60, 
    __beg=0x61d00001f2e6 "{\335gn: {y {\335gn: {y {\335gn: {y {\335gn: {y {\335gn& y ", <incomplete sequence \335>, __end=<optimized out>) at /usr/include/c++/5/bits/basic_string.tcc:229
#12 0x00007ffff79ec408 in std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >::_M_construct_aux<char const*> (__end=<optimized out>, __beg=<optimized out>, this=0x7fffffffdf60)
    at /usr/include/c++/5/bits/basic_string.h:195
#13 std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >::_M_construct<char const*>
    (__end=<optimized out>, __beg=<optimized out>, this=0x7fffffffdf60)
    at /usr/include/c++/5/bits/basic_string.h:214
#14 std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >::basic_string<char const*, void> (__a=..., __end=<optimized out>, __beg=<optimized out>, this=0x7fffffffdf60)
    at /usr/include/c++/5/bits/basic_string.h:538
#15 Sass::handle_error (c_ctx=c_ctx@entry=0x611000009f00) at sass_context.cpp:91
#16 0x00007ffff79ecfa7 in Sass::handle_errors (c_ctx=c_ctx@entry=0x611000009f00) at sass_context.cpp:200
#17 0x00007ffff7b61879 in Sass::sass_parse_block (compiler=0x6040000097d0) at sass_context.cpp:246
#18 sass_compiler_parse (compiler=compiler@entry=0x6040000097d0) at sass_context.cpp:476
#19 0x00007ffff7b61c59 in sass_compile_context (c_ctx=0x611000009f00, cpp_ctx=<optimized out>)
    at sass_context.cpp:364
#20 0x00000000004ddfb6 in compile_file (options=0x60c00000bf80, input_path=<optimized out>, outfile=0x0)
    at sassc.c:145
---Type <return> to continue, or q <return> to quit---
#21 0x00000000004debd6 in main (argc=<optimized out>, argv=<optimized out>) at sassc.c:335
(gdb) 

The bug was trigged by function  json_mkstream() at line libsass/src/sass_context.cpp:91.

namespace Sass {
  // see sass_copy_c_string(std::string str)
  static inline JsonNode* json_mkstream(const std::stringstream& stream)
  {
    // hold on to string on stack!
 82         while (line_end && *line_end && *line_end != '\n') {
 83           if (*line_end == '\n') break;
 84           if (*line_end == '\r') break;
 85           line_end++;
 86         }
 87         size_t max_left = 42; size_t max_right = 78;
 88         size_t move_in = e.pstate.column > max_left ? e.pstate.column - max_left : 0;
 89         size_t shorten = (line_end - line_beg) - move_in > max_right ?
 90           (line_end - line_beg) - move_in - max_right : 0;
 91         msg_stream << ">> " << std::string(line_beg + move_in, line_end - shorten) << "\n";
 92         msg_stream << "   " << std::string(e.pstate.column - move_in, '-') << "^\n";
 93       }


Actual results:

crash

Expected results:

crash

Additional info:

This vulnerability is detected by team OWL337, with our custom fuzzer collAFL. Please contact ganshuitao@gmail.com   and chaoz@tsinghua.edu.cn if you need more info about the team, the tool or the vulnerability.
Comment 3 Jan Kurik 2017-08-15 05:11:04 EDT
This bug appears to have been reported against 'rawhide' during the Fedora 27 development cycle.
Changing version to '27'.

Note You need to log in before you can comment on or make changes to this bug.