summaryrefslogtreecommitdiff
path: root/fs
diff options
context:
space:
mode:
authorSun YangKai <sunyangkai@fnnas.com>2026-07-09 16:23:35 +0800
committerDavid Sterba <dsterba@suse.com>2026-07-21 06:44:08 +0200
commit5e6fa0d7657227c59793295c2eee3a3cb74e98c7 (patch)
tree57d81e162ca385eb6ec016d611cb77d4add3b4e3 /fs
parentac4f1cb81977cfd6ebafe23a45d545cb950da720 (diff)
downloadlinux-next-5e6fa0d7657227c59793295c2eee3a3cb74e98c7.tar.gz
linux-next-5e6fa0d7657227c59793295c2eee3a3cb74e98c7.zip
btrfs: check if root is readonly when setting posix ACL
For a filesystem which has btrfs read-only property set to true, all write operations including ACL and xattr should be denied. However, ACL can still be set even if btrfs ro property is true. This happens because no function on the set_acl code path checks the root is readonly or not. It was checked in btrfs_setxattr_trans() but got removed in commit 353c2ea735e4 ("btrfs: remove redundant readonly root check in btrfs_setxattr_trans") That commit didn't check if all the callers properly check the root's read-only flag. A previous fix is commit b51111271b03 ("btrfs: check if root is readonly while setting security xattr"). Always check if the root is read-only before performing the set ACL operation. Fixes: 353c2ea735e4 ("btrfs: remove redundant readonly root check in btrfs_setxattr_trans") Reviewed-by: Johannes Thumshirn <johannes.thumshirn@wdc.com> Reviewed-by: Filipe Manana <fdmanana@suse.com> Signed-off-by: Sun YangKai <sunyangkai@fnnas.com> Signed-off-by: Filipe Manana <fdmanana@suse.com> Reviewed-by: David Sterba <dsterba@suse.com> Signed-off-by: David Sterba <dsterba@suse.com>
Diffstat (limited to 'fs')
-rw-r--r--fs/btrfs/acl.c4
1 files changed, 4 insertions, 0 deletions
diff --git a/fs/btrfs/acl.c b/fs/btrfs/acl.c
index e55b686fe1ab..662cdd1cbdef 100644
--- a/fs/btrfs/acl.c
+++ b/fs/btrfs/acl.c
@@ -15,6 +15,7 @@
#include "xattr.h"
#include "acl.h"
#include "misc.h"
+#include "btrfs_inode.h"
struct posix_acl *btrfs_get_acl(struct inode *inode, int type, bool rcu)
{
@@ -107,6 +108,9 @@ int btrfs_set_acl(struct mnt_idmap *idmap, struct dentry *dentry,
struct inode *inode = d_inode(dentry);
umode_t old_mode = inode->i_mode;
+ if (btrfs_root_readonly(BTRFS_I(inode)->root))
+ return -EROFS;
+
if (type == ACL_TYPE_ACCESS && acl) {
ret = posix_acl_update_mode(idmap, inode,
&inode->i_mode, &acl);