* [PATCH -next] tracing/osnoise: fix null-ptr-deref in bitmap_parselist
@ 2025-09-05 3:25 Wang Liang
2025-09-05 22:44 ` Steven Rostedt
0 siblings, 1 reply; 3+ messages in thread
From: Wang Liang @ 2025-09-05 3:25 UTC (permalink / raw)
To: rostedt, mhiramat, mathieu.desnoyers, tglozar
Cc: yuehaibing, zhangchangzhong, wangliang74, linux-trace-kernel,
linux-kernel
A crash was observed with the following output:
BUG: kernel NULL pointer dereference, address: 0000000000000010
Oops: Oops: 0000 [#1] SMP NOPTI
CPU: 2 UID: 0 PID: 92 Comm: osnoise_cpus Not tainted 6.17.0-rc4-00201-gd69eb204c255 #138 PREEMPT(voluntary)
RIP: 0010:bitmap_parselist+0x53/0x3e0
Call Trace:
<TASK>
osnoise_cpus_write+0x7a/0x190
vfs_write+0xf8/0x410
? do_sys_openat2+0x88/0xd0
ksys_write+0x60/0xd0
do_syscall_64+0xa4/0x260
entry_SYSCALL_64_after_hwframe+0x77/0x7f
</TASK>
This issue can be reproduced by below code:
fd=open("/sys/kernel/debug/tracing/osnoise/cpus", O_WRONLY);
write(fd, "0-2", 0);
When user pass 'count=0' to osnoise_cpus_write(), kmalloc() will return
ZERO_SIZE_PTR (16) and cpulist_parse() treat it as a normal value, which
trigger the null pointer dereference. Add check for the parameter 'count'.
Fixes: 17f89102fe23 ("tracing/osnoise: Allow arbitrarily long CPU string")
Signed-off-by: Wang Liang <wangliang74@huawei.com>
---
kernel/trace/trace_osnoise.c | 3 +++
1 file changed, 3 insertions(+)
diff --git a/kernel/trace/trace_osnoise.c b/kernel/trace/trace_osnoise.c
index fd259da0aa64..edf5178d0317 100644
--- a/kernel/trace/trace_osnoise.c
+++ b/kernel/trace/trace_osnoise.c
@@ -2322,6 +2322,9 @@ osnoise_cpus_write(struct file *filp, const char __user *ubuf, size_t count,
int running, err;
char *buf __free(kfree) = NULL;
+ if (count < 1)
+ return -EINVAL;
+
buf = kmalloc(count, GFP_KERNEL);
if (!buf)
return -ENOMEM;
--
2.33.0
^ permalink raw reply related [flat|nested] 3+ messages in thread* Re: [PATCH -next] tracing/osnoise: fix null-ptr-deref in bitmap_parselist
2025-09-05 3:25 [PATCH -next] tracing/osnoise: fix null-ptr-deref in bitmap_parselist Wang Liang
@ 2025-09-05 22:44 ` Steven Rostedt
2025-09-06 2:58 ` Wang Liang
0 siblings, 1 reply; 3+ messages in thread
From: Steven Rostedt @ 2025-09-05 22:44 UTC (permalink / raw)
To: Wang Liang
Cc: mhiramat, mathieu.desnoyers, tglozar, yuehaibing, zhangchangzhong,
linux-trace-kernel, linux-kernel
On Fri, 5 Sep 2025 11:25:44 +0800
Wang Liang <wangliang74@huawei.com> wrote:
Hi Wang,
FYI, the tracincg subsystem requires capital subject:
tracing/osnoise: Fix null-ptr-deref in bitmap_parselist()
And parenthesis for function names.
> A crash was observed with the following output:
>
> BUG: kernel NULL pointer dereference, address: 0000000000000010
> Oops: Oops: 0000 [#1] SMP NOPTI
> CPU: 2 UID: 0 PID: 92 Comm: osnoise_cpus Not tainted 6.17.0-rc4-00201-gd69eb204c255 #138 PREEMPT(voluntary)
> RIP: 0010:bitmap_parselist+0x53/0x3e0
> Call Trace:
> <TASK>
> osnoise_cpus_write+0x7a/0x190
> vfs_write+0xf8/0x410
> ? do_sys_openat2+0x88/0xd0
> ksys_write+0x60/0xd0
> do_syscall_64+0xa4/0x260
> entry_SYSCALL_64_after_hwframe+0x77/0x7f
> </TASK>
>
> This issue can be reproduced by below code:
>
> fd=open("/sys/kernel/debug/tracing/osnoise/cpus", O_WRONLY);
> write(fd, "0-2", 0);
>
> When user pass 'count=0' to osnoise_cpus_write(), kmalloc() will return
> ZERO_SIZE_PTR (16) and cpulist_parse() treat it as a normal value, which
> trigger the null pointer dereference. Add check for the parameter 'count'.
>
> Fixes: 17f89102fe23 ("tracing/osnoise: Allow arbitrarily long CPU string")
> Signed-off-by: Wang Liang <wangliang74@huawei.com>
> ---
> kernel/trace/trace_osnoise.c | 3 +++
> 1 file changed, 3 insertions(+)
>
> diff --git a/kernel/trace/trace_osnoise.c b/kernel/trace/trace_osnoise.c
> index fd259da0aa64..edf5178d0317 100644
> --- a/kernel/trace/trace_osnoise.c
> +++ b/kernel/trace/trace_osnoise.c
> @@ -2322,6 +2322,9 @@ osnoise_cpus_write(struct file *filp, const char __user *ubuf, size_t count,
> int running, err;
> char *buf __free(kfree) = NULL;
>
> + if (count < 1)
> + return -EINVAL;
Sending a count of 0 is not invalid. This should simply return 0;
-- Steve
> +
> buf = kmalloc(count, GFP_KERNEL);
> if (!buf)
> return -ENOMEM;
^ permalink raw reply [flat|nested] 3+ messages in thread* Re: [PATCH -next] tracing/osnoise: fix null-ptr-deref in bitmap_parselist
2025-09-05 22:44 ` Steven Rostedt
@ 2025-09-06 2:58 ` Wang Liang
0 siblings, 0 replies; 3+ messages in thread
From: Wang Liang @ 2025-09-06 2:58 UTC (permalink / raw)
To: Steven Rostedt
Cc: mhiramat, mathieu.desnoyers, tglozar, yuehaibing, zhangchangzhong,
linux-trace-kernel, linux-kernel
在 2025/9/6 6:44, Steven Rostedt 写道:
> On Fri, 5 Sep 2025 11:25:44 +0800
> Wang Liang <wangliang74@huawei.com> wrote:
>
> Hi Wang,
>
> FYI, the tracincg subsystem requires capital subject:
>
> tracing/osnoise: Fix null-ptr-deref in bitmap_parselist()
>
> And parenthesis for function names.
Thanks for your guide, it is clear and helpful!
>> A crash was observed with the following output:
>>
>> BUG: kernel NULL pointer dereference, address: 0000000000000010
>> Oops: Oops: 0000 [#1] SMP NOPTI
>> CPU: 2 UID: 0 PID: 92 Comm: osnoise_cpus Not tainted 6.17.0-rc4-00201-gd69eb204c255 #138 PREEMPT(voluntary)
>> RIP: 0010:bitmap_parselist+0x53/0x3e0
>> Call Trace:
>> <TASK>
>> osnoise_cpus_write+0x7a/0x190
>> vfs_write+0xf8/0x410
>> ? do_sys_openat2+0x88/0xd0
>> ksys_write+0x60/0xd0
>> do_syscall_64+0xa4/0x260
>> entry_SYSCALL_64_after_hwframe+0x77/0x7f
>> </TASK>
>>
>> This issue can be reproduced by below code:
>>
>> fd=open("/sys/kernel/debug/tracing/osnoise/cpus", O_WRONLY);
>> write(fd, "0-2", 0);
>>
>> When user pass 'count=0' to osnoise_cpus_write(), kmalloc() will return
>> ZERO_SIZE_PTR (16) and cpulist_parse() treat it as a normal value, which
>> trigger the null pointer dereference. Add check for the parameter 'count'.
>>
>> Fixes: 17f89102fe23 ("tracing/osnoise: Allow arbitrarily long CPU string")
>> Signed-off-by: Wang Liang <wangliang74@huawei.com>
>> ---
>> kernel/trace/trace_osnoise.c | 3 +++
>> 1 file changed, 3 insertions(+)
>>
>> diff --git a/kernel/trace/trace_osnoise.c b/kernel/trace/trace_osnoise.c
>> index fd259da0aa64..edf5178d0317 100644
>> --- a/kernel/trace/trace_osnoise.c
>> +++ b/kernel/trace/trace_osnoise.c
>> @@ -2322,6 +2322,9 @@ osnoise_cpus_write(struct file *filp, const char __user *ubuf, size_t count,
>> int running, err;
>> char *buf __free(kfree) = NULL;
>>
>> + if (count < 1)
>> + return -EINVAL;
> Sending a count of 0 is not invalid. This should simply return 0;
>
> -- Steve
Ok. I will correct it and send a v2 patch later.
------
Best regards
Wang Liang
>> +
>> buf = kmalloc(count, GFP_KERNEL);
>> if (!buf)
>> return -ENOMEM;
>
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2025-09-06 2:58 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-09-05 3:25 [PATCH -next] tracing/osnoise: fix null-ptr-deref in bitmap_parselist Wang Liang
2025-09-05 22:44 ` Steven Rostedt
2025-09-06 2:58 ` Wang Liang
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox