From: Mikhail Gavrilov <mikhail.v.gavrilov@gmail.com>
To: Kairui Song <ryncsn@gmail.com>
Cc: Linux Memory Management List <linux-mm@kvack.org>,
Linux List Kernel Mailing <linux-kernel@vger.kernel.org>,
Andrew Morton <akpm@linux-foundation.org>,
Vlastimil Babka <vbabka@suse.cz>,
chrisl@kernel.org, Hugh Dickins <hughd@google.com>
Subject: Re: [RFC PATCH] mm/page_alloc: fix use-after-free in swap due to stale page data after split_page()
Date: Mon, 2 Feb 2026 10:27:01 +0500 [thread overview]
Message-ID: <CABXGCsPwjTNfT0eYMJqQ7UaiEMObpvLh0BOmev9HGFAqomNpBg@mail.gmail.com> (raw)
In-Reply-To: <CAMgjq7BpeaDU9_DhXYvLMadTgDq_ObJeBb+ndfMygzz7n_FjTg@mail.gmail.com>
On Mon, Feb 2, 2026 at 8:18 AM Kairui Song <ryncsn@gmail.com> wrote:
>
> Right, but with __GFP_COMP, prep_compound_page clears the tail pages'
> private too, so the code snip I posted will clear their lru on use?
You're right that prep_compound_tail() clears page->private for tail
pages. But the issue is that vmalloc explicitly avoids __GFP_COMP -
see commit 3b8000ae185c ("mm/vmalloc: huge vmalloc backing pages
should be split rather than compound"). So prep_compound_page() is
never called for these allocations.
> I took a look at the history, commit 3b8000ae185c ("mm/vmalloc: huge
> vmalloc backing pages should be split rather than compound") dropped
> __GFP_COMP and added split_page, that's the commit added the comment
> you mentioned.
Good find! That's exactly where the problem was introduced.
> Fixing it with this patch you posted seems could result in other
> issues, e.g. split_free_pages / split_free_frozen_pages would call
> split_page while the page is on a list, so at least clearing head
> page's LRU seems incorrect?
You're absolutely right, that's a problem I missed. split_free_page()
calls split_page() on pages that are still on the buddy free list -
initializing head->lru there would corrupt the list.
So the fix should only initialize tail pages, not the head page:
/*
* Split pages may contain stale data from previous use. Initialize
* page->private and page->lru for tail pages which may have
* LIST_POISON values. Head page is left alone as callers like
* split_free_page() may have it on a list.
*/
for (i = 1; i < (1 << order); i++) {
set_page_refcounted(page + i);
set_page_private(page + i, 0);
INIT_LIST_HEAD(&page[i].lru);
}
But then we still have the problem for head page in vmalloc case.
Maybe the fix should be in vmalloc.c instead, after split_page()
returns?
Or alternatively, fix it in swapfile.c by unconditionally calling
INIT_LIST_HEAD() - the comment there is already wrong, so we should
fix both the comment and the code?
What do you think is the cleanest approach?
--
Best Regards,
Mike Gavrilov.
next prev parent reply other threads:[~2026-02-02 5:27 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-01-30 13:49 Mikhail Gavrilov
2026-01-30 13:59 ` Matthew Wilcox
2026-01-30 14:16 ` Mikhail Gavrilov
2026-01-30 15:30 ` Kairui Song
2026-01-30 15:47 ` Mikhail Gavrilov
2026-02-02 3:17 ` Kairui Song
2026-02-02 5:27 ` Mikhail Gavrilov [this message]
2026-02-02 17:54 ` Kairui Song
2026-02-02 20:21 ` Mikhail Gavrilov
2026-02-03 7:14 ` Mikhail Gavrilov
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=CABXGCsPwjTNfT0eYMJqQ7UaiEMObpvLh0BOmev9HGFAqomNpBg@mail.gmail.com \
--to=mikhail.v.gavrilov@gmail.com \
--cc=akpm@linux-foundation.org \
--cc=chrisl@kernel.org \
--cc=hughd@google.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=ryncsn@gmail.com \
--cc=vbabka@suse.cz \
/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