linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
From: David Hildenbrand <david@redhat.com>
To: Lorenzo Stoakes <lorenzo.stoakes@oracle.com>,
	Yuntao Liu <liuyuntao12@huawei.com>
Cc: linux-kernel@vger.kernel.org, linux-mm@kvack.org,
	mhocko@suse.com, surenb@google.com, rppt@kernel.org,
	vbabka@suse.cz, Liam.Howlett@oracle.com,
	akpm@linux-foundation.org
Subject: Re: [PATCH -next] mm/memory: fix null pointer dereference in fault_dirty_shared_page
Date: Mon, 7 Jul 2025 14:27:01 +0200	[thread overview]
Message-ID: <ea66f8a5-de20-4f6e-afcc-2eda84709958@redhat.com> (raw)
In-Reply-To: <2b716e2f-0642-49df-a955-abfe0525cefd@lucifer.local>

On 07.07.25 13:14, Lorenzo Stoakes wrote:
> On Mon, Jul 07, 2025 at 10:51:18AM +0000, Yuntao Liu wrote:
>> Page mapping with "VM_READ|VM_WRITE|VM_MAYREAD|VM_MAYWRITE|VM_SHARED",
>> the first time accessing this address through a write operation will
>> trigger a do_shared_fault, if mapping is anonymous, it can lead to a
>> null pointer dereference.
> 
> How can it be anonymous with VM_SHARED set? This would be a far, far bigger
> bug.
> 
>>
>> [   23.232336][  T195] Call trace:
>> [   23.232542][  T195]  file_update_time+0x2c/0xd8
>> [   23.232801][  T195]  fault_dirty_shared_page+0x1a0/0x220
>> [   23.233099][  T195]  do_shared_fault+0xe8/0x240
>> [   23.233374][  T195]  do_fault+0x78/0x240
>> [   23.233629][  T195]  handle_pte_fault+0x1f0/0x3f0
>> [   23.233905][  T195]  __handle_mm_fault+0x2b0/0x548
>> [   23.234186][  T195]  handle_mm_fault+0xd4/0x2f8
>> [   23.234462][  T195]  do_page_fault+0x2f0/0x5f8
>> [   23.234727][  T195]  do_translation_fault+0x8c/0xc8
>> [   23.235021][  T195]  do_mem_abort+0x68/0x100
>> [   23.235283][  T195]  el0_da+0x4c/0x1a8
>> [   23.235551][  T195]  el0t_64_sync_handler+0xe4/0x158
>> [   23.235861][  T195]  el0t_64_sync+0x37c/0x380
> 
> How have you obtained this? Are you somehow injecting invalid state here?
> 
>>
>> Signed-off-by: Yuntao Liu <liuyuntao12@huawei.com>
>> ---
>>   mm/memory.c | 2 +-
>>   1 file changed, 1 insertion(+), 1 deletion(-)
>>
>> diff --git a/mm/memory.c b/mm/memory.c
>> index eaf98d518289..8106ef8a5036 100644
>> --- a/mm/memory.c
>> +++ b/mm/memory.c
>> @@ -3412,7 +3412,7 @@ static vm_fault_t fault_dirty_shared_page(struct vm_fault *vmf)
>>   	mapping = folio_raw_mapping(folio);
>>   	folio_unlock(folio);
>>
>> -	if (!page_mkwrite)
>> +	if (!page_mkwrite && vma->vm_file)
> 
> The function is ltierally fault_dirty_shared_page(), how are we arriving
> here with !vma->vm_file?

IIRC, MAP_ANON |MAP_SHARED would have done a shmem_zero_setup().

mm/mmap.c still has the comment "mmap_region() will call 
shmem_zero_setup() to create a file".

I think this was moved to __mmap_new_vma().

Is there any (error) path where we could not call that by accident?

-- 
Cheers,

David / dhildenb



  reply	other threads:[~2025-07-07 12:27 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-07-07 10:51 Yuntao Liu
2025-07-07 11:14 ` Lorenzo Stoakes
2025-07-07 12:27   ` David Hildenbrand [this message]
2025-07-07 12:32     ` Lorenzo Stoakes

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=ea66f8a5-de20-4f6e-afcc-2eda84709958@redhat.com \
    --to=david@redhat.com \
    --cc=Liam.Howlett@oracle.com \
    --cc=akpm@linux-foundation.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mm@kvack.org \
    --cc=liuyuntao12@huawei.com \
    --cc=lorenzo.stoakes@oracle.com \
    --cc=mhocko@suse.com \
    --cc=rppt@kernel.org \
    --cc=surenb@google.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