Skip to content

Commit 067df9e

Browse files
Zheng Yejianrostedt
authored andcommitted
tracing: Fix potential null-pointer-access of entry in list 'tr->err_log'
Entries in list 'tr->err_log' will be reused after entry number exceed TRACING_LOG_ERRS_MAX. The cmd string of the to be reused entry will be freed first then allocated a new one. If the allocation failed, then the entry will still be in list 'tr->err_log' but its 'cmd' field is set to be NULL, later access of 'cmd' is risky. Currently above problem can cause the loss of 'cmd' information of first entry in 'tr->err_log'. When execute `cat /sys/kernel/tracing/error_log`, reproduce logs like: [ 37.495100] trace_kprobe: error: Maxactive is not for kprobe(null) ^ [ 38.412517] trace_kprobe: error: Maxactive is not for kprobe Command: p4:myprobe2 do_sys_openat2 ^ Link: https://lore.kernel.org/linux-trace-kernel/[email protected] Fixes: 1581a88 ("tracing: Remove size restriction on tracing_log_err cmd strings") Signed-off-by: Zheng Yejian <[email protected]> Acked-by: Masami Hiramatsu (Google) <[email protected]> Signed-off-by: Steven Rostedt (Google) <[email protected]>
1 parent b875206 commit 067df9e

File tree

1 file changed

+5
-4
lines changed

1 file changed

+5
-4
lines changed

kernel/trace/trace.c

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7803,6 +7803,7 @@ static struct tracing_log_err *get_tracing_log_err(struct trace_array *tr,
78037803
int len)
78047804
{
78057805
struct tracing_log_err *err;
7806+
char *cmd;
78067807

78077808
if (tr->n_err_log_entries < TRACING_LOG_ERRS_MAX) {
78087809
err = alloc_tracing_log_err(len);
@@ -7811,12 +7812,12 @@ static struct tracing_log_err *get_tracing_log_err(struct trace_array *tr,
78117812

78127813
return err;
78137814
}
7814-
7815+
cmd = kzalloc(len, GFP_KERNEL);
7816+
if (!cmd)
7817+
return ERR_PTR(-ENOMEM);
78157818
err = list_first_entry(&tr->err_log, struct tracing_log_err, list);
78167819
kfree(err->cmd);
7817-
err->cmd = kzalloc(len, GFP_KERNEL);
7818-
if (!err->cmd)
7819-
return ERR_PTR(-ENOMEM);
7820+
err->cmd = cmd;
78207821
list_del(&err->list);
78217822

78227823
return err;

0 commit comments

Comments
 (0)