* [PATCH 0/2] tracing: Add missing LOCKDOWN_TRACEFS checking
@ 2023-09-05 18:26 Steven Rostedt
  2023-09-05 18:26 ` [PATCH 1/2] tracefs: Add missing lockdown check to tracefs_create_dir() Steven Rostedt
  2023-09-05 18:26 ` [PATCH 2/2] tracefs/eventfs: Add missing lockdown checks Steven Rostedt
  0 siblings, 2 replies; 3+ messages in thread
From: Steven Rostedt @ 2023-09-05 18:26 UTC (permalink / raw)
  To: linux-kernel, linux-trace-kernel
  Cc: Masami Hiramatsu, Mark Rutland, Andrew Morton, Ajay Kaher,
	kernel test robot, Ching-lin Yu
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/202309050916.58201dc6-oliver.sang@intel.com/
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(+)
^ permalink raw reply	[flat|nested] 3+ messages in thread
* [PATCH 1/2] tracefs: Add missing lockdown check to tracefs_create_dir()
  2023-09-05 18:26 [PATCH 0/2] tracing: Add missing LOCKDOWN_TRACEFS checking Steven Rostedt
@ 2023-09-05 18:26 ` Steven Rostedt
  2023-09-05 18:26 ` [PATCH 2/2] tracefs/eventfs: Add missing lockdown checks Steven Rostedt
  1 sibling, 0 replies; 3+ messages in thread
From: Steven Rostedt @ 2023-09-05 18:26 UTC (permalink / raw)
  To: linux-kernel, linux-trace-kernel
  Cc: Masami Hiramatsu, Mark Rutland, Andrew Morton, Ajay Kaher,
	kernel test robot, Ching-lin Yu, stable
From: "Steven Rostedt (Google)" <rostedt@goodmis.org>
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.
Link: https://lore.kernel.org/all/202309050916.58201dc6-oliver.sang@intel.com/
Cc: stable@vger.kernel.org
Fixes: bf8e602186ec4 ("tracing: Do not create tracefs files if tracefs lockdown is in effect")
Reported-by: kernel test robot <oliver.sang@intel.com>
Signed-off-by: Steven Rostedt (Google) <rostedt@goodmis.org>
---
 fs/tracefs/inode.c | 3 +++
 1 file changed, 3 insertions(+)
diff --git a/fs/tracefs/inode.c b/fs/tracefs/inode.c
index de5b72216b1a..3b8dd938b1c8 100644
--- a/fs/tracefs/inode.c
+++ b/fs/tracefs/inode.c
@@ -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);
 }
 
-- 
2.40.1
^ permalink raw reply related	[flat|nested] 3+ messages in thread
* [PATCH 2/2] tracefs/eventfs: Add missing lockdown checks
  2023-09-05 18:26 [PATCH 0/2] tracing: Add missing LOCKDOWN_TRACEFS checking Steven Rostedt
  2023-09-05 18:26 ` [PATCH 1/2] tracefs: Add missing lockdown check to tracefs_create_dir() Steven Rostedt
@ 2023-09-05 18:26 ` Steven Rostedt
  1 sibling, 0 replies; 3+ messages in thread
From: Steven Rostedt @ 2023-09-05 18:26 UTC (permalink / raw)
  To: linux-kernel, linux-trace-kernel
  Cc: Masami Hiramatsu, Mark Rutland, Andrew Morton, Ajay Kaher,
	kernel test robot, Ching-lin Yu
From: "Steven Rostedt (Google)" <rostedt@goodmis.org>
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.
Link: https://lore.kernel.org/all/202309050916.58201dc6-oliver.sang@intel.com/
Reported-by: kernel test robot <oliver.sang@intel.com>
Signed-off-by: Steven Rostedt (Google) <rostedt@goodmis.org>
---
 fs/tracefs/event_inode.c | 15 +++++++++++++++
 1 file changed, 15 insertions(+)
diff --git a/fs/tracefs/event_inode.c b/fs/tracefs/event_inode.c
index 237c6f370ad9..fa1a1679a886 100644
--- a/fs/tracefs/event_inode.c
+++ b/fs/tracefs/event_inode.c
@@ -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;
 
-- 
2.40.1
^ permalink raw reply related	[flat|nested] 3+ messages in thread
end of thread, other threads:[~2023-09-05 20:08 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-09-05 18:26 [PATCH 0/2] tracing: Add missing LOCKDOWN_TRACEFS checking Steven Rostedt
2023-09-05 18:26 ` [PATCH 1/2] tracefs: Add missing lockdown check to tracefs_create_dir() Steven Rostedt
2023-09-05 18:26 ` [PATCH 2/2] tracefs/eventfs: Add missing lockdown checks Steven Rostedt
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).