Skip to content

Commit 2f13437

Browse files
committed
Merge tag 'trace-v5.5-2' of git://git.kernel.org/pub/scm/linux/kernel/git/rostedt/linux-trace
Pull more tracing updates from Steven Rostedt: "Two fixes and one patch that was missed: Fixes: - Missing __print_hex_dump undef for processing new function in trace events - Stop WARN_ON messages when lockdown disables tracing on boot up Enhancement: - Debug option to inject trace events from userspace (for rasdaemon)" The enhancement has its own config option and is non invasive. It's been discussed for sever months and should have been added to my original push, but I never pulled it into my queue. * tag 'trace-v5.5-2' of git://git.kernel.org/pub/scm/linux/kernel/git/rostedt/linux-trace: tracing: Do not create directories if lockdown is in affect tracing: Introduce trace event injection tracing: Fix __print_hex_dump scope
2 parents 056df57 + a356646 commit 2f13437

File tree

8 files changed

+372
-0
lines changed

8 files changed

+372
-0
lines changed

include/trace/trace_events.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -757,6 +757,7 @@ static inline void ftrace_test_probe_##call(void) \
757757
#undef __get_str
758758
#undef __get_bitmask
759759
#undef __print_array
760+
#undef __print_hex_dump
760761

761762
#undef TP_printk
762763
#define TP_printk(fmt, args...) "\"" fmt "\", " __stringify(args)

kernel/trace/Kconfig

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -671,6 +671,15 @@ config HIST_TRIGGERS
671671
See Documentation/trace/histogram.rst.
672672
If in doubt, say N.
673673

674+
config TRACE_EVENT_INJECT
675+
bool "Trace event injection"
676+
depends on TRACING
677+
help
678+
Allow user-space to inject a specific trace event into the ring
679+
buffer. This is mainly used for testing purpose.
680+
681+
If unsure, say N.
682+
674683
config MMIOTRACE_TEST
675684
tristate "Test module for mmiotrace"
676685
depends on MMIOTRACE && m

kernel/trace/Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@ obj-$(CONFIG_EVENT_TRACING) += trace_event_perf.o
6969
endif
7070
obj-$(CONFIG_EVENT_TRACING) += trace_events_filter.o
7171
obj-$(CONFIG_EVENT_TRACING) += trace_events_trigger.o
72+
obj-$(CONFIG_TRACE_EVENT_INJECT) += trace_events_inject.o
7273
obj-$(CONFIG_HIST_TRIGGERS) += trace_events_hist.o
7374
obj-$(CONFIG_BPF_EVENTS) += bpf_trace.o
7475
obj-$(CONFIG_KPROBE_EVENTS) += trace_kprobe.o

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.

kernel/trace/trace.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1601,6 +1601,7 @@ extern struct list_head ftrace_events;
16011601

16021602
extern const struct file_operations event_trigger_fops;
16031603
extern const struct file_operations event_hist_fops;
1604+
extern const struct file_operations event_inject_fops;
16041605

16051606
#ifdef CONFIG_HIST_TRIGGERS
16061607
extern int register_trigger_hist_cmd(void);

kernel/trace/trace_events.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2044,6 +2044,12 @@ event_create_dir(struct dentry *parent, struct trace_event_file *file)
20442044
trace_create_file("format", 0444, file->dir, call,
20452045
&ftrace_event_format_fops);
20462046

2047+
#ifdef CONFIG_TRACE_EVENT_INJECT
2048+
if (call->event.type && call->class->reg)
2049+
trace_create_file("inject", 0200, file->dir, file,
2050+
&event_inject_fops);
2051+
#endif
2052+
20472053
return 0;
20482054
}
20492055

0 commit comments

Comments
 (0)