Linux filesystem development
 help / color / mirror / Atom feed
From: Matthew Wilcox <willy@infradead.org>
To: Usama Arif <usama.arif@linux.dev>
Cc: Andrew Morton <akpm@linux-foundation.org>,
	Jane Chu <jane.chu@oracle.com>,
	linux-mm@kvack.org, Muchun Song <muchun.song@linux.dev>,
	Oscar Salvador <osalvador@suse.de>,
	David Hildenbrand <david@kernel.org>,
	Miaohe Lin <linmiaohe@huawei.com>,
	Naoya Horiguchi <nao.horiguchi@gmail.com>,
	Jan Kara <jack@suse.cz>,
	linux-fsdevel@vger.kernel.org,
	Christian Brauner <christian@brauner.io>
Subject: Re: [PATCH v2 06/10] memory-failure: Prevent UAF in raw_hwp_page list
Date: Fri, 10 Jul 2026 18:16:54 +0100	[thread overview]
Message-ID: <alEpBqExnyvBnnxi@casper.infradead.org> (raw)
In-Reply-To: <20260710150204.1887475-1-usama.arif@linux.dev>

On Fri, Jul 10, 2026 at 08:02:03AM -0700, Usama Arif wrote:
> > +void folio_clear_hugetlb_hwpoison(struct folio *folio)
> > +{
> > +	mutex_lock(&mf_mutex);
> 
> This wrapper can now sleep, but its external caller is the hugetlb free
> path.  __update_and_free_hugetlb_folio() is reached from
> update_and_free_hugetlb_folio(), which has a comment saying
> "Defer freeing to avoid using GFP_ATOMIC"

Yeah, Sashiko also pointed this out.

I think I'm going to have to change how we track hwpoison in hugetlb
in order to make this work.  Let me think out loud here:

is_page_hwpoison() can be called without a reference on the folio
containing the page.  The answer can be wrong in this case, but any
UAF must be benign.

Grabbing the mf_mutex inside hugetlb_page_hwpoison() is insufficient
because we can't protect against folio_clear_hugetlb_hwpoison() (the
approach attempted in this patch).

We could add a spinlock for protecting freeing & checking of the list.
That's probably simplest.

It'd be better to protect the list with RCU.  But then we'd need to
put an RCU head inside raw_hwp_page, doubling its size from 2 pointers
to 4.

We could completely change how we do this; instead of having an llist,
we could have an array of 32-bit page indices.  Reallocate it when we
run out, doubling its size each time, and put an rcu head in that.
That'd give us 32-bytes the first time, space for 4 indices, then double
to 64 (space for 12 indices), double again to 128 (28 indices), etc.

We could also RCU-free the folio if it's hwpoisoned.  We'd need to
clear the hugetlb flag before asking RCU to cover up this problem
to ensure that any reader that saw the hugetlb flag set started its
grace period before.

Probably all too much trouble.  I think I'll add a global spinlock.

> > +	__folio_clear_hugetlb_hwpoison(folio);
> > +	mutex_unlock(&mf_mutex);
> > +}
> > +
> >  static int get_huge_page_for_hwpoison(unsigned long pfn, int flags,
> >  				 bool *migratable_cleared)
> >  {
> > @@ -2051,7 +2058,7 @@ static int try_memory_failure_hugetlb(unsigned long pfn, int flags)
> >  	folio_lock(folio);
> >  
> >  	if (hwpoison_filter(p)) {
> > -		folio_clear_hugetlb_hwpoison(folio);
> > +		__folio_clear_hugetlb_hwpoison(folio);
> >  		if (migratable_cleared)
> >  			folio_set_hugetlb_migratable(folio);
> >  		folio_unlock(folio);
> > -- 
> > 2.47.3
> > 
> > 

  reply	other threads:[~2026-07-10 17:17 UTC|newest]

Thread overview: 21+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-07-09 18:47 [PATCH v2 00/10] Use generic_file_read_iter() in hugetlbfs Matthew Wilcox (Oracle)
2026-07-09 18:47 ` [PATCH v2 01/10] mm: Rename folio_contain_hwpoison_page() to folio_has_hwpoison_page() Matthew Wilcox (Oracle)
2026-07-10 14:27   ` Usama Arif
2026-07-09 18:47 ` [PATCH v2 02/10] hugetlb: Mark some function arguments as const Matthew Wilcox (Oracle)
2026-07-10 14:28   ` Usama Arif
2026-07-09 18:47 ` [PATCH v2 03/10] filemap: Remove checks in mapping_set_folio_order_range() Matthew Wilcox (Oracle)
2026-07-10 14:42   ` Usama Arif
2026-07-09 18:47 ` [PATCH v2 04/10] hugetlb: Set mapping folio order Matthew Wilcox (Oracle)
2026-07-10 14:49   ` Usama Arif
2026-07-09 18:47 ` [PATCH v2 05/10] memory-failure: Remove raw_hwp_list_head() Matthew Wilcox (Oracle)
2026-07-10 14:55   ` Usama Arif
2026-07-09 18:47 ` [PATCH v2 06/10] memory-failure: Prevent UAF in raw_hwp_page list Matthew Wilcox (Oracle)
2026-07-10 15:02   ` Usama Arif
2026-07-10 17:16     ` Matthew Wilcox [this message]
2026-07-09 18:47 ` [PATCH v2 07/10] mm: Handle hugetlb correctly in is_page_hwpoison() Matthew Wilcox (Oracle)
2026-07-09 18:47 ` [PATCH v2 08/10] filemap: Add hwpoison handling to filemap_read() Matthew Wilcox (Oracle)
2026-07-09 18:47 ` [PATCH v2 09/10] filemap: Add support for authoritative mappings Matthew Wilcox (Oracle)
2026-07-09 18:47 ` [PATCH v2 10/10] hugetlb: replace hugetlbfs_read_iter() with generic_file_read_iter() Matthew Wilcox (Oracle)
2026-07-09 19:19 ` [PATCH v2 00/10] Use generic_file_read_iter() in hugetlbfs Matthew Wilcox
2026-07-10 14:25 ` Usama Arif
2026-07-10 23:04 ` [syzbot ci] " syzbot ci

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=alEpBqExnyvBnnxi@casper.infradead.org \
    --to=willy@infradead.org \
    --cc=akpm@linux-foundation.org \
    --cc=christian@brauner.io \
    --cc=david@kernel.org \
    --cc=jack@suse.cz \
    --cc=jane.chu@oracle.com \
    --cc=linmiaohe@huawei.com \
    --cc=linux-fsdevel@vger.kernel.org \
    --cc=linux-mm@kvack.org \
    --cc=muchun.song@linux.dev \
    --cc=nao.horiguchi@gmail.com \
    --cc=osalvador@suse.de \
    --cc=usama.arif@linux.dev \
    /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