CVE-2026-139785: mm/vma: avoid losing atomic VMA flags when setting sticky VMA flags
In the Linux kernel, the following vulnerability has been resolved:
mm/vma: avoid losing atomic VMA flags when setting sticky VMA flags
vmamergeexistingrange() merges an existing VMA (middle) when its attributes have changed to match those of one or both adjacent VMAs.
Sticky flags are propagated if they are set in any of the merged VMAs. They are initialised from vmg->vmaflags, which is assumed to contain middle's sticky flags when the function is invoked.
However, the VMA write lock is not held for middle when they are first populated, so concurrent updates to atomic VMA flags may occur, which will be lost upon merge.
This can result in fork failing to propagate guard region markers and (if file-backed) THP collapse discarding them.
Resolve this by propagating the sticky flags after middle is locked.
Make life easier by factoring this into propagatestickyflags(), which treats vmg->vmaflags as its base (in case any sticky flags are set there), updating it as sticky flags are accumulated from merged VMAs.
Also update vmaexpand() to use propagatestickyflags() so all merge paths utilise it.
propagatestickyflags() also asserts that the VMA write lock is held for the VMA whose sticky flags are being read, with a comment explaining why.
Another means by which atomic VMA flags can fail to be observed is when the merge is finalised in commitmerge().
rmap locks are dropped in vmacomplete() before the sticky flags are written, meaning an rmap walker can observe the VMA without sticky flags set, which can also result in retractpagetables() discarding guard markers.
Resolve this by assigning the sticky flags before dropping rmap locks, factored into commitstickyflags() with a write assert on the VMA being written to.
Also remove the vmasetflagsmask() invocation at the end of vmamergeexistingrange() as this was introduced by commit 64212ba02e66 ("mm: implement sticky VMA flags") to propagate sticky flags, which is now redundant with the introduction of commitstickyflags().
The vmasetflagsmask() invocation at the end of vmaexpand() setting sticky flags only is also removed for the same reason.
Also update vmamergeexistingrange()'s comment to reflect the fact that vmg->vmaflags gets updated.
Finally, update the userland VMA tests to reflect a previously missed const-ification in vmaassertwritelocked() which would otherwise cause a warning when building them.
Affected Software
Remediation
Recommended actions to resolve this vulnerability, in priority order.
- Upgrade
Upgrade
linux/Kernelto a version that resolves this vulnerability.Fixed in 6.18.65 - Upgrade
Upgrade
linux/Kernelto a version that resolves this vulnerability.Fixed in 7.3.6
Event History
Frequently Asked Questions
Under what conditions can the issue occur?
It can occur when an existing middle VMA is merged because its attributes changed to match adjacent VMAs, while atomic VMA flags are updated concurrently before the middle VMA write lock is held.
What observable effects can result from lost VMA flags?
A fork can fail to propagate guard-region markers. For file-backed mappings, THP collapse can discard those markers.
What does the resolved change do to prevent the loss?
It propagates sticky flags only after the middle VMA is write-locked, preserving concurrently updated atomic VMA flags. The same propagation helper is used for VMA expansion so all merge paths use the corrected handling.