WSL2-Linux-Kernel/arch/powerpc/mm
Jiangfeng Xiao 2738e0aa2f powerpc/kasan: Fix addr error caused by page alignment
[ Upstream commit 4a7aee96200ad281a5cc4cf5c7a2e2a49d2b97b0 ]

In kasan_init_region, when k_start is not page aligned, at the begin of
for loop, k_cur = k_start & PAGE_MASK is less than k_start, and then
`va = block + k_cur - k_start` is less than block, the addr va is invalid,
because the memory address space from va to block is not alloced by
memblock_alloc, which will not be reserved by memblock_reserve later, it
will be used by other places.

As a result, memory overwriting occurs.

for example:
int __init __weak kasan_init_region(void *start, size_t size)
{
[...]
	/* if say block(dcd97000) k_start(feef7400) k_end(feeff3fe) */
	block = memblock_alloc(k_end - k_start, PAGE_SIZE);
	[...]
	for (k_cur = k_start & PAGE_MASK; k_cur < k_end; k_cur += PAGE_SIZE) {
		/* at the begin of for loop
		 * block(dcd97000) va(dcd96c00) k_cur(feef7000) k_start(feef7400)
		 * va(dcd96c00) is less than block(dcd97000), va is invalid
		 */
		void *va = block + k_cur - k_start;
		[...]
	}
[...]
}

Therefore, page alignment is performed on k_start before
memblock_alloc() to ensure the validity of the VA address.

Fixes: 663c0c9496 ("powerpc/kasan: Fix shadow area set up for modules.")
Signed-off-by: Jiangfeng Xiao <xiaojiangfeng@huawei.com>
Signed-off-by: Michael Ellerman <mpe@ellerman.id.au>
Link: https://msgid.link/1705974359-43790-1-git-send-email-xiaojiangfeng@huawei.com
Signed-off-by: Sasha Levin <sashal@kernel.org>
2024-02-23 08:55:04 +01:00
..
book3s32 powerpc/32s: Do kuep_lock() and kuep_unlock() in assembly 2023-10-25 11:58:59 +02:00
book3s64 powerpc: pmd_move_must_withdraw() is only needed for CONFIG_TRANSPARENT_HUGEPAGE 2024-02-23 08:54:37 +01:00
kasan powerpc/kasan: Fix addr error caused by page alignment 2024-02-23 08:55:04 +01:00
nohash powerpc/32: Call mmu_mark_initmem_nx() regardless of data block mapping. 2022-08-17 14:24:12 +02:00
ptdump powerpc/ptdump: Fix display of RW pages on FSL_BOOK3E 2022-08-17 14:22:58 +02:00
Makefile
cacheflush.c
copro_fault.c
dma-noncoherent.c
drmem.c
fault.c powerpc/64s: Don't use DSISR for SLB faults 2022-04-08 14:23:38 +02:00
hugetlbpage.c
init-common.c powerpc/mm: Fix null-pointer dereference in pgtable_cache_add 2024-02-23 08:54:36 +01:00
init_32.c
init_64.c powerpc/mm/altmap: Fix altmap boundary check 2023-08-11 15:13:59 +02:00
ioremap.c
ioremap_32.c
ioremap_64.c
maccess.c
mem.c powerpc/mm: Fix boot crash with FLATMEM 2023-11-08 17:26:48 +01:00
mmap.c
mmu_context.c powerpc/mm: Switch obsolete dssall to .long 2022-06-14 18:36:27 +02:00
mmu_decl.h powerpc/64s: Fix CONFIG_NUMA=n build due to create_section_mapping() 2024-02-23 08:54:36 +01:00
numa.c powerpc/papr_scm: Update the NUMA distance table for the target node 2023-04-20 12:13:56 +02:00
pageattr.c powerpc/set_memory: Avoid spinlock recursion in change_page_attr() 2022-04-13 20:59:05 +02:00
pgtable-frag.c
pgtable.c powerpc/fixmap: Fix VM debug warning on unmap 2022-02-16 12:56:12 +01:00
pgtable_32.c powerpc/32: Call mmu_mark_initmem_nx() regardless of data block mapping. 2022-08-17 14:24:12 +02:00
pgtable_64.c powerpc/64s/radix: Fix huge vmap false positive 2022-01-27 11:05:12 +01:00
slice.c