[PATCH V2] x86/mm: Fix NULL pointer dereference in kernel_page_present()
From: Tanya Agarwal
Date: Sat Jan 11 2025 - 12:58:28 EST
From: Tanya Agarwal <tanyaagarwal25699@xxxxxxxxx>
The static code analysis tool "Coverity Scan" pointed the following
details out for further development considerations:
CID 1271215: Dereference null return value (NULL_RETURNS)
dereference: Dereferencing pte, which is known to be NULL.
Conclusion:
Add WARN_ON_ONCE() and NULL check for pte before dereferencing it.
Fixes: 8a235efad548 ("Hibernation: Handle DEBUG_PAGEALLOC on x86")
Signed-off-by: Tanya Agarwal <tanyaagarwal25699@xxxxxxxxx>
---
V2: add WARN_ON_ONCE() as suggested by Dave
Coverity Link:
https://scan5.scan.coverity.com/#/project-view/63683/10063?selectedIssue=1271215
arch/x86/mm/pat/set_memory.c | 3 +++
1 file changed, 3 insertions(+)
diff --git a/arch/x86/mm/pat/set_memory.c b/arch/x86/mm/pat/set_memory.c
index 95bc50a8541c..8f9d418e6a8c 100644
--- a/arch/x86/mm/pat/set_memory.c
+++ b/arch/x86/mm/pat/set_memory.c
@@ -2495,6 +2495,9 @@ bool kernel_page_present(struct page *page)
return false;
pte = lookup_address((unsigned long)page_address(page), &level);
+ if (WARN_ON_ONCE(!pte))
+ return false;
+
return (pte_val(*pte) & _PAGE_PRESENT);
}
--
2.39.5