Skip to contentSkip to conversation

riscv: mm: add null check for find_vm_area in set_memory

PATCH Superseded Osama Abdelkader 2 participants 4 messages Mar 14 – Mar 16 RISC-V

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 riscv: mm: add null check for find_vm_area in set_memory

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

---
 arch/riscv/mm/pageattr.c | 4 ++++
 1 file changed, 4 insertions(+)
arch/riscv/mm/pageattr.c +4 -0
index 3f76db3d2769..46a999c86b26 100644
@@ -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) {
Signature · 1 line
2.43.0
#1 lore raw
Quoted 2 lines

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

#2 lore raw
Quoted 4 lines · Markus Elfring
Quoted 2 lines

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.

Quoted 6 lines

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.

Quoted 3 lines

Regards,
Markus

Thanks,
Osama

#3 lore raw
Quoted 6 lines
Quoted 4 lines
Quoted 2 lines

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

_______________________________________________
linux-riscv mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-riscv