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

* Re: [PATCH V2] x86/mm: Fix NULL pointer dereference in kernel_page_present()
  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
  1 sibling, 0 replies; 3+ messages in thread
From: Tanya Agarwal @ 2025-01-24 16:47 UTC (permalink / raw)
  To: dave.hansen, luto, peterz, tglx, mingo, bp
  Cc: x86, hpa, kirill.shutemov, rick.p.edgecombe, akpm, skhan,
	anupnewsmail, linux-kernel

On Sat, Jan 11, 2025 at 11:28 PM Tanya Agarwal
<tanyaagarwal25699@gmail.com> wrote:
>
> 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
>

Hi Dave,

I just wanted to check if you've had a chance to review it or need any
more information.

Thanks,
Tanya

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

* Re: [PATCH V2] x86/mm: Fix NULL pointer dereference in kernel_page_present()
  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
  1 sibling, 0 replies; 3+ messages in thread
From: Dave Hansen @ 2025-01-24 17:10 UTC (permalink / raw)
  To: Tanya Agarwal, dave.hansen, luto, peterz, tglx, mingo, bp
  Cc: x86, hpa, kirill.shutemov, rick.p.edgecombe, akpm, skhan,
	anupnewsmail, linux-kernel

On 1/11/25 09:58, Tanya Agarwal wrote:
> 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.

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.

^ 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®