linux-yocto/kernel/locking
Wang Liang 9253f39bcf locktorture: Fix memory leak in param_set_cpumask()
[ Upstream commit e52b43883d084a9af263c573f2a1bd1ca5088389 ]

With CONFIG_CPUMASK_OFFSTACK=y, the 'bind_writers' buffer is allocated via
alloc_cpumask_var() in param_set_cpumask(). But it is not freed, when
setting the module parameter multiple times by sysfs interface or removing
module.

Below kmemleak trace is seen for this issue:

unreferenced object 0xffff888100aabff8 (size 8):
  comm "bash", pid 323, jiffies 4295059233
  hex dump (first 8 bytes):
    07 00 00 00 00 00 00 00                          ........
  backtrace (crc ac50919):
    __kmalloc_node_noprof+0x2e5/0x420
    alloc_cpumask_var_node+0x1f/0x30
    param_set_cpumask+0x26/0xb0 [locktorture]
    param_attr_store+0x93/0x100
    module_attr_store+0x1b/0x30
    kernfs_fop_write_iter+0x114/0x1b0
    vfs_write+0x300/0x410
    ksys_write+0x60/0xd0
    do_syscall_64+0xa4/0x260
    entry_SYSCALL_64_after_hwframe+0x77/0x7f

This issue can be reproduced by:
  insmod locktorture.ko bind_writers=1
  rmmod locktorture

or:
  insmod locktorture.ko bind_writers=1
  echo 2 > /sys/module/locktorture/parameters/bind_writers

Considering that setting the module parameter 'bind_writers' or
'bind_readers' by sysfs interface has no real effect, set the parameter
permissions to 0444. To fix the memory leak when removing module, free
'bind_writers' and 'bind_readers' memory in lock_torture_cleanup().

Fixes: 73e3412424 ("locktorture: Add readers_bind and writers_bind module parameters")
Suggested-by: Zhang Changzhong <zhangchangzhong@huawei.com>
Signed-off-by: Wang Liang <wangliang74@huawei.com>
Signed-off-by: Paul E. McKenney <paulmck@kernel.org>
Signed-off-by: Frederic Weisbecker <frederic@kernel.org>
Signed-off-by: Sasha Levin <sashal@kernel.org>
2025-12-18 14:02:51 +01:00
..
irqflag-debug.c
lock_events_list.h bpf_res_spin_lock 2025-03-30 13:06:27 -07:00
lock_events.c locking/debug: Fix debugfs API return value checks to use IS_ERR() 2023-10-03 10:11:25 +02:00
lock_events.h locking/qspinlock: Always evaluate lockevent* non-event parameter once 2024-03-21 20:45:17 +01:00
lockdep_internals.h locking/lockdep: Change 'static const' variables to enum values 2025-07-14 21:57:29 -07:00
lockdep_proc.c locking/lockdep: Avoid struct return in lock_stats() 2025-07-14 21:57:20 -07:00
lockdep_states.h
lockdep.c lockdep: Speed up lockdep_unregister_key() with expedited RCU synchronization 2025-07-14 21:57:29 -07:00
locktorture.c locktorture: Fix memory leak in param_set_cpumask() 2025-12-18 14:02:51 +01:00
Makefile locking/lockdep: Disable KASAN instrumentation of lockdep.c 2025-03-08 00:55:03 +01:00
mcs_spinlock.h locking: Allow obtaining result of arch_mcs_spin_lock_contended 2025-03-19 08:03:04 -07:00
mutex-debug.c locking/mutex: Add p->blocked_on wrappers for correctness checks 2025-07-14 17:16:32 +02:00
mutex.c Locking updates for v6.16: 2025-07-29 18:11:32 -07:00
mutex.h sched: Start blocked_on chain processing in find_proxy_task() 2025-07-14 17:16:33 +02:00
osq_lock.c locking/osq_lock: Use atomic_try_cmpxchg_release() in osq_unlock() 2024-10-25 10:01:50 +02:00
percpu-rwsem.c locking/percpu-rwsem: add freezable alternative to down_read 2025-04-07 09:37:16 +02:00
qrwlock.c locking: Add __lockfunc to slow path functions 2022-08-19 19:47:51 +02:00
qspinlock_paravirt.h locking/pvqspinlock: Convert fields of 'enum vcpu_state' to uppercase 2024-10-17 21:21:16 -07:00
qspinlock_stat.h
qspinlock.c locking: Move common qspinlock helpers to a private header 2025-03-19 08:02:29 -07:00
qspinlock.h locking: Move common qspinlock helpers to a private header 2025-03-19 08:02:29 -07:00
rtmutex_api.c locking/rtmutex: Move max_lock_depth into rtmutex.c 2025-07-23 11:52:47 +02:00
rtmutex_common.h locking/local_lock: Introduce local_lock_is_locked(). 2025-09-29 09:42:35 +02:00
rtmutex.c locking/lock_events: Add locking events for rtmutex slow paths 2025-03-08 00:55:03 +01:00
rwbase_rt.c locking/mutex: Remove wakeups from under mutex::wait_lock 2024-10-14 12:52:40 +02:00
rwsem.c Significant patch series in this pull request: 2025-08-03 16:23:09 -07:00
semaphore.c hung_task: show the blocker task if the task is hung on semaphore 2025-05-11 17:54:08 -07:00
spinlock_debug.c locking/spinlock/debug: Fix data-race in do_raw_write_lock 2025-12-12 18:42:45 +01:00
spinlock_rt.c Scheduler changes for v6.13: 2024-11-19 14:16:06 -08:00
spinlock.c locking/spinlocks: Make __raw_* lock ops static 2024-10-07 09:28:35 +02:00
test-ww_mutex.c locking/ww_mutex/test: Use swap() macro 2024-12-15 11:49:35 -08:00
ww_mutex.h locking: Fix __clear_task_blocked_on() warning from __ww_mutex_wound() path 2025-08-13 10:34:54 +02:00
ww_rt_mutex.c locking/rtmutex: Avoid unconditional slowpath for DEBUG_RT_MUTEXES 2023-09-20 09:31:11 +02:00