Use After Free in vim/vim
Description
A use-after-free vulnerability in Vim's command-line window and BufEnter autocmd can lead to memory corruption when a freed buffer pointer is accessed.
AI Insight
LLM-synthesized narrative grounded in this CVE's description and references.
A use-after-free vulnerability in Vim's command-line window and BufEnter autocmd can lead to memory corruption when a freed buffer pointer is accessed.
Vulnerability
A use-after-free vulnerability exists in Vim prior to version 9.0.0490. The bug is located in the getcmdline_int() function, where a pointer (b_im_ptr) to a buffer's b_p_iminsert or b_p_imsearch field was stored without tracking which buffer it belongs to. When the command-line window (cmdwin) triggers a BufEnter autocmd, the buffer can be freed, leaving the pointer dangling. The patch introduces a new variable b_im_ptr_buf to validate the buffer before dereferencing.
Exploitation
An attacker can exploit this vulnerability by crafting a sequence of Vim commands that trigger the command-line window with a BufEnter autocmd, which causes the target buffer to be freed. The attacker must be able to execute arbitrary Vim commands (e.g., via a malicious file that sets up autocmds and runs :normal). The race window involves the freed buffer's memory being reused before the dangling pointer is accessed.
Impact
Successful exploitation allows an attacker to access freed memory, leading to a use-after-free condition. This can result in memory corruption, potentially enabling arbitrary code execution or causing a denial of service crash. The attacker gains the privilege level of the Vim process.
Mitigation
The vulnerability is fixed in Vim version 9.0.0490, released on 2022-09-18 [1]. Users should upgrade to this version or later. No workarounds are available for earlier versions. Fedora package announcements are available but do not provide further details [2][3][4].
AI Insight generated on May 27, 2026. Synthesized from this CVE's description and the cited reference URLs; citations are validated against the source bundle.
Affected products
41- osv-coords39 versionspkg:rpm/opensuse/vim&distro=openSUSE%20Leap%2015.3pkg:rpm/opensuse/vim&distro=openSUSE%20Leap%2015.4pkg:rpm/opensuse/vim&distro=openSUSE%20Leap%20Micro%205.2pkg:rpm/opensuse/vim&distro=openSUSE%20Leap%20Micro%205.3pkg:rpm/opensuse/vim&distro=openSUSE%20Tumbleweedpkg:rpm/suse/vim&distro=SUSE%20Enterprise%20Storage%206pkg:rpm/suse/vim&distro=SUSE%20Enterprise%20Storage%207pkg:rpm/suse/vim&distro=SUSE%20Linux%20Enterprise%20High%20Performance%20Computing%2015%20SP1-ESPOSpkg:rpm/suse/vim&distro=SUSE%20Linux%20Enterprise%20High%20Performance%20Computing%2015%20SP1-LTSSpkg:rpm/suse/vim&distro=SUSE%20Linux%20Enterprise%20High%20Performance%20Computing%2015%20SP2-ESPOSpkg:rpm/suse/vim&distro=SUSE%20Linux%20Enterprise%20High%20Performance%20Computing%2015%20SP2-LTSSpkg:rpm/suse/vim&distro=SUSE%20Linux%20Enterprise%20High%20Performance%20Computing%2015-ESPOSpkg:rpm/suse/vim&distro=SUSE%20Linux%20Enterprise%20High%20Performance%20Computing%2015-LTSSpkg:rpm/suse/vim&distro=SUSE%20Linux%20Enterprise%20Micro%205.1pkg:rpm/suse/vim&distro=SUSE%20Linux%20Enterprise%20Micro%205.2pkg:rpm/suse/vim&distro=SUSE%20Linux%20Enterprise%20Micro%205.3pkg:rpm/suse/vim&distro=SUSE%20Linux%20Enterprise%20Module%20for%20Basesystem%2015%20SP3pkg:rpm/suse/vim&distro=SUSE%20Linux%20Enterprise%20Module%20for%20Basesystem%2015%20SP4pkg:rpm/suse/vim&distro=SUSE%20Linux%20Enterprise%20Module%20for%20Desktop%20Applications%2015%20SP3pkg:rpm/suse/vim&distro=SUSE%20Linux%20Enterprise%20Module%20for%20Desktop%20Applications%2015%20SP4pkg:rpm/suse/vim&distro=SUSE%20Linux%20Enterprise%20Server%2012%20SP2-BCLpkg:rpm/suse/vim&distro=SUSE%20Linux%20Enterprise%20Server%2012%20SP3-BCLpkg:rpm/suse/vim&distro=SUSE%20Linux%20Enterprise%20Server%2012%20SP4-LTSSpkg:rpm/suse/vim&distro=SUSE%20Linux%20Enterprise%20Server%2012%20SP5pkg:rpm/suse/vim&distro=SUSE%20Linux%20Enterprise%20Server%2015%20SP1-BCLpkg:rpm/suse/vim&distro=SUSE%20Linux%20Enterprise%20Server%2015%20SP1-LTSSpkg:rpm/suse/vim&distro=SUSE%20Linux%20Enterprise%20Server%2015%20SP2-BCLpkg:rpm/suse/vim&distro=SUSE%20Linux%20Enterprise%20Server%2015%20SP2-LTSSpkg:rpm/suse/vim&distro=SUSE%20Linux%20Enterprise%20Server%2015-LTSSpkg:rpm/suse/vim&distro=SUSE%20Linux%20Enterprise%20Server%20for%20SAP%20Applications%2012%20SP4pkg:rpm/suse/vim&distro=SUSE%20Linux%20Enterprise%20Server%20for%20SAP%20Applications%2012%20SP5pkg:rpm/suse/vim&distro=SUSE%20Linux%20Enterprise%20Server%20for%20SAP%20Applications%2015pkg:rpm/suse/vim&distro=SUSE%20Linux%20Enterprise%20Server%20for%20SAP%20Applications%2015%20SP1pkg:rpm/suse/vim&distro=SUSE%20Linux%20Enterprise%20Server%20for%20SAP%20Applications%2015%20SP2pkg:rpm/suse/vim&distro=SUSE%20Manager%20Proxy%204.1pkg:rpm/suse/vim&distro=SUSE%20Manager%20Retail%20Branch%20Server%204.1pkg:rpm/suse/vim&distro=SUSE%20Manager%20Server%204.1pkg:rpm/suse/vim&distro=SUSE%20OpenStack%20Cloud%209pkg:rpm/suse/vim&distro=SUSE%20OpenStack%20Cloud%20Crowbar%209
< 9.0.0814-150000.5.28.1+ 38 more
- (no CPE)range: < 9.0.0814-150000.5.28.1
- (no CPE)range: < 9.0.0814-150000.5.28.1
- (no CPE)range: < 9.0.0814-150000.5.28.1
- (no CPE)range: < 9.0.0814-150000.5.28.1
- (no CPE)range: < 9.0.0500-1.1
- (no CPE)range: < 9.0.0814-150000.5.28.1
- (no CPE)range: < 9.0.0814-150000.5.28.1
- (no CPE)range: < 9.0.0814-150000.5.28.1
- (no CPE)range: < 9.0.0814-150000.5.28.1
- (no CPE)range: < 9.0.0814-150000.5.28.1
- (no CPE)range: < 9.0.0814-150000.5.28.1
- (no CPE)range: < 9.0.0814-150000.5.28.1
- (no CPE)range: < 9.0.0814-150000.5.28.1
- (no CPE)range: < 9.0.0814-150000.5.28.1
- (no CPE)range: < 9.0.0814-150000.5.28.1
- (no CPE)range: < 9.0.0814-150000.5.28.1
- (no CPE)range: < 9.0.0814-150000.5.28.1
- (no CPE)range: < 9.0.0814-150000.5.28.1
- (no CPE)range: < 9.0.0814-150000.5.28.1
- (no CPE)range: < 9.0.0814-150000.5.28.1
- (no CPE)range: < 9.0.0814-17.9.1
- (no CPE)range: < 9.0.0814-17.9.1
- (no CPE)range: < 9.0.0814-17.9.1
- (no CPE)range: < 9.0.0814-17.9.1
- (no CPE)range: < 9.0.0814-150000.5.28.1
- (no CPE)range: < 9.0.0814-150000.5.28.1
- (no CPE)range: < 9.0.0814-150000.5.28.1
- (no CPE)range: < 9.0.0814-150000.5.28.1
- (no CPE)range: < 9.0.0814-150000.5.28.1
- (no CPE)range: < 9.0.0814-17.9.1
- (no CPE)range: < 9.0.0814-17.9.1
- (no CPE)range: < 9.0.0814-150000.5.28.1
- (no CPE)range: < 9.0.0814-150000.5.28.1
- (no CPE)range: < 9.0.0814-150000.5.28.1
- (no CPE)range: < 9.0.0814-150000.5.28.1
- (no CPE)range: < 9.0.0814-150000.5.28.1
- (no CPE)range: < 9.0.0814-150000.5.28.1
- (no CPE)range: < 9.0.0814-17.9.1
- (no CPE)range: < 9.0.0814-17.9.1
Patches
0No patches discovered yet.
Vulnerability mechanics
Root cause
"Use-after-free: a pointer (`b_im_ptr`) into the current buffer is cached but not invalidated when a `BufEnter` autocommand switches buffers during command-line editing, causing the pointer to reference freed memory."
Attack vector
An attacker can trigger a use-after-free by crafting a file that, when opened, causes a `BufEnter` autocommand to switch buffers while the command-line window (`cmdwin`) is active. The sequence is: open a file that sets up a `BufEnter` autocommand (e.g., `au BufEnter * next 0| file`), then enter command-line mode (e.g., with `q/`). When the autocommand fires during command-line editing, `curbuf` changes and the previously saved `b_im_ptr` points into freed memory. The attacker does not need authentication if they can trick a victim into opening the crafted file [ref_id=1].
Affected code
The vulnerability is in the `getcmdline_int()` function in Vim's command-line editing code. The patch shows that a pointer `b_im_ptr` was stored pointing into `curbuf` (the current buffer), but when a `BufEnter` autocommand switches buffers during command-line editing, `curbuf` changes and `b_im_ptr` becomes a dangling pointer to freed memory. The fix introduces a companion variable `b_im_ptr_buf` to track which buffer the pointer belongs to, and adds `buf_valid()` checks before dereferencing `b_im_ptr`.
What the fix does
The patch introduces `b_im_ptr_buf`, a pointer to the buffer that `b_im_ptr` belongs to, set alongside `b_im_ptr` at initialization. Before dereferencing `b_im_ptr` in the `Ctrl_HAT` handler and in the `im_save_status` call, the code now checks `buf_valid(b_im_ptr_buf)` — if the buffer has been freed, `b_im_ptr` is treated as NULL (or skipped) instead of being used as a dangling pointer. This closes the use-after-free by ensuring the pointer is only used when its originating buffer is still valid [ref_id=1].
Preconditions
- inputVictim must open a file that defines a BufEnter autocommand which switches buffers
- authAttacker must trick the victim into opening the crafted file (no authentication required)
Generated on May 28, 2026. Inputs: CWE entries + fix-commit diffs from this CVE's patches. Citations validated against bundle.
References
7- lists.fedoraproject.org/archives/list/package-announce%40lists.fedoraproject.org/message/4QI7AETXBHPC7SGA77Q7O5IEGULWYET7/mitrevendor-advisory
- lists.fedoraproject.org/archives/list/package-announce%40lists.fedoraproject.org/message/GTBVD4J2SKVSWK4VBN5JP5OEVK6GDS3N/mitrevendor-advisory
- lists.fedoraproject.org/archives/list/package-announce%40lists.fedoraproject.org/message/LSSEWQLK55MCNT4Z2IIJEJYEI5HLCODI/mitrevendor-advisory
- security.gentoo.org/glsa/202305-16mitrevendor-advisory
- lists.debian.org/debian-lts-announce/2022/11/msg00032.htmlmitremailing-list
- github.com/vim/vim/commit/1c3dd8ddcba63c1af5112e567215b3cec2de11d0mitre
- huntr.dev/bounties/96d5f7a0-a834-4571-b73b-0fe523b941afmitre
News mentions
0No linked articles in our index yet.