tracing: Updates for 5.3
Subsystems (4)
Steven Rostedt
maintainercover tracing: Updates for 5.3
Various fixes for tracing.
Denis Efremov (1):
tracing: Make exported ftrace_set_clr_event non-static
Jakub Kicinski (1):
tracing: Correct kdoc formats
Jisheng Zhang (1):
ftrace/x86: Remove mcount() declaration
Naveen N. Rao (2):
ftrace: Fix NULL pointer dereference in t_probe_next()
ftrace: Check for successful allocation of hash
Steven Rostedt (VMware) (1):
ftrace: Check for empty hash and comment the race with registering probes
Xinpeng Liu (1):
tracing/probe: Fix null pointer dereference
----
arch/x86/include/asm/ftrace.h | 1 - include/linux/trace_events.h | 1 + kernel/trace/ftrace.c | 17 +++++++++++++++++ kernel/trace/trace.c | 26 ++++++++++++++------------ kernel/trace/trace_events.c | 2 +- kernel/trace/trace_probe.c | 3 ++- 6 files changed, 35 insertions(+), 15 deletions(-)
Steven Rostedt
maintainerPATCH 1/7 ftrace: Fix NULL pointer dereference in t_probe_next()
From: "Naveen N. Rao" <[email protected]>
LTP testsuite on powerpc results in the below crash:
Unable to handle kernel paging request for data at address 0x00000000 Faulting instruction address: 0xc00000000029d800 Oops: Kernel access of bad area, sig: 11 [#1] LE SMP NR_CPUS=2048 NUMA PowerNV ... CPU: 68 PID: 96584 Comm: cat Kdump: loaded Tainted: G W NIP: c00000000029d800 LR: c00000000029dac4 CTR: c0000000001e6ad0 REGS: c0002017fae8ba10 TRAP: 0300 Tainted: G W MSR: 9000000000009033 <SF,HV,EE,ME,IR,DR,RI,LE> CR: 28022422 XER: 20040000 CFAR: c00000000029d90c DAR: 0000000000000000 DSISR: 40000000 IRQMASK: 0 ... NIP [c00000000029d800] t_probe_next+0x60/0x180 LR [c00000000029dac4] t_mod_start+0x1a4/0x1f0 Call Trace: [c0002017fae8bc90] [c000000000cdbc40] _cond_resched+0x10/0xb0 (unreliable) [c0002017fae8bce0] [c0000000002a15b0] t_start+0xf0/0x1c0 [c0002017fae8bd30] [c0000000004ec2b4] seq_read+0x184/0x640 [c0002017fae8bdd0] [c0000000004a57bc] sys_read+0x10c/0x300 [c0002017fae8be30] [c00000000000b388] system_call+0x5c/0x70
The test (ftrace_set_ftrace_filter.sh) is part of ftrace stress tests and the crash happens when the test does 'cat $TRACING_PATH/set_ftrace_filter'.
The address points to the second line below, in t_probe_next(), where filter_hash is dereferenced:
hash = iter->probe->ops.func_hash->filter_hash;
size = 1 << hash->size_bits;
This happens due to a race with register_ftrace_function_probe(). A new ftrace_func_probe is created and added into the func_probes list in trace_array under ftrace_lock. However, before initializing the filter, we drop ftrace_lock, and re-acquire it after acquiring regex_lock. If another process is trying to read set_ftrace_filter, it will be able to acquire ftrace_lock during this window and it will end up seeing a NULL filter_hash.
Fix this by just checking for a NULL filter_hash in t_probe_next(). If the filter_hash is NULL, then this probe is just being added and we can simply return from here.
--- kernel/trace/ftrace.c | 4 ++++ 1 file changed, 4 insertions(+)
kernel/trace/ftrace.c +4 -0
@@ -3095,6 +3095,10 @@ t_probe_next(struct seq_file *m, loff_t *pos) hnd = &iter->probe_entry->hlist; hash = iter->probe->ops.func_hash->filter_hash; + +if (!hash) +return NULL ; + size =1 << hash->size_bits; retry:
Signature · 1 line
2.20.1
Steven Rostedt
maintainerPATCH 2/7 ftrace: Check for empty hash and comment the race with registering probes
In reply to Steven RostedtFrom: "Steven Rostedt (VMware)" <[email protected]>
The race between adding a function probe and reading the probes that exist is very subtle. It needs a comment. Also, the issue can also happen if the probe has has the EMPTY_HASH as its func_hash.
--- kernel/trace/ftrace.c | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-)
kernel/trace/ftrace.c +9 -1
@@ -3096,7 +3096,11 @@ t_probe_next(struct seq_file *m, loff_t *pos) hash = iter->probe->ops.func_hash->filter_hash; -if (!hash) +/* +* A probe being registered may temporarily have an empty hash +* and it's at the end of the func_probes list. +*/ +if (!hash || hash ==EMPTY_HASH )return NULL ; size =1 << hash->size_bits;
@@ -4324,6 +4328,10 @@ register_ftrace_function_probe(char *glob, struct trace_array *tr,mutex_unlock (&ftrace_lock); +/* +* Note, there's a small window here that the func_hash->filter_hash +* may be NULL or empty. Need to be carefule when reading the loop. +*/ mutex_lock (&probe->ops.func_hash->regex_lock); orig_hash = &probe->ops.func_hash->filter_hash;
Signature · 1 line
2.20.1
Steven Rostedt
maintainerPATCH 3/7 ftrace: Check for successful allocation of hash
In reply to Steven RostedtFrom: "Naveen N. Rao" <[email protected]>
In register_ftrace_function_probe(), we are not checking the return value of alloc_and_copy_ftrace_hash(). The subsequent call to ftrace_match_records() may end up dereferencing the same. Add a check to ensure this doesn't happen.
--- kernel/trace/ftrace.c | 5 +++++ 1 file changed, 5 insertions(+)
kernel/trace/ftrace.c +5 -0
@@ -4338,6 +4338,11 @@ register_ftrace_function_probe(char *glob, struct trace_array *tr, old_hash = *orig_hash; hash =alloc_and_copy_ftrace_hash (FTRACE_HASH_DEFAULT_BITS , old_hash); +if (!hash) { + ret = -ENOMEM ; + goto out; + } + ret =ftrace_match_records (hash, glob,strlen (glob));/* Nothing found? */
Signature · 1 line
2.20.1
Steven Rostedt
maintainerPATCH 4/7 tracing: Make exported ftrace_set_clr_event non-static
In reply to Steven RostedtFrom: Denis Efremov <[email protected]>
The function ftrace_set_clr_event is declared static and marked EXPORT_SYMBOL_GPL(), which is at best an odd combination. Because the function was decided to be a part of API, this commit removes the static attribute and adds the declaration to the header.
--- include/linux/trace_events.h | 1 + kernel/trace/trace_events.c | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-)
include/linux/trace_events.h +1 -0
@@ -548,6 +548,7 @@ extern int trace_event_get_offsets(struct trace_event_call *call);#define is_signed_type (type) (((type)(-1)) < (type)1) +int ftrace_set_clr_event (struct trace_array *tr,char *buf,int set);int trace_set_clr_event (const char *system,const char *event,int set);/*
kernel/trace/trace_events.c +1 -1
@@ -787,7 +787,7 @@ static int __ftrace_set_clr_event(struct trace_array *tr, const char *match,return ret; } -static int ftrace_set_clr_event (struct trace_array *tr,char *buf,int set) +int ftrace_set_clr_event (struct trace_array *tr,char *buf,int set) {char *event =NULL , *sub =NULL , *match;int ret;
Signature · 1 line
2.20.1
Steven Rostedt
maintainerPATCH 5/7 tracing/probe: Fix null pointer dereference
In reply to Steven RostedtFrom: Xinpeng Liu <[email protected]>
BUG: KASAN: null-ptr-deref in trace_probe_cleanup+0x8d/0xd0 Read of size 8 at addr 0000000000000000 by task syz-executor.0/9746 trace_probe_cleanup+0x8d/0xd0 free_trace_kprobe.part.14+0x15/0x50 alloc_trace_kprobe+0x23e/0x250
--- kernel/trace/trace_probe.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
kernel/trace/trace_probe.c +2 -1
@@ -895,7 +895,8 @@ void trace_probe_cleanup(struct trace_probe *tp)for (i =0 ; i < tp->nr_args; i++)traceprobe_free_probe_arg (&tp->args[i]); -kfree (call->class->system); +if (call->class) +kfree (call->class->system);kfree (call->name);kfree (call->print_fmt); }
Signature · 1 line
2.20.1
Steven Rostedt
maintainerPATCH 6/7 ftrace/x86: Remove mcount() declaration
In reply to Steven RostedtFrom: Jisheng Zhang <[email protected]>
Commit 562e14f72292 ("ftrace/x86: Remove mcount support") removed the support for using mcount, so we could remove the mcount() declaration to clean up.
--- arch/x86/include/asm/ftrace.h | 1 - 1 file changed, 1 deletion(-)
arch/x86/include/asm/ftrace.h +0 -1
@@ -16,7 +16,6 @@#define HAVE_FUNCTION_GRAPH_RET_ADDR_PTR #ifndef __ASSEMBLY__ -extern void mcount (void );extern atomic_t modifying_ftrace_code;extern void __fentry__ (void );
Signature · 1 line
2.20.1
Steven Rostedt
maintainerPATCH 7/7 tracing: Correct kdoc formats
In reply to Steven RostedtFrom: Jakub Kicinski <[email protected]>
Fix the following kdoc warnings:
kernel/trace/trace.c:1579: warning: Function parameter or member 'tr' not described in 'update_max_tr_single' kernel/trace/trace.c:1579: warning: Function parameter or member 'tsk' not described in 'update_max_tr_single' kernel/trace/trace.c:1579: warning: Function parameter or member 'cpu' not described in 'update_max_tr_single' kernel/trace/trace.c:1776: warning: Function parameter or member 'type' not described in 'register_tracer' kernel/trace/trace.c:2239: warning: Function parameter or member 'task' not described in 'tracing_record_taskinfo' kernel/trace/trace.c:2239: warning: Function parameter or member 'flags' not described in 'tracing_record_taskinfo' kernel/trace/trace.c:2269: warning: Function parameter or member 'prev' not described in 'tracing_record_taskinfo_sched_switch' kernel/trace/trace.c:2269: warning: Function parameter or member 'next' not described in 'tracing_record_taskinfo_sched_switch' kernel/trace/trace.c:2269: warning: Function parameter or member 'flags' not described in 'tracing_record_taskinfo_sched_switch' kernel/trace/trace.c:3078: warning: Function parameter or member 'ip' not described in 'trace_vbprintk' kernel/trace/trace.c:3078: warning: Function parameter or member 'fmt' not described in 'trace_vbprintk' kernel/trace/trace.c:3078: warning: Function parameter or member 'args' not described in 'trace_vbprintk'
--- kernel/trace/trace.c | 26 ++++++++++++++------------ 1 file changed, 14 insertions(+), 12 deletions(-)
kernel/trace/trace.c +14 -12
@@ -1567,9 +1567,9 @@ update_max_tr(struct trace_array *tr, struct task_struct *tsk, int cpu,/** * update_max_tr_single - only copy one trace over, and reset the rest -* @tr - tracer -* @tsk - task with the latency -* @cpu - the cpu of the buffer to copy. +* @tr: tracer +* @tsk: task with the latency +* @cpu: the cpu of the buffer to copy. * * Flip the trace of a single CPU buffer between the @tr and the max_tr. */
@@ -1767,7 +1767,7 @@ static void __init apply_trace_boot_options(void);/** * register_tracer - register a tracer with the ftrace system. -* @type - the plugin for the tracer +* @type: the plugin for the tracer * * Register a new plugin tracer. */
@@ -2230,9 +2230,9 @@ static bool tracing_record_taskinfo_skip(int flags)/** * tracing_record_taskinfo - record the task info of a task * -* @task - task to record -* @flags - TRACE_RECORD_CMDLINE for recording comm -* - TRACE_RECORD_TGID for recording tgid +* @task: task to record +* @flags: TRACE_RECORD_CMDLINE for recording comm +* TRACE_RECORD_TGID for recording tgid */ void tracing_record_taskinfo (struct task_struct *task,int flags) {
@@ -2258,10 +2258,10 @@ void tracing_record_taskinfo(struct task_struct *task, int flags)/** * tracing_record_taskinfo_sched_switch - record task info for sched_switch * -* @prev - previous task during sched_switch -* @next - next task during sched_switch -* @flags - TRACE_RECORD_CMDLINE for recording comm -* TRACE_RECORD_TGID for recording tgid +* @prev: previous task during sched_switch +* @next: next task during sched_switch +* @flags: TRACE_RECORD_CMDLINE for recording comm +* TRACE_RECORD_TGID for recording tgid */ void tracing_record_taskinfo_sched_switch (struct task_struct *prev,struct task_struct *next,int flags)
@@ -3072,7 +3072,9 @@ static void trace_printk_start_stop_comm(int enabled)/** * trace_vbprintk - write binary msg to tracing buffer -* +* @ip: The address of the caller +* @fmt: The string format to write to the buffer +* @args: Arguments for @fmt */ int trace_vbprintk (unsigned long ip,const char *fmt,va_list args) {
Signature · 1 line
2.20.1