linux/arch/s390/kernel
Thomas Richter aa1ac98268 s390/cpumf: Fix double free on error in cpumf_pmu_event_init()
In PMU event initialization functions
 - cpumsf_pmu_event_init()
 - cpumf_pmu_event_init()
 - cfdiag_event_init()
the partially created event had to be removed when an error was detected.
The event::event_init() member function had to release all resources
it allocated in case of error. event::destroy() had to be called
on freeing an event after it was successfully created and
event::event_init() returned success.

With

commit c70ca29803 ("perf/core: Simplify the perf_event_alloc() error path")

this is not necessary anymore. The performance subsystem common
code now always calls event::destroy() to clean up the allocated
resources created during event initialization.

Remove the event::destroy() invocation in PMU event initialization
or that function is called twice for each event that runs into an
error condition in event creation.

This is the kernel log entry which shows up without the fix:

------------[ cut here ]------------
refcount_t: underflow; use-after-free.
WARNING: CPU: 0 PID: 43388 at lib/refcount.c:87	refcount_dec_not_one+0x74/0x90
CPU: 0 UID: 0 PID: 43388 Comm: perf Not tainted 6.15.0-20250407.rc1.git0.300.fc41.s390x+git #1 NONE
Hardware name: IBM 3931 A01 704 (LPAR)
Krnl PSW : 0704c00180000000 00000209cb2c1b88 (refcount_dec_not_one+0x78/0x90)
           R:0 T:1 IO:1 EX:1 Key:0 M:1 W:0 P:0 AS:3 CC:0 PM:0 RI:0 EA:3
Krnl GPRS: 0000020900000027 0000020900000023 0000000000000026 0000018900000000
           00000004a2200a00 0000000000000000 0000000000000057 ffffffffffffffea
           00000002b386c600 00000002b3f5b3e0 00000209cc51f140 00000209cc7fc550
           0000000001449d38 ffffffffffffffff 00000209cb2c1b84 00000189d67dfb80
Krnl Code: 00000209cb2c1b78: c02000506727	larl	%r2,00000209cbcce9c6
           00000209cb2c1b7e: c0e5ffbd4431	brasl	%r14,00000209caa6a3e0
          #00000209cb2c1b84: af000000		mc	0,0
          >00000209cb2c1b88: a7480001		lhi	%r4,1
           00000209cb2c1b8c: ebeff0a00004	lmg	%r14,%r15,160(%r15)
           00000209cb2c1b92: ec243fbf0055	risbg	%r2,%r4,63,191,0
           00000209cb2c1b98: 07fe		bcr	15,%r14
           00000209cb2c1b9a: 47000700		bc	0,1792
Call Trace:
 [<00000209cb2c1b88>] refcount_dec_not_one+0x78/0x90
 [<00000209cb2c1dc4>] refcount_dec_and_mutex_lock+0x24/0x90
 [<00000209caa3c29e>] hw_perf_event_destroy+0x2e/0x80
 [<00000209cacaf8b4>] __free_event+0x74/0x270
 [<00000209cacb47c4>] perf_event_alloc.part.0+0x4a4/0x730
 [<00000209cacbf3e8>] __do_sys_perf_event_open+0x248/0xc20
 [<00000209cacc14a4>] __s390x_sys_perf_event_open+0x44/0x50
 [<00000209cb8114de>] __do_syscall+0x12e/0x260
 [<00000209cb81ce34>] system_call+0x74/0x98
Last Breaking-Event-Address:
 [<00000209caa6a4d2>] __warn_printk+0xf2/0x100
---[ end trace 0000000000000000 ]---

Fixes: c70ca29803 ("perf/core: Simplify the perf_event_alloc() error path")
Signed-off-by: Thomas Richter <tmricht@linux.ibm.com>
Reviewed-by: Sumanth Korikkar <sumanthk@linux.ibm.com>
Signed-off-by: Heiko Carstens <hca@linux.ibm.com>
2025-04-09 12:12:42 +02:00
..
diag s390: Use inline qualifier for all EX_TABLE and ALTERNATIVE inline assemblies 2025-03-18 17:13:51 +01:00
syscalls fs: add open_tree_attr() 2025-02-12 12:12:28 +01:00
vdso32 s390/vdso: Switch to generic storage implementation 2025-02-21 09:54:02 +01:00
vdso64 s390/vdso: Switch to generic storage implementation 2025-02-21 09:54:02 +01:00
.gitignore
abs_lowcore.c s390/lowcore: Convert relocated lowcore alternative to machine feature 2025-03-04 17:18:05 +01:00
alternative.c s390/alternatives: Add debug functionality 2025-03-04 17:18:08 +01:00
asm-offsets.c s390/asm-offsets: Remove ASM_OFFSETS_C 2025-03-31 12:20:39 +02:00
audit.c audit: add support for the openat2 syscall 2021-10-01 16:52:48 -04:00
audit.h
cache.c s390/cache: prevent rebuild of shared_cpu_list 2024-03-07 14:41:15 +01:00
cert_store.c s390: Use inline qualifier for all EX_TABLE and ALTERNATIVE inline assemblies 2025-03-18 17:13:51 +01:00
compat_audit.c audit: add support for the openat2 syscall 2021-10-01 16:52:48 -04:00
compat_linux.c
compat_linux.h s390/compat: cleanup compat_linux.h header file 2022-05-06 20:45:16 +02:00
compat_ptrace.h
compat_signal.c s390/vdso: Move vdso symbol handling to separate header file 2024-09-13 17:28:36 +02:00
cpacf.c s390/crypto/cpacf: Constify 'struct bin_attribute' 2025-01-07 10:05:35 +01:00
cpcmd.c s390/cpcmd: Convert to use flag output macros 2024-11-13 14:31:32 +01:00
cpufeature.c s390/uvdevice: autoload module based on CPU facility 2022-07-19 16:18:49 +02:00
crash_dump.c s390/crash: Use note name macros 2025-02-10 16:56:58 -08:00
ctlreg.c s390/ctlreg: add system_ctl_load() 2023-09-19 13:26:57 +02:00
debug.c treewide: const qualify ctl_tables where applicable 2025-01-28 13:48:37 +01:00
dis.c s390/disassembler: Remove duplicate instruction format RSY_RDRU 2024-09-12 14:13:27 +02:00
dumpstack.c s390/asm-offsets: Remove ASM_OFFSETS_C 2025-03-31 12:20:39 +02:00
early.c s390/asm-offsets: Remove ASM_OFFSETS_C 2025-03-31 12:20:39 +02:00
early_printk.c s390/early: Dump register contents and call trace for early crashes 2024-08-22 19:28:11 +02:00
ebcdic.c s390/ebcdic: fix typo in comment 2023-07-27 13:11:35 +02:00
entry.h s390/traps: Change stack overflow message 2025-03-04 17:34:03 +01:00
entry.S s390/entry: Fix setting _CIF_MCCK_GUEST with lowcore relocation 2025-03-31 12:20:39 +02:00
facility.c
fpu.c s390/fpu: Re-add exception handling in load_fpu_state() 2024-07-31 16:30:20 +02:00
ftrace.c s390 updates for 6.15 merge window 2025-03-29 11:59:43 -07:00
ftrace.h s390/ftrace: Remove unused ftrace_plt_template* 2024-08-27 20:16:48 +02:00
guarded_storage.c s390/cpufeature: Convert MACHINE_HAS_GS to cpu_has_gs() 2025-03-04 17:18:04 +01:00
head64.S s390/time: Convert MACHINE_HAS_SCC to machine_has_scc() 2025-03-04 17:18:06 +01:00
hiperdispatch.c s390/cpufeature: Convert MACHINE_HAS_TOPOLOGY to cpu_has_topology() 2025-03-04 17:18:05 +01:00
idle.c s390/idle: Remove duplicate get_lowcore() calls 2024-06-18 17:01:33 +02:00
ima_arch.c s390/kexec_file: Disable kexec_load when IPLed secure 2019-04-29 10:44:03 +02:00
ipl.c s390: Use inline qualifier for all EX_TABLE and ALTERNATIVE inline assemblies 2025-03-18 17:13:51 +01:00
ipl_vmparm.c s390/cio: remove unused include linux/spinlock.h from cio.h 2021-07-27 09:39:13 +02:00
irq.c s390 updates for 6.15 merge window 2025-03-29 11:59:43 -07:00
jump_label.c jump_label: make initial NOP patching the special case 2022-06-24 09:48:55 +02:00
kdebugfs.c
kexec_elf.c
kexec_image.c
kprobes.c s390/cpufeature: Convert MACHINE_HAS_SEQ_INSN to cpu_has_seq_insn() 2025-03-04 17:18:04 +01:00
lgr.c s390: kernel: convert timeouts to use secs_to_jiffies() 2025-01-12 20:21:01 -08:00
machine_kexec.c s390: Convert MACHINE_IS_[LPAR|VM|KVM], etc, machine_is_[lpar|vm|kvm]() 2025-03-04 17:18:07 +01:00
machine_kexec_file.c s390, crash: wrap crash dumping code into crash related ifdefs 2024-02-23 17:48:23 -08:00
machine_kexec_reloc.c
Makefile s390/diag: Move diag.c to diag specific folder 2024-12-17 12:46:14 +01:00
mcount.S s390/tracing: Enable HAVE_FTRACE_GRAPH_FUNC 2024-12-26 10:50:05 -05:00
module.c arch: make execmem setup available regardless of CONFIG_MODULES 2024-05-14 00:31:44 -07:00
nmi.c s390/cpufeature: Convert MACHINE_HAS_GS to cpu_has_gs() 2025-03-04 17:18:04 +01:00
nospec-branch.c s390/nospec: Push down alternative handling 2024-07-23 16:02:31 +02:00
nospec-sysfs.c s390/nospec: Switch over to sysfs_emit() 2024-10-25 16:03:24 +02:00
numa.c mm/memblock: add memblock_alloc_or_panic interface 2025-01-25 20:22:38 -08:00
os_info.c s390: Remove __bootdata annotations from declarations 2024-12-15 16:19:04 +01:00
perf_cpum_cf.c s390/cpumf: Fix double free on error in cpumf_pmu_event_init() 2025-04-09 12:12:42 +02:00
perf_cpum_cf_events.c s390/cpumf: Update CPU Measurement facility extended counter set support 2025-04-09 12:12:41 +02:00
perf_cpum_sf.c s390/cpumf: Fix double free on error in cpumf_pmu_event_init() 2025-04-09 12:12:42 +02:00
perf_event.c Performance events changes for v6.13: 2024-11-19 13:34:06 -08:00
perf_pai_crypto.c perf: Supply task information to sched_task() 2025-03-17 11:23:37 +01:00
perf_pai_ext.c perf: Supply task information to sched_task() 2025-03-17 11:23:37 +01:00
perf_regs.c
process.c s390: Replace S390_lowcore by get_lowcore() 2024-06-18 17:01:33 +02:00
processor.c s390: Add z17 elf platform 2025-04-09 12:12:41 +02:00
ptrace.c s390/ptrace: Avoid KASAN false positives in regs_get_kernel_stack_nth() 2025-03-18 17:13:05 +01:00
reipl.S s390/kdump: Make kdump ready for lowcore relocation 2024-07-23 16:02:32 +02:00
relocate_kernel.S s390/relocate_kernel: adjust indentation 2023-04-19 17:24:18 +02:00
rethook.c s390/rethook: add local rethook header file 2023-02-06 11:13:53 +01:00
rethook.h s390/rethook: add local rethook header file 2023-02-06 11:13:53 +01:00
runtime_instr.c s390/runtime_instrumentation: fix storage key handling 2020-08-17 13:17:10 +02:00
setup.c s390/lowcore: Remove unused machine_flags 2025-03-31 12:20:39 +02:00
signal.c s390/vdso: Move vdso symbol handling to separate header file 2024-09-13 17:28:36 +02:00
smp.c s390/smp: Add support for HOTPLUG_SMT 2025-03-31 12:20:39 +02:00
stacktrace.c s390/asm-offsets: Remove ASM_OFFSETS_C 2025-03-31 12:20:39 +02:00
sthyi.c s390/sthyi: Convert to use flag output macros 2024-11-13 14:31:31 +01:00
syscall.c s390: Remove 2k vs 4k page table leftovers 2025-03-18 17:13:05 +01:00
sysinfo.c s390: Convert MACHINE_IS_[LPAR|VM|KVM], etc, machine_is_[lpar|vm|kvm]() 2025-03-04 17:18:07 +01:00
text_amode31.S s390/amode31: Use exrl instead of ex 2025-01-13 09:50:17 +01:00
time.c treewide: Switch/rename to timer_delete[_sync]() 2025-04-05 10:30:12 +02:00
topology.c s390/cpufeature: Convert MACHINE_HAS_TOPOLOGY to cpu_has_topology() 2025-03-04 17:18:05 +01:00
trace.c s390/ftrace: fix potential crashes when switching tracers 2020-04-22 16:20:55 +02:00
traps.c s390 updates for 6.15 merge window 2025-03-29 11:59:43 -07:00
unwind_bc.c s390/unwind: disable KMSAN checks 2024-07-03 19:30:25 -07:00
uprobes.c s390/switch_to: use generic header file 2024-02-12 15:03:33 +01:00
uv.c KVM: s390: pv: fix race when making a page secure 2025-03-14 15:24:19 +01:00
vdso.c mseal sysmap: enable s390 2025-04-01 15:17:16 -07:00
vmcore_info.c s390: Remove __bootdata annotations from declarations 2024-12-15 16:19:04 +01:00
vmlinux.lds.S s390/fpu: Add fpc exception handler / remove fixup section again 2025-01-26 17:24:04 +01:00
vtime.c s390/vtime: Remove duplicate get_lowcore() calls 2024-06-18 17:01:33 +02:00
wti.c s390/wti: Add debugfs file to display missed grace periods per cpu 2024-08-29 22:56:35 +02:00