From: Pu Lehui <pulehui@huaweicloud.com>
To: Lorenzo Stoakes <lorenzo.stoakes@oracle.com>,
David Hildenbrand <david@redhat.com>
Cc: Oleg Nesterov <oleg@redhat.com>,
mhiramat@kernel.org, peterz@infradead.org,
Liam.Howlett@oracle.com, akpm@linux-foundation.org,
vbabka@suse.cz, jannh@google.com, pfalcato@suse.de,
linux-mm@kvack.org, linux-kernel@vger.kernel.org,
pulehui@huawei.com
Subject: Re: [RFC PATCH] mm/mmap: Fix uprobe anon page be overwritten when expanding vma during mremap
Date: Tue, 27 May 2025 21:39:55 +0800 [thread overview]
Message-ID: <03b171c9-0de2-4d25-9d12-6d49d4daa2b5@huaweicloud.com> (raw)
In-Reply-To: <b84f00c8-966c-46f2-8afe-d09465153217@lucifer.local>
On 2025/5/27 19:42, Lorenzo Stoakes wrote:
> On Mon, May 26, 2025 at 08:46:07PM +0200, David Hildenbrand wrote:
>> On 26.05.25 17:48, Oleg Nesterov wrote:
>>> Hi Lehui,
>>>
>>> As I said, I don't understand mm/, so can't comment, but...
>>>
>>> On 05/26, Pu Lehui wrote:
>>>>
>>>> To make things simpler, perhaps we could try post-processing, that is:
>>>>
>>>> diff --git a/mm/mremap.c b/mm/mremap.c
>>>> index 83e359754961..46a757fd26dc 100644
>>>> --- a/mm/mremap.c
>>>> +++ b/mm/mremap.c
>>>> @@ -240,6 +240,11 @@ static int move_ptes(struct pagetable_move_control
>>>> *pmc,
>>>> if (pte_none(ptep_get(old_pte)))
>>>> continue;
>>>>
>>>> + /* skip move pte when expanded range has uprobe */
>>>> + if (unlikely(pte_present(*new_pte) &&
>>>> + vma_has_uprobes(pmc->new, new_addr, new_addr +
>>>> PAGE_SIZE)))
>
> This feels like a horrible hack, note that we also move page tables at higher
> page table levels _anyway_ so this would be broken by that (unless uprobes split
> huge mappings).
Got it. Won't do this try...
>
> If it's uprobe code that's putting the new PTE in place, then this is
> just... yeah. I'm with David's suggestion of just disallowing this scenario, I
> really dislike the idea that we're ok with an invalid condition being ok, only
> to cover off this one specific case.
>
>
>>>> + continue;
>>>> +
>>>
>>> I was thinking about
>>>
>>> WARN_ON(!pte_none(*new_pte))
>>>
>>> at the start of the main loop.
>>>
>>> Obviously not to fix the problem, but rather to make it more explicit.
>>
>> Yeah, WARN_ON_ONCE().
>>
>> We really should fix the code to not install uprobes into the area we are
>> moving.
>>
>> Likely, the correct fix will be to pass the range as well to uprobe_mmap(),
>> and passing that range to build_probe_list().
>>
>> Only when growing using mremap(), we want to call it on the extended range
>> only.
>
> We might be able to implement a simpler version of the proposed patch though
> which might avoid us needing to do something like this.
>
> Having a look...
>
>>
>> --
>> Cheers,
>>
>> David / dhildenb
>>
next prev parent reply other threads:[~2025-05-27 13:40 UTC|newest]
Thread overview: 31+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-05-21 9:25 Pu Lehui
2025-05-21 10:25 ` David Hildenbrand
2025-05-22 14:37 ` Pu Lehui
2025-05-22 15:14 ` David Hildenbrand
2025-05-26 14:52 ` Pu Lehui
2025-05-26 15:48 ` Oleg Nesterov
2025-05-26 18:46 ` David Hildenbrand
2025-05-27 11:42 ` Lorenzo Stoakes
2025-05-27 11:44 ` Lorenzo Stoakes
2025-05-27 13:39 ` Pu Lehui [this message]
2025-05-27 13:38 ` Pu Lehui
2025-05-28 9:03 ` David Hildenbrand
2025-05-29 16:07 ` Pu Lehui
2025-05-30 8:33 ` David Hildenbrand
2025-05-30 8:41 ` Lorenzo Stoakes
2025-05-30 8:50 ` David Hildenbrand
2025-05-30 9:03 ` Lorenzo Stoakes
2025-05-30 9:27 ` David Hildenbrand
2025-05-30 18:09 ` Oleg Nesterov
2025-05-30 18:34 ` David Hildenbrand
2025-05-30 22:48 ` Pu Lehui
2025-05-27 13:23 ` Pu Lehui
2025-05-21 13:13 ` Lorenzo Stoakes
2025-05-22 15:00 ` Pu Lehui
2025-05-22 15:18 ` Lorenzo Stoakes
2025-05-24 16:45 ` Oleg Nesterov
2025-05-24 21:45 ` David Hildenbrand
2025-05-25 9:59 ` Oleg Nesterov
2025-05-25 10:24 ` David Hildenbrand
2025-05-26 16:29 ` Oleg Nesterov
2025-05-26 17:38 ` Oleg Nesterov
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=03b171c9-0de2-4d25-9d12-6d49d4daa2b5@huaweicloud.com \
--to=pulehui@huaweicloud.com \
--cc=Liam.Howlett@oracle.com \
--cc=akpm@linux-foundation.org \
--cc=david@redhat.com \
--cc=jannh@google.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=lorenzo.stoakes@oracle.com \
--cc=mhiramat@kernel.org \
--cc=oleg@redhat.com \
--cc=peterz@infradead.org \
--cc=pfalcato@suse.de \
--cc=pulehui@huawei.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