From: "李佑鸿 " <dayou5941@163.com>
To: "David Hildenbrand (Arm)" <david@kernel.org>
Cc: akpm@linux-foundation.org, ljs@kernel.org, ziy@nvidia.com,
linux-mm@kvack.org, liyouhong <liyouhong@kylinos.cn>
Subject: Re:Re: [PATCH] mm/huge_memory: avoid TOCTOU race in min_order_for_split()
Date: Wed, 5 Aug 2026 15:20:27 +0800 (CST) [thread overview]
Message-ID: <4198eece.54ca.19fd0cb87fe.Coremail.dayou5941@163.com> (raw)
In-Reply-To: <9ac32dd4-498e-46b2-9cb4-3fa853840cfa@kernel.org>
At 2026-08-04 18:04:15, "David Hildenbrand (Arm)" <david@kernel.org> wrote:
>On 8/4/26 05:58, dayou5941@163.com wrote:
>> From: liyouhong <liyouhong@kylinos.cn>
>>
>> min_order_for_split() reads folio->mapping twice without any
>> synchronization. Concurrent truncate or invalidate can clear
>> folio->mapping between the check and subsequent function call.
>> Even with a held folio reference preventing the folio from
>> being freed, folio->mapping can still be overwritten to NULL. This
>> TOCTOU race allows passing a NULL mapping into mapping_min_folio_order(),
>> which leads to a NULL pointer dereference.
>>
>> Cache folio->mapping to a local variable using READ_ONCE() to guarantee a
>> single memory load and remove the race window.
>
>In __folio_split() we hold the folio lock, so concurrent truncation is impossible.
>
>So is this about memory-failure.c ?
>
>We should rather fix that code to not call min_order_for_split() without the folio lock
>(we take it either way in try_to_split_thp_page), no?
Yes, you're right. The real issue is in memory-failure.c where the callers
do not hold the folio lock when calling min_order_for_split(). I'll send a
v2 that adds the folio lock at the call sites and also adds a
VM_WARN_ON_ONCE_FOLIO() in min_order_for_split() to catch any future
callers that don't hold the lock. Thanks for the review.
Cheers,
liyouhong
next prev parent reply other threads:[~2026-08-05 7:20 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-08-04 3:58 [PATCH] mm/huge_memory: avoid TOCTOU race in min_order_for_split() dayou5941
[not found] ` <9ac32dd4-498e-46b2-9cb4-3fa853840cfa@kernel.org>
2026-08-05 7:20 ` 李佑鸿 [this message]
[not found] ` <anG6-Dm5oo4LJxRx@lucifer>
2026-08-05 7:23 ` 李佑鸿
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=4198eece.54ca.19fd0cb87fe.Coremail.dayou5941@163.com \
--to=dayou5941@163.com \
--cc=akpm@linux-foundation.org \
--cc=david@kernel.org \
--cc=linux-mm@kvack.org \
--cc=liyouhong@kylinos.cn \
--cc=ljs@kernel.org \
--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.