Skip to content

Commit 7d660c9

Browse files
committed
tracing: Have tracing_max_latency inc the trace array ref count
The tracing_max_latency file points to the trace_array max_latency field. For an instance, if the file is opened and the instance is deleted, reading or writing to the file will cause a use after free. Up the ref count of the trace_array when tracing_max_latency is opened. Link: https://lkml.kernel.org/r/[email protected] Link: https://lore.kernel.org/all/[email protected]/ Cc: [email protected] Cc: Masami Hiramatsu <[email protected]> Cc: Mark Rutland <[email protected]> Cc: Andrew Morton <[email protected]> Cc: Zheng Yejian <[email protected]> Fixes: 8530dec ("tracing: Add tracing_check_open_get_tr()") Tested-by: Linux Kernel Functional Testing <[email protected]> Tested-by: Naresh Kamboju <[email protected]> Signed-off-by: Steven Rostedt (Google) <[email protected]>
1 parent f5ca233 commit 7d660c9

File tree

1 file changed

+10
-5
lines changed

1 file changed

+10
-5
lines changed

kernel/trace/trace.c

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1772,7 +1772,7 @@ static void trace_create_maxlat_file(struct trace_array *tr,
17721772
init_irq_work(&tr->fsnotify_irqwork, latency_fsnotify_workfn_irq);
17731773
tr->d_max_latency = trace_create_file("tracing_max_latency",
17741774
TRACE_MODE_WRITE,
1775-
d_tracer, &tr->max_latency,
1775+
d_tracer, tr,
17761776
&tracing_max_lat_fops);
17771777
}
17781778

@@ -1805,7 +1805,7 @@ void latency_fsnotify(struct trace_array *tr)
18051805

18061806
#define trace_create_maxlat_file(tr, d_tracer) \
18071807
trace_create_file("tracing_max_latency", TRACE_MODE_WRITE, \
1808-
d_tracer, &tr->max_latency, &tracing_max_lat_fops)
1808+
d_tracer, tr, &tracing_max_lat_fops)
18091809

18101810
#endif
18111811

@@ -6717,14 +6717,18 @@ static ssize_t
67176717
tracing_max_lat_read(struct file *filp, char __user *ubuf,
67186718
size_t cnt, loff_t *ppos)
67196719
{
6720-
return tracing_nsecs_read(filp->private_data, ubuf, cnt, ppos);
6720+
struct trace_array *tr = filp->private_data;
6721+
6722+
return tracing_nsecs_read(&tr->max_latency, ubuf, cnt, ppos);
67216723
}
67226724

67236725
static ssize_t
67246726
tracing_max_lat_write(struct file *filp, const char __user *ubuf,
67256727
size_t cnt, loff_t *ppos)
67266728
{
6727-
return tracing_nsecs_write(filp->private_data, ubuf, cnt, ppos);
6729+
struct trace_array *tr = filp->private_data;
6730+
6731+
return tracing_nsecs_write(&tr->max_latency, ubuf, cnt, ppos);
67286732
}
67296733

67306734
#endif
@@ -7778,10 +7782,11 @@ static const struct file_operations tracing_thresh_fops = {
77787782

77797783
#ifdef CONFIG_TRACER_MAX_TRACE
77807784
static const struct file_operations tracing_max_lat_fops = {
7781-
.open = tracing_open_generic,
7785+
.open = tracing_open_generic_tr,
77827786
.read = tracing_max_lat_read,
77837787
.write = tracing_max_lat_write,
77847788
.llseek = generic_file_llseek,
7789+
.release = tracing_release_generic_tr,
77857790
};
77867791
#endif
77877792

0 commit comments

Comments
 (0)