* [PATCH 6.18.y] mm/page_owner: use memcg_data snapshot to avoid TOCTOU in print_page_owner_memcg()
[not found] <20260906181100.reply7-sasha@kernel.org>
@ 2026-12-04 21:05 ` Artem Dinaburg
2026-12-05 12:48 ` Sasha Levin
0 siblings, 1 reply; 2+ messages in thread
From: Artem Dinaburg @ 2026-12-04 21:05 UTC (permalink / raw)
To: stable
Cc: akpm, brendan.jackman, david, hannes, harshit.m.mogalapalli,
linux-mm, ljs, mhocko, sashal, surenb, vbabka, ye.liu, ziy
From: Ye Liu <ye.liu@linux.dev>
Date: Tue, 14 Jul 2026 09:51:08 +0800
[ Upstream commit 90f095b816e25c6a9e4446d299bac5007fdcb3df ]
print_page_owner_memcg() reads page->memcg_data via READ_ONCE() at the
start to guard against tail pages and NULL data. However, it later
re-reads page->memcg_data locklessly in two places:
1: page_memcg_check(page)
2: PageMemcgKmem(page) (via folio_memcg_kmem(), which includes
VM_BUG_ON assertions for tail pages and MEMCG_DATA_OBJEXTS)
If the page is concurrently freed and reallocated as a THP tail page or
slab page between these calls, the VM_BUG_ON assertions can trigger on
CONFIG_DEBUG_VM=y builds, crashing the kernel.
Fix both TOCTOU issues by using the memcg_data snapshot throughout.
Link: https://lore.kernel.org/20260714015117.78351-10-ye.liu@linux.dev
Fixes: fcf8935832b8 ("mm/page_owner: print memcg information")
Signed-off-by: Ye Liu <ye.liu@linux.dev>
Reported-by: Sashiko <sashiko-bot@kernel.org>
Reviewed-by: Zi Yan <ziy@nvidia.com>
Reviewed-by: Vlastimil Babka (SUSE) <vbabka@kernel.org>
Cc: Brendan Jackman <jackmanb@google.com>
Cc: Johannes Weiner <hannes@cmpxchg.org>
Cc: Lorenzo Stoakes <ljs@kernel.org>
Cc: Michal Hocko <mhocko@suse.com>
Cc: Suren Baghdasaryan <surenb@google.com>
Cc: David Hildenbrand (Arm) <david@kernel.org>
Cc: <stable@vger.kernel.org>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
[ Backport to 6.18.y: Commit f1cf8d2f36dc ("mm: memcontrol: eliminate
the problem of dying memory cgroup for LRU folios") changed ordinary
folio charges to use obj_cgroup pointers upstream. On 6.18.y, only
MEMCG_DATA_KMEM denotes an obj_cgroup. Use the same snapshot for the
charge and its label. For ordinary charges, use the direct mem_cgroup
pointer. Keep the existing CSS_ONLINE test. ]
Signed-off-by: Artem Dinaburg <artem@trailofbits.com>
---
Hi,
Please apply this 6.18.y backport for CVE-2026-93216. The September
review dropped the earlier version because it treated ordinary memcg
pointers as obj_cgroup pointers. This version keeps the two encodings
distinct.
The fix is in mainline from 7.3 and in 7.2.y from 7.2.4. The 6.6.160
backport handles both charge types. Linux 6.12.114 took the
unconditional obj_cgroup decoder, which still needs correcting in
6.12.y. The fix is also missing from 6.1.y.
Compile-tested on 6.18.66 (page_owner.o).
I used an LLM to help prepare this backport and reviewed the result.
Thanks,
Artem Dinaburg
mm/page_owner.c | 14 +++++++++++---
1 file changed, 11 insertions(+), 3 deletions(-)
diff --git a/mm/page_owner.c b/mm/page_owner.c
index 4862fc52c5ec8df41d3bcbddf3bb32f05b9434c6..e4bdaaaa9ae21bb9d8a7483c6dc231a21d37f94d 100644
--- a/mm/page_owner.c
+++ b/mm/page_owner.c
@@ -504,6 +504,7 @@ static inline int print_page_owner_memcg(char *kbuf, size_t count, int ret,
{
#ifdef CONFIG_MEMCG
unsigned long memcg_data;
+ struct obj_cgroup *objcg;
struct mem_cgroup *memcg;
bool online;
char name[80];
@@ -513,11 +514,18 @@ static inline int print_page_owner_memcg(char *kbuf, size_t count, int ret,
if (!memcg_data || PageTail(page))
goto out_unlock;
- if (memcg_data & MEMCG_DATA_OBJEXTS)
+ if (memcg_data & MEMCG_DATA_OBJEXTS) {
ret += scnprintf(kbuf + ret, count - ret,
"Slab cache page\n");
+ goto out_unlock;
+ }
- memcg = page_memcg_check(page);
+ if (memcg_data & MEMCG_DATA_KMEM) {
+ objcg = (void *)(memcg_data & ~OBJEXTS_FLAGS_MASK);
+ memcg = objcg ? obj_cgroup_memcg(objcg) : NULL;
+ } else {
+ memcg = (void *)(memcg_data & ~OBJEXTS_FLAGS_MASK);
+ }
if (!memcg)
goto out_unlock;
@@ -525,7 +533,7 @@ static inline int print_page_owner_memcg(char *kbuf, size_t count, int ret,
cgroup_name(memcg->css.cgroup, name, sizeof(name));
ret += scnprintf(kbuf + ret, count - ret,
"Charged %sto %smemcg %s\n",
- PageMemcgKmem(page) ? "(via objcg) " : "",
+ (memcg_data & MEMCG_DATA_KMEM) ? "(via objcg) " : "",
online ? "" : "offline ",
name);
out_unlock:
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [PATCH 6.18.y] mm/page_owner: use memcg_data snapshot to avoid TOCTOU in print_page_owner_memcg()
2026-12-04 21:05 ` [PATCH 6.18.y] mm/page_owner: use memcg_data snapshot to avoid TOCTOU in print_page_owner_memcg() Artem Dinaburg
@ 2026-12-05 12:48 ` Sasha Levin
0 siblings, 0 replies; 2+ messages in thread
From: Sasha Levin @ 2026-12-05 12:48 UTC (permalink / raw)
To: stable
Cc: Sasha Levin, akpm, brendan.jackman, david, hannes,
harshit.m.mogalapalli, linux-mm, ljs, mhocko, surenb, vbabka,
ye.liu, ziy, Artem Dinaburg
> Please apply this 6.18.y backport for CVE-2026-93216. The September
> review dropped the earlier version because it treated ordinary memcg
> pointers as obj_cgroup pointers. This version keeps the two encodings
> distinct.
Queued for 6.18, thanks.
--
Thanks,
Sasha
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2026-12-05 12:49 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
[not found] <20260906181100.reply7-sasha@kernel.org>
2026-12-04 21:05 ` [PATCH 6.18.y] mm/page_owner: use memcg_data snapshot to avoid TOCTOU in print_page_owner_memcg() Artem Dinaburg
2026-12-05 12:48 ` Sasha Levin
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox