From: Artem Dinaburg <artem@trailofbits.com>
To: stable@vger.kernel.org
Cc: akpm@linux-foundation.org, brendan.jackman@linux.dev,
david@kernel.org, hannes@cmpxchg.org,
harshit.m.mogalapalli@oracle.com, linux-mm@kvack.org,
ljs@kernel.org, mhocko@suse.com, sashal@kernel.org,
surenb@google.com, vbabka@kernel.org, ye.liu@linux.dev,
ziy@nvidia.com
Subject: [PATCH 6.18.y] mm/page_owner: use memcg_data snapshot to avoid TOCTOU in print_page_owner_memcg()
Date: Fri, 4 Dec 2026 16:05:56 -0500 [thread overview]
Message-ID: <20261204210556.47905-1-artem@trailofbits.com> (raw)
In-Reply-To: <20260906181100.reply7-sasha@kernel.org>
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:
next parent reply other threads:[~2026-12-04 21:06 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <20260906181100.reply7-sasha@kernel.org>
2026-12-04 21:05 ` Artem Dinaburg [this message]
2026-12-05 12:48 ` [PATCH 6.18.y] mm/page_owner: use memcg_data snapshot to avoid TOCTOU in print_page_owner_memcg() Sasha Levin
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20261204210556.47905-1-artem@trailofbits.com \
--to=artem@trailofbits.com \
--cc=akpm@linux-foundation.org \
--cc=brendan.jackman@linux.dev \
--cc=david@kernel.org \
--cc=hannes@cmpxchg.org \
--cc=harshit.m.mogalapalli@oracle.com \
--cc=linux-mm@kvack.org \
--cc=ljs@kernel.org \
--cc=mhocko@suse.com \
--cc=sashal@kernel.org \
--cc=stable@vger.kernel.org \
--cc=surenb@google.com \
--cc=vbabka@kernel.org \
--cc=ye.liu@linux.dev \
--cc=ziy@nvidia.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox