linux-stable/arch/powerpc/mm
Jiangfeng Xiao 4a7aee9620 powerpc/kasan: Fix addr error caused by page alignment
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
2024-02-05 22:57:26 +11:00
..
book3s32 powerpc/32s: Introduce _PAGE_READ and remove _PAGE_USER 2023-10-19 17:12:47 +11:00
book3s64 Many singleton patches against the MM code. The patch series which 2024-01-09 11:18:47 -08:00
kasan powerpc/kasan: Fix addr error caused by page alignment 2024-02-05 22:57:26 +11:00
nohash powerpc updates for 6.7 2023-11-03 10:07:39 -10:00
ptdump powerpc/ptdump: Display _PAGE_READ and _PAGE_WRITE 2023-10-19 17:12:47 +11:00
cacheflush.c powerpc: implement the new page table range API 2023-08-24 16:20:23 -07:00
copro_fault.c powerpc/mm: convert coprocessor fault to lock_mm_and_find_vma() 2023-06-24 14:12:58 -07:00
dma-noncoherent.c
drmem.c powerpc: Annotate endianness of various variables and functions 2023-10-19 17:12:47 +11:00
fault.c arch/mm/fault: fix major fault accounting when retrying under per-VMA lock 2023-12-29 11:06:49 -08:00
hugetlbpage.c mm, treewide: rename MAX_ORDER to MAX_PAGE_ORDER 2024-01-08 15:27:15 -08:00
init-common.c powerpc/mm: Fix null-pointer dereference in pgtable_cache_add 2023-12-13 22:13:41 +11:00
init_32.c powerpc: Untangle fixmap.h and pgtable.h and mmu.h 2023-10-19 17:12:44 +11:00
init_64.c powerpc updates for 6.6 2023-08-31 12:43:10 -07:00
ioremap.c powerpc/nohash: Replace pte_user() by pte_read() 2023-10-19 17:12:46 +11:00
ioremap_32.c powerpc: mm: convert to GENERIC_IOREMAP 2023-08-18 10:12:35 -07:00
ioremap_64.c powerpc: mm: convert to GENERIC_IOREMAP 2023-08-18 10:12:35 -07:00
maccess.c powerpc/inst: Optimise copy_inst_from_kernel_nofault() 2021-12-09 22:41:21 +11:00
Makefile powerpc/mm: Convert to default topdown mmap layout 2022-05-05 22:11:58 +10:00
mem.c powerpc: Remove file parameter from phys_mem_access_prot() 2023-11-06 15:21:33 +11:00
mmu_context.c powerpc: Add mm_cpumask warning when context switching 2023-08-02 22:22:19 +10:00
mmu_decl.h powerpc/64s: Fix CONFIG_NUMA=n build due to create_section_mapping() 2023-11-30 21:31:09 +11:00
numa.c powerpc/pseries: Move VPHN constants into vphn.h 2023-08-24 22:33:16 +10:00
pageattr.c powerpc: align address to page boundary in change_page_attr() 2022-05-08 22:15:41 +10:00
pgtable-frag.c powerpc: convert various functions to use ptdescs 2023-08-21 13:37:54 -07:00
pgtable.c powerpc updates for 6.7 2023-11-03 10:07:39 -10:00
pgtable_32.c powerpc: move __end_rodata to cover arch read-only sections 2022-09-26 20:58:16 +10:00
pgtable_64.c powerpc: Remove asm/prom.h from all files that don't need it 2022-05-08 22:15:04 +10:00