Skip to content

Commit b511112

Browse files
Goldwyn Rodrigueskdave
authored andcommitted
btrfs: check if root is readonly while setting security xattr
For a filesystem which has btrfs read-only property set to true, all write operations including xattr should be denied. However, security xattr can still be changed even if btrfs ro property is true. This happens because xattr_permission() does not have any restrictions on security.*, system.* and in some cases trusted.* from VFS and the decision is left to the underlying filesystem. See comments in xattr_permission() for more details. This patch checks if the root is read-only before performing the set xattr operation. Testcase: DEV=/dev/vdb MNT=/mnt mkfs.btrfs -f $DEV mount $DEV $MNT echo "file one" > $MNT/f1 setfattr -n "security.one" -v 2 $MNT/f1 btrfs property set /mnt ro true setfattr -n "security.one" -v 1 $MNT/f1 umount $MNT CC: [email protected] # 4.9+ Reviewed-by: Qu Wenruo <[email protected]> Reviewed-by: Filipe Manana <[email protected]> Signed-off-by: Goldwyn Rodrigues <[email protected]> Reviewed-by: David Sterba <[email protected]> Signed-off-by: David Sterba <[email protected]>
1 parent 899b7f6 commit b511112

File tree

1 file changed

+3
-0
lines changed

1 file changed

+3
-0
lines changed

fs/btrfs/xattr.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -371,6 +371,9 @@ static int btrfs_xattr_handler_set(const struct xattr_handler *handler,
371371
const char *name, const void *buffer,
372372
size_t size, int flags)
373373
{
374+
if (btrfs_root_readonly(BTRFS_I(inode)->root))
375+
return -EROFS;
376+
374377
name = xattr_full_name(handler, name);
375378
return btrfs_setxattr_trans(inode, name, buffer, size, flags);
376379
}

0 commit comments

Comments
 (0)