Skip to content

Commit 8339f7d

Browse files
mrutland-armctmarinas
authored andcommitted
arm64: module: remove old !KASAN_VMALLOC logic
Historically, KASAN could be selected with or without KASAN_VMALLOC, and we had to be very careful where to place modules when KASAN_VMALLOC was not selected. However, since commit: f6f37d9 ("arm64: select KASAN_VMALLOC for SW/HW_TAGS modes") Selecting CONFIG_KASAN on arm64 will also select CONFIG_KASAN_VMALLOC, and so the logic for handling CONFIG_KASAN without CONFIG_KASAN_VMALLOC is redundant and can be removed. Note: the "kasan.vmalloc={on,off}" option which only exists for HW_TAGS changes whether the vmalloc region is given non-match-all tags, and does not affect the page table manipulation code. The VM_DEFER_KMEMLEAK flag was only necessary for !CONFIG_KASAN_VMALLOC as described in its introduction in commit: 60115fa ("mm: defer kmemleak object creation of module_alloc()") ... and therefore it can also be removed. Remove the redundant logic for !CONFIG_KASAN_VMALLOC. At the same time, add the missing braces around the multi-line conditional block in arch/arm64/kernel/module.c. Suggested-by: Ard Biesheuvel <[email protected]> Signed-off-by: Mark Rutland <[email protected]> Reviewed-by: Ard Biesheuvel <[email protected]> Cc: Alexander Potapenko <[email protected]> Cc: Andrew Morton <[email protected]> Cc: Andrey Konovalov <[email protected]> Cc: Andrey Ryabinin <[email protected]> Cc: Dmitry Vyukov <[email protected]> Cc: Will Deacon <[email protected]> Tested-by: Shanker Donthineni <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Catalin Marinas <[email protected]>
1 parent 44c026a commit 8339f7d

File tree

2 files changed

+3
-30
lines changed

2 files changed

+3
-30
lines changed

arch/arm64/kernel/kaslr.c

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -48,16 +48,6 @@ static int __init kaslr_init(void)
4848

4949
pr_info("KASLR enabled\n");
5050

51-
/*
52-
* KASAN without KASAN_VMALLOC does not expect the module region to
53-
* intersect the vmalloc region, since shadow memory is allocated for
54-
* each module at load time, whereas the vmalloc region will already be
55-
* shadowed by KASAN zero pages.
56-
*/
57-
BUILD_BUG_ON((IS_ENABLED(CONFIG_KASAN_GENERIC) ||
58-
IS_ENABLED(CONFIG_KASAN_SW_TAGS)) &&
59-
!IS_ENABLED(CONFIG_KASAN_VMALLOC));
60-
6151
seed = get_random_u32();
6252

6353
if (IS_ENABLED(CONFIG_RANDOMIZE_MODULE_REGION_FULL)) {

arch/arm64/kernel/module.c

Lines changed: 3 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -32,33 +32,16 @@ void *module_alloc(unsigned long size)
3232
if (IS_ENABLED(CONFIG_ARM64_MODULE_PLTS))
3333
gfp_mask |= __GFP_NOWARN;
3434

35-
if (IS_ENABLED(CONFIG_KASAN_GENERIC) ||
36-
IS_ENABLED(CONFIG_KASAN_SW_TAGS))
37-
/* don't exceed the static module region - see below */
38-
module_alloc_end = MODULES_END;
39-
4035
p = __vmalloc_node_range(size, MODULE_ALIGN, module_alloc_base,
41-
module_alloc_end, gfp_mask, PAGE_KERNEL, VM_DEFER_KMEMLEAK,
36+
module_alloc_end, gfp_mask, PAGE_KERNEL, 0,
4237
NUMA_NO_NODE, __builtin_return_address(0));
4338

44-
if (!p && IS_ENABLED(CONFIG_ARM64_MODULE_PLTS) &&
45-
(IS_ENABLED(CONFIG_KASAN_VMALLOC) ||
46-
(!IS_ENABLED(CONFIG_KASAN_GENERIC) &&
47-
!IS_ENABLED(CONFIG_KASAN_SW_TAGS))))
48-
/*
49-
* KASAN without KASAN_VMALLOC can only deal with module
50-
* allocations being served from the reserved module region,
51-
* since the remainder of the vmalloc region is already
52-
* backed by zero shadow pages, and punching holes into it
53-
* is non-trivial. Since the module region is not randomized
54-
* when KASAN is enabled without KASAN_VMALLOC, it is even
55-
* less likely that the module region gets exhausted, so we
56-
* can simply omit this fallback in that case.
57-
*/
39+
if (!p && IS_ENABLED(CONFIG_ARM64_MODULE_PLTS)) {
5840
p = __vmalloc_node_range(size, MODULE_ALIGN, module_alloc_base,
5941
module_alloc_base + SZ_2G, GFP_KERNEL,
6042
PAGE_KERNEL, 0, NUMA_NO_NODE,
6143
__builtin_return_address(0));
44+
}
6245

6346
if (p && (kasan_alloc_module_shadow(p, size, gfp_mask) < 0)) {
6447
vfree(p);

0 commit comments

Comments
 (0)