linux-stable/arch/powerpc
Jiangfeng Xiao 0c09912dd8 powerpc/kasan: Fix addr error caused by page alignment
[ Upstream commit 4a7aee9620 ]

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 09:12:35 +01:00
..
boot powerpc/boot: Disable power10 features after BOOTAFLAGS assignment 2023-09-13 09:42:20 +02:00
configs - Yu Zhao's Multi-Gen LRU patches are here. They've been under test in 2022-10-10 17:53:04 -07:00
crypto treewide: use get_random_bytes() when possible 2022-10-11 17:42:58 -06:00
include work around gcc bugs with 'asm goto' with outputs 2024-02-23 09:12:28 +01:00
kernel work around gcc bugs with 'asm goto' with outputs 2024-02-23 09:12:28 +01:00
kexec powerpc/64/kdump: Limit kdump base to 512MB 2022-09-28 19:22:09 +10:00
kvm powerpc: Don't include lppaca.h in paca.h 2023-09-13 09:42:48 +02:00
lib powerpc/lib: Validate size for vector operations 2024-02-05 20:12:47 +00:00
math-emu powerpc/math-emu: Inhibit W=1 warnings 2022-09-08 11:11:18 +10:00
mm powerpc/kasan: Fix addr error caused by page alignment 2024-02-23 09:12:35 +01:00
net powerpc/bpf/32: Only set a stack frame when necessary 2023-03-17 08:50:30 +01:00
perf powerpc/imc-pmu: Add a null pointer check in update_events_in_group() 2024-01-25 15:27:19 -08:00
platforms powerpc/powernv: Add a null pointer check in opal_powercap_init() 2024-01-25 15:27:19 -08:00
purgatory powerpc/purgatory: remove PGO flags 2023-06-21 16:00:55 +02:00
sysdev powerpc/xive: Fix endian conversion size 2023-11-20 11:52:12 +01:00
tools powerpc/64: Add UADDR64 relocation support 2022-03-09 21:47:53 +11:00
xmon powerpc: Don't include lppaca.h in paca.h 2023-09-13 09:42:48 +02:00
Kbuild
Kconfig Revert "powerpc/64s: Increase default stack size to 32KB" 2024-01-31 16:17:10 -08:00
Kconfig.debug powerpc: allow PPC_EARLY_DEBUG_CPM only when SERIAL_CPM=y 2023-07-19 16:22:04 +02:00
Makefile powerpc: remove checks for binutils older than 2.25 2024-01-25 15:27:18 -08:00
Makefile.postlink