linux/arch/s390/mm
Miaoqian Lin 07ad45e06b s390/mm: Fix memory leak in add_marker() when kvrealloc() fails
The function has a memory leak when kvrealloc() fails.
The function directly assigns NULL to the markers pointer, losing the
reference to the previously allocated memory. This causes kvfree() in
pt_dump_init() to free NULL instead of the leaked memory.

Fix by:
1. Using kvrealloc() uniformly for all allocations
2. Using a temporary variable to preserve the original pointer until
   allocation succeeds
3. Removing the error path that sets markers_cnt=0 to keep
   consistency between markers and markers_cnt

Found via static analysis and this is similar to commit 42378a9ca5
("bpf, verifier: Fix memory leak in array reallocation for stack state")

Fixes: d0e7915d2a ("s390/mm/ptdump: Generate address marker array dynamically")
Cc: stable@vger.kernel.org
Signed-off-by: Miaoqian Lin <linmq006@gmail.com>
Signed-off-by: Heiko Carstens <hca@linux.ibm.com>
2025-10-29 14:17:50 +01:00
..
Makefile KVM: s390: Refactor and split some gmap helpers 2025-05-28 17:48:04 +02:00
cmm.c treewide: Switch/rename to timer_delete[_sync]() 2025-04-05 10:30:12 +02:00
dump_pagetables.c s390/mm: Fix memory leak in add_marker() when kvrealloc() fails 2025-10-29 14:17:50 +01:00
extable.c s390/uaccess: Shorten raw_copy_from_user() / raw_copy_to_user() inline assemblies 2025-03-04 17:18:03 +01:00
extmem.c s390/extmem: Add workaround for DCSS unload diag 2025-05-17 10:55:00 +02:00
fault.c more s390 updates for 6.16 merge window 2025-06-06 18:02:37 -07:00
gmap.c mm: introduce memdesc_flags_t 2025-09-13 16:55:07 -07:00
gmap_helpers.c KVM: s390: A bugfix and a performance improvement 2025-09-30 13:09:20 -04:00
hugetlbpage.c mm: introduce memdesc_flags_t 2025-09-13 16:55:07 -07:00
init.c s390: Handle KCOV __init vs inline mismatches 2025-07-21 21:44:01 -07:00
maccess.c s390: Remove superfluous newlines from inline assemblies 2025-09-29 13:52:08 +02:00
mmap.c mm: constify arch_pick_mmap_layout() for improved const-correctness 2025-09-21 14:22:14 -07:00
page-states.c
pageattr.c s390/cpufeature: Convert MACHINE_HAS_IDTE to cpu_has_idte() 2025-03-04 17:18:05 +01:00
pfault.c s390/asm-offsets: Remove ASM_OFFSETS_C 2025-03-31 12:20:39 +02:00
pgalloc.c more s390 updates for 6.18 merge window 2025-10-09 10:51:43 -07:00
pgtable.c LoongArch KVM changes for v6.18 2025-09-30 13:23:44 -04:00
physaddr.c
vmem.c s390/mm: Allocate page table with PAGE_SIZE granularity 2025-08-05 14:23:20 +02:00