From: Wang Liang <wangliang74@huawei.com>
To: Zhang Changzhong <zhangchangzhong@huawei.com>,
<dave@stgolabs.net>, <paulmck@kernel.org>,
<josh@joshtriplett.org>, <frederic@kernel.org>
Cc: <yuehaibing@huawei.com>, <linux-kernel@vger.kernel.org>
Subject: Re: [PATCH] locktorture: Fix memory leak in param_set_cpumask()
Date: Mon, 15 Sep 2025 10:13:33 +0800 [thread overview]
Message-ID: <9d51ece8-cb07-450b-a91a-095abcb8472a@huawei.com> (raw)
In-Reply-To: <6b433670-c79e-4439-9b9a-f10c548a727f@huawei.com>
在 2025/9/12 10:16, Zhang Changzhong 写道:
>
> 在 2025/9/12 9:57, Wang Liang 写道:
>> When setting the locktorture module parameter 'bind_writers', the variable
>> 'cpumask_var_t bind_writers' is allocated in param_set_cpumask(). But it
>> is not freed, when removing module or setting the parameter again.
>>
>> 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
>> echo 0-2 > /sys/module/locktorture/parameters/bind_writers
>> rmmod locktorture
>>
>> or:
>> insmod locktorture.ko
>> echo 0-2 > /sys/module/locktorture/parameters/bind_writers
>> echo 0-2 > /sys/module/locktorture/parameters/bind_writers
>>
>> The parameter 'bind_readers' also has the same problem. Free the memory
>> when removing module or setting the parameter.
>>
>> Fixes: 73e341242483 ("locktorture: Add readers_bind and writers_bind module parameters")
>> Signed-off-by: Wang Liang <wangliang74@huawei.com>
>> ---
>> kernel/locking/locktorture.c | 9 +++++++++
>> 1 file changed, 9 insertions(+)
>>
>> diff --git a/kernel/locking/locktorture.c b/kernel/locking/locktorture.c
>> index ce0362f0a871..cad80c050502 100644
>> --- a/kernel/locking/locktorture.c
>> +++ b/kernel/locking/locktorture.c
>> @@ -70,6 +70,9 @@ static int param_set_cpumask(const char *val, const struct kernel_param *kp)
>> int ret;
>> char *s;
>>
>> + free_cpumask_var(*cm_bind);
>> + *cm_bind = NULL;
> 这个NULL没必要吧
Setting global pointer to NULL after free may be more safe. ^-^
>> +
>> if (!alloc_cpumask_var(cm_bind, GFP_KERNEL)) {
>> s = "Out of memory";
>> ret = -ENOMEM;
>> @@ -1211,6 +1214,12 @@ static void lock_torture_cleanup(void)
>> cxt.cur_ops->exit();
>> cxt.init_called = false;
>> }
>> +
>> + free_cpumask_var(bind_readers);
>> + free_cpumask_var(bind_writers);
>> + bind_readers = NULL;
>> + bind_writers = NULL;
> 同上
>
>> +
>> torture_cleanup_end();
>> }
>>
next prev parent reply other threads:[~2025-09-15 2:13 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-09-12 1:57 Wang Liang
2025-09-12 2:16 ` Zhang Changzhong
2025-09-15 2:13 ` Wang Liang [this message]
2025-09-18 9:03 ` Paul E. McKenney
2025-09-18 11:17 ` Wang Liang
2025-09-18 11:40 ` Paul E. McKenney
2025-09-18 15:06 ` Zhang Changzhong
2025-09-18 15:20 ` Paul E. McKenney
2025-09-19 10:22 ` Zhang Changzhong
2025-09-19 10:41 ` Paul E. McKenney
2025-09-23 3:42 ` Wang Liang
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=9d51ece8-cb07-450b-a91a-095abcb8472a@huawei.com \
--to=wangliang74@huawei.com \
--cc=dave@stgolabs.net \
--cc=frederic@kernel.org \
--cc=josh@joshtriplett.org \
--cc=linux-kernel@vger.kernel.org \
--cc=paulmck@kernel.org \
--cc=yuehaibing@huawei.com \
--cc=zhangchangzhong@huawei.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®