public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH] riscv: mm: add null check for find_vm_area in set_memory
@ 2026-03-14 22:28 Osama Abdelkader
  2026-03-16 10:22 ` Markus Elfring
  0 siblings, 1 reply; 4+ messages in thread
From: Osama Abdelkader @ 2026-03-14 22:28 UTC (permalink / raw)
  To: Paul Walmsley, Palmer Dabbelt, Albert Ou, Alexandre Ghiti,
	Suren Baghdasaryan, Lorenzo Stoakes, Oscar Salvador,
	Andrew Morton, Qi Zheng, Osama Abdelkader, linux-riscv,
	linux-kernel

find_vm_area() can return NULL. Add a null check to avoid potential
null pointer dereference, matching the pattern used by other arches.

Signed-off-by: Osama Abdelkader <osama.abdelkader@gmail.com>
---
 arch/riscv/mm/pageattr.c | 4 ++++
 1 file changed, 4 insertions(+)

diff --git a/arch/riscv/mm/pageattr.c b/arch/riscv/mm/pageattr.c
index 3f76db3d2769..46a999c86b26 100644
--- a/arch/riscv/mm/pageattr.c
+++ b/arch/riscv/mm/pageattr.c
@@ -289,6 +289,10 @@ static int __set_memory(unsigned long addr, int numpages, pgprot_t set_mask,
 		int i, page_start;
 
 		area = find_vm_area((void *)start);
+		if (!area) {
+			ret = -EINVAL;
+			goto unlock;
+		}
 		page_start = (start - (unsigned long)area->addr) >> PAGE_SHIFT;
 
 		for (i = page_start; i < page_start + numpages; ++i) {
-- 
2.43.0


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

* Re: [PATCH] riscv: mm: add null check for find_vm_area in set_memory
  2026-03-14 22:28 [PATCH] riscv: mm: add null check for find_vm_area in set_memory Osama Abdelkader
@ 2026-03-16 10:22 ` Markus Elfring
  2026-03-16 15:21   ` Osama Abdelkader
  0 siblings, 1 reply; 4+ messages in thread
From: Markus Elfring @ 2026-03-16 10:22 UTC (permalink / raw)
  To: Osama Abdelkader, linux-riscv, Albert Ou, Alexandre Ghiti,
	Andrew Morton, Lorenzo Stoakes, Oscar Salvador, Palmer Dabbelt,
	Paul Walmsley, Qi Zheng, Suren Baghdasaryan
  Cc: LKML

> find_vm_area() can return NULL. Add a null check to avoid potential
> null pointer dereference, matching the pattern used by other arches.

1. Were any source code analysis tools involved here?

2. How do you think about to add any tags (like “Fixes” and “Cc”) accordingly?
   https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/Documentation/process/submitting-patches.rst?h=v7.0-rc4#n145

3. Would you like to refer to the function “__set_memory” in the summary phrase?


Regards,
Markus

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

* Re: [PATCH] riscv: mm: add null check for find_vm_area in set_memory
  2026-03-16 10:22 ` Markus Elfring
@ 2026-03-16 15:21   ` Osama Abdelkader
  2026-03-16 16:34     ` Markus Elfring
  0 siblings, 1 reply; 4+ messages in thread
From: Osama Abdelkader @ 2026-03-16 15:21 UTC (permalink / raw)
  To: Markus Elfring
  Cc: linux-riscv, Albert Ou, Alexandre Ghiti, Andrew Morton,
	Lorenzo Stoakes, Oscar Salvador, Palmer Dabbelt, Paul Walmsley,
	Qi Zheng, Suren Baghdasaryan, LKML

On Mon, Mar 16, 2026 at 11:22:26AM +0100, Markus Elfring wrote:
> > find_vm_area() can return NULL. Add a null check to avoid potential
> > null pointer dereference, matching the pattern used by other arches.
> 
> 1. Were any source code analysis tools involved here?

No, both were found during manual review and compare with arm64.

> 
> 2. How do you think about to add any tags (like “Fixes” and “Cc”) accordingly?
>    https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/Documentation/process/submitting-patches.rst?h=v7.0-rc4#n145
> 
> 3. Would you like to refer to the function “__set_memory” in the summary phrase?
>

Done, I just sent v2, appreciate your review.
 
> 
> Regards,
> Markus

Thanks,
Osama

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

* Re: riscv: mm: add null check for find_vm_area in set_memory
  2026-03-16 15:21   ` Osama Abdelkader
@ 2026-03-16 16:34     ` Markus Elfring
  0 siblings, 0 replies; 4+ messages in thread
From: Markus Elfring @ 2026-03-16 16:34 UTC (permalink / raw)
  To: Osama Abdelkader, linux-riscv
  Cc: Albert Ou, Alexandre Ghiti, Andrew Morton, Lorenzo Stoakes,
	Oscar Salvador, Palmer Dabbelt, Paul Walmsley, Qi Zheng,
	Suren Baghdasaryan, LKML

>>> find_vm_area() can return NULL. Add a null check to avoid potential
>>> null pointer dereference, matching the pattern used by other arches.
>>
>> 1. Were any source code analysis tools involved here?
> 
> No, both were found during manual review and compare with arm64.

Would be looking for the support of advanced approaches
which would make such a “comparison” more convenient?

Regards,
Markus

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

end of thread, other threads:[~2026-03-16 16:35 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-03-14 22:28 [PATCH] riscv: mm: add null check for find_vm_area in set_memory Osama Abdelkader
2026-03-16 10:22 ` Markus Elfring
2026-03-16 15:21   ` Osama Abdelkader
2026-03-16 16:34     ` Markus Elfring

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