From 25aabc2b8ee1e19ced6f4da9d866cf9378fc4c5a Mon Sep 17 00:00:00 2001 From: Christian Brabandt Date: Tue, 14 Nov 2023 19:31:34 +0100 Subject: [PATCH] patch 9.0.2106: [security]: Use-after-free in win_close() Problem: [security]: Use-after-free in win_close() Solution: Check window is valid, before accessing it If the current window structure is no longer valid (because a previous autocommand has already freed this window), fail and return before attempting to set win->w_closing variable. Add a test to trigger ASAN in CI Signed-off-by: Christian Brabandt --- src/testdir/crash/poc1 | Bin 0 -> 3264 bytes src/testdir/test_crash.vim | 33 +++++++++++++++++++++++++++++++++ src/version.c | 2 ++ src/window.c | 2 ++ 4 files changed, 37 insertions(+) create mode 100644 src/testdir/crash/poc1 diff --git a/src/testdir/crash/poc1 b/src/testdir/crash/poc1 new file mode 100644 index 0000000000000000000000000000000000000000..ec223f16b8803b676e4c47620190a77f13a18e93 GIT binary patch literal 3264 zc-rk&O=uHA6rM`%M9u|<@` zLlM(TJ&Jl04C=*0y$U_)C5Ilodlv*zXz68rvs-Ig+xkP$3Vx8?H#6UxdEdZkW2!I4cz-zyWZfBTMR+_O37^E;D6lnyfdq>#~_S-o}!Aa?E7i znxR-dDxd7eUaJS>oNcg^xpY65l?x_kZH!OykR^v$$0j-RBBz5-ZjCWnS6V{d@<=Y- z6KZ9UzQU4Xt(2w=r$%Kx!_}-cDx0m4l2tZgW_x)$tMZo1;iSziTg1`W(b&;&ED}y~ z(+sx)V_eBH(Ezuua1vP$T-Mf7cMu22$O0I2X-?n;{$9;_Xl`zfEzr96=>gtE5g){Z zP57SAs)K{QpSt3mp$O*|Ex#+5%Y)zH9&O}TX`M)tC~aAOQ%~tWT*!Yu5(Zq7(WP@3 zF@i^AYB3pkb#ylqe0ug<+~#)Bh>v+uT3I+^;qPcHqB>RK-LVVH`}&w+JV` z23b|iYHG)>OHSSixFDp41S+sU5U>dm>V@h(LOt#V0q$_e%vWe)sL46hhH^Z?=89lj zs@yj`Pmzz?6(!hP@|+8sYc?0%YlY~N5F4ERZTExqk>9yvFMs3&i2Qnw+T2xtr-V0O ugN0QToNJr&pZwIU+s4ix{u_2)f$ePPBwzYhvAykl '.. result .. "\") + call TermWait(buf, 150) + + " clean up + exe buf .. "bw!" + + exe "sp " .. result + + let expected = [ + \ 'crash 1: [OK]', + \ ] + + call assert_equal(expected, getline(1, '$')) + bw! + + call delete(result) +endfunc + func Test_crash2() " The following used to crash Vim let opts = #{wait_for_ruler: 0, rows: 20} diff --git a/src/version.c b/src/version.c index f9d1593c0d..ec021985f2 100644 --- a/src/version.c +++ b/src/version.c @@ -704,6 +704,8 @@ static char *(features[]) = static int included_patches[] = { /* Add new patch number below this line */ +/**/ + 2106, /**/ 2105, /**/ diff --git a/src/window.c b/src/window.c index f77ede330d..55ce31c886 100644 --- a/src/window.c +++ b/src/window.c @@ -2682,6 +2682,8 @@ win_close(win_T *win, int free_buf) reset_VIsual_and_resel(); // stop Visual mode other_buffer = TRUE; + if (!win_valid(win)) + return FAIL; win->w_closing = TRUE; apply_autocmds(EVENT_BUFLEAVE, NULL, NULL, FALSE, curbuf); if (!win_valid(win)) -- 2.47.3