Heap-based Buffer Overflow in function msg_puts_printf in vim/vim

Valid

Reported on

Jan 3rd 2023


Description

Heap-based Buffer Overflow in function msg_puts_printf at message.c:3058

vim version

git log
commit ea720aea851e645f4c8ec3b20afb27c7ca38184c (HEAD -> master, tag: v9.0.1137, origin/master, origin/HEAD)

POC

./vim -u NONE -i NONE -n -m -X -Z -e -s -S ./poc_hbo01_s.dat -c :qa!
==================================================================
==3042==ERROR: AddressSanitizer: heap-buffer-overflow on address 0x602000006236 at pc 0x000000430c16 bp 0x7ffdc0a8c000 sp 0x7ffdc0a8b7c0
READ of size 7 at 0x602000006236 thread T0
    #0 0x430c15 in strlen (/home/fuzz/vim/src/vim+0x430c15)
    #1 0x14ea6a9 in msg_puts_printf /home/fuzz/vim/src/message.c:3058:20
    #2 0x14dd728 in msg_puts_attr_len /home/fuzz/vim/src/message.c:2226:2
    #3 0x14dcfe0 in msg_outtrans_len_attr /home/fuzz/vim/src/message.c:1696:2
    #4 0x14dd0ad in msg_outtrans_len /home/fuzz/vim/src/message.c:1593:12
    #5 0x887f14 in draw_cmdline /home/fuzz/vim/src/ex_getln.c:3441:2
    #6 0x88990b in put_on_cmdline /home/fuzz/vim/src/ex_getln.c:3599:6
    #7 0x87fcbc in getcmdline_int /home/fuzz/vim/src/ex_getln.c:2435:3
    #8 0x8746ce in getcmdline /home/fuzz/vim/src/ex_getln.c:1551:12
    #9 0xe3ac7a in get_expr_register /home/fuzz/vim/src/register.c:104:16
    #10 0xb8e7b2 in nv_at /home/fuzz/vim/src/normal.c:7178:6
    #11 0xb62f4b in normal_cmd /home/fuzz/vim/src/normal.c:939:5
    #12 0x83d7ae in exec_normal /home/fuzz/vim/src/ex_docmd.c:8888:6
    #13 0x83cfd8 in exec_normal_cmd /home/fuzz/vim/src/ex_docmd.c:8851:5
    #14 0x83cb89 in ex_normal /home/fuzz/vim/src/ex_docmd.c:8769:6
    #15 0x804e61 in do_one_cmd /home/fuzz/vim/src/ex_docmd.c:2581:2
    #16 0x7f1885 in do_cmdline /home/fuzz/vim/src/ex_docmd.c:994:17
    #17 0xea0575 in do_source_ext /home/fuzz/vim/src/scriptfile.c:1672:5
    #18 0xe9cfd6 in do_source /home/fuzz/vim/src/scriptfile.c:1818:12
    #19 0xe9c90c in cmd_source /home/fuzz/vim/src/scriptfile.c:1163:14
    #20 0xe9bfee in ex_source /home/fuzz/vim/src/scriptfile.c:1189:2
    #21 0x804e61 in do_one_cmd /home/fuzz/vim/src/ex_docmd.c:2581:2
    #22 0x7f1885 in do_cmdline /home/fuzz/vim/src/ex_docmd.c:994:17
    #23 0x7f65d1 in do_cmdline_cmd /home/fuzz/vim/src/ex_docmd.c:588:12
    #24 0x14b9732 in exe_commands /home/fuzz/vim/src/main.c:3146:2
    #25 0x14b58ce in vim_main2 /home/fuzz/vim/src/main.c:782:2
    #26 0x14aad69 in main /home/fuzz/vim/src/main.c:433:12
    #27 0x7f4e5c126082 in __libc_start_main /build/glibc-SzIz7B/glibc-2.31/csu/../csu/libc-start.c:308:16
    #28 0x41eaad in _start (/home/fuzz/vim/src/vim+0x41eaad)

0x602000006236 is located 0 bytes to the right of 6-byte region [0x602000006230,0x602000006236)
allocated by thread T0 here:
    #0 0x499d0d in malloc (/home/fuzz/vim/src/vim+0x499d0d)
    #1 0x4cb3ea in lalloc /home/fuzz/vim/src/alloc.c:246:11
    #2 0x4cb2ca in alloc /home/fuzz/vim/src/alloc.c:151:12
    #3 0x88765c in draw_cmdline /home/fuzz/vim/src/ex_getln.c:3374:20
    #4 0x88990b in put_on_cmdline /home/fuzz/vim/src/ex_getln.c:3599:6
    #5 0x87fcbc in getcmdline_int /home/fuzz/vim/src/ex_getln.c:2435:3
    #6 0x8746ce in getcmdline /home/fuzz/vim/src/ex_getln.c:1551:12
    #7 0xe3ac7a in get_expr_register /home/fuzz/vim/src/register.c:104:16
    #8 0xb8e7b2 in nv_at /home/fuzz/vim/src/normal.c:7178:6
    #9 0xb62f4b in normal_cmd /home/fuzz/vim/src/normal.c:939:5
    #10 0x83d7ae in exec_normal /home/fuzz/vim/src/ex_docmd.c:8888:6
    #11 0x83cfd8 in exec_normal_cmd /home/fuzz/vim/src/ex_docmd.c:8851:5
    #12 0x83cb89 in ex_normal /home/fuzz/vim/src/ex_docmd.c:8769:6
    #13 0x804e61 in do_one_cmd /home/fuzz/vim/src/ex_docmd.c:2581:2
    #14 0x7f1885 in do_cmdline /home/fuzz/vim/src/ex_docmd.c:994:17
    #15 0xea0575 in do_source_ext /home/fuzz/vim/src/scriptfile.c:1672:5
    #16 0xe9cfd6 in do_source /home/fuzz/vim/src/scriptfile.c:1818:12
    #17 0xe9c90c in cmd_source /home/fuzz/vim/src/scriptfile.c:1163:14
    #18 0xe9bfee in ex_source /home/fuzz/vim/src/scriptfile.c:1189:2
    #19 0x804e61 in do_one_cmd /home/fuzz/vim/src/ex_docmd.c:2581:2
    #20 0x7f1885 in do_cmdline /home/fuzz/vim/src/ex_docmd.c:994:17
    #21 0x7f65d1 in do_cmdline_cmd /home/fuzz/vim/src/ex_docmd.c:588:12
    #22 0x14b9732 in exe_commands /home/fuzz/vim/src/main.c:3146:2
    #23 0x14b58ce in vim_main2 /home/fuzz/vim/src/main.c:782:2
    #24 0x14aad69 in main /home/fuzz/vim/src/main.c:433:12
    #25 0x7f4e5c126082 in __libc_start_main /build/glibc-SzIz7B/glibc-2.31/csu/../csu/libc-start.c:308:16

SUMMARY: AddressSanitizer: heap-buffer-overflow (/home/fuzz/vim/src/vim+0x430c15) in strlen
Shadow bytes around the buggy address:
  0x0c047fff8bf0: fa fa fd fa fa fa fd fa fa fa fd fa fa fa 06 fa
  0x0c047fff8c00: fa fa fd fa fa fa fd fa fa fa 07 fa fa fa fd fa
  0x0c047fff8c10: fa fa fd fa fa fa fd fa fa fa fd fa fa fa fd fa
  0x0c047fff8c20: fa fa fd fa fa fa fd fa fa fa fd fa fa fa fd fa
  0x0c047fff8c30: fa fa 00 00 fa fa 00 00 fa fa 05 fa fa fa fd fd
=>0x0c047fff8c40: fa fa 01 fa fa fa[06]fa fa fa fa fa fa fa fa fa
  0x0c047fff8c50: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
  0x0c047fff8c60: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
  0x0c047fff8c70: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
  0x0c047fff8c80: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
  0x0c047fff8c90: 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
==3042==ABORTING

poc_hbo01_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 5 days ago

I can reproduce it.

Uinitech has been awarded the disclosure bounty
The fix bounty is now up for grabs
The researcher's credibility has increased: +7
Bram Moolenaar marked this as fixed in 9.0.1144 with commit c32949 5 days ago
Bram Moolenaar has been awarded the fix bounty
This vulnerability has been assigned a CVE
Bram Moolenaar published this vulnerability 5 days ago
message.c#L3058 has been validated
to join this conversation