Self-registration is disabled due to spam issue (mail gorcunov@gmail.com or hpa@zytor.com to create an account)
Bug 3392643 - stack-use-after-scope in expand_mmac_params at asm/preproc.c:4931
Summary: stack-use-after-scope in expand_mmac_params at asm/preproc.c:4931
Status: CLOSED FIXED
Alias: None
Product: NASM
Classification: Unclassified
Component: Assembler (show other bugs)
Version: 2.15.xx
Hardware: PC Linux
: Medium normal
Assignee: nobody
URL:
Depends on:
Blocks:
 
Reported: 2020-01-06 01:20 PST by Suhwan
Modified: 2020-08-19 01:47 PDT (History)
4 users (show)

Obtained from: Built from git using configure
Generated by: ---
Bug category:
Breaks existing code: ---


Attachments
poc (1.74 KB, application/octet-stream)
2020-01-06 01:20 PST, Suhwan
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Suhwan 2020-01-06 01:20:23 PST
Created attachment 411754 [details]
poc

Hi, 
I found a stack-use-after-scope in expand_mmac_params at asm/preproc.c:4931
It is triggered in nasm version 2.15.
Please run following command

nasm -o /dev/null -f bin $PoC

Here's ASAN LOG
==30308==ERROR: AddressSanitizer: stack-use-after-scope on address 0x7ffc324707c0 at pc 0x00000062e905 bp 0x7ffc32470790 sp 0x7ffc32470788
WRITE of size 8 at 0x7ffc324707c0 thread T0
    #0 0x62e904 in expand_mmac_params /home/suhwan/project/program/nasm-2.15rc0-20191023/asm/preproc.c:4931:11
    #1 0x5e8123 in pp_tokline /home/suhwan/project/program/nasm-2.15rc0-20191023/asm/preproc.c:6361:21
    #2 0x5e8123 in pp_getline /home/suhwan/project/program/nasm-2.15rc0-20191023/asm/preproc.c:6428
    #3 0x50a7f9 in assemble_file /home/suhwan/project/program/nasm-2.15rc0-20191023/asm/nasm.c:1630:24
    #4 0x50a7f9 in main /home/suhwan/project/program/nasm-2.15rc0-20191023/asm/nasm.c:637
    #5 0x7f2ca11a5b96 in __libc_start_main /build/glibc-OTsEL5/glibc-2.27/csu/../csu/libc-start.c:310
    #6 0x41a4a9 in _start (/mnt/hda2/suhwan/BUG_AFL/ezxml_fuzzing/nasm+0x41a4a9)

Address 0x7ffc324707c0 is located in stack of thread T0 at offset 32 in frame
    #0 0x61fc6f in expand_mmac_params /home/suhwan/project/program/nasm-2.15rc0-20191023/asm/preproc.c:4749

  This frame has 5 object(s):
    [32, 40) 'newlist.i249' (line 979) <== Memory access at offset 32 is inside this variable
    [64, 72) 'newlist.i' (line 1002)
    [96, 104) 'thead' (line 4750)
    [128, 136) 'ep' (line 4816)
    [160, 168) 'ep36' (line 4834)
HINT: this may be a false positive if your program uses some custom stack unwind mechanism or swapcontext
      (longjmp and C++ exceptions *are* supported)
SUMMARY: AddressSanitizer: stack-use-after-scope /home/suhwan/project/program/nasm-2.15rc0-20191023/asm/preproc.c:4931:11 in expand_mmac_params
Shadow bytes around the buggy address:
  0x1000064860a0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
  0x1000064860b0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
  0x1000064860c0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
  0x1000064860d0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
  0x1000064860e0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
=>0x1000064860f0: 00 00 00 00 f1 f1 f1 f1[f8]f2 f2 f2 f8 f2 f2 f2
  0x100006486100: 00 f2 f2 f2 f8 f2 f2 f2 f8 f3 f3 f3 00 00 00 00
  0x100006486110: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
  0x100006486120: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
  0x100006486130: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
  0x100006486140: f1 f1 f1 f1 f8 f2 f2 f2 f8 f2 f2 f2 f8 f2 f2 f2
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
==30308==ABORTING

NASM version 2.15rc0-20191023 compiled on Dec  9 2019
Comment 1 Cyrill Gorcunov 2020-08-19 01:47:47 PDT
Doesn't trigger in nasm-2.15.04rc5-4-g51e23ac7