Skip to content

Commit d81786f

Browse files
committed
tracefs: Zero out the tracefs_inode when allocating it
eventfs uses the tracefs_inode and assumes that it's already initialized to zero. That is, it doesn't set fields to zero (like ti->private) after getting its tracefs_inode. This causes bugs due to stale values. Just initialize the entire structure to zero on allocation so there isn't any more surprises. This is a partial fix to access to ti->private. The assignment still needs to be made before the dentry is instantiated. Link: https://lore.kernel.org/linux-trace-kernel/20240131185512.315825944@goodmis.org Cc: stable@vger.kernel.org Cc: Masami Hiramatsu <mhiramat@kernel.org> Cc: Mark Rutland <mark.rutland@arm.com> Cc: Mathieu Desnoyers <mathieu.desnoyers@efficios.com> Cc: Christian Brauner <brauner@kernel.org> Cc: Al Viro <viro@ZenIV.linux.org.uk> Cc: Ajay Kaher <ajay.kaher@broadcom.com> Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org> Fixes: 5790b1f ("eventfs: Remove eventfs_file and just use eventfs_inode") Reported-by: kernel test robot <oliver.sang@intel.com> Closes: https://lore.kernel.org/oe-lkp/202401291043.e62e89dc-oliver.sang@intel.com Suggested-by: Linus Torvalds <torvalds@linux-foundation.org> Signed-off-by: Steven Rostedt (Google) <rostedt@goodmis.org>
1 parent 66bbea9 commit d81786f

File tree

2 files changed

+6
-3
lines changed

2 files changed

+6
-3
lines changed

fs/tracefs/inode.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,6 @@ static struct inode *tracefs_alloc_inode(struct super_block *sb)
3838
if (!ti)
3939
return NULL;
4040

41-
ti->flags = 0;
42-
4341
return &ti->vfs_inode;
4442
}
4543

@@ -779,7 +777,11 @@ static void init_once(void *foo)
779777
{
780778
struct tracefs_inode *ti = (struct tracefs_inode *) foo;
781779

780+
/* inode_init_once() calls memset() on the vfs_inode portion */
782781
inode_init_once(&ti->vfs_inode);
782+
783+
/* Zero out the rest */
784+
memset_after(ti, 0, vfs_inode);
783785
}
784786

785787
static int __init tracefs_init(void)

fs/tracefs/internal.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,10 @@ enum {
1111
};
1212

1313
struct tracefs_inode {
14+
struct inode vfs_inode;
15+
/* The below gets initialized with memset_after(ti, 0, vfs_inode) */
1416
unsigned long flags;
1517
void *private;
16-
struct inode vfs_inode;
1718
};
1819

1920
/*

0 commit comments

Comments
 (0)