Skip to content

Commit ad19db7

Browse files
cschauflerchrismason-xx
authored andcommitted
BTRFS: Establish i_ops before calling d_instantiate
The Smack LSM hook for security_d_instantiate checks the inode's i_op->getxattr value to determine if the containing filesystem supports extended attributes. The BTRFS filesystem sets the inode's i_op value only after it has instantiated the inode. This results in Smack incorrectly giving new BTRFS inodes attributes from the filesystem defaults on the assumption that values can't be stored on the filesystem. This patch moves the assignment of inode operation vectors ahead of the calls to d_instantiate, letting Smack know that the filesystem supports extended attributes. There should be no impact on the performance or behavior of BTRFS. Signed-off-by: Casey Schaufler <casey@schaufler-ca.com> Signed-off-by: Chris Mason <chris.mason@oracle.com>
1 parent 8f3b65a commit ad19db7

1 file changed

Lines changed: 26 additions & 5 deletions

File tree

‎fs/btrfs/inode.c‎

Lines changed: 26 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4596,11 +4596,18 @@ static int btrfs_mknod(struct inode *dir, struct dentry *dentry,
45964596
goto out_unlock;
45974597
}
45984598

4599+
/*
4600+
* If the active LSM wants to access the inode during
4601+
* d_instantiate it needs these. Smack checks to see
4602+
* if the filesystem supports xattrs by looking at the
4603+
* ops vector.
4604+
*/
4605+
4606+
inode->i_op = &btrfs_special_inode_operations;
45994607
err = btrfs_add_nondir(trans, dir, dentry, inode, 0, index);
46004608
if (err)
46014609
drop_inode = 1;
46024610
else {
4603-
inode->i_op = &btrfs_special_inode_operations;
46044611
init_special_inode(inode, inode->i_mode, rdev);
46054612
btrfs_update_inode(trans, root, inode);
46064613
}
@@ -4654,14 +4661,21 @@ static int btrfs_create(struct inode *dir, struct dentry *dentry,
46544661
goto out_unlock;
46554662
}
46564663

4664+
/*
4665+
* If the active LSM wants to access the inode during
4666+
* d_instantiate it needs these. Smack checks to see
4667+
* if the filesystem supports xattrs by looking at the
4668+
* ops vector.
4669+
*/
4670+
inode->i_fop = &btrfs_file_operations;
4671+
inode->i_op = &btrfs_file_inode_operations;
4672+
46574673
err = btrfs_add_nondir(trans, dir, dentry, inode, 0, index);
46584674
if (err)
46594675
drop_inode = 1;
46604676
else {
46614677
inode->i_mapping->a_ops = &btrfs_aops;
46624678
inode->i_mapping->backing_dev_info = &root->fs_info->bdi;
4663-
inode->i_fop = &btrfs_file_operations;
4664-
inode->i_op = &btrfs_file_inode_operations;
46654679
BTRFS_I(inode)->io_tree.ops = &btrfs_extent_io_ops;
46664680
}
46674681
out_unlock:
@@ -7117,14 +7131,21 @@ static int btrfs_symlink(struct inode *dir, struct dentry *dentry,
71177131
goto out_unlock;
71187132
}
71197133

7134+
/*
7135+
* If the active LSM wants to access the inode during
7136+
* d_instantiate it needs these. Smack checks to see
7137+
* if the filesystem supports xattrs by looking at the
7138+
* ops vector.
7139+
*/
7140+
inode->i_fop = &btrfs_file_operations;
7141+
inode->i_op = &btrfs_file_inode_operations;
7142+
71207143
err = btrfs_add_nondir(trans, dir, dentry, inode, 0, index);
71217144
if (err)
71227145
drop_inode = 1;
71237146
else {
71247147
inode->i_mapping->a_ops = &btrfs_aops;
71257148
inode->i_mapping->backing_dev_info = &root->fs_info->bdi;
7126-
inode->i_fop = &btrfs_file_operations;
7127-
inode->i_op = &btrfs_file_inode_operations;
71287149
BTRFS_I(inode)->io_tree.ops = &btrfs_extent_io_ops;
71297150
}
71307151
if (drop_inode)

0 commit comments

Comments
 (0)