From: Sasha Levin <sashal@kernel.org>
To: stable@vger.kernel.org
Cc: Yafang Shao <laoar.shao@gmail.com>,
Andrew Morton <akpm@linux-foundation.org>,
Zi Yan <ziy@nvidia.com>,
"David Hildenbrand (Arm)" <david@kernel.org>,
Ying Huang <ying.huang@linux.alibaba.com>,
Matthew Wilcox <willy@infradead.org>,
Matthew Brost <matthew.brost@intel.com>,
Joshua Hahn <joshua.hahnjy@gmail.com>,
Byungchul Park <byungchul@sk.com>,
Gregory Price <gourry@gourry.net>,
Alistair Popple <apopple@nvidia.com>,
Sasha Levin <sashal@kernel.org>
Subject: [PATCH 6.1.y] mm/migrate: snapshot the source nid before the misplaced migration
Date: Sat, 14 Nov 2026 12:47:06 -0500 [thread overview]
Message-ID: <20261114174651.355700-1-sashal@kernel.org> (raw)
In-Reply-To: <20261109201713-failed-6.1-fe623a81ad9e@kernel.org>
From: Yafang Shao <laoar.shao@gmail.com>
[ Upstream commit fe623a81ad9eddf10059b4e44bca0440d9120613 ]
A successful migration frees the source folio before the promotion
counter update, so the folio_nid() read there operates on a freed
folio — which may already have been reallocated. It happens to work
today, as Zi explained:
: Strictly speaking, it can be seen as a benign UAF. It works, because
: 1. folio->flags happens to be the same as page->flags,
: 2. folio/page nid is stored in the ->flags and never changed.
:
: In memdesc world, after a folio is freed, I assume folio->flags would be
: zeroed since struct folio is freed and calling folio_nid() on a freed
: folio would give a bogus result (yeah, it can be mitigated by not
: zeroing node field and each node has its own struct folio pool, but that
: makes folio_nid() implementation dependent).
and Matthew explained further:
: once struct folio is separately allocated, it's a UAF. It could be
: recycled to a different NID or maybe the slab containing the folio could
: be freed (assuming we're not holding the RCU read lock at this point in
: migration, and I don't see why we would be).
A separate concern is memory hot-removal. With memory-tiering mode
enabled, successful migration can release the source before the
promotion-accounting folio_nid() read. If the task is preempted there,
an otherwise-free source block can be offlined and removed first. On
the x86 path, removal can unmap the source's vmemmap, so the later read
can fault. The snapshot avoids that read.
Link: https://lore.kernel.org/20261027021721.95781-1-laoar.shao@gmail.com
Fixes: e39bb6be9f2b ("NUMA Balancing: add page promotion counter")
Signed-off-by: Yafang Shao <laoar.shao@gmail.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Suggested-by: Zi Yan <ziy@nvidia.com>
Suggested-by: Andrew Morton <akpm@linux-foundation.org>
Acked-by: Zi Yan <ziy@nvidia.com>
Acked-by: David Hildenbrand (Arm) <david@kernel.org>
Cc: Ying Huang <ying.huang@linux.alibaba.com>
Cc: Matthew Wilcox <willy@infradead.org>
Cc: Matthew Brost <matthew.brost@intel.com>
Cc: Joshua Hahn <joshua.hahnjy@gmail.com>
Cc: Byungchul Park <byungchul@sk.com>
Cc: Gregory Price <gourry@gourry.net>
Cc: Alistair Popple <apopple@nvidia.com>
Cc: <stable@vger.kernel.org>
[ sashal: adapted folio_nid(folio) to page_to_nid(page) in migrate_misplaced_page() ]
Signed-off-by: Sasha Levin <sashal@kernel.org>
---
mm/migrate.c | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/mm/migrate.c b/mm/migrate.c
index 09acee0c43569..0f3af8eb6356c 100644
--- a/mm/migrate.c
+++ b/mm/migrate.c
@@ -2458,6 +2458,7 @@ int migrate_misplaced_page(struct page *page, struct vm_area_struct *vma,
int isolated;
int nr_remaining;
unsigned int nr_succeeded;
+ int src_node = page_to_nid(page);
LIST_HEAD(migratepages);
int nr_pages = thp_nr_pages(page);
@@ -2495,7 +2496,7 @@ int migrate_misplaced_page(struct page *page, struct vm_area_struct *vma,
}
if (nr_succeeded) {
count_vm_numa_events(NUMA_PAGE_MIGRATE, nr_succeeded);
- if (!node_is_toptier(page_to_nid(page)) && node_is_toptier(node))
+ if (!node_is_toptier(src_node) && node_is_toptier(node))
mod_node_page_state(pgdat, PGPROMOTE_SUCCESS,
nr_succeeded);
}
--
2.53.0
prev parent reply other threads:[~2026-11-14 17:47 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-10 1:17 FAILED: patch "[PATCH] mm/migrate: snapshot the source nid before the misplaced migration" failed to apply to 6.1-stable tree Sasha Levin
2026-11-14 17:47 ` Sasha Levin [this message]
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=20261114174651.355700-1-sashal@kernel.org \
--to=sashal@kernel.org \
--cc=akpm@linux-foundation.org \
--cc=apopple@nvidia.com \
--cc=byungchul@sk.com \
--cc=david@kernel.org \
--cc=gourry@gourry.net \
--cc=joshua.hahnjy@gmail.com \
--cc=laoar.shao@gmail.com \
--cc=matthew.brost@intel.com \
--cc=stable@vger.kernel.org \
--cc=willy@infradead.org \
--cc=ying.huang@linux.alibaba.com \
--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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.