arch/riscv/mm/pageattr.c | 4 ++++ 1 file changed, 4 insertions(+)
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
> 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
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
>>> 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
© 2016 - 2026 Red Hat, Inc.