[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <ebbd54a7-1d84-4a47-8a66-394bdcb53d65@arm.com>
Date: Mon, 28 Jul 2025 17:01:10 +0530
From: Dev Jain <dev.jain@....com>
To: Ryan Roberts <ryan.roberts@....com>, catalin.marinas@....com,
will@...nel.org
Cc: anshuman.khandual@....com, quic_zhenhuah@...cinc.com,
kevin.brodsky@....com, yangyicong@...ilicon.com, joey.gouly@....com,
linux-arm-kernel@...ts.infradead.org, linux-kernel@...r.kernel.org,
mark.rutland@....com, maz@...nel.org, stable@...r.kernel.org
Subject: Re: [PATCH] arm64/mm: Fix use-after-free due to race between memory
hotunplug and ptdump
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 :(
Powered by blists - more mailing lists