tracing: Fixes for v6.17
Subsystems (3)
cover tracing: Fixes for v6.17
git://git.kernel.org/pub/scm/linux/kernel/git/trace/linux-trace.git
trace/fixes
Head SHA1: c1628c00c4351dd0727ef7f670694f68d9e663d8
Guenter Roeck (1):
trace/fgraph: Fix error handling
Luo Gengkun (1):
tracing: Fix tracing_marker may trigger page fault during preempt_disable
Qianfeng Rong (1):
trace: Remove redundant __GFP_NOWARN
Vladimir Riabchun (1):
ftrace/samples: Fix function size computation
Wang Liang (1):
tracing/osnoise: Fix null-ptr-deref in bitmap_parselist()
----
kernel/trace/fgraph.c | 3 ++- kernel/trace/trace.c | 4 ++-- kernel/trace/trace_events_user.c | 2 +- kernel/trace/trace_osnoise.c | 3 +++ samples/ftrace/ftrace-direct-modify.c | 2 +- 5 files changed, 9 insertions(+), 5 deletions(-)
PATCH 1/5 trace: Remove redundant __GFP_NOWARN
From: Qianfeng Rong <[email protected]>
Commit 16f5dfbc851b ("gfp: include __GFP_NOWARN in GFP_NOWAIT") made GFP_NOWAIT implicitly include __GFP_NOWARN.
Therefore, explicit __GFP_NOWARN combined with GFP_NOWAIT (e.g., GFP_NOWAIT | __GFP_NOWARN) is now redundant. Let's clean up these redundant flags across subsystems.
No functional changes.
--- kernel/trace/trace_events_user.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
kernel/trace/trace_events_user.c +1 -1
@@ -496,7 +496,7 @@ static bool user_event_enabler_queue_fault(struct user_event_mm *mm, {struct user_event_enabler_fault *fault; - fault =kmem_cache_zalloc (fault_cache,GFP_NOWAIT | __GFP_NOWARN); + fault =kmem_cache_zalloc (fault_cache,GFP_NOWAIT );if (!fault)return false;
Signature · 1 line
2.50.1
PATCH 2/5 tracing: Fix tracing_marker may trigger page fault during preempt_disable
In reply to Steven RostedtFrom: Luo Gengkun <[email protected]>
Both tracing_mark_write and tracing_mark_raw_write call __copy_from_user_inatomic during preempt_disable. But in some case, __copy_from_user_inatomic may trigger page fault, and will call schedule() subtly. And if a task is migrated to other cpu, the following warning will be trigger:
if (RB_WARN_ON(cpu_buffer,
!local_read(&cpu_buffer->committing)))An example can illustrate this issue:
process flow CPU
---------------------------------------------------------------------
tracing_mark_raw_write(): cpu:0
...
ring_buffer_lock_reserve(): cpu:0
...
cpu = raw_smp_processor_id() cpu:0
cpu_buffer = buffer->buffers[cpu] cpu:0
...
...
__copy_from_user_inatomic(): cpu:0
...
# page fault
do_mem_abort(): cpu:0
...
# Call schedule
schedule() cpu:0
...
# the task schedule to cpu1
__buffer_unlock_commit(): cpu:1
...
ring_buffer_unlock_commit(): cpu:1
...
cpu = raw_smp_processor_id() cpu:1
cpu_buffer = buffer->buffers[cpu] cpu:1As shown above, the process will acquire cpuid twice and the return values are not the same.
To fix this problem using copy_from_user_nofault instead of __copy_from_user_inatomic, as the former performs 'access_ok' before copying.
--- kernel/trace/trace.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
kernel/trace/trace.c +2 -2
@@ -7209,7 +7209,7 @@ static ssize_t write_marker_to_buffer(struct trace_array *tr, const char __user entry =ring_buffer_event_data (event); entry->ip = ip; - len =__copy_from_user_inatomic (&entry->buf, ubuf, cnt); + len =copy_from_user_nofault (&entry->buf, ubuf, cnt);if (len) {memcpy (&entry->buf,FAULTED_STR ,FAULTED_SIZE ); cnt =FAULTED_SIZE ;
@@ -7306,7 +7306,7 @@ static ssize_t write_raw_marker_to_buffer(struct trace_array *tr, entry =ring_buffer_event_data (event); - len =__copy_from_user_inatomic (&entry->id, ubuf, cnt); + len =copy_from_user_nofault (&entry->id, ubuf, cnt);if (len) { entry->id =-1 ;memcpy (&entry->buf,FAULTED_STR ,FAULTED_SIZE );
Signature · 1 line
2.50.1
PATCH 3/5 ftrace/samples: Fix function size computation
In reply to Steven RostedtFrom: Vladimir Riabchun <[email protected]>
In my_tramp1 function .size directive was placed above ASM_RET instruction, leading to a wrong function size.
--- samples/ftrace/ftrace-direct-modify.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
samples/ftrace/ftrace-direct-modify.c +1 -1
@@ -75,8 +75,8 @@ asm (CALL_DEPTH_ACCOUNT " call my_direct_func1\n" " leave\n" -" .size my_tramp1, .-my_tramp1\n" ASM_RET +" .size my_tramp1, .-my_tramp1\n" " .type my_tramp2, @function\n" " .globl my_tramp2\n"
Signature · 1 line
2.50.1
PATCH 4/5 trace/fgraph: Fix error handling
In reply to Steven RostedtFrom: Guenter Roeck <[email protected]>
Commit edede7a6dcd7 ("trace/fgraph: Fix the warning caused by missing unregister notifier") added a call to unregister the PM notifier if register_ftrace_graph() failed. It does so unconditionally. However, the PM notifier is only registered with the first call to register_ftrace_graph(). If the first registration was successful and a subsequent registration failed, the notifier is now unregistered even if ftrace graphs are still registered.
Fix the problem by only unregistering the PM notifier during error handling if there are no active fgraph registrations.
--- kernel/trace/fgraph.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
kernel/trace/fgraph.c +2 -1
@@ -1397,7 +1397,8 @@ int register_ftrace_graph(struct fgraph_ops *gops) ftrace_graph_active--; gops->saved_func =NULL ;fgraph_lru_release_index (i); -unregister_pm_notifier (&ftrace_suspend_notifier); +if (!ftrace_graph_active) +unregister_pm_notifier (&ftrace_suspend_notifier); }return ret; }
Signature · 1 line
2.50.1
PATCH 5/5 tracing/osnoise: Fix null-ptr-deref in bitmap_parselist()
In reply to Steven RostedtFrom: Wang Liang <[email protected]>
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'.
--- kernel/trace/trace_osnoise.c | 3 +++ 1 file changed, 3 insertions(+)
kernel/trace/trace_osnoise.c +3 -0
@@ -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 0 ; + buf =kmalloc (count,GFP_KERNEL );if (!buf)return -ENOMEM ;
Signature · 1 line
2.50.1