All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH 0/3] [GIT PULL] tracing: three more updates
@ 2019-12-05  2:04 Steven Rostedt
  2019-12-05  2:05 ` [PATCH 1/3] tracing: Fix __print_hex_dump scope Steven Rostedt
                   ` (2 more replies)
  0 siblings, 3 replies; 7+ messages in thread
From: Steven Rostedt @ 2019-12-05  2:04 UTC (permalink / raw)
  To: linux-kernel; +Cc: Linus Torvalds, Ingo Molnar, Andrew Morton


Linus,

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.

Please pull the latest trace-v5.5-2 tree, which can be found at:


  git://git.kernel.org/pub/scm/linux/kernel/git/rostedt/linux-trace.git
trace-v5.5-2

Tag SHA1: 075c954bfa42bcd2dad254f1fe6fcd81197512de
Head SHA1: a356646a56857c2e5ad875beec734d7145ecd49a


Cong Wang (1):
      tracing: Introduce trace event injection

Piotr Maziarz (1):
      tracing: Fix __print_hex_dump scope

Steven Rostedt (VMware) (1):
      tracing: Do not create directories if lockdown is in affect

----
 include/trace/trace_events.h       |   1 +
 kernel/trace/Kconfig               |   9 +
 kernel/trace/Makefile              |   1 +
 kernel/trace/ring_buffer.c         |   6 +
 kernel/trace/trace.c               |  17 ++
 kernel/trace/trace.h               |   1 +
 kernel/trace/trace_events.c        |   6 +
 kernel/trace/trace_events_inject.c | 331 +++++++++++++++++++++++++++++++++++++
 8 files changed, 372 insertions(+)
 create mode 100644 kernel/trace/trace_events_inject.c

^ permalink raw reply	[flat|nested] 7+ messages in thread

* [PATCH 1/3] tracing: Fix __print_hex_dump scope
  2019-12-05  2:04 [PATCH 0/3] [GIT PULL] tracing: three more updates Steven Rostedt
@ 2019-12-05  2:05 ` Steven Rostedt
  2019-12-05  2:05 ` [PATCH 2/3] tracing: Introduce trace event injection Steven Rostedt
  2019-12-05  2:05 ` [PATCH 3/3] tracing: Do not create directories if lockdown is in affect Steven Rostedt
  2 siblings, 0 replies; 7+ messages in thread
From: Steven Rostedt @ 2019-12-05  2:05 UTC (permalink / raw)
  To: linux-kernel
  Cc: Linus Torvalds, Ingo Molnar, Andrew Morton, Piotr Maziarz,
	Cezary Rojewski

From: Piotr Maziarz <piotrx.maziarz@linux.intel.com>

undef is needed for parsing __print_hex_dump in traceevent lib.

Link: http://lkml.kernel.org/r/1574762791-14883-1-git-send-email-piotrx.maziarz@linux.intel.com

Signed-off-by: Piotr Maziarz <piotrx.maziarz@linux.intel.com>
Signed-off-by: Cezary Rojewski <cezary.rojewski@intel.com>
Signed-off-by: Steven Rostedt (VMware) <rostedt@goodmis.org>
---
 include/trace/trace_events.h | 1 +
 1 file changed, 1 insertion(+)

diff --git a/include/trace/trace_events.h b/include/trace/trace_events.h
index 7089760d4c7a..472b33d23a10 100644
--- a/include/trace/trace_events.h
+++ b/include/trace/trace_events.h
@@ -757,6 +757,7 @@ static inline void ftrace_test_probe_##call(void)			\
 #undef __get_str
 #undef __get_bitmask
 #undef __print_array
+#undef __print_hex_dump
 
 #undef TP_printk
 #define TP_printk(fmt, args...) "\"" fmt "\", "  __stringify(args)
-- 
2.24.0



^ permalink raw reply related	[flat|nested] 7+ messages in thread

* [PATCH 2/3] tracing: Introduce trace event injection
  2019-12-05  2:04 [PATCH 0/3] [GIT PULL] tracing: three more updates Steven Rostedt
  2019-12-05  2:05 ` [PATCH 1/3] tracing: Fix __print_hex_dump scope Steven Rostedt
@ 2019-12-05  2:05 ` Steven Rostedt
  2019-12-05  2:05 ` [PATCH 3/3] tracing: Do not create directories if lockdown is in affect Steven Rostedt
  2 siblings, 0 replies; 7+ messages in thread
From: Steven Rostedt @ 2019-12-05  2:05 UTC (permalink / raw)
  To: linux-kernel
  Cc: Linus Torvalds, Ingo Molnar, Andrew Morton, Ingo Molnar, Cong Wang

From: Cong Wang <xiyou.wangcong@gmail.com>

We have been trying to use rasdaemon to monitor hardware errors like
correctable memory errors. rasdaemon uses trace events to monitor
various hardware errors. In order to test it, we have to inject some
hardware errors, unfortunately not all of them provide error
injections. MCE does provide a way to inject MCE errors, but errors
like PCI error and devlink error don't, it is not easy to add error
injection to each of them. Instead, it is relatively easier to just
allow users to inject trace events in a generic way so that all trace
events can be injected.

This patch introduces trace event injection, where a new 'inject' is
added to each tracepoint directory. Users could write into this file
with key=value pairs to specify the value of each fields of the trace
event, all unspecified fields are set to zero values by default.

For example, for the net/net_dev_queue tracepoint, we can inject:

  INJECT=/sys/kernel/debug/tracing/events/net/net_dev_queue/inject
  echo "" > $INJECT
  echo "name='test'" > $INJECT
  echo "name='test' len=1024" > $INJECT
  cat /sys/kernel/debug/tracing/trace
  ...
   <...>-614   [000] ....    36.571483: net_dev_queue: dev= skbaddr=00000000fbf338c2 len=0
   <...>-614   [001] ....   136.588252: net_dev_queue: dev=test skbaddr=00000000fbf338c2 len=0
   <...>-614   [001] .N..   208.431878: net_dev_queue: dev=test skbaddr=00000000fbf338c2 len=1024

Triggers could be triggered as usual too:

  echo "stacktrace if len == 1025" > /sys/kernel/debug/tracing/events/net/net_dev_queue/trigger
  echo "len=1025" > $INJECT
  cat /sys/kernel/debug/tracing/trace
  ...
      bash-614   [000] ....    36.571483: net_dev_queue: dev= skbaddr=00000000fbf338c2 len=0
      bash-614   [001] ....   136.588252: net_dev_queue: dev=test skbaddr=00000000fbf338c2 len=0
      bash-614   [001] .N..   208.431878: net_dev_queue: dev=test skbaddr=00000000fbf338c2 len=1024
      bash-614   [001] .N.1   284.236349: <stack trace>
 => event_inject_write
 => vfs_write
 => ksys_write
 => do_syscall_64
 => entry_SYSCALL_64_after_hwframe

The only thing that can't be injected is string pointers as they
require constant string pointers, this can't be done at run time.

Link: http://lkml.kernel.org/r/20191130045218.18979-1-xiyou.wangcong@gmail.com

Cc: Ingo Molnar <mingo@redhat.com>
Signed-off-by: Cong Wang <xiyou.wangcong@gmail.com>
Signed-off-by: Steven Rostedt (VMware) <rostedt@goodmis.org>
---
 kernel/trace/Kconfig               |   9 +
 kernel/trace/Makefile              |   1 +
 kernel/trace/trace.h               |   1 +
 kernel/trace/trace_events.c        |   6 +
 kernel/trace/trace_events_inject.c | 331 +++++++++++++++++++++++++++++
 5 files changed, 348 insertions(+)
 create mode 100644 kernel/trace/trace_events_inject.c

diff --git a/kernel/trace/Kconfig b/kernel/trace/Kconfig
index f67620499faa..29a9c5058b62 100644
--- a/kernel/trace/Kconfig
+++ b/kernel/trace/Kconfig
@@ -672,6 +672,15 @@ config HIST_TRIGGERS
 	  See Documentation/trace/histogram.rst.
 	  If in doubt, say N.
 
+config TRACE_EVENT_INJECT
+	bool "Trace event injection"
+	depends on TRACING
+	help
+	  Allow user-space to inject a specific trace event into the ring
+	  buffer. This is mainly used for testing purpose.
+
+	  If unsure, say N.
+
 config MMIOTRACE_TEST
 	tristate "Test module for mmiotrace"
 	depends on MMIOTRACE && m
diff --git a/kernel/trace/Makefile b/kernel/trace/Makefile
index c2b2148bb1d2..0e63db62225f 100644
--- a/kernel/trace/Makefile
+++ b/kernel/trace/Makefile
@@ -69,6 +69,7 @@ obj-$(CONFIG_EVENT_TRACING) += trace_event_perf.o
 endif
 obj-$(CONFIG_EVENT_TRACING) += trace_events_filter.o
 obj-$(CONFIG_EVENT_TRACING) += trace_events_trigger.o
+obj-$(CONFIG_TRACE_EVENT_INJECT) += trace_events_inject.o
 obj-$(CONFIG_HIST_TRIGGERS) += trace_events_hist.o
 obj-$(CONFIG_BPF_EVENTS) += bpf_trace.o
 obj-$(CONFIG_KPROBE_EVENTS) += trace_kprobe.o
diff --git a/kernel/trace/trace.h b/kernel/trace/trace.h
index ca7fccafbcbb..63bf60f79398 100644
--- a/kernel/trace/trace.h
+++ b/kernel/trace/trace.h
@@ -1601,6 +1601,7 @@ extern struct list_head ftrace_events;
 
 extern const struct file_operations event_trigger_fops;
 extern const struct file_operations event_hist_fops;
+extern const struct file_operations event_inject_fops;
 
 #ifdef CONFIG_HIST_TRIGGERS
 extern int register_trigger_hist_cmd(void);
diff --git a/kernel/trace/trace_events.c b/kernel/trace/trace_events.c
index 6b3a69e9aa6a..c6de3cebc127 100644
--- a/kernel/trace/trace_events.c
+++ b/kernel/trace/trace_events.c
@@ -2044,6 +2044,12 @@ event_create_dir(struct dentry *parent, struct trace_event_file *file)
 	trace_create_file("format", 0444, file->dir, call,
 			  &ftrace_event_format_fops);
 
+#ifdef CONFIG_TRACE_EVENT_INJECT
+	if (call->event.type && call->class->reg)
+		trace_create_file("inject", 0200, file->dir, file,
+				  &event_inject_fops);
+#endif
+
 	return 0;
 }
 
diff --git a/kernel/trace/trace_events_inject.c b/kernel/trace/trace_events_inject.c
new file mode 100644
index 000000000000..d43710718ee5
--- /dev/null
+++ b/kernel/trace/trace_events_inject.c
@@ -0,0 +1,331 @@
+// SPDX-License-Identifier: GPL-2.0
+/*
+ * trace_events_inject - trace event injection
+ *
+ * Copyright (C) 2019 Cong Wang <cwang@twitter.com>
+ */
+
+#include <linux/module.h>
+#include <linux/ctype.h>
+#include <linux/mutex.h>
+#include <linux/slab.h>
+#include <linux/rculist.h>
+
+#include "trace.h"
+
+static int
+trace_inject_entry(struct trace_event_file *file, void *rec, int len)
+{
+	struct trace_event_buffer fbuffer;
+	struct ring_buffer *buffer;
+	int written = 0;
+	void *entry;
+
+	rcu_read_lock_sched();
+	buffer = file->tr->trace_buffer.buffer;
+	entry = trace_event_buffer_reserve(&fbuffer, file, len);
+	if (entry) {
+		memcpy(entry, rec, len);
+		written = len;
+		trace_event_buffer_commit(&fbuffer);
+	}
+	rcu_read_unlock_sched();
+
+	return written;
+}
+
+static int
+parse_field(char *str, struct trace_event_call *call,
+	    struct ftrace_event_field **pf, u64 *pv)
+{
+	struct ftrace_event_field *field;
+	char *field_name;
+	int s, i = 0;
+	int len;
+	u64 val;
+
+	if (!str[i])
+		return 0;
+	/* First find the field to associate to */
+	while (isspace(str[i]))
+		i++;
+	s = i;
+	while (isalnum(str[i]) || str[i] == '_')
+		i++;
+	len = i - s;
+	if (!len)
+		return -EINVAL;
+
+	field_name = kmemdup_nul(str + s, len, GFP_KERNEL);
+	if (!field_name)
+		return -ENOMEM;
+	field = trace_find_event_field(call, field_name);
+	kfree(field_name);
+	if (!field)
+		return -ENOENT;
+
+	*pf = field;
+	while (isspace(str[i]))
+		i++;
+	if (str[i] != '=')
+		return -EINVAL;
+	i++;
+	while (isspace(str[i]))
+		i++;
+	s = i;
+	if (isdigit(str[i]) || str[i] == '-') {
+		char *num, c;
+		int ret;
+
+		/* Make sure the field is not a string */
+		if (is_string_field(field))
+			return -EINVAL;
+
+		if (str[i] == '-')
+			i++;
+
+		/* We allow 0xDEADBEEF */
+		while (isalnum(str[i]))
+			i++;
+		num = str + s;
+		c = str[i];
+		if (c != '\0' && !isspace(c))
+			return -EINVAL;
+		str[i] = '\0';
+		/* Make sure it is a value */
+		if (field->is_signed)
+			ret = kstrtoll(num, 0, &val);
+		else
+			ret = kstrtoull(num, 0, &val);
+		str[i] = c;
+		if (ret)
+			return ret;
+
+		*pv = val;
+		return i;
+	} else if (str[i] == '\'' || str[i] == '"') {
+		char q = str[i];
+
+		/* Make sure the field is OK for strings */
+		if (!is_string_field(field))
+			return -EINVAL;
+
+		for (i++; str[i]; i++) {
+			if (str[i] == '\\' && str[i + 1]) {
+				i++;
+				continue;
+			}
+			if (str[i] == q)
+				break;
+		}
+		if (!str[i])
+			return -EINVAL;
+
+		/* Skip quotes */
+		s++;
+		len = i - s;
+		if (len >= MAX_FILTER_STR_VAL)
+			return -EINVAL;
+
+		*pv = (unsigned long)(str + s);
+		str[i] = 0;
+		/* go past the last quote */
+		i++;
+		return i;
+	}
+
+	return -EINVAL;
+}
+
+static int trace_get_entry_size(struct trace_event_call *call)
+{
+	struct ftrace_event_field *field;
+	struct list_head *head;
+	int size = 0;
+
+	head = trace_get_fields(call);
+	list_for_each_entry(field, head, link) {
+		if (field->size + field->offset > size)
+			size = field->size + field->offset;
+	}
+
+	return size;
+}
+
+static void *trace_alloc_entry(struct trace_event_call *call, int *size)
+{
+	int entry_size = trace_get_entry_size(call);
+	struct ftrace_event_field *field;
+	struct list_head *head;
+	void *entry = NULL;
+
+	/* We need an extra '\0' at the end. */
+	entry = kzalloc(entry_size + 1, GFP_KERNEL);
+	if (!entry)
+		return NULL;
+
+	head = trace_get_fields(call);
+	list_for_each_entry(field, head, link) {
+		if (!is_string_field(field))
+			continue;
+		if (field->filter_type == FILTER_STATIC_STRING)
+			continue;
+		if (field->filter_type == FILTER_DYN_STRING) {
+			u32 *str_item;
+			int str_loc = entry_size & 0xffff;
+
+			str_item = (u32 *)(entry + field->offset);
+			*str_item = str_loc; /* string length is 0. */
+		} else {
+			char **paddr;
+
+			paddr = (char **)(entry + field->offset);
+			*paddr = "";
+		}
+	}
+
+	*size = entry_size + 1;
+	return entry;
+}
+
+#define INJECT_STRING "STATIC STRING CAN NOT BE INJECTED"
+
+/* Caller is responsible to free the *pentry. */
+static int parse_entry(char *str, struct trace_event_call *call, void **pentry)
+{
+	struct ftrace_event_field *field;
+	unsigned long irq_flags;
+	void *entry = NULL;
+	int entry_size;
+	u64 val;
+	int len;
+
+	entry = trace_alloc_entry(call, &entry_size);
+	*pentry = entry;
+	if (!entry)
+		return -ENOMEM;
+
+	local_save_flags(irq_flags);
+	tracing_generic_entry_update(entry, call->event.type, irq_flags,
+				     preempt_count());
+
+	while ((len = parse_field(str, call, &field, &val)) > 0) {
+		if (is_function_field(field))
+			return -EINVAL;
+
+		if (is_string_field(field)) {
+			char *addr = (char *)(unsigned long) val;
+
+			if (field->filter_type == FILTER_STATIC_STRING) {
+				strlcpy(entry + field->offset, addr, field->size);
+			} else if (field->filter_type == FILTER_DYN_STRING) {
+				int str_len = strlen(addr) + 1;
+				int str_loc = entry_size & 0xffff;
+				u32 *str_item;
+
+				entry_size += str_len;
+				*pentry = krealloc(entry, entry_size, GFP_KERNEL);
+				if (!*pentry) {
+					kfree(entry);
+					return -ENOMEM;
+				}
+				entry = *pentry;
+
+				strlcpy(entry + (entry_size - str_len), addr, str_len);
+				str_item = (u32 *)(entry + field->offset);
+				*str_item = (str_len << 16) | str_loc;
+			} else {
+				char **paddr;
+
+				paddr = (char **)(entry + field->offset);
+				*paddr = INJECT_STRING;
+			}
+		} else {
+			switch (field->size) {
+			case 1: {
+				u8 tmp = (u8) val;
+
+				memcpy(entry + field->offset, &tmp, 1);
+				break;
+			}
+			case 2: {
+				u16 tmp = (u16) val;
+
+				memcpy(entry + field->offset, &tmp, 2);
+				break;
+			}
+			case 4: {
+				u32 tmp = (u32) val;
+
+				memcpy(entry + field->offset, &tmp, 4);
+				break;
+			}
+			case 8:
+				memcpy(entry + field->offset, &val, 8);
+				break;
+			default:
+				return -EINVAL;
+			}
+		}
+
+		str += len;
+	}
+
+	if (len < 0)
+		return len;
+
+	return entry_size;
+}
+
+static ssize_t
+event_inject_write(struct file *filp, const char __user *ubuf, size_t cnt,
+		   loff_t *ppos)
+{
+	struct trace_event_call *call;
+	struct trace_event_file *file;
+	int err = -ENODEV, size;
+	void *entry = NULL;
+	char *buf;
+
+	if (cnt >= PAGE_SIZE)
+		return -EINVAL;
+
+	buf = memdup_user_nul(ubuf, cnt);
+	if (IS_ERR(buf))
+		return PTR_ERR(buf);
+	strim(buf);
+
+	mutex_lock(&event_mutex);
+	file = event_file_data(filp);
+	if (file) {
+		call = file->event_call;
+		size = parse_entry(buf, call, &entry);
+		if (size < 0)
+			err = size;
+		else
+			err = trace_inject_entry(file, entry, size);
+	}
+	mutex_unlock(&event_mutex);
+
+	kfree(entry);
+	kfree(buf);
+
+	if (err < 0)
+		return err;
+
+	*ppos += err;
+	return cnt;
+}
+
+static ssize_t
+event_inject_read(struct file *file, char __user *buf, size_t size,
+		  loff_t *ppos)
+{
+	return -EPERM;
+}
+
+const struct file_operations event_inject_fops = {
+	.open = tracing_open_generic,
+	.read = event_inject_read,
+	.write = event_inject_write,
+};
-- 
2.24.0



^ permalink raw reply related	[flat|nested] 7+ messages in thread

* [PATCH 3/3] tracing: Do not create directories if lockdown is in affect
  2019-12-05  2:04 [PATCH 0/3] [GIT PULL] tracing: three more updates Steven Rostedt
  2019-12-05  2:05 ` [PATCH 1/3] tracing: Fix __print_hex_dump scope Steven Rostedt
  2019-12-05  2:05 ` [PATCH 2/3] tracing: Introduce trace event injection Steven Rostedt
@ 2019-12-05  2:05 ` Steven Rostedt
  2020-01-10 16:31   ` Steven Rostedt
  2 siblings, 1 reply; 7+ messages in thread
From: Steven Rostedt @ 2019-12-05  2:05 UTC (permalink / raw)
  To: linux-kernel; +Cc: Linus Torvalds, Ingo Molnar, Andrew Morton, Matthew Garrett

From: "Steven Rostedt (VMware)" <rostedt@goodmis.org>

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: 17911ff38aa5 ("tracing: Add locked_down checks to the open calls of files created for tracefs")
Signed-off-by: Steven Rostedt (VMware) <rostedt@goodmis.org>
---
 kernel/trace/ring_buffer.c |  6 ++++++
 kernel/trace/trace.c       | 17 +++++++++++++++++
 2 files changed, 23 insertions(+)

diff --git a/kernel/trace/ring_buffer.c b/kernel/trace/ring_buffer.c
index 66358d66c933..4bf050fcfe3b 100644
--- a/kernel/trace/ring_buffer.c
+++ b/kernel/trace/ring_buffer.c
@@ -11,6 +11,7 @@
 #include <linux/trace_seq.h>
 #include <linux/spinlock.h>
 #include <linux/irq_work.h>
+#include <linux/security.h>
 #include <linux/uaccess.h>
 #include <linux/hardirq.h>
 #include <linux/kthread.h>	/* for self test */
@@ -5068,6 +5069,11 @@ static __init int test_ringbuffer(void)
 	int cpu;
 	int ret = 0;
 
+	if (security_locked_down(LOCKDOWN_TRACEFS)) {
+		pr_warning("Lockdown is enabled, skipping ring buffer tests\n");
+		return 0;
+	}
+
 	pr_info("Running ring buffer tests...\n");
 
 	buffer = ring_buffer_alloc(RB_TEST_BUFFER_SIZE, RB_FL_OVERWRITE);
diff --git a/kernel/trace/trace.c b/kernel/trace/trace.c
index 02a23a6e5e00..23459d53d576 100644
--- a/kernel/trace/trace.c
+++ b/kernel/trace/trace.c
@@ -1888,6 +1888,12 @@ int __init register_tracer(struct tracer *type)
 		return -1;
 	}
 
+	if (security_locked_down(LOCKDOWN_TRACEFS)) {
+		pr_warning("Can not register tracer %s due to lockdown\n",
+			   type->name);
+		return -EPERM;
+	}
+
 	mutex_lock(&trace_types_lock);
 
 	tracing_selftest_running = true;
@@ -8789,6 +8795,11 @@ struct dentry *tracing_init_dentry(void)
 {
 	struct trace_array *tr = &global_trace;
 
+	if (security_locked_down(LOCKDOWN_TRACEFS)) {
+		pr_warning("Tracing disabled due to lockdown\n");
+		return ERR_PTR(-EPERM);
+	}
+
 	/* The top level trace array uses  NULL as parent */
 	if (tr->dir)
 		return NULL;
@@ -9231,6 +9242,12 @@ __init static int tracer_alloc_buffers(void)
 	int ring_buf_size;
 	int ret = -ENOMEM;
 
+
+	if (security_locked_down(LOCKDOWN_TRACEFS)) {
+		pr_warning("Tracing disabled due to lockdown\n");
+		return -EPERM;
+	}
+
 	/*
 	 * Make sure we don't accidently add more trace options
 	 * than we have bits for.
-- 
2.24.0



^ permalink raw reply related	[flat|nested] 7+ messages in thread

* Re: [PATCH 3/3] tracing: Do not create directories if lockdown is in affect
  2019-12-05  2:05 ` [PATCH 3/3] tracing: Do not create directories if lockdown is in affect Steven Rostedt
@ 2020-01-10 16:31   ` Steven Rostedt
  2020-01-10 16:54     ` Greg KH
  0 siblings, 1 reply; 7+ messages in thread
From: Steven Rostedt @ 2020-01-10 16:31 UTC (permalink / raw)
  To: linux-kernel, stable
  Cc: Linus Torvalds, Ingo Molnar, Andrew Morton, Matthew Garrett, bugzilla

I should have marked this for stable. The commit it fixes (see Fixes tag) is
in 5.4, and it appears this has yet to make it to 5.4 yet.

-- Steve


On Wed, Dec 04, 2019 at 09:05:02PM -0500, Steven Rostedt wrote:
> From: "Steven Rostedt (VMware)" <rostedt@goodmis.org>
> 
> 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: 17911ff38aa5 ("tracing: Add locked_down checks to the open calls of files created for tracefs")
> Signed-off-by: Steven Rostedt (VMware) <rostedt@goodmis.org>
> ---
>  kernel/trace/ring_buffer.c |  6 ++++++
>  kernel/trace/trace.c       | 17 +++++++++++++++++
>  2 files changed, 23 insertions(+)
> 
> diff --git a/kernel/trace/ring_buffer.c b/kernel/trace/ring_buffer.c
> index 66358d66c933..4bf050fcfe3b 100644
> --- a/kernel/trace/ring_buffer.c
> +++ b/kernel/trace/ring_buffer.c
> @@ -11,6 +11,7 @@
>  #include <linux/trace_seq.h>
>  #include <linux/spinlock.h>
>  #include <linux/irq_work.h>
> +#include <linux/security.h>
>  #include <linux/uaccess.h>
>  #include <linux/hardirq.h>
>  #include <linux/kthread.h>	/* for self test */
> @@ -5068,6 +5069,11 @@ static __init int test_ringbuffer(void)
>  	int cpu;
>  	int ret = 0;
>  
> +	if (security_locked_down(LOCKDOWN_TRACEFS)) {
> +		pr_warning("Lockdown is enabled, skipping ring buffer tests\n");
> +		return 0;
> +	}
> +
>  	pr_info("Running ring buffer tests...\n");
>  
>  	buffer = ring_buffer_alloc(RB_TEST_BUFFER_SIZE, RB_FL_OVERWRITE);
> diff --git a/kernel/trace/trace.c b/kernel/trace/trace.c
> index 02a23a6e5e00..23459d53d576 100644
> --- a/kernel/trace/trace.c
> +++ b/kernel/trace/trace.c
> @@ -1888,6 +1888,12 @@ int __init register_tracer(struct tracer *type)
>  		return -1;
>  	}
>  
> +	if (security_locked_down(LOCKDOWN_TRACEFS)) {
> +		pr_warning("Can not register tracer %s due to lockdown\n",
> +			   type->name);
> +		return -EPERM;
> +	}
> +
>  	mutex_lock(&trace_types_lock);
>  
>  	tracing_selftest_running = true;
> @@ -8789,6 +8795,11 @@ struct dentry *tracing_init_dentry(void)
>  {
>  	struct trace_array *tr = &global_trace;
>  
> +	if (security_locked_down(LOCKDOWN_TRACEFS)) {
> +		pr_warning("Tracing disabled due to lockdown\n");
> +		return ERR_PTR(-EPERM);
> +	}
> +
>  	/* The top level trace array uses  NULL as parent */
>  	if (tr->dir)
>  		return NULL;
> @@ -9231,6 +9242,12 @@ __init static int tracer_alloc_buffers(void)
>  	int ring_buf_size;
>  	int ret = -ENOMEM;
>  
> +
> +	if (security_locked_down(LOCKDOWN_TRACEFS)) {
> +		pr_warning("Tracing disabled due to lockdown\n");
> +		return -EPERM;
> +	}
> +
>  	/*
>  	 * Make sure we don't accidently add more trace options
>  	 * than we have bits for.
> -- 
> 2.24.0
> 

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH 3/3] tracing: Do not create directories if lockdown is in affect
  2020-01-10 16:31   ` Steven Rostedt
@ 2020-01-10 16:54     ` Greg KH
  2020-01-10 17:02       ` Steven Rostedt
  0 siblings, 1 reply; 7+ messages in thread
From: Greg KH @ 2020-01-10 16:54 UTC (permalink / raw)
  To: Steven Rostedt
  Cc: linux-kernel, stable, Linus Torvalds, Ingo Molnar, Andrew Morton,
	Matthew Garrett, bugzilla

On Fri, Jan 10, 2020 at 11:31:05AM -0500, Steven Rostedt wrote:
> I should have marked this for stable. The commit it fixes (see Fixes tag) is
> in 5.4, and it appears this has yet to make it to 5.4 yet.
> 
> -- Steve
> 
> 
> On Wed, Dec 04, 2019 at 09:05:02PM -0500, Steven Rostedt wrote:
> > From: "Steven Rostedt (VMware)" <rostedt@goodmis.org>
> > 
> > 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: 17911ff38aa5 ("tracing: Add locked_down checks to the open calls of files created for tracefs")
> > Signed-off-by: Steven Rostedt (VMware) <rostedt@goodmis.org>

Relying only on the Fixes: tag to get things picked up by stable is a
sure way to get it on the "slow, and maybe eventually, hopefully, it
might make it into stable" path :)

I have over 1000 patches right now in that "bucket" that need to be
checked to see if they are relevant for stable backporting, just since
5.4 was released.  I have automated a lot of it, but still, they require
manual review.

I'll go queue this up now, as it's simplest just to ask us to take it
after it hits Linus's tree :)

thanks,

greg k-h

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH 3/3] tracing: Do not create directories if lockdown is in affect
  2020-01-10 16:54     ` Greg KH
@ 2020-01-10 17:02       ` Steven Rostedt
  0 siblings, 0 replies; 7+ messages in thread
From: Steven Rostedt @ 2020-01-10 17:02 UTC (permalink / raw)
  To: Greg KH
  Cc: linux-kernel, stable, Linus Torvalds, Ingo Molnar, Andrew Morton,
	Matthew Garrett, bugzilla

On Fri, 10 Jan 2020 17:54:04 +0100
Greg KH <greg@kroah.com> wrote:

> Relying only on the Fixes: tag to get things picked up by stable is a
> sure way to get it on the "slow, and maybe eventually, hopefully, it
> might make it into stable" path :)

I've been numbed by all the AUTOSEL patches, where I tend to think
Fixes is becoming enough. That said, this particular patch, I thought
was going in the same release as what it fixed, which is why I never
added stable to it. :-/

> 
> I have over 1000 patches right now in that "bucket" that need to be
> checked to see if they are relevant for stable backporting, just since
> 5.4 was released.  I have automated a lot of it, but still, they require
> manual review.
> 
> I'll go queue this up now, as it's simplest just to ask us to take it
> after it hits Linus's tree :)

Again, I thought the AUTOSEL would pick it up, as it seems to pick
other patches I don't intend on going to stable quickly ;-)

-- Steve

^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2020-01-10 17:02 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-12-05  2:04 [PATCH 0/3] [GIT PULL] tracing: three more updates Steven Rostedt
2019-12-05  2:05 ` [PATCH 1/3] tracing: Fix __print_hex_dump scope Steven Rostedt
2019-12-05  2:05 ` [PATCH 2/3] tracing: Introduce trace event injection Steven Rostedt
2019-12-05  2:05 ` [PATCH 3/3] tracing: Do not create directories if lockdown is in affect Steven Rostedt
2020-01-10 16:31   ` Steven Rostedt
2020-01-10 16:54     ` Greg KH
2020-01-10 17:02       ` Steven Rostedt

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.