Re: [RFC PATCH] mm/page_alloc: fix use-after-free in swap due to stale page data after split_page()
From: Mikhail Gavrilov
Date: Mon Feb 02 2026 - 15:22:59 EST
On Mon, Feb 2, 2026 at 10:55 PM Kairui Song <ryncsn@xxxxxxxxx> wrote:
>
> Right, then I think we need a Fixes tag, and is swap really the only
> victim of that change?
Good question. The comment in vmalloc.c mentions "some use
page->mapping, page->lru, etc." but I haven't found other concrete
examples that would hit this bug. Swap seems to be the only one
relying on page->private being zero.
> Or maybe clean page->private instead? The problem is triggered by
> free_swap_count_continuations which checks page_private to tell if the
> page has list data, and ignores the list if not. So the pages should
> have their private cleaned upon allocation.
You're right. Looking at swap_count_continued(), it already checks
page_private(head) != SWP_CONTINUED, not page_private(head) == 0.
The fix in swapfile.c should use the same condition in
add_swap_count_continuation():
diff --git a/mm/swapfile.c b/mm/swapfile.c
index 46d2008e4b99..f131494d4262 100644
--- a/mm/swapfile.c
+++ b/mm/swapfile.c
@@ -3859,10 +3859,11 @@ int add_swap_count_continuation(swp_entry_t
entry, gfp_t gfp_mask)
spin_lock(&si->cont_lock);
/*
- * Page allocation does not initialize the page's lru field,
- * but it does always reset its private field.
+ * Page allocation does not initialize the page's lru field, and
+ * vmalloc pages from split_page() may have stale page->private.
+ * Check for SWP_CONTINUED not just non-zero.
*/
- if (!page_private(head)) {
+ if (page_private(head) != SWP_CONTINUED) {
BUG_ON(count & COUNT_CONTINUED);
INIT_LIST_HEAD(&head->lru);
set_page_private(head, SWP_CONTINUED);
This handles both cases:
- page_private == 0 (normal fresh page)
- page_private == stale non-zero value (vmalloc split_page bug)
And the comment should be updated to reflect that vmalloc pages may
have stale page->private.
Should I send a v2 with this approach?
--
Best Regards,
Mike Gavrilov.