[PATCH v2] riscv: mm: add null check for find_vm_area in __set_memory

Andrew Morton akpm at linux-foundation.org
Mon Mar 16 08:44:55 PDT 2026


On Mon, 16 Mar 2026 16:16:39 +0100 Osama Abdelkader <osama.abdelkader at gmail.com> wrote:

> find_vm_area() can return NULL. Add a null check to avoid potential
> null pointer dereference, matching the pattern used by other arches.
> 
> Fixes: 311cd2f6e253 ("riscv: Fix set_memory_XX() and set_direct_map_XX() by splitting huge linear mappings")

Three years ago.

> Cc: stable at vger.kernel.org

Why cc:stable?  Has anyone ever hit this?  Are we able to identify a
scenario where this bug might be triggered?

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



More information about the linux-riscv mailing list