x86/mm: Fix NULL pointer dereference in kernel_page_present()
PATCH v2 1/1 x86/mm: Fix NULL pointer dereference in kernel_page_present()
From: Tanya Agarwal <[email protected]>
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.
---
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(+)
arch/x86/mm/pat/set_memory.c +3 -0
@@ -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); }
Signature · 1 line
2.39.5
Quoted 37 lines · Tanya Agarwal
From: Tanya Agarwal <[email protected]>
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:
AddWARN_ON_ONCE()and NULL check for pte before dereferencing it.Fixes 8a235efad548 ("Hibernation: Handle DEBUG_PAGEALLOC on x86")Signed-off-by Tanya Agarwal <[email protected]>---
V2: addWARN_ON_ONCE()as suggested by DaveCoverity Link:
https://scan5.scan.coverity.com/#/project-view/63683/10063?selectedIssue=1271215arch/x86/mm/pat/set_memory.c | 3 +++ 1 file changed, 3 insertions(+)arch/x86/mm/pat/set_memory.c +3
-1@@ -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); } --
Quoted 2 lines
2.39.5
Hi Dave,
I just wanted to check if you've had a chance to review it or need any more information.
Thanks,
Tanya
Quoted 6 lines · Tanya Agarwal
From: Tanya Agarwal <[email protected]>
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.
I think we need an actual changelog for this, as opposed to just blindly trusting Coverity. You can say that Coverity helped identify this as an issue, but we don't need the "CID" or other Coverity gunk in our changelogs. We don't care.
Could you please elaborate on where this issue might affect people? It's also entirely theoretical as far as I can tell. I can't even conjure up a contrived case where it could be triggered.
We won't do _anything_ with this patch until the merge window closes, so you've got at least a week to spruce up the changelog.