Heap-based Buffer Overflow in vim/vim
Reported on
Jan 18th 2022
Description
Heap-buffer-overflow in vim
Proof of Concept
./vim -u NONE -X -Z -e -s -S poc3 -c :qa!
POC3 is here.
Bt
==728741==ERROR: AddressSanitizer: heap-buffer-overflow on address 0x621000025500 at pc 0x0000008961b2 bp 0x7ffca76ad0b0 sp 0x7ffca76ad0a8
READ of size 1 at 0x621000025500 thread T0
#0 0x8961b1 in utf_head_off /home/zxq/CVE_testing/ASAN-install/vim/src/mbyte.c:3866:9
#1 0x989caa in block_insert /home/zxq/CVE_testing/ASAN-install/vim/src/ops.c:538:9
#2 0x9891ee in op_insert /home/zxq/CVE_testing/ASAN-install/vim/src/ops.c:1704:7
#3 0x99f0ae in do_pending_operator /home/zxq/CVE_testing/ASAN-install/vim/src/ops.c:4179:3
#4 0x935dfe in normal_cmd /home/zxq/CVE_testing/ASAN-install/vim/src/normal.c:1146:2
#5 0x71372b in exec_normal /home/zxq/CVE_testing/ASAN-install/vim/src/ex_docmd.c:8638:6
#6 0x7132da in exec_normal_cmd /home/zxq/CVE_testing/ASAN-install/vim/src/ex_docmd.c:8601:5
#7 0x71300d in ex_normal /home/zxq/CVE_testing/ASAN-install/vim/src/ex_docmd.c:8519:6
#8 0x6ed643 in do_one_cmd /home/zxq/CVE_testing/ASAN-install/vim/src/ex_docmd.c:2573:2
#9 0x6e043c in do_cmdline /home/zxq/CVE_testing/ASAN-install/vim/src/ex_docmd.c:993:17
#10 0xb53dd5 in do_source /home/zxq/CVE_testing/ASAN-install/vim/src/scriptfile.c:1512:5
#11 0xb513ea in cmd_source /home/zxq/CVE_testing/ASAN-install/vim/src/scriptfile.c:1098:14
#12 0xb51140 in ex_source /home/zxq/CVE_testing/ASAN-install/vim/src/scriptfile.c:1124:2
#13 0x6ed643 in do_one_cmd /home/zxq/CVE_testing/ASAN-install/vim/src/ex_docmd.c:2573:2
#14 0x6e043c in do_cmdline /home/zxq/CVE_testing/ASAN-install/vim/src/ex_docmd.c:993:17
#15 0x6e3a53 in do_cmdline_cmd /home/zxq/CVE_testing/ASAN-install/vim/src/ex_docmd.c:587:12
#16 0xf6bf78 in exe_commands /home/zxq/CVE_testing/ASAN-install/vim/src/main.c:3091:2
#17 0xf690cd in vim_main2 /home/zxq/CVE_testing/ASAN-install/vim/src/main.c:774:2
#18 0xf61baf in main /home/zxq/CVE_testing/ASAN-install/vim/src/main.c:426:12
#19 0x7f6f765e20b2 in __libc_start_main /build/glibc-eX1tMB/glibc-2.31/csu/../csu/libc-start.c:308:16
#20 0x41ee8d in _start (/home/zxq/CVE_testing/ASAN-install/vim/src/vim+0x41ee8d)
0x621000025500 is located 0 bytes to the right of 4096-byte region [0x621000024500,0x621000025500)
allocated by thread T0 here:
#0 0x4975cd in malloc (/home/zxq/CVE_testing/ASAN-install/vim/src/vim+0x4975cd)
#1 0x4c70fd in lalloc /home/zxq/CVE_testing/ASAN-install/vim/src/alloc.c:248:11
#2 0x4c7049 in alloc /home/zxq/CVE_testing/ASAN-install/vim/src/alloc.c:151:12
#3 0xf72e94 in mf_alloc_bhdr /home/zxq/CVE_testing/ASAN-install/vim/src/memfile.c:884:21
#4 0xf721fe in mf_new /home/zxq/CVE_testing/ASAN-install/vim/src/memfile.c:376:26
#5 0x8a77e3 in ml_new_data /home/zxq/CVE_testing/ASAN-install/vim/src/memline.c:4077:15
#6 0x8c1b04 in ml_append_int /home/zxq/CVE_testing/ASAN-install/vim/src/memline.c:2982:16
#7 0x8b9e09 in ml_append_flush /home/zxq/CVE_testing/ASAN-install/vim/src/memline.c:3322:12
#8 0x8b9cc6 in ml_append_flags /home/zxq/CVE_testing/ASAN-install/vim/src/memline.c:3357:12
#9 0x8b66c7 in ml_append /home/zxq/CVE_testing/ASAN-install/vim/src/memline.c:3344:12
#10 0x7660d8 in readfile /home/zxq/CVE_testing/ASAN-install/vim/src/fileio.c:2235:8
#11 0x71ea46 in ex_read /home/zxq/CVE_testing/ASAN-install/vim/src/ex_docmd.c:7255:10
#12 0x6ed643 in do_one_cmd /home/zxq/CVE_testing/ASAN-install/vim/src/ex_docmd.c:2573:2
#13 0x6e043c in do_cmdline /home/zxq/CVE_testing/ASAN-install/vim/src/ex_docmd.c:993:17
#14 0xb53dd5 in do_source /home/zxq/CVE_testing/ASAN-install/vim/src/scriptfile.c:1512:5
#15 0xb513ea in cmd_source /home/zxq/CVE_testing/ASAN-install/vim/src/scriptfile.c:1098:14
#16 0xb51140 in ex_source /home/zxq/CVE_testing/ASAN-install/vim/src/scriptfile.c:1124:2
#17 0x6ed643 in do_one_cmd /home/zxq/CVE_testing/ASAN-install/vim/src/ex_docmd.c:2573:2
#18 0x6e043c in do_cmdline /home/zxq/CVE_testing/ASAN-install/vim/src/ex_docmd.c:993:17
#19 0x6e3a53 in do_cmdline_cmd /home/zxq/CVE_testing/ASAN-install/vim/src/ex_docmd.c:587:12
#20 0xf6bf78 in exe_commands /home/zxq/CVE_testing/ASAN-install/vim/src/main.c:3091:2
#21 0xf690cd in vim_main2 /home/zxq/CVE_testing/ASAN-install/vim/src/main.c:774:2
#22 0xf61baf in main /home/zxq/CVE_testing/ASAN-install/vim/src/main.c:426:12
#23 0x7f6f765e20b2 in __libc_start_main /build/glibc-eX1tMB/glibc-2.31/csu/../csu/libc-start.c:308:16
SUMMARY: AddressSanitizer: heap-buffer-overflow /home/zxq/CVE_testing/ASAN-install/vim/src/mbyte.c:3866:9 in utf_head_off
Shadow bytes around the buggy address:
0x0c427fffca50: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
0x0c427fffca60: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
0x0c427fffca70: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
0x0c427fffca80: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
0x0c427fffca90: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
=>0x0c427fffcaa0:[fa]fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
0x0c427fffcab0: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
0x0c427fffcac0: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
0x0c427fffcad0: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
0x0c427fffcae0: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
0x0c427fffcaf0: 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
==728741==ABORTING
The POC is much too long. Please reduce it to the minimal necessary to reproduce the problem.
I can reproduce it now. The POC is still long and a bit obscure, especially because it reads itself. I'll see if I can come up with a simpler test.
Fixed with patch 8.2.4151. The test didn't trigger a valgrind error, could not make it cover the actual problem.