Skip to content

Commit 519ea6f

Browse files
fvincenzoctmarinas
authored andcommitted
arm64: Fix kernel address detection of __is_lm_address()
Currently, the __is_lm_address() check just masks out the top 12 bits of the address, but if they are 0, it still yields a true result. This has as a side effect that virt_addr_valid() returns true even for invalid virtual addresses (e.g. 0x0). Fix the detection checking that it's actually a kernel address starting at PAGE_OFFSET. Fixes: 68dd8ef ("arm64: memory: Fix virt_addr_valid() using __is_lm_address()") Cc: <[email protected]> # 5.4.x Cc: Will Deacon <[email protected]> Suggested-by: Catalin Marinas <[email protected]> Reviewed-by: Catalin Marinas <[email protected]> Acked-by: Mark Rutland <[email protected]> Signed-off-by: Vincenzo Frascino <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Catalin Marinas <[email protected]>
1 parent 75bd4bf commit 519ea6f

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

arch/arm64/include/asm/memory.h

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -247,9 +247,11 @@ static inline const void *__tag_set(const void *addr, u8 tag)
247247

248248

249249
/*
250-
* The linear kernel range starts at the bottom of the virtual address space.
250+
* Check whether an arbitrary address is within the linear map, which
251+
* lives in the [PAGE_OFFSET, PAGE_END) interval at the bottom of the
252+
* kernel's TTBR1 address range.
251253
*/
252-
#define __is_lm_address(addr) (((u64)(addr) & ~PAGE_OFFSET) < (PAGE_END - PAGE_OFFSET))
254+
#define __is_lm_address(addr) (((u64)(addr) ^ PAGE_OFFSET) < (PAGE_END - PAGE_OFFSET))
253255

254256
#define __lm_to_phys(addr) (((addr) & ~PAGE_OFFSET) + PHYS_OFFSET)
255257
#define __kimg_to_phys(addr) ((addr) - kimage_voffset)

0 commit comments

Comments
 (0)