Skip to content

Commit 194c2c7

Browse files
committed
tracing: Get trace_array reference for available_tracers files
As instances may have different tracers available, we need to look at the trace_array descriptor that shows the list of the available tracers for the instance. But there's a race between opening the file and an admin deleting the instance. The trace_array_get() needs to be called before accessing the trace_array. Cc: [email protected] Fixes: 607e2ea ("tracing: Set up infrastructure to allow tracers for instances") Signed-off-by: Steven Rostedt (VMware) <[email protected]>
1 parent 9ef1669 commit 194c2c7

File tree

1 file changed

+15
-2
lines changed

1 file changed

+15
-2
lines changed

kernel/trace/trace.c

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4355,16 +4355,29 @@ static int show_traces_open(struct inode *inode, struct file *file)
43554355
if (tracing_disabled)
43564356
return -ENODEV;
43574357

4358+
if (trace_array_get(tr) < 0)
4359+
return -ENODEV;
4360+
43584361
ret = seq_open(file, &show_traces_seq_ops);
4359-
if (ret)
4362+
if (ret) {
4363+
trace_array_put(tr);
43604364
return ret;
4365+
}
43614366

43624367
m = file->private_data;
43634368
m->private = tr;
43644369

43654370
return 0;
43664371
}
43674372

4373+
static int show_traces_release(struct inode *inode, struct file *file)
4374+
{
4375+
struct trace_array *tr = inode->i_private;
4376+
4377+
trace_array_put(tr);
4378+
return seq_release(inode, file);
4379+
}
4380+
43684381
static ssize_t
43694382
tracing_write_stub(struct file *filp, const char __user *ubuf,
43704383
size_t count, loff_t *ppos)
@@ -4395,8 +4408,8 @@ static const struct file_operations tracing_fops = {
43954408
static const struct file_operations show_traces_fops = {
43964409
.open = show_traces_open,
43974410
.read = seq_read,
4398-
.release = seq_release,
43994411
.llseek = seq_lseek,
4412+
.release = show_traces_release,
44004413
};
44014414

44024415
static ssize_t

0 commit comments

Comments
 (0)