Linux-mm Archive on lore.kernel.org
 help / color / mirror / Atom feed
From: Andrew Morton <akpm@linux-foundation.org>
To: Ye Liu <ye.liu@linux.dev>
Cc: "Vlastimil Babka (SUSE)" <vbabka@kernel.org>,
	Suren Baghdasaryan <surenb@google.com>,
	Michal Hocko <mhocko@suse.com>,
	Brendan Jackman <jackmanb@google.com>,
	Johannes Weiner <hannes@cmpxchg.org>, Zi Yan <ziy@nvidia.com>,
	linux-mm@kvack.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH v6 9/9] mm/page_owner: use memcg_data snapshot to avoid TOCTOU in print_page_owner_memcg()
Date: Sun, 19 Jul 2026 22:42:55 -0700	[thread overview]
Message-ID: <20260719224255.8e2bc60e8a42681fb541e6ad@linux-foundation.org> (raw)
In-Reply-To: <e3f17e17-495e-423c-9c21-48aace4367d1@linux.dev>

On Mon, 20 Jul 2026 10:45:56 +0800 Ye Liu <ye.liu@linux.dev> wrote:

> > These points have too much detail that's already in the code. Would just
> > mention that we opencode applicable parts of page_memcg_check() and
> > PageMemcgKmem() using the snapshot?
> Yes,It's a bit wordy.
> > 
> >> This avoids both TOCTOU windows and the assertions entirely.
> >>
> >> Signed-off-by: Ye Liu <ye.liu@linux.dev>
> > 
> > Reviewed-by: Vlastimil Babka (SUSE) <vbabka@kernel.org>
> > 
> > Was all of this reported by sashiko? At least the new-in-v6 was?
> > Then:
> > 
> > Reported-by: Sashiko <sashiko-bot@kernel.org>
> > 
> > But it's no longer a cleanup but a fix, so probably this?
> > 
> > Fixes: fcf8935832b8 ("mm/page_owner: print memcg information")
> > Cc: stable@vger.kernel.org
> > 
> > It's not fixing a new regression so I think it's fine to keep it part of
> > this series for next release and not need to split out for mm-hotfixes.
> > 
> Hi Andrew,
> 
> Could you please help me revise the above?

Sure, how does this look?


From: Ye Liu <ye.liu@linux.dev>
Subject: mm/page_owner: use memcg_data snapshot to avoid TOCTOU in print_page_owner_memcg()
Date: Tue, 14 Jul 2026 09:51:08 +0800

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>
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>


  reply	other threads:[~2026-07-20  5:43 UTC|newest]

Thread overview: 23+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-07-14  1:50 [PATCH v6 0/9] mm/page_owner: misc cleanups Ye Liu
2026-07-14  1:51 ` [PATCH v6 1/9] mm/page_owner: extract skip_buddy_pages() helper to unify buddy page skipping Ye Liu
2026-07-14  1:51 ` [PATCH v6 2/9] mm/page_owner: add MR_NEVER to enum migrate_reason and use it for last_migrate_reason Ye Liu
2026-07-14 13:05   ` David Hildenbrand (Arm)
2026-07-14 13:09     ` Vlastimil Babka (SUSE)
2026-07-14 13:22       ` David Hildenbrand (Arm)
2026-07-14 13:49         ` Vlastimil Babka (SUSE)
2026-07-14 14:44           ` David Hildenbrand (Arm)
2026-07-20  2:39             ` Ye Liu
2026-07-14  1:51 ` [PATCH v6 3/9] mm: use enum migrate_reason instead of int for migration reason parameters Ye Liu
2026-07-14 13:07   ` David Hildenbrand (Arm)
2026-07-14  1:51 ` [PATCH v6 4/9] mm/page_owner: hoist CONFIG_MEMCG to function level for print_page_owner_memcg() Ye Liu
2026-07-14  1:51 ` [PATCH v6 5/9] mm/page_owner: add missing newline to count_threshold format string Ye Liu
2026-07-14  1:51 ` [PATCH v6 6/9] mm/page_owner: move free_ts_nsec output to free section in __dump_page_owner() Ye Liu
2026-07-14  1:51 ` [PATCH v6 7/9] mm/page_owner: drop redundant page_owner prefix from static symbols Ye Liu
2026-07-14  1:51 ` [PATCH v6 8/9] mm/page_owner: clamp skip_buddy_pages() PFN advance at MAX_ORDER_NR_PAGES boundary Ye Liu
2026-07-14  1:51 ` [PATCH v6 9/9] mm/page_owner: use memcg_data snapshot to avoid TOCTOU in print_page_owner_memcg() Ye Liu
2026-07-14  1:56   ` Zi Yan
2026-07-14  8:24   ` Vlastimil Babka (SUSE)
2026-07-20  2:45     ` Ye Liu
2026-07-20  5:42       ` Andrew Morton [this message]
2026-07-20  6:58         ` Ye Liu
2026-07-14  3:16 ` [PATCH v6 0/9] mm/page_owner: misc cleanups Andrew Morton

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=20260719224255.8e2bc60e8a42681fb541e6ad@linux-foundation.org \
    --to=akpm@linux-foundation.org \
    --cc=hannes@cmpxchg.org \
    --cc=jackmanb@google.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mm@kvack.org \
    --cc=mhocko@suse.com \
    --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