Use After Free in vim/vim
Description
Vim suffers from a use-after-free vulnerability in the regex engine when processing marks, potentially leading to memory corruption.
AI Insight
LLM-synthesized narrative grounded in this CVE's description and references.
Vim suffers from a use-after-free vulnerability in the regex engine when processing marks, potentially leading to memory corruption.
Vulnerability
The vulnerability is a use-after-free in vim's regexp engine when handling marks (NFA_MARK_GT, NFA_MARK_LT). Specifically, in the nfa_regmatch function, after obtaining a mark position via getmark_buf, the code uses rex.input and rex.line pointers. Under certain conditions, the line referenced by rex.line can be freed, leaving a dangling pointer. The bug affects vim versions prior to patch 8.2.3612 [2]. The issue was introduced by earlier changes that allowed marks to be used in regex patterns.
Exploitation
An attacker can exploit this by crafting a file that, when opened in vim, triggers a regex operation using a mark (e.g., :%s/\'t/). The attacker needs to convince the victim to open the malicious file or execute the pattern. No special privileges are required. The exploit occurs during the pattern matching, causing a use-after-free condition.
Impact
Successful exploitation could lead to memory corruption, potentially allowing arbitrary code execution. However, the exact impact is limited because vim typically runs with user privileges. The vulnerability is categorized as a use-after-free, which commonly leads to denial of service or information disclosure, but code execution is theoretically possible.
Mitigation
The fix was committed in vim patch 8.2.3612 [2] on 2021-11-19 (the same day as the CVE publication). Users should upgrade to vim version 8.2.3612 or later. Fedora and other distributions have backported the patch. No workaround is available; upgrading is recommended.
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
36- osv-coords35 versionspkg:rpm/opensuse/vim&distro=openSUSE%20Leap%2015.3pkg:rpm/opensuse/vim&distro=openSUSE%20Leap%2015.4pkg: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%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
< 8.2.5038-150000.5.21.1+ 34 more
- (no CPE)range: < 8.2.5038-150000.5.21.1
- (no CPE)range: < 8.2.5038-150000.5.21.1
- (no CPE)range: < 8.2.5038-150000.5.21.1
- (no CPE)range: < 8.2.5038-150000.5.21.1
- (no CPE)range: < 8.2.5038-150000.5.21.1
- (no CPE)range: < 8.2.5038-150000.5.21.1
- (no CPE)range: < 8.2.5038-150000.5.21.1
- (no CPE)range: < 8.2.5038-150000.5.21.1
- (no CPE)range: < 8.2.5038-150000.5.21.1
- (no CPE)range: < 8.2.5038-150000.5.21.1
- (no CPE)range: < 8.2.5038-150000.5.21.1
- (no CPE)range: < 8.2.5038-150000.5.21.1
- (no CPE)range: < 8.2.5038-150000.5.21.1
- (no CPE)range: < 8.2.5038-150000.5.21.1
- (no CPE)range: < 8.2.5038-150000.5.21.1
- (no CPE)range: < 8.2.5038-150000.5.21.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: < 8.2.5038-150000.5.21.1
- (no CPE)range: < 8.2.5038-150000.5.21.1
- (no CPE)range: < 8.2.5038-150000.5.21.1
- (no CPE)range: < 8.2.5038-150000.5.21.1
- (no CPE)range: < 8.2.5038-150000.5.21.1
- (no CPE)range: < 9.0.0814-17.9.1
- (no CPE)range: < 9.0.0814-17.9.1
- (no CPE)range: < 8.2.5038-150000.5.21.1
- (no CPE)range: < 8.2.5038-150000.5.21.1
- (no CPE)range: < 8.2.5038-150000.5.21.1
- (no CPE)range: < 8.2.5038-150000.5.21.1
- (no CPE)range: < 8.2.5038-150000.5.21.1
- (no CPE)range: < 8.2.5038-150000.5.21.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: `rex.input` pointer is not updated after `getmark_buf()` may free and reallocate the line buffer."
Attack vector
An attacker can trigger a use-after-free by crafting a regex pattern that uses a mark reference (`\%'` or `\%<` / `\%>`) in a substitution command. When `getmark_buf()` is called, the underlying line buffer may be freed and reallocated, but `rex.input` still points to the old freed memory. The test case in the patch shows the crash with `s/\%')` on a single-line buffer [ref_id=1]. No authentication or special privileges are required beyond the ability to open a file and run a substitution command in Vim.
Affected code
The vulnerability is in `nfa_regmatch()` in Vim's regexp engine. The `rex.input` pointer was stored as an offset into `rex.line`, but after `getmark_buf()` is called the line buffer could be freed and reallocated, leaving `rex.input` pointing into freed memory. The patch changes the `input` field's comment from "points into \"regline\"" to "points into \"line\"" and adds code to re-fetch `rex.line` and recompute `rex.input` after retrieving the mark position [ref_id=1].
What the fix does
The patch adds a `size_t col = rex.input - rex.line;` before the `getmark_buf()` call, then after the call, if `REG_MULTI` is set, it re-fetches `rex.line` via `reg_getline(rex.lnum)` and recomputes `rex.input = rex.line + col;`. This ensures that even if the line buffer was freed and reallocated by `getmark_buf()`, the `input` pointer is recalculated to point into the valid new buffer. The comment change from "points into \"regline\"" to "points into \"line\"" reflects that the pointer is now relative to `rex.line` rather than the old `regline` field [ref_id=1].
Preconditions
- inputUser must open a file in Vim and execute a substitution command with a regex pattern containing a mark reference (e.g., `s/\%')`).
- configThe regex engine must be in NFA mode (the default in many Vim builds).
Generated on May 29, 2026. Inputs: CWE entries + fix-commit diffs from this CVE's patches. Citations validated against bundle.
References
8- lists.fedoraproject.org/archives/list/package-announce%40lists.fedoraproject.org/message/FNXY7T5OORA7UJIMGSJBGHFMU6UZWS6P/mitrevendor-advisory
- lists.fedoraproject.org/archives/list/package-announce%40lists.fedoraproject.org/message/IH2LS2DXBTYOCWGAKFMBF3HTWWXPBEFL/mitrevendor-advisory
- security.gentoo.org/glsa/202208-32mitrevendor-advisory
- www.openwall.com/lists/oss-security/2022/01/15/1mitremailing-list
- lists.debian.org/debian-lts-announce/2022/03/msg00018.htmlmitremailing-list
- lists.debian.org/debian-lts-announce/2022/11/msg00009.htmlmitremailing-list
- github.com/vim/vim/commit/64066b9acd9f8cffdf4840f797748f938a13f2d6mitre
- huntr.dev/bounties/e402cb2c-8ec4-4828-a692-c95f8e0de6d4mitre
News mentions
0No linked articles in our index yet.