CVE-2026-99697: mm: memcontrol: fix NULL pointer deref and UAF from high_work_func() on dying memcg
In the Linux kernel, the following vulnerability has been resolved:
mm: memcontrol: fix NULL pointer deref and UAF from highworkfunc() on dying memcg
When memory.high is exceeded in non-task context, trychargememcg() schedules memcg->highwork without taking a reference on the memcg, and highworkfunc() invokes reclaimhigh() without pinning the memcg.
With objcgroup reparenting, introduced in commit bf4f059954dc ("mm: memcg/slab: objcgroup API"), objects charged to a child memcg are reparented to its parent in memcgroupcssoffline() instead of holding a reference on the child until uncharged. Subsequent uncharges of those objects go to the parent, which can leave the child's memory use permanently above its high limit, so any later charge on the offlined memcg in non-task context schedules highwork. This was later widened from kernel memory to LRU folios when commit f1cf8d2f36dc ("mm: memcontrol: eliminate the problem of dying memory cgroup for LRU folios") converted LRU folios to use objcgroup reparenting.
cancelworksync(&memcg->highwork) only runs at the end of teardown in memcgroupcssfree(), so highworkfunc() can start or still be running reclaimhigh() after memcgroupcssreleased() or shrinkmany() has called lrugenreleasememcg() and unhashed lruvec->lrugen.list. If reclaim tries to rotate the memcg, lrugenrotatememcg() dereferences a NULL pprev pointer. This issue is specific to MGLRU and was introduced with the memcg LRU in commit e4dde56cd208 ("mm: multi-gen LRU: per-node lrugenfolio lists").
With either traditional LRU or MGLRU, cssfreerworkfn() calls cssrstatexit() which frees per-CPU rstat data before calling memcgroupcssfree(). If reclaimhigh() is still running, rstat updates via modlruvecstate() -> cssrstatupdated() cause a use-after-free on the per-CPU rstat data. This was introduced when commit 5da3bfa029d6 ("cgroup: use separate rstat trees for each subsystem") moved cssrstatexit() ahead of ss->cssfree().
Fix both problems by acquiring a reference with csstrygetonline() in highworkfunc() before calling reclaimhigh(), and by resetting memory.high and swap.high to PAGECOUNTERMAX in memcgroupcssoffline() so that charges via references on an offlined memcg do not trigger highwork on the dead child and skip checking live ancestors in trychargememcg().
Acquiring the reference in highworkfunc() rather than before scheduling highwork is safe because memcgroupcssfree() calls irqworksync() and cancelworksync() which cancels pending work and waits for an already running highworkfunc() to complete before memcgroupfree() frees the memcg. csstrygetonline() uses percpureftrygetlive() and is safe to call after percpurefexit() before the cgroup is freed unlike csstryget().
Oops: general protection fault, probably for non-canonical address 0xdffffc0000000000: 0000 [#1] SMP KASAN NOPTI KASAN: null-ptr-deref in range [0x0000000000000000-0x0000000000000007] CPU: 1 UID: 0 PID: 27 Comm: kworker/1:0 Tainted: G B W 7.3.0-rc5-g2bba28e98578 #284 PREEMPT(full) Tainted: [B]=BADPAGE, [W]=WARN <-- Taint from lrugenrotatememcg() VMWARNONONCE Hardware name: QEMU Standard PC (i440FX + PIIX, 1996), BIOS 1.17.0-debian-1.17.0-1 04/01/2014 Workqueue: events highworkfunc RIP: 0010:lrugenrotatememcg+0x1a3/0xe90 Call Trace: <TASK> ? readctrlpos+0x22f/0x3f0 shrinklruvec+0x16cb/0x1b80 ? retfromforkasm+0x1a/0x30 ? lapicnextevent+0x15/0x20 ? clockeventsprogramevent+0x2bb/0x6f0 ? lapicnextevent+0x15/0x20 ? pfxshrinklruvec+0x10/0x10 ? pfxclockeventsprogramevent+0x10/0x10 ? rawspinlock+0x84/0xe0 ? pfxrawspinlock+0x10/0x10 ? kasansavestack+0x30/0x50 ? psigroupchange+0x381/0x740 ? pfxschedclockcpu+0x10/0x10 ? savefpregstofpstate+0xc4/0x2c0 ? finishtaskswitch.isra.0+0x1de/0xac0 ? schedule+0xf62/0x42c0 ? pfxschedule+0x10/0x10 ? pfxirqworkqueuelo ---truncated---
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.12.118 - Upgrade
Upgrade
linux/Kernelto a version that resolves this vulnerability.Fixed in 6.18.64 - Upgrade
Upgrade
linux/Kernelto a version that resolves this vulnerability.Fixed in 7.3.5 - Compensating control
In the kernel, acquire a memcg reference with css_tryget_online() in high_work_func() before calling reclaim_high(), and reset memory.high and swap.high to PAGE_COUNTER_MAX in mem_cgroup_css_offline().
Frequently Asked Questions
What conditions are needed to trigger the unsafe work item?
A child memory cgroup must be offlined while its memory usage can remain above memory.high due to object reparenting. A later charge to that offlined memcg from non-task context can then schedule high_work without holding a reference to the memcg.
Why can teardown race with reclaim work?
high_work_func() can enter or continue reclaim_high() without pinning the memory cgroup. The work is cancelled synchronously only at the end of teardown in mem_cgroup_css_free(), allowing the work to run while the memcg is being destroyed.
Are non-task-context memory charges specifically relevant?
Yes. The described scheduling path is try_charge_memcg() when memory.high is exceeded in non-task context; this path schedules high_work without taking a memcg reference.