Out-of-bounds Read in function get_lisp_indent in vim/vim

Valid

Reported on

Jun 20th 2022


Description

Out-of-bounds Read in function get_lisp_indent at indent.c:2083

vim version

git log
commit e366ed4f2c6fa8cb663f1b9599b39d57ddbd8a2a (HEAD -> master, tag: v8.2.5136, origin/master, origin/HEAD)

POC

./vim -u NONE -i NONE -n -m -X -Z -e -s -S /mnt/share/max/fuzz/poc/vim/poc_obr2_s.dat -c :qa!


=================================================================
==11737==ERROR: AddressSanitizer: heap-buffer-overflow on address 0x621000013d00 at pc 0x0000009a1d14 bp 0x7fffffff6a70 sp 0x7fffffff6a68
READ of size 1 at 0x621000013d00 thread T0
    #0 0x9a1d13 in get_lisp_indent /home/fuzz/fuzz/vim/afl/src/indent.c:2083:14
    #1 0x99f321 in op_reindent /home/fuzz/fuzz/vim/afl/src/indent.c:1101:16
    #2 0xbb0d6d in do_pending_operator /home/fuzz/fuzz/vim/afl/src/ops.c:4057:7
    #3 0xb1fd43 in normal_cmd /home/fuzz/fuzz/vim/afl/src/normal.c:961:2
    #4 0x814fee in exec_normal /home/fuzz/fuzz/vim/afl/src/ex_docmd.c:8809:6
    #5 0x814818 in exec_normal_cmd /home/fuzz/fuzz/vim/afl/src/ex_docmd.c:8772:5
    #6 0x8143c9 in ex_normal /home/fuzz/fuzz/vim/afl/src/ex_docmd.c:8690:6
    #7 0x7dd349 in do_one_cmd /home/fuzz/fuzz/vim/afl/src/ex_docmd.c:2570:2
    #8 0x7ca205 in do_cmdline /home/fuzz/fuzz/vim/afl/src/ex_docmd.c:992:17
    #9 0xe5928e in do_source_ext /home/fuzz/fuzz/vim/afl/src/scriptfile.c:1674:5
    #10 0xe55d26 in do_source /home/fuzz/fuzz/vim/afl/src/scriptfile.c:1801:12
    #11 0xe55663 in cmd_source /home/fuzz/fuzz/vim/afl/src/scriptfile.c:1174:14
    #12 0xe54d6e in ex_source /home/fuzz/fuzz/vim/afl/src/scriptfile.c:1200:2
    #13 0x7dd349 in do_one_cmd /home/fuzz/fuzz/vim/afl/src/ex_docmd.c:2570:2
    #14 0x7ca205 in do_cmdline /home/fuzz/fuzz/vim/afl/src/ex_docmd.c:992:17
    #15 0x7cee81 in do_cmdline_cmd /home/fuzz/fuzz/vim/afl/src/ex_docmd.c:586:12
    #16 0x1423142 in exe_commands /home/fuzz/fuzz/vim/afl/src/main.c:3133:2
    #17 0x141f2db in vim_main2 /home/fuzz/fuzz/vim/afl/src/main.c:780:2
    #18 0x14147ed in main /home/fuzz/fuzz/vim/afl/src/main.c:432:12
    #19 0x7ffff7bed082 in __libc_start_main /build/glibc-SzIz7B/glibc-2.31/csu/../csu/libc-start.c:308:16
    #20 0x41ea5d in _start (/home/fuzz/fuzz/vim/afl/src/vim+0x41ea5d)

0x621000013d00 is located 0 bytes to the right of 4096-byte region [0x621000012d00,0x621000013d00)
allocated by thread T0 here:
    #0 0x499cbd in malloc (/home/fuzz/fuzz/vim/afl/src/vim+0x499cbd)
    #1 0x4cb392 in lalloc /home/fuzz/fuzz/vim/afl/src/alloc.c:246:11
    #2 0x4cb27a in alloc /home/fuzz/fuzz/vim/afl/src/alloc.c:151:12
    #3 0x142ca45 in mf_alloc_bhdr /home/fuzz/fuzz/vim/afl/src/memfile.c:884:21
    #4 0x142b857 in mf_new /home/fuzz/fuzz/vim/afl/src/memfile.c:375:26
    #5 0xa61068 in ml_new_data /home/fuzz/fuzz/vim/afl/src/memline.c:4080:15
    #6 0xa5fa11 in ml_open /home/fuzz/fuzz/vim/afl/src/memline.c:394:15
    #7 0x501c9a in open_buffer /home/fuzz/fuzz/vim/afl/src/buffer.c:186:9
    #8 0x142098c in create_windows /home/fuzz/fuzz/vim/afl/src/main.c:2902:9
    #9 0x141ec5a in vim_main2 /home/fuzz/fuzz/vim/afl/src/main.c:711:5
    #10 0x14147ed in main /home/fuzz/fuzz/vim/afl/src/main.c:432:12
    #11 0x7ffff7bed082 in __libc_start_main /build/glibc-SzIz7B/glibc-2.31/csu/../csu/libc-start.c:308:16

SUMMARY: AddressSanitizer: heap-buffer-overflow /home/fuzz/fuzz/vim/afl/src/indent.c:2083:14 in get_lisp_indent
Shadow bytes around the buggy address:
  0x0c427fffa750: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
  0x0c427fffa760: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
  0x0c427fffa770: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
  0x0c427fffa780: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
  0x0c427fffa790: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
=>0x0c427fffa7a0:[fa]fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
  0x0c427fffa7b0: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
  0x0c427fffa7c0: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
  0x0c427fffa7d0: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
  0x0c427fffa7e0: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
  0x0c427fffa7f0: 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
  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
  Shadow gap:              cc
==11737==ABORTING

poc_obr2_s.dat

Impact

This vulnerability is capable of crashing software, modify memory, and possible remote execution.

We are processing your report and will contact the vim team within 24 hours. 6 days ago
We have contacted a member of the vim team and are waiting to hear back 5 days ago
Bram Moolenaar validated this vulnerability 3 days ago

I can reproduce the problem. I can use the POC to create a regression test. It can be simplified a bit more.

TDHX ICS Security has been awarded the disclosure bounty
The fix bounty is now up for grabs
The researcher's credibility has increased: +7
Bram Moolenaar
3 days ago

Maintainer


Fixed with patch 8.2.5151

Bram Moolenaar confirmed that a fix has been merged on 8eba2b 3 days ago
Bram Moolenaar has been awarded the fix bounty
to join this conversation