Skip to contentSkip to conversation

tracing: Add missing LOCKDOWN_TRACEFS checking

PATCH New Steven Rostedt 1 participant 3 messages Sep 5, 2023

Subsystems (2)
lore
Share & tools
lore

Steven Rostedt

author maintainer
#0 lore raw

cover tracing: Add missing LOCKDOWN_TRACEFS checking

When LOCKDOWN_TRACEFS is activated, some of the tracefs functions can still return success leaving tracefs in an undefined state.

I broke this up into two patches. One that fixes just tracefs that existed before this merge window and needs to be backported to stable. The other fixes changes added to this merge window.

This should fix the issue reported by kernel test robot:

https://lore.kernel.org/all/[email protected]/

Steven Rostedt (Google) (2):
tracefs: Add missing lockdown check to tracefs_create_dir() tracefs/eventfs: Add missing lockdown checks

----

 fs/tracefs/event_inode.c | 15 +++++++++++++++
 fs/tracefs/inode.c       |  3 +++
 2 files changed, 18 insertions(+)
author maintainer
#1 lore raw

PATCH 1/2 tracefs: Add missing lockdown check to tracefs_create_dir()

From: "Steven Rostedt (Google)" <[email protected]>

The function tracefs_create_dir() was missing a lockdown check and was called by the RV code. This gave an inconsistent behavior of this function returning success while other tracefs functions failed. This caused the inode being freed by the wrong kmem_cache.

Fixes bf8e602186ec4 ("tracing: Do not create tracefs files if tracefs lockdown is in effect")
---
 fs/tracefs/inode.c | 3 +++
 1 file changed, 3 insertions(+)
fs/tracefs/inode.c +3 -0
index de5b72216b1a..3b8dd938b1c8 100644
@@ -673,6 +673,9 @@ static struct dentry *__create_dir(const char *name, struct dentry *parent,
  */
 struct dentry *tracefs_create_dir(const char *name, struct dentry *parent)
 {
+	if (security_locked_down(LOCKDOWN_TRACEFS))
+		return NULL;
+
 	return __create_dir(name, parent, &simple_dir_inode_operations);
 }
 
Signature · 1 line
2.40.1
author maintainer
#2 lore raw

PATCH 2/2 tracefs/eventfs: Add missing lockdown checks

In reply to Steven Rostedt

From: "Steven Rostedt (Google)" <[email protected]>

All the eventfs external functions do not check if TRACEFS_LOCKDOWN was set or not. This can caused some functions to return success while others fail, which can trigger unexpected errors.

Add the missing lockdown checks.

---
 fs/tracefs/event_inode.c | 15 +++++++++++++++
 1 file changed, 15 insertions(+)
fs/tracefs/event_inode.c +15 -0
index 237c6f370ad9..fa1a1679a886 100644
@@ -491,6 +491,9 @@ struct dentry *eventfs_create_events_dir(const char *name,
 	struct tracefs_inode *ti;
 	struct inode *inode;
 
+	if (security_locked_down(LOCKDOWN_TRACEFS))
+		return NULL;
+
 	if (IS_ERR(dentry))
 		return dentry;
 
@@ -538,6 +541,9 @@ struct eventfs_file *eventfs_add_subsystem_dir(const char *name,
 	struct eventfs_inode *ei_parent;
 	struct eventfs_file *ef;
 
+	if (security_locked_down(LOCKDOWN_TRACEFS))
+		return NULL;
+
 	if (!parent)
 		return ERR_PTR(-EINVAL);
 
@@ -569,6 +575,9 @@ struct eventfs_file *eventfs_add_dir(const char *name,
 {
 	struct eventfs_file *ef;
 
+	if (security_locked_down(LOCKDOWN_TRACEFS))
+		return NULL;
+
 	if (!ef_parent)
 		return ERR_PTR(-EINVAL);
 
@@ -606,6 +615,9 @@ int eventfs_add_events_file(const char *name, umode_t mode,
 	struct eventfs_inode *ei;
 	struct eventfs_file *ef;
 
+	if (security_locked_down(LOCKDOWN_TRACEFS))
+		return -ENODEV;
+
 	if (!parent)
 		return -EINVAL;
 
@@ -654,6 +666,9 @@ int eventfs_add_file(const char *name, umode_t mode,
 {
 	struct eventfs_file *ef;
 
+	if (security_locked_down(LOCKDOWN_TRACEFS))
+		return -ENODEV;
+
 	if (!ef_parent)
 		return -EINVAL;
 
Signature · 1 line
2.40.1