Skip to content

Commit

Permalink
riscv: virt_addr_valid must check the address belongs to linear mapping
Browse files Browse the repository at this point in the history
[ Upstream commit 2ab5438 ]

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>
Signed-off-by: Sasha Levin <sashal@kernel.org>
  • Loading branch information
AlexGhiti authored and gregkh committed Feb 17, 2021
1 parent cd0604d commit 4fccb50
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion arch/riscv/include/asm/page.h
Expand Up @@ -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

Expand Down

0 comments on commit 4fccb50

Please sign in to comment.