All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] Check if root is readonly while setting xattr
@ 2022-08-15 19:34 Goldwyn Rodrigues
  2022-08-16  0:45 ` Qu Wenruo
  2022-08-16  8:34 ` Filipe Manana
  0 siblings, 2 replies; 5+ messages in thread
From: Goldwyn Rodrigues @ 2022-08-15 19:34 UTC (permalink / raw)
  To: linux-btrfs; +Cc: David Sterba

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 patch checks if the root is read-only before performing the set
xattr operation.

Testcase: 

#!/bin/bash

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

# Following statement should fail
setfattr -n "security.one" -v 1 $MNT/f1

umount $MNT

Signed-off-by: Goldwyn Rodrigues <rgoldwyn@suse.com>


diff --git a/fs/btrfs/xattr.c b/fs/btrfs/xattr.c
index 7421abcf325a..5bb8d8c86311 100644
--- a/fs/btrfs/xattr.c
+++ b/fs/btrfs/xattr.c
@@ -371,6 +371,9 @@ static int btrfs_xattr_handler_set(const struct xattr_handler *handler,
 				   const char *name, const void *buffer,
 				   size_t size, int flags)
 {
+	if (btrfs_root_readonly(BTRFS_I(inode)->root))
+		return -EROFS;
+
 	name = xattr_full_name(handler, name);
 	return btrfs_setxattr_trans(inode, name, buffer, size, flags);
 }

-- 
Goldwyn

^ permalink raw reply related	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2022-08-16 13:04 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2022-08-15 19:34 [PATCH] Check if root is readonly while setting xattr Goldwyn Rodrigues
2022-08-16  0:45 ` Qu Wenruo
2022-08-16  8:34 ` Filipe Manana
2022-08-16 12:44   ` Goldwyn Rodrigues
2022-08-16 13:03     ` Filipe Manana

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.