]> git.proxmox.com Git - mirror_ubuntu-hirsute-kernel.git/commitdiff
riscv: virt_addr_valid must check the address belongs to linear mapping
authorAlexandre Ghiti <alex@ghiti.fr>
Fri, 29 Jan 2021 17:31:05 +0000 (12:31 -0500)
committerPalmer Dabbelt <palmerdabbelt@google.com>
Wed, 3 Feb 2021 02:31:13 +0000 (18:31 -0800)
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>
arch/riscv/include/asm/page.h

index 2d50f76efe4819ffa8645ac1aa1d1c7473fe400f..64a675c5c30acb2c9806645ba9f3f5e7297cef21 100644 (file)
@@ -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