linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
From: Yuntao Liu <liuyuntao12@huawei.com>
To: <linux-kernel@vger.kernel.org>, <linux-mm@kvack.org>
Cc: <mhocko@suse.com>, <surenb@google.com>, <rppt@kernel.org>,
	<vbabka@suse.cz>, <Liam.Howlett@oracle.com>,
	<lorenzo.stoakes@oracle.com>, <liuyuntao12@huawei.com>,
	<david@redhat.com>, <akpm@linux-foundation.org>
Subject: [PATCH -next] mm/memory: fix null pointer dereference in fault_dirty_shared_page
Date: Mon, 7 Jul 2025 10:51:18 +0000	[thread overview]
Message-ID: <20250707105118.413056-1-liuyuntao12@huawei.com> (raw)

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.

[   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

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)
 		file_update_time(vma->vm_file);
 
 	/*
-- 
2.34.1



             reply	other threads:[~2025-07-07 11:04 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-07-07 10:51 Yuntao Liu [this message]
2025-07-07 11:14 ` Lorenzo Stoakes
2025-07-07 12:27   ` David Hildenbrand
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=20250707105118.413056-1-liuyuntao12@huawei.com \
    --to=liuyuntao12@huawei.com \
    --cc=Liam.Howlett@oracle.com \
    --cc=akpm@linux-foundation.org \
    --cc=david@redhat.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mm@kvack.org \
    --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