From f7f987912ecc4798249717f9658e1b177f1375fd Mon Sep 17 00:00:00 2001 From: yinyongkang Date: Fri, 2 Aug 2024 09:50:00 +0800 Subject: [PATCH] fix CVE-2024-41957 --- backport-CVE-2024-41957.patch | 62 ++++++++++++++++++++++++++++++++++ double_free | Bin 0 -> 561 bytes vim.spec | 12 ++++++- 3 files changed, 73 insertions(+), 1 deletion(-) create mode 100644 backport-CVE-2024-41957.patch create mode 100644 double_free diff --git a/backport-CVE-2024-41957.patch b/backport-CVE-2024-41957.patch new file mode 100644 index 0000000..4093f5b --- /dev/null +++ b/backport-CVE-2024-41957.patch @@ -0,0 +1,62 @@ +From 8a0bbe7b8aad6f8da28dee218c01bc8a0185a2d5 Mon Sep 17 00:00:00 2001 +From: Christian Brabandt +Date: Thu, 1 Aug 2024 20:16:51 +0200 +Subject: [PATCH] patch 9.1.0647: [security] use-after-free in + tagstack_clear_entry + +Problem: [security] use-after-free in tagstack_clear_entry + (Suyue Guo ) +Solution: Instead of manually calling vim_free() on each of the tagstack + entries, let's use tagstack_clear_entry(), which will + also free the stack, but using the VIM_CLEAR macro, + which prevents a use-after-free by setting those pointers + to NULL + +This addresses CVE-2024-41957 + +Github advisory: +https://github.com/vim/vim/security/advisories/GHSA-f9cr-gv85-hcr4 + +Signed-off-by: Christian Brabandt +--- + src/testdir/test_crash.vim | 6 ++++++ + src/window.c | 5 +---- + 2 files changed, 7 insertions(+), 4 deletions(-) + create mode 100644 src/testdir/crash/double_free + +diff --git a/src/testdir/test_crash.vim b/src/testdir/test_crash.vim +index 5cd07e2a3f0b53a0ec5b766a6f86b1f29fab18e7..6e701dcfad090c8f723f38f4d65327e2b5f2eaed 100644 +--- a/src/testdir/test_crash.vim ++++ b/src/testdir/test_crash.vim +@@ -86,6 +86,12 @@ func Test_crash1() + call delete('Xerr') + call delete('@') + ++ let file = 'crash/double_free' ++ let cmn_args = "%s -u NONE -i NONE -n -e -s -S %s -c ':qa!'\" ++ let args = printf(cmn_args, vim, file) ++ call term_sendkeys(buf, args) ++ call TermWait(buf, 50) ++ + " clean up + exe buf .. "bw!" + +diff --git a/src/window.c b/src/window.c +index 55ce31c8864373303f333d46959354243b85e025..2afa28d66ffb2ed811dfcc32f654562beccc64bc 100644 +--- a/src/window.c ++++ b/src/window.c +@@ -5661,10 +5661,7 @@ win_free( + win_free_lsize(wp); + + for (i = 0; i < wp->w_tagstacklen; ++i) +- { +- vim_free(wp->w_tagstack[i].tagname); +- vim_free(wp->w_tagstack[i].user_data); +- } ++ tagstack_clear_entry(&wp->w_tagstack[i]); + vim_free(wp->w_localdir); + vim_free(wp->w_prevdir); + +-- +2.41.0 + diff --git a/double_free b/double_free new file mode 100644 index 0000000000000000000000000000000000000000..895c4a04b6ab1c2eabc80a486e52cabd7a99a5ea GIT binary patch literal 561 zcmY+BL2DC16vtm$FL@r)OM?`VNi5idX;=tFTegZ#(3FA_g$iA9XET#zWiz{-+3kcR z+8h)-c<|7hpT_Uv_ZVMH6#QM@@PBXKoA)1nT!N}!;A@rCk*nK{qi~J@P`Y>8t4q{~#Di*6H;w(jtG~j{r!x z#3aqYpoj+pgIo_KYyg;mrs*+t$*`Q-X0v(1u%E^Ti}j5W!>AYtFB0B)5P^C!=IhEP z!)mp9s)zTK=uG0=i|@l@%s - 2:9.0.2092-7 +- Type:CVE +- ID:CVE-2024-41957 +- SUG:NA +- DESC:fix CVE-2024-41957 + * Fri Jul 12 2024 wangjiang - 2:9.0.2092-6 - Type:CVE - ID:CVE-2023-48232 -- Gitee