mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH V2] x86/mm: Fix NULL pointer dereference in kernel_page_present()
@ 2025-01-11 17:58 Tanya Agarwal
  2025-01-24 16:47 ` Tanya Agarwal
  2025-01-24 17:10 ` Dave Hansen
  0 siblings, 2 replies; 3+ messages in thread
From: Tanya Agarwal @ 2025-01-11 17:58 UTC (permalink / raw)
  To: dave.hansen, luto, peterz, tglx, mingo, bp
  Cc: x86, hpa, kirill.shutemov, rick.p.edgecombe, akpm,
	tanyaagarwal25699, skhan, anupnewsmail, linux-kernel

From: Tanya Agarwal <tanyaagarwal25699@gmail.com>

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@gmail.com>
---
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


^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2025-01-24 17:10 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2025-01-11 17:58 [PATCH V2] x86/mm: Fix NULL pointer dereference in kernel_page_present() Tanya Agarwal
2025-01-24 16:47 ` Tanya Agarwal
2025-01-24 17:10 ` Dave Hansen

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®