]> git.proxmox.com Git - mirror_ubuntu-jammy-kernel.git/commit
btrfs: check if root is readonly while setting security xattr
authorGoldwyn Rodrigues <rgoldwyn@suse.de>
Tue, 16 Aug 2022 21:42:56 +0000 (16:42 -0500)
committerStefan Bader <stefan.bader@canonical.com>
Mon, 17 Oct 2022 09:57:49 +0000 (11:57 +0200)
commit69ce7b291169c30bb5826b9dd8d8bac9e472ea58
tree78a8f365a187bca71b8ca089a5c504b2233f2c70
parent3f2ef7ae9353349dfff29cd7ee56ace10063ed31
btrfs: check if root is readonly while setting security xattr

BugLink: https://bugs.launchpad.net/bugs/1991717
commit b51111271b0352aa596c5ae8faf06939e91b3b68 upstream.

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: stable@vger.kernel.org # 4.9+
Reviewed-by: Qu Wenruo <wqu@suse.com>
Reviewed-by: Filipe Manana <fdmanana@suse.com>
Signed-off-by: Goldwyn Rodrigues <rgoldwyn@suse.com>
Reviewed-by: David Sterba <dsterba@suse.com>
Signed-off-by: David Sterba <dsterba@suse.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Signed-off-by: Kamal Mostafa <kamal@canonical.com>
Signed-off-by: Stefan Bader <stefan.bader@canonical.com>
fs/btrfs/xattr.c