Skip to content

Commit 793213a

Browse files
Vasily GorbikMartin Schwidefsky
authored andcommitted
s390/kasan: dynamic shadow mem allocation for modules
Move from modules area entire shadow memory preallocation to dynamic allocation per module load. This behaivior has been introduced for x86 with bebf56a: "This patch also forces module_alloc() to return 8*PAGE_SIZE aligned address making shadow memory handling ( kasan_module_alloc()/kasan_module_free() ) more simple. Such alignment guarantees that each shadow page backing modules address space correspond to only one module_alloc() allocation" Signed-off-by: Vasily Gorbik <[email protected]> Signed-off-by: Martin Schwidefsky <[email protected]>
1 parent 0dac8f6 commit 793213a

File tree

2 files changed

+14
-12
lines changed

2 files changed

+14
-12
lines changed

arch/s390/kernel/module.c

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
#include <linux/fs.h>
1717
#include <linux/string.h>
1818
#include <linux/kernel.h>
19+
#include <linux/kasan.h>
1920
#include <linux/moduleloader.h>
2021
#include <linux/bug.h>
2122
#include <asm/alternative.h>
@@ -32,12 +33,18 @@
3233

3334
void *module_alloc(unsigned long size)
3435
{
36+
void *p;
37+
3538
if (PAGE_ALIGN(size) > MODULES_LEN)
3639
return NULL;
37-
return __vmalloc_node_range(size, 1, MODULES_VADDR, MODULES_END,
38-
GFP_KERNEL, PAGE_KERNEL_EXEC,
39-
0, NUMA_NO_NODE,
40-
__builtin_return_address(0));
40+
p = __vmalloc_node_range(size, MODULE_ALIGN, MODULES_VADDR, MODULES_END,
41+
GFP_KERNEL, PAGE_KERNEL_EXEC, 0, NUMA_NO_NODE,
42+
__builtin_return_address(0));
43+
if (p && (kasan_module_alloc(p, size) < 0)) {
44+
vfree(p);
45+
return NULL;
46+
}
47+
return p;
4148
}
4249

4350
void module_arch_freeing_init(struct module *mod)

arch/s390/mm/kasan_init.c

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -214,8 +214,6 @@ void __init kasan_early_init(void)
214214

215215
memsize = min(max_physmem_end, KASAN_SHADOW_START);
216216
shadow_alloc_size = memsize >> KASAN_SHADOW_SCALE_SHIFT;
217-
if (IS_ENABLED(CONFIG_MODULES))
218-
shadow_alloc_size += MODULES_LEN >> KASAN_SHADOW_SCALE_SHIFT;
219217
pgalloc_low = round_up((unsigned long)_end, _SEGMENT_SIZE);
220218
if (IS_ENABLED(CONFIG_BLK_DEV_INITRD)) {
221219
initrd_end =
@@ -239,18 +237,15 @@ void __init kasan_early_init(void)
239237
* +- shadow end -+ | mapping |
240238
* | ... gap ... |\ | (untracked) |
241239
* +- modules vaddr -+ \ +----------------+
242-
* | 2Gb | \| 256Mb |
240+
* | 2Gb | \| unmapped | allocated per module
243241
* +-----------------+ +- shadow end ---+
244242
*/
245243
/* populate identity mapping */
246244
kasan_early_vmemmap_populate(0, memsize, POPULATE_ONE2ONE);
247-
/* populate kasan shadow (for identity mapping / modules / zero page) */
245+
/* populate kasan shadow (for identity mapping and zero page mapping) */
248246
kasan_early_vmemmap_populate(__sha(0), __sha(memsize), POPULATE_MAP);
249-
if (IS_ENABLED(CONFIG_MODULES)) {
247+
if (IS_ENABLED(CONFIG_MODULES))
250248
untracked_mem_end = vmax - MODULES_LEN;
251-
kasan_early_vmemmap_populate(__sha(untracked_mem_end),
252-
__sha(vmax), POPULATE_MAP);
253-
}
254249
kasan_early_vmemmap_populate(__sha(memsize), __sha(untracked_mem_end),
255250
POPULATE_ZERO_SHADOW);
256251
kasan_set_pgd(early_pg_dir, asce_type);

0 commit comments

Comments
 (0)