From: Dev Jain <dev.jain@arm.com>
To: Ryan Roberts <ryan.roberts@arm.com>,
catalin.marinas@arm.com, will@kernel.org
Cc: anshuman.khandual@arm.com, quic_zhenhuah@quicinc.com,
kevin.brodsky@arm.com, yangyicong@hisilicon.com,
joey.gouly@arm.com, linux-arm-kernel@lists.infradead.org,
linux-kernel@vger.kernel.org, mark.rutland@arm.com,
maz@kernel.org, stable@vger.kernel.org
Subject: Re: [PATCH] arm64/mm: Fix use-after-free due to race between memory hotunplug and ptdump
Date: Mon, 28 Jul 2025 17:01:10 +0530 [thread overview]
Message-ID: <ebbd54a7-1d84-4a47-8a66-394bdcb53d65@arm.com> (raw)
In-Reply-To: <f0e12d1e-110d-4a56-9f77-8fe2d664b0d1@arm.com>
On 28/07/25 4:43 pm, Ryan Roberts wrote:
> On 28/07/2025 11:31, Dev Jain wrote:
>> Memory hotunplug is done under the hotplug lock and ptdump walk is done
>> under the init_mm.mmap_lock. Therefore, ptdump and hotunplug can run
>> simultaneously without any synchronization. During hotunplug,
>> free_empty_tables() is ultimately called to free up the pagetables.
>> The following race can happen, where x denotes the level of the pagetable:
>>
>> CPU1 CPU2
>> free_empty_pxd_table
>> ptdump_walk_pgd()
>> Get p(x+1)d table from pxd entry
>> pxd_clear
>> free_hotplug_pgtable_page(p(x+1)dp)
>> Still using the p(x+1)d table
>>
>> which leads to a user-after-free.
> I'm not sure I understand this. ptdump_show() protects against this with
> get_online_mems()/put_online_mems(), doesn't it? There are 2 paths that call
> ptdump_walk_pgd(). This protects one of them. The other is ptdump_check_wx(); I
> thought you (or Anshuman?) had a patch in flight to fix that with
> [get|put]_online_mems() too?
>
> Sorry if my memory is failing me here...
Nope, I think I just had a use-after-free in my memory so I came up with this patch :)
Because of the recent work with ptdump, I was so concentrated on ptdump_walk_pgd() that I
didn't even bother looking up the call chain. And I even forgot we had these [get|put]_online_mems()
patches recently.
Sorry for the noise, it must have been incredibly confusing to see this patch :(
next prev parent reply other threads:[~2025-07-28 11:34 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-07-28 10:31 [PATCH] arm64/mm: Fix use-after-free due to race between memory hotunplug and ptdump Dev Jain
2025-07-28 10:42 ` Dev Jain
2025-07-28 11:13 ` Ryan Roberts
2025-07-28 11:31 ` Dev Jain [this message]
2025-07-28 11:56 ` Ryan Roberts
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=ebbd54a7-1d84-4a47-8a66-394bdcb53d65@arm.com \
--to=dev.jain@arm.com \
--cc=anshuman.khandual@arm.com \
--cc=catalin.marinas@arm.com \
--cc=joey.gouly@arm.com \
--cc=kevin.brodsky@arm.com \
--cc=linux-arm-kernel@lists.infradead.org \
--cc=linux-kernel@vger.kernel.org \
--cc=mark.rutland@arm.com \
--cc=maz@kernel.org \
--cc=quic_zhenhuah@quicinc.com \
--cc=ryan.roberts@arm.com \
--cc=stable@vger.kernel.org \
--cc=will@kernel.org \
--cc=yangyicong@hisilicon.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox