summaryrefslogtreecommitdiff
path: root/arch
diff options
context:
space:
mode:
authorAlexandre Ghiti <alex@ghiti.fr>2021-01-29 20:31:05 +0300
committerPalmer Dabbelt <palmerdabbelt@google.com>2021-02-03 05:31:13 +0300
commit2ab543823322b564f205cb15d0f0302803c87d11 (patch)
tree7b8ad0e5c2d6547e1e42886ce9e28f16af2c7336 /arch
parent1048ba83fb1c00cd24172e23e8263972f6b5d9ac (diff)
downloadlinux-2ab543823322b564f205cb15d0f0302803c87d11.tar.xz
riscv: virt_addr_valid must check the address belongs to linear mapping
virt_addr_valid macro checks that a virtual address is valid, ie that the address belongs to the linear mapping and that the corresponding physical page exists. Add the missing check that ensures the virtual address belongs to the linear mapping, otherwise __virt_to_phys, when compiled with CONFIG_DEBUG_VIRTUAL enabled, raises a WARN that is interpreted as a kernel bug by syzbot. Signed-off-by: Alexandre Ghiti <alex@ghiti.fr> Reviewed-by: Atish Patra <atish.patra@wdc.com> Signed-off-by: Palmer Dabbelt <palmerdabbelt@google.com>
Diffstat (limited to 'arch')
-rw-r--r--arch/riscv/include/asm/page.h5
1 files changed, 4 insertions, 1 deletions
diff --git a/arch/riscv/include/asm/page.h b/arch/riscv/include/asm/page.h
index 2d50f76efe48..64a675c5c30a 100644
--- a/arch/riscv/include/asm/page.h
+++ b/arch/riscv/include/asm/page.h
@@ -135,7 +135,10 @@ extern phys_addr_t __phys_addr_symbol(unsigned long x);
#endif /* __ASSEMBLY__ */
-#define virt_addr_valid(vaddr) (pfn_valid(virt_to_pfn(vaddr)))
+#define virt_addr_valid(vaddr) ({ \
+ unsigned long _addr = (unsigned long)vaddr; \
+ (unsigned long)(_addr) >= PAGE_OFFSET && pfn_valid(virt_to_pfn(_addr)); \
+})
#define VM_DATA_DEFAULT_FLAGS VM_DATA_FLAGS_NON_EXEC