Skip to content

Commit 931dde8

Browse files
eafergregkh
authored andcommitted
btrfs: preserve i_mode if __btrfs_set_acl() fails
commit d7d8249 upstream. When changing a file's acl mask, btrfs_set_acl() will first set the group bits of i_mode to the value of the mask, and only then set the actual extended attribute representing the new acl. If the second part fails (due to lack of space, for example) and the file had no acl attribute to begin with, the system will from now on assume that the mask permission bits are actual group permission bits, potentially granting access to the wrong users. Prevent this by restoring the original mode bits if __btrfs_set_acl fails. Signed-off-by: Ernesto A. Fernández <ernesto.mnd.fernandez@gmail.com> Reviewed-by: David Sterba <dsterba@suse.com> Signed-off-by: David Sterba <dsterba@suse.com> Signed-off-by: Nikolay Borisov <nborisov@suse.com> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
1 parent 2b70de4 commit 931dde8

1 file changed

Lines changed: 5 additions & 1 deletion

File tree

fs/btrfs/acl.c

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,13 +114,17 @@ static int __btrfs_set_acl(struct btrfs_trans_handle *trans,
114114
int btrfs_set_acl(struct inode *inode, struct posix_acl *acl, int type)
115115
{
116116
int ret;
117+
umode_t old_mode = inode->i_mode;
117118

118119
if (type == ACL_TYPE_ACCESS && acl) {
119120
ret = posix_acl_update_mode(inode, &inode->i_mode, &acl);
120121
if (ret)
121122
return ret;
122123
}
123-
return __btrfs_set_acl(NULL, inode, acl, type);
124+
ret = __btrfs_set_acl(NULL, inode, acl, type);
125+
if (ret)
126+
inode->i_mode = old_mode;
127+
return ret;
124128
}
125129

126130
/*

0 commit comments

Comments
 (0)