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/[email protected] Cc: [email protected] Cc: Masami Hiramatsu <[email protected]> Cc: Mark Rutland <[email protected]> Cc: Mathieu Desnoyers <[email protected]> Cc: Christian Brauner <[email protected]> Cc: Al Viro <[email protected]> Cc: Ajay Kaher <[email protected]> Cc: Greg Kroah-Hartman <[email protected]> Fixes: 5790b1f ("eventfs: Remove eventfs_file and just use eventfs_inode") Reported-by: kernel test robot <[email protected]> Closes: https://lore.kernel.org/oe-lkp/[email protected] Suggested-by: Linus Torvalds <[email protected]> Signed-off-by: Steven Rostedt (Google) <[email protected]>
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)