Skip to content

Commit

Permalink
lkl: follow up fix after v6.1 merge (kasan_addr_to_slab)
Browse files Browse the repository at this point in the history
A note from Eugene Rodionov on github:

kasan_addr_to_slab() in mm/kasan/common.c, when addr doesn't correspond
to the LKL virtual memory but points in stack. LKL assumes that all the
virtual memory is located between memory_start and memory_end variables
which are initialized in arch/lkl/mm/bootmem.c. However, the actual
memory for stack for LKL threads is located outside of this region and,
thus, calling virt_to_slab for a stack address which is outside of the
region of LKL memory would result in the crash.

In theory, virt_addr_valid above should prevent from calling virt_to_slab
on the pointer which isn't a valid virtual address but if we look at the
implementation of virt_addr_valid used in LKL we find that it checks the
pointer only against memory_end but memory_start isn't used.

// include/asm-generic/page.h
 #define virt_addr_valid(kaddr) (((void *)(kaddr) >= (void *)PAGE_OFFSET) \
                                 && ((void *)(kaddr) < (void *)memory_end))

As a result, if the stack memory is located below the LKL virtual memory
(which is in my case), then virt_addr_valid would return a non-zero value
leading to the call to virt_to_slab.

This commit fixes this issue to set PAGE_OFFSET value to memory_start,
instead of the default value, 0.

Fixes: 0f282f1 ("kasan: use kasan_addr_to_slab in print_address_description")

Reported-by: Eugene Rodionov <[email protected]>
Co-developed-by: Octavian Purdila <[email protected]>
Signed-off-by: Octavian Purdila <[email protected]>
Signed-off-by: Hajime Tazaki <[email protected]>
  • Loading branch information
thehajime committed Jun 23, 2023
1 parent 2115b79 commit e88a85a
Showing 1 changed file with 3 additions and 0 deletions.
3 changes: 3 additions & 0 deletions arch/lkl/include/asm/page.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,7 @@ void bootmem_init(unsigned long mem_size);

#include <asm-generic/page.h>

#undef PAGE_OFFSET
#define PAGE_OFFSET memory_start

#endif /* _ASM_LKL_PAGE_H */

0 comments on commit e88a85a

Please sign in to comment.