Skip to content

Commit cdb281e

Browse files
Qi Zhengtorvalds
Qi Zheng
authored andcommitted
mm: fix NULL pointer dereference in wp_page_reuse()
The vmf->page can be NULL when the wp_page_reuse() is invoked by wp_pfn_shared(), it will cause the following panic: BUG: kernel NULL pointer dereference, address: 000000000000008 #PF: supervisor read access in kernel mode #PF: error_code(0x0000) - not-present page PGD 0 P4D 0 Oops: 0000 [#1] PREEMPT SMP PTI CPU: 18 PID: 923 Comm: Xorg Not tainted 5.19.0-rc8.bm.1-amd64 #263 Hardware name: QEMU Standard PC (i440FX + PIIX, 1996), BIOS rel-1.14.0-0-g14 RIP: 0010:_compound_head+0x0/0x40 [...] Call Trace: wp_page_reuse+0x1c/0xa0 do_wp_page+0x1a5/0x3f0 __handle_mm_fault+0x8cf/0xd20 handle_mm_fault+0xd5/0x2a0 do_user_addr_fault+0x1d0/0x680 exc_page_fault+0x78/0x170 asm_exc_page_fault+0x22/0x30 To fix it, this patch performs a NULL pointer check before dereferencing the vmf->page. Fixes: 6c28760 ("mm: remember exclusively mapped anonymous pages with PG_anon_exclusive") Signed-off-by: Qi Zheng <[email protected]> Reviewed-by: David Hildenbrand <[email protected]> Signed-off-by: Linus Torvalds <[email protected]>
1 parent e0dccc3 commit cdb281e

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

mm/memory.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3043,7 +3043,7 @@ static inline void wp_page_reuse(struct vm_fault *vmf)
30433043
pte_t entry;
30443044

30453045
VM_BUG_ON(!(vmf->flags & FAULT_FLAG_WRITE));
3046-
VM_BUG_ON(PageAnon(page) && !PageAnonExclusive(page));
3046+
VM_BUG_ON(page && PageAnon(page) && !PageAnonExclusive(page));
30473047

30483048
/*
30493049
* Clear the pages cpupid information as the existing

0 commit comments

Comments
 (0)