Skip to content

Commit b301cb2

Browse files
rostedtgregkh
authored andcommitted
tracing: Do not create directories if lockdown is in affect
commit a356646 upstream. If lockdown is disabling tracing on boot up, it prevents the tracing files from even bering created. But when that happens, there's several places that will give a warning that the files were not created as that is usually a sign of a bug. Add in strategic locations where a check is made to see if tracing is disabled by lockdown, and if it is, do not go further, and fail silently (but print that tracing is disabled by lockdown, without doing a WARN_ON()). Cc: Matthew Garrett <mjg59@google.com> Fixes: 17911ff ("tracing: Add locked_down checks to the open calls of files created for tracefs") Signed-off-by: Steven Rostedt (VMware) <rostedt@goodmis.org> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
1 parent 8b8cd87 commit b301cb2

2 files changed

Lines changed: 23 additions & 0 deletions

File tree

‎kernel/trace/ring_buffer.c‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
#include <linux/trace_seq.h>
1212
#include <linux/spinlock.h>
1313
#include <linux/irq_work.h>
14+
#include <linux/security.h>
1415
#include <linux/uaccess.h>
1516
#include <linux/hardirq.h>
1617
#include <linux/kthread.h> /* for self test */
@@ -5068,6 +5069,11 @@ static __init int test_ringbuffer(void)
50685069
int cpu;
50695070
int ret = 0;
50705071

5072+
if (security_locked_down(LOCKDOWN_TRACEFS)) {
5073+
pr_warning("Lockdown is enabled, skipping ring buffer tests\n");
5074+
return 0;
5075+
}
5076+
50715077
pr_info("Running ring buffer tests...\n");
50725078

50735079
buffer = ring_buffer_alloc(RB_TEST_BUFFER_SIZE, RB_FL_OVERWRITE);

‎kernel/trace/trace.c‎

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1804,6 +1804,12 @@ int __init register_tracer(struct tracer *type)
18041804
return -1;
18051805
}
18061806

1807+
if (security_locked_down(LOCKDOWN_TRACEFS)) {
1808+
pr_warning("Can not register tracer %s due to lockdown\n",
1809+
type->name);
1810+
return -EPERM;
1811+
}
1812+
18071813
mutex_lock(&trace_types_lock);
18081814

18091815
tracing_selftest_running = true;
@@ -8647,6 +8653,11 @@ struct dentry *tracing_init_dentry(void)
86478653
{
86488654
struct trace_array *tr = &global_trace;
86498655

8656+
if (security_locked_down(LOCKDOWN_TRACEFS)) {
8657+
pr_warning("Tracing disabled due to lockdown\n");
8658+
return ERR_PTR(-EPERM);
8659+
}
8660+
86508661
/* The top level trace array uses NULL as parent */
86518662
if (tr->dir)
86528663
return NULL;
@@ -9089,6 +9100,12 @@ __init static int tracer_alloc_buffers(void)
90899100
int ring_buf_size;
90909101
int ret = -ENOMEM;
90919102

9103+
9104+
if (security_locked_down(LOCKDOWN_TRACEFS)) {
9105+
pr_warning("Tracing disabled due to lockdown\n");
9106+
return -EPERM;
9107+
}
9108+
90929109
/*
90939110
* Make sure we don't accidently add more trace options
90949111
* than we have bits for.

0 commit comments

Comments
 (0)