Skip to content

Commit 2ed8b50

Browse files
author
Alexander Gordeev
committed
s390/kasan: fix insecure W+X mapping warning
Since commit 3b5c3f000c2e ("s390/kasan: move shadow mapping to decompressor") the decompressor establishes mappings for the shadow memory and sets initial protection attributes to RWX. The decompressed kernel resets protection to RW+NX later on. In case a shadow memory range is not aligned on page boundary (e.g. as result of mem= kernel command line parameter use), the "Checked W+X mappings: FAILED, 1 W+X pages found" warning hits. Reported-by: Vasily Gorbik <[email protected]> Fixes: 557b197 ("s390/kasan: move shadow mapping to decompressor") Reviewed-by: Vasily Gorbik <[email protected]> Signed-off-by: Alexander Gordeev <[email protected]>
1 parent f471c65 commit 2ed8b50

File tree

1 file changed

+10
-4
lines changed

1 file changed

+10
-4
lines changed

arch/s390/mm/vmem.c

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -667,7 +667,15 @@ static void __init memblock_region_swap(void *a, void *b, int size)
667667

668668
#ifdef CONFIG_KASAN
669669
#define __sha(x) ((unsigned long)kasan_mem_to_shadow((void *)x))
670+
671+
static inline int set_memory_kasan(unsigned long start, unsigned long end)
672+
{
673+
start = PAGE_ALIGN_DOWN(__sha(start));
674+
end = PAGE_ALIGN(__sha(end));
675+
return set_memory_rwnx(start, (end - start) >> PAGE_SHIFT);
676+
}
670677
#endif
678+
671679
/*
672680
* map whole physical memory to virtual memory (identity mapping)
673681
* we reserve enough space in the vmalloc area for vmemmap to hotplug
@@ -737,10 +745,8 @@ void __init vmem_map_init(void)
737745
}
738746

739747
#ifdef CONFIG_KASAN
740-
for_each_mem_range(i, &base, &end) {
741-
set_memory_rwnx(__sha(base),
742-
(__sha(end) - __sha(base)) >> PAGE_SHIFT);
743-
}
748+
for_each_mem_range(i, &base, &end)
749+
set_memory_kasan(base, end);
744750
#endif
745751
set_memory_rox((unsigned long)_stext,
746752
(unsigned long)(_etext - _stext) >> PAGE_SHIFT);

0 commit comments

Comments
 (0)