Skip to content

Commit a356646

Browse files
committed
tracing: Do not create directories if lockdown is in affect
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 <[email protected]> Fixes: 17911ff ("tracing: Add locked_down checks to the open calls of files created for tracefs") Signed-off-by: Steven Rostedt (VMware) <[email protected]>
1 parent 6c3edaf commit a356646

File tree

2 files changed

+23
-0
lines changed

2 files changed

+23
-0
lines changed

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
@@ -1888,6 +1888,12 @@ int __init register_tracer(struct tracer *type)
18881888
return -1;
18891889
}
18901890

1891+
if (security_locked_down(LOCKDOWN_TRACEFS)) {
1892+
pr_warning("Can not register tracer %s due to lockdown\n",
1893+
type->name);
1894+
return -EPERM;
1895+
}
1896+
18911897
mutex_lock(&trace_types_lock);
18921898

18931899
tracing_selftest_running = true;
@@ -8789,6 +8795,11 @@ struct dentry *tracing_init_dentry(void)
87898795
{
87908796
struct trace_array *tr = &global_trace;
87918797

8798+
if (security_locked_down(LOCKDOWN_TRACEFS)) {
8799+
pr_warning("Tracing disabled due to lockdown\n");
8800+
return ERR_PTR(-EPERM);
8801+
}
8802+
87928803
/* The top level trace array uses NULL as parent */
87938804
if (tr->dir)
87948805
return NULL;
@@ -9231,6 +9242,12 @@ __init static int tracer_alloc_buffers(void)
92319242
int ring_buf_size;
92329243
int ret = -ENOMEM;
92339244

9245+
9246+
if (security_locked_down(LOCKDOWN_TRACEFS)) {
9247+
pr_warning("Tracing disabled due to lockdown\n");
9248+
return -EPERM;
9249+
}
9250+
92349251
/*
92359252
* Make sure we don't accidently add more trace options
92369253
* than we have bits for.

0 commit comments

Comments
 (0)