btrfs: check if root is readonly when setting posix acl
PATCH v2 1/1 btrfs: check if root is readonly when setting posix acl
From: Sun YangKai <[email protected]>
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.
---
Changes to v1:
- add the missing header file
--- fs/btrfs/acl.c | 4 ++++ 1 file changed, 4 insertions(+)
fs/btrfs/acl.c +4 -0
@@ -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);
Signature · 1 line
2.54.0
Looks good,
Quoted 16 lines · Sun YangKai
From: Sun YangKai <[email protected]>
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_aclcode path checks the root
is readonly or not. It was checked inbtrfs_setxattr_trans()but got
removed in
commit353c2ea735e4("btrfs: remove redundant readonly root check inbtrfs_setxattr_trans")That commit didn't check if all the callers properly check the root's read-only flag. A previous fix is
commitb51111271b03("btrfs: check if root is readonly while setting security xattr")
Quoted 5 lines
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")Signed-off-by Sun YangKai <[email protected]>
Test case please (fstests).
Quoted 34 lines
---
Changes to v1:
- add the missing header file--- fs/btrfs/acl.c | 4 ++++ 1 file changed, 4 insertions(+)fs/btrfs/acl.c +4
-1@@ -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); --2.54.0
Quoted 17 lines · Filipe Manana
Quoted 16 lines · Sun YangKai
From: Sun YangKai <[email protected]>
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_aclcode path checks the root
is readonly or not. It was checked inbtrfs_setxattr_trans()but got
removed in
commit353c2ea735e4("btrfs: remove redundant readonly root check inbtrfs_setxattr_trans")That commit didn't check if all the callers properly check the root's read-only flag. A previous fix is
commitb51111271b03("btrfs: check if root is readonly while setting security xattr")
Quoted 7 lines
Quoted 5 lines
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")Signed-off-by Sun YangKai <[email protected]>Test case please (fstests).
Ok, I'll work on that later.
I've noticed the test case btrfs/275 for b51111271b03 and I'll take that as reference.
Thanks,
Sun YangKai
Quoted 35 lines
Quoted 35 lines
---
Changes to v1:
- add the missing header file--- fs/btrfs/acl.c | 4 ++++ 1 file changed, 4 insertions(+)fs/btrfs/acl.c +4
-1@@ -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); --2.54.0
PATCH 1/1 btrfs: test POSIX ACL changes for RO btrfs property
In reply to Sun YangKaiFrom: Sun YangKai <[email protected]>
Test creation, modification and deletion of POSIX ACLs for a btrfs filesystem which has the read-only property set to true.
Re-test the same after the read-only property is set to false.
This complements btrfs/275, which covers the generic ->setxattr path. POSIX ACLs are set and removed through the ->set_acl inode operation (btrfs_set_acl), which is a separate code path that is not covered by the RO check added for security xattrs in commit b51111271b03 ("btrfs:
check if root is readonly while setting security xattr"). As a result, ACLs could still be modified on a read-only subvolume, bypassing the RO protection that applies to every other xattr.
The test exercises the set, get and remove cycle of an access ACL on a regular file, and expects all modifications to fail with EROFS while the subvolume is read-only.
--- tests/btrfs/353 | 97 +++++++++++++++++++++++++++++++++++++++++++++ tests/btrfs/353.out | 39 ++++++++++++++++++ 2 files changed, 136 insertions(+) create mode 100755 tests/btrfs/353 create mode 100644 tests/btrfs/353.out
tests/btrfs/353 new file +97 -0
@@ -0,0 +1,97 @@ +#! /bin/bash +# SPDX-License-Identifier: GPL-2.0 +# Copyright (C) 2026 YOUR NAME HERE. All Rights Reserved. +# +# FS QA Test No. 353 +# +# Test that POSIX ACLs cannot be changed once a btrfs subvolume has the +# read-only property set. +# +# Setting or removing a POSIX ACL goes through the ->set_acl inode +# operation, which is a different code path from the generic ->setxattr +# one covered by btrfs/275. It used to be allowed on a read-only +# subvolume and thus bypassed the RO protection. Such modifications must +# fail with EROFS, just like any other xattr. +# +. ./common/preamble +_begin_fstest auto quick acl attr + +. ./common/filter +. ./common/attr + +# TODO: fill in the kernel commit hash that fixes the ->set_acl path once +# it is merged. +# _fixed_by_kernel_commit <HASH> \ +# "btrfs: check if root is readonly when setting posix acl" + +_require_acls +_require_btrfs_command "property" +_require_scratch + +_scratch_mkfs >> $seqres.full 2>&1 +_scratch_mount + +FILENAME=$SCRATCH_MNT/foo + +set_acl() +{ + local perm=$1 + + # Use -n so setfacl does not recalculate the mask, keeping the + # golden output deterministic regardless of the named user's + # permissions. + setfacl -n -m u:$acl2:$perm,m::rwx $FILENAME 2>&1 | _filter_scratch +} + +get_acl() +{ + getfacl --absolute-names -n $FILENAME | _filter_scratch | _getfacl_filter_id +} + +del_acl() +{ + setfacl -b $FILENAME 2>&1 | _filter_scratch +} + +_acl_setup_ids + +# Create a test file. +echo "hello world" > $FILENAME + +# Set an initial ACL while the subvolume is writable. +set_acl rwx + +# Attempt to change the ACL once the subvolume is read-only. This must +# fail with EROFS. +$BTRFS_UTIL_PROG property set $SCRATCH_MNT ro true +$BTRFS_UTIL_PROG property get $SCRATCH_MNT ro + +set_acl r-- + +# The ACL must not have changed. +get_acl + +# Attempt to remove the ACL from the read-only subvolume. This must +# fail with EROFS as well. +del_acl + +# The ACL must still be present. +get_acl + +# Make the subvolume writable again. +$BTRFS_UTIL_PROG property set $SCRATCH_MNT ro false +$BTRFS_UTIL_PROG property get $SCRATCH_MNT ro + +# Now changing the ACL must succeed. +set_acl r-- + +get_acl + +# And removing it must succeed too. +del_acl + +# Check the ACL is really gone. +get_acl + +status=0 +exit
tests/btrfs/353.out new file +39 -0
@@ -0,0 +1,39 @@ +QA output created by 353 +ro=true +setfacl: SCRATCH_MNT/foo: Read-only file system +# file: SCRATCH_MNT/foo +# owner: 0 +# group: 0 +user::rw- +user:id2:rwx +group::r-- +mask::rwx +other::r-- + +setfacl: SCRATCH_MNT/foo: Read-only file system +# file: SCRATCH_MNT/foo +# owner: 0 +# group: 0 +user::rw- +user:id2:rwx +group::r-- +mask::rwx +other::r-- + +ro=false +# file: SCRATCH_MNT/foo +# owner: 0 +# group: 0 +user::rw- +user:id2:r-- +group::r-- +mask::rwx +other::r-- + +# file: SCRATCH_MNT/foo +# owner: 0 +# group: 0 +user::rw- +group::r-- +other::r-- +
Signature · 1 line
2.54.0
PATCH v2 1/1 btrfs: test POSIX ACL changes for RO btrfs property
In reply to Sun YangKaiFrom: Sun YangKai <[email protected]>
Test creation, modification and deletion of POSIX ACLs on a btrfs filesystem that has the read-only property set to true, and re-test the same after the property is cleared.
Commit 353c2ea735e4 ("btrfs: remove redundant readonly root check in btrfs_setxattr_trans") removed the read-only root check from btrfs_setxattr_trans() under the assumption that none of its callers can run on a read-only root. That assumption does not hold for the ->set_acl
path: btrfs_set_acl() -> __btrfs_set_acl() reaches btrfs_setxattr_trans() directly, bypassing the handler-level read-only checks that were later (re)added by commit b51111271b03 ("btrfs: check if root is readonly while setting security xattr"). As a result, ACLs could still be set or removed on a read-only subvolume, bypassing the RO protection that applies to every other xattr.
The restoring kernel fix adds the read-only check directly to btrfs_set_acl(). This test complements btrfs/275, which covers the generic ->setxattr path.
The test exercises the set, get and remove cycle of an access ACL on a regular file, and expects all modifications to fail with EROFS while the subvolume is read-only, then succeed once it is writable again.
---
Changes from v1:
- fix copywrite header
- better wording for commit message
Sorry for bothering.
--- tests/btrfs/353 | 97 +++++++++++++++++++++++++++++++++++++++++++++ tests/btrfs/353.out | 39 ++++++++++++++++++ 2 files changed, 136 insertions(+) create mode 100755 tests/btrfs/353 create mode 100644 tests/btrfs/353.out
tests/btrfs/353 new file +97 -0
@@ -0,0 +1,97 @@ +#! /bin/bash +# SPDX-License-Identifier: GPL-2.0 +# Copyright (C) 2026 Fygo OS. All Rights Reserved. +# +# FS QA Test No. 353 +# +# Test that POSIX ACLs cannot be changed once a btrfs subvolume has the +# read-only property set. +# +# Setting or removing a POSIX ACL goes through the ->set_acl inode +# operation, which is a different code path from the generic ->setxattr +# one covered by btrfs/275. It used to be allowed on a read-only +# subvolume and thus bypassed the RO protection. Such modifications must +# fail with EROFS, just like any other xattr. +# +. ./common/preamble +_begin_fstest auto quick acl attr + +. ./common/filter +. ./common/attr + +# TODO: fill in the kernel commit hash that fixes the ->set_acl path once +# it is merged. +# _fixed_by_kernel_commit <HASH> \ +# "btrfs: check if root is readonly when setting posix acl" + +_require_acls +_require_btrfs_command "property" +_require_scratch + +_scratch_mkfs >> $seqres.full 2>&1 +_scratch_mount + +FILENAME=$SCRATCH_MNT/foo + +set_acl() +{ + local perm=$1 + + # Use -n so setfacl does not recalculate the mask, keeping the + # golden output deterministic regardless of the named user's + # permissions. + setfacl -n -m u:$acl2:$perm,m::rwx $FILENAME 2>&1 | _filter_scratch +} + +get_acl() +{ + getfacl --absolute-names -n $FILENAME | _filter_scratch | _getfacl_filter_id +} + +del_acl() +{ + setfacl -b $FILENAME 2>&1 | _filter_scratch +} + +_acl_setup_ids + +# Create a test file. +echo "hello world" > $FILENAME + +# Set an initial ACL while the subvolume is writable. +set_acl rwx + +# Attempt to change the ACL once the subvolume is read-only. This must +# fail with EROFS. +$BTRFS_UTIL_PROG property set $SCRATCH_MNT ro true +$BTRFS_UTIL_PROG property get $SCRATCH_MNT ro + +set_acl r-- + +# The ACL must not have changed. +get_acl + +# Attempt to remove the ACL from the read-only subvolume. This must +# fail with EROFS as well. +del_acl + +# The ACL must still be present. +get_acl + +# Make the subvolume writable again. +$BTRFS_UTIL_PROG property set $SCRATCH_MNT ro false +$BTRFS_UTIL_PROG property get $SCRATCH_MNT ro + +# Now changing the ACL must succeed. +set_acl r-- + +get_acl + +# And removing it must succeed too. +del_acl + +# Check the ACL is really gone. +get_acl + +status=0 +exit
tests/btrfs/353.out new file +39 -0
@@ -0,0 +1,39 @@ +QA output created by 353 +ro=true +setfacl: SCRATCH_MNT/foo: Read-only file system +# file: SCRATCH_MNT/foo +# owner: 0 +# group: 0 +user::rw- +user:id2:rwx +group::r-- +mask::rwx +other::r-- + +setfacl: SCRATCH_MNT/foo: Read-only file system +# file: SCRATCH_MNT/foo +# owner: 0 +# group: 0 +user::rw- +user:id2:rwx +group::r-- +mask::rwx +other::r-- + +ro=false +# file: SCRATCH_MNT/foo +# owner: 0 +# group: 0 +user::rw- +user:id2:r-- +group::r-- +mask::rwx +other::r-- + +# file: SCRATCH_MNT/foo +# owner: 0 +# group: 0 +user::rw- +group::r-- +other::r-- +
Signature · 1 line
2.54.0
Re: [PATCH v2] btrfs: test POSIX ACL changes for RO btrfs property
Quoted 7 lines · Sun YangKai
From: Sun YangKai <[email protected]>
Test creation, modification and deletion of POSIX ACLs on a btrfs filesystem that has the read-only property set to true, and re-test the same after the property is cleared.
Quoted 10 lines
Commit
353c2ea735e4("btrfs: remove redundant readonly root check inbtrfs_setxattr_trans") removed the read-only root check frombtrfs_setxattr_trans()under the assumption that none of its callers can run on a read-only root. That assumption does not hold for the ->set_acl
path:btrfs_set_acl()->__btrfs_set_acl()reachesbtrfs_setxattr_trans()directly, bypassing the handler-level read-only checks that were later (re)added by commitb51111271b03("btrfs: check if root is readonly while setting security xattr"). As a result, ACLs could still be set or removed on a read-only subvolume, bypassing the RO protection that applies to every other xattr.
You don't need to explain this in a test case, those are details for the kernel patch...
Just say what the test does and that it exercises a bug fixed by a kernel patch that has the subject:
"btrfs: check if root is readonly when setting posix acl"
Quoted 46 lines
The restoring kernel fix adds the read-only check directly to
btrfs_set_acl(). This test complements btrfs/275, which covers the generic ->setxattr path.The test exercises the set, get and remove cycle of an access ACL on a regular file, and expects all modifications to fail with EROFS while the subvolume is read-only, then succeed once it is writable again.
Signed-off-by Sun YangKai <[email protected]>---
Changes from v1:- fix copywrite header
- better wording for commit messageSorry for bothering.
--- tests/btrfs/353 | 97 +++++++++++++++++++++++++++++++++++++++++++++ tests/btrfs/353.out | 39 ++++++++++++++++++ 2 files changed, 136 insertions(+) create mode 100755 tests/btrfs/353 create mode 100644 tests/btrfs/353.outtests/btrfs/353 new file +15
-0@@ -0,0 +1,97 @@ +#! /bin/bash +# SPDX-License-Identifier: GPL-2.0 +# Copyright (C) 2026 Fygo OS. All Rights Reserved. +# +# FS QA Test No. 353 +# +# Test that POSIX ACLs cannot be changed once a btrfs subvolume has the +# read-only property set. +# +# Setting or removing a POSIX ACL goes through the ->set_acl inode +# operation, which is a different code path from the generic ->setxattr +# one covered by btrfs/275. It used to be allowed on a read-only +# subvolume and thus bypassed the RO protection. Such modifications must +# fail with EROFS, just like any other xattr. +#
tests/btrfs/353 line 25
Quoted 10 lines
tests/btrfs/353 new file +10
-0+. ./common/preamble +_begin_fstest auto quick acl attr + +. ./common/filter +. ./common/attr + +# TODO: fill in the kernel commit hash that fixes the ->set_acl path once +# it is merged. +# _fixed_by_kernel_commit <HASH> \ +# "btrfs: check if root is readonly when setting posix acl"
That's not how we handle patches not yet in Linus' tree. First don't comment it, second use xxxxxxxxxxxx for the hash. Like this:
_fixed_by_kernel_commit xxxxxxxxxxxx \
"btrfs: check if root is readonly when setting posix acl"
We normally find and update tests that need the hash by greping with something like: egrep -ri 'commit xxxxx' tests/
tests/btrfs/353 line 31
Quoted 6 lines
tests/btrfs/353 new file +6
-0+ +_require_acls +_require_btrfs_command "property" +_require_scratch + +_scratch_mkfs >> $seqres.full 2>&1
Nowadays we have the practice of also adding: || _fail "mkfs failed"
tests/btrfs/353 line 34
Quoted 3 lines
tests/btrfs/353 new file +3
-0+_scratch_mount + +FILENAME=$SCRATCH_MNT/foo
Don't use upper case variable names.
With that fixed:
Thanks.
Quoted 112 lines
tests/btrfs/353 new file +63
-0+ +set_acl() +{ + local perm=$1 + + # Use -n so setfacl does not recalculate the mask, keeping the + # golden output deterministic regardless of the named user's + # permissions. + setfacl -n -m u:$acl2:$perm,m::rwx $FILENAME 2>&1 | _filter_scratch +} + +get_acl() +{ + getfacl --absolute-names -n $FILENAME | _filter_scratch | _getfacl_filter_id +} + +del_acl() +{ + setfacl -b $FILENAME 2>&1 | _filter_scratch +} + +_acl_setup_ids + +# Create a test file. +echo "hello world" > $FILENAME + +# Set an initial ACL while the subvolume is writable. +set_acl rwx + +# Attempt to change the ACL once the subvolume is read-only. This must +# fail with EROFS. +$BTRFS_UTIL_PROG property set $SCRATCH_MNT ro true +$BTRFS_UTIL_PROG property get $SCRATCH_MNT ro + +set_acl r-- + +# The ACL must not have changed. +get_acl + +# Attempt to remove the ACL from the read-only subvolume. This must +# fail with EROFS as well. +del_acl + +# The ACL must still be present. +get_acl + +# Make the subvolume writable again. +$BTRFS_UTIL_PROG property set $SCRATCH_MNT ro false +$BTRFS_UTIL_PROG property get $SCRATCH_MNT ro + +# Now changing the ACL must succeed. +set_acl r-- + +get_acl + +# And removing it must succeed too. +del_acl + +# Check the ACL is really gone. +get_acl + +status=0 +exittests/btrfs/353.out new file +39
-1@@ -0,0 +1,39 @@ +QA output created by 353 +ro=true +setfacl: SCRATCH_MNT/foo: Read-only file system +# file: SCRATCH_MNT/foo +# owner: 0 +# group: 0 +user::rw- +user:id2:rwx +group::r-- +mask::rwx +other::r-- + +setfacl: SCRATCH_MNT/foo: Read-only file system +# file: SCRATCH_MNT/foo +# owner: 0 +# group: 0 +user::rw- +user:id2:rwx +group::r-- +mask::rwx +other::r-- + +ro=false +# file: SCRATCH_MNT/foo +# owner: 0 +# group: 0 +user::rw- +user:id2:r-- +group::r-- +mask::rwx +other::r-- + +# file: SCRATCH_MNT/foo +# owner: 0 +# group: 0 +user::rw- +group::r-- +other::r-- + --2.54.0
Re: [PATCH v2] btrfs: test POSIX ACL changes for RO btrfs property
This is my first time to contribute to fstests project so thanks a lot for pointing those things out and it really helps a lot. I'll fix them and send a v2 version later.
Thanks,
Sun YangKai
Quoted 230 lines · Filipe Manana
Quoted 7 lines · Sun YangKai
From: Sun YangKai <[email protected]>
Test creation, modification and deletion of POSIX ACLs on a btrfs filesystem that has the read-only property set to true, and re-test the same after the property is cleared.
Quoted 10 lines
Commit
353c2ea735e4("btrfs: remove redundant readonly root check inbtrfs_setxattr_trans") removed the read-only root check frombtrfs_setxattr_trans()under the assumption that none of its callers can run on a read-only root. That assumption does not hold for the ->set_acl
path:btrfs_set_acl()->__btrfs_set_acl()reachesbtrfs_setxattr_trans()directly, bypassing the handler-level read-only checks that were later (re)added by commitb51111271b03("btrfs: check if root is readonly while setting security xattr"). As a result, ACLs could still be set or removed on a read-only subvolume, bypassing the RO protection that applies to every other xattr.You don't need to explain this in a test case, those are details for the kernel patch...
Just say what the test does and that it exercises a bug fixed by a kernel patch that has the subject:
"btrfs: check if root is readonly when setting posix acl"
Quoted 46 lines
The restoring kernel fix adds the read-only check directly to
btrfs_set_acl(). This test complements btrfs/275, which covers the generic ->setxattr path.The test exercises the set, get and remove cycle of an access ACL on a regular file, and expects all modifications to fail with EROFS while the subvolume is read-only, then succeed once it is writable again.
Signed-off-by Sun YangKai <[email protected]>---
Changes from v1:- fix copywrite header
- better wording for commit messageSorry for bothering.
--- tests/btrfs/353 | 97 +++++++++++++++++++++++++++++++++++++++++++++ tests/btrfs/353.out | 39 ++++++++++++++++++ 2 files changed, 136 insertions(+)create mode 100755 tests/btrfs/353
create mode 100644 tests/btrfs/353.outtests/btrfs/353 new file +15
-0@@ -0,0 +1,97 @@ +#! /bin/bash +# SPDX-License-Identifier: GPL-2.0 +# Copyright (C) 2026 Fygo OS. All Rights Reserved. +# +# FS QA Test No. 353 +# +# Test that POSIX ACLs cannot be changed once a btrfs subvolume has the +# read-only property set. +# +# Setting or removing a POSIX ACL goes through the ->set_acl inode +# operation, which is a different code path from the generic ->setxattr +# one covered by btrfs/275. It used to be allowed on a read-only +# subvolume and thus bypassed the RO protection. Such modifications must +# fail with EROFS, just like any other xattr. +#tests/btrfs/353 line 25
Quoted 10 lines
tests/btrfs/353 new file +10
-0+. ./common/preamble +_begin_fstest auto quick acl attr + +. ./common/filter +. ./common/attr + +# TODO: fill in the kernel commit hash that fixes the ->set_acl path once +# it is merged. +# _fixed_by_kernel_commit <HASH> \ +# "btrfs: check if root is readonly when setting posix acl"That's not how we handle patches not yet in Linus' tree. First don't comment it, second use xxxxxxxxxxxx for the hash. Like this:
_fixed_by_kernel_commitxxxxxxxxxxxx \
"btrfs: check if root is readonly when setting posix acl"We normally find and update tests that need the hash by greping with something like: egrep -ri 'commit xxxxx' tests/
tests/btrfs/353 line 31
Quoted 6 lines
tests/btrfs/353 new file +6
-0+ +_require_acls +_require_btrfs_command "property" +_require_scratch + +_scratch_mkfs >> $seqres.full 2>&1Nowadays we have the practice of also adding: ||
_fail"mkfs failed"tests/btrfs/353 line 34
Quoted 3 lines
tests/btrfs/353 new file +3
-0+_scratch_mount + +FILENAME=$SCRATCH_MNT/fooDon't use upper case variable names.
With that fixed:
Reviewed-by Filipe Manana <[email protected]>Thanks.
Quoted 112 lines
tests/btrfs/353 new file +63
-0+ +set_acl() +{ + local perm=$1 + + # Use -n so setfacl does not recalculate the mask, keeping the + # golden output deterministic regardless of the named user's + # permissions. + setfacl -n -m u:$acl2:$perm,m::rwx $FILENAME 2>&1 | _filter_scratch +} + +get_acl() +{ + getfacl --absolute-names -n $FILENAME | _filter_scratch | _getfacl_filter_id +} + +del_acl() +{ + setfacl -b $FILENAME 2>&1 | _filter_scratch +} + +_acl_setup_ids + +# Create a test file. +echo "hello world" > $FILENAME + +# Set an initial ACL while the subvolume is writable. +set_acl rwx + +# Attempt to change the ACL once the subvolume is read-only. This must +# fail with EROFS. +$BTRFS_UTIL_PROG property set $SCRATCH_MNT ro true +$BTRFS_UTIL_PROG property get $SCRATCH_MNT ro + +set_acl r-- + +# The ACL must not have changed. +get_acl + +# Attempt to remove the ACL from the read-only subvolume. This must +# fail with EROFS as well. +del_acl + +# The ACL must still be present. +get_acl + +# Make the subvolume writable again. +$BTRFS_UTIL_PROG property set $SCRATCH_MNT ro false +$BTRFS_UTIL_PROG property get $SCRATCH_MNT ro + +# Now changing the ACL must succeed. +set_acl r-- + +get_acl + +# And removing it must succeed too. +del_acl + +# Check the ACL is really gone. +get_acl + +status=0 +exittests/btrfs/353.out new file +39
-1@@ -0,0 +1,39 @@ +QA output created by 353 +ro=true +setfacl: SCRATCH_MNT/foo: Read-only file system +# file: SCRATCH_MNT/foo +# owner: 0 +# group: 0 +user::rw- +user:id2:rwx +group::r-- +mask::rwx +other::r-- + +setfacl: SCRATCH_MNT/foo: Read-only file system +# file: SCRATCH_MNT/foo +# owner: 0 +# group: 0 +user::rw- +user:id2:rwx +group::r-- +mask::rwx +other::r-- + +ro=false +# file: SCRATCH_MNT/foo +# owner: 0 +# group: 0 +user::rw- +user:id2:r-- +group::r-- +mask::rwx +other::r-- + +# file: SCRATCH_MNT/foo +# owner: 0 +# group: 0 +user::rw- +group::r-- +other::r-- + --2.54.0
Quoted 11 lines · Sun YangKai
From: Sun YangKai <[email protected]>
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_aclcode path checks the root
is readonly or not. It was checked inbtrfs_setxattr_trans()but got
removed in
commit353c2ea735e4("btrfs: remove redundant readonly root check inbtrfs_setxattr_trans")
This can be split across multiple lines, the only place it shouldn't be is in the Fixes tag.
Quoted 4 lines
That commit didn't check if all the callers properly check the root's read-only flag. A previous fix is
commitb51111271b03("btrfs: check if root is readonly while setting security xattr")
Please always leave a space between the commit hash and the opening parenthesis.
I've amended that and pushed to for-next on github, thanks.
Quoted 40 lines
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")Signed-off-by Sun YangKai <[email protected]>---
Changes to v1:
- add the missing header file--- fs/btrfs/acl.c | 4 ++++ 1 file changed, 4 insertions(+)fs/btrfs/acl.c +4
-1@@ -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); --2.54.0
Quoted 8 lines · Filipe Manana
Quoted 7 lines · Sun YangKai
From: Sun YangKai <[email protected]>
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.
Quoted 7 lines
Quoted 4 lines
This happens because no function on the
set_aclcode path checks the root
is readonly or not. It was checked inbtrfs_setxattr_trans()but got
removed in
commit353c2ea735e4("btrfs: remove redundant readonly root check inbtrfs_setxattr_trans")This can be split across multiple lines, the only place it shouldn't be is in the Fixes tag.
Got it.
Quoted 6 lines
Quoted 4 lines
That commit didn't check if all the callers properly check the root's read-only flag. A previous fix is
commitb51111271b03("btrfs: check if root is readonly while setting security xattr")Please always leave a space between the commit hash and the opening parenthesis.
My bad
Quoted 3 lines
I've amended that and pushed to for-next on github, thanks.
Reviewed-by Filipe Manana <[email protected]>
Thanks a lot for your fix and review.
Sun YangKai
Quoted 40 lines
Quoted 40 lines
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")Signed-off-by Sun YangKai <[email protected]>---
Changes to v1:
- add the missing header file--- fs/btrfs/acl.c | 4 ++++ 1 file changed, 4 insertions(+)fs/btrfs/acl.c +4
-1@@ -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); --2.54.0
PATCH v3 1/1 btrfs: test POSIX ACL changes for RO btrfs property
In reply to Sun YangKaiFrom: Sun YangKai <[email protected]>
Test creation, modification and deletion of POSIX ACLs on a btrfs filesystem that has the read-only property set to true.
This exercises a bug fixed by the kernel patch with subject:
"btrfs: check if root is readonly when setting posix acl"
---
Changes since v2:
- updated commit message
- proper format for fixed_by_kernel_commit
- lower case variable name
- handle mkfs failure
Suggested by Filipe Manana
--- tests/btrfs/353 | 95 +++++++++++++++++++++++++++++++++++++++++++++ tests/btrfs/353.out | 39 +++++++++++++++++++ 2 files changed, 134 insertions(+) create mode 100755 tests/btrfs/353 create mode 100644 tests/btrfs/353.out
tests/btrfs/353 new file +95 -0
@@ -0,0 +1,95 @@ +#! /bin/bash +# SPDX-License-Identifier: GPL-2.0 +# Copyright (C) 2026 Fygo OS. All Rights Reserved. +# +# FS QA Test No. 353 +# +# Test that POSIX ACLs cannot be changed once a btrfs subvolume has the +# read-only property set. +# +# Setting or removing a POSIX ACL goes through the ->set_acl inode +# operation, which is a different code path from the generic ->setxattr +# one covered by btrfs/275. It used to be allowed on a read-only +# subvolume and thus bypassed the RO protection. Such modifications must +# fail with EROFS, just like any other xattr. +# +. ./common/preamble +_begin_fstest auto quick acl attr + +. ./common/filter +. ./common/attr + +_fixed_by_kernel_commit xxxxxxxxxxxx \ + "btrfs: check if root is readonly when setting posix acl" + +_require_acls +_require_btrfs_command "property" +_require_scratch + +_scratch_mkfs >> $seqres.full 2>&1 || _fail "mkfs failed" +_scratch_mount + +filename=$SCRATCH_MNT/foo + +set_acl() +{ + local perm=$1 + + # Use -n so setfacl does not recalculate the mask, keeping the + # golden output deterministic regardless of the named user's + # permissions. + setfacl -n -m u:$acl2:$perm,m::rwx $filename 2>&1 | _filter_scratch +} + +get_acl() +{ + getfacl --absolute-names -n $filename | _filter_scratch | _getfacl_filter_id +} + +del_acl() +{ + setfacl -b $filename 2>&1 | _filter_scratch +} + +_acl_setup_ids + +# Create a test file. +echo "hello world" > $filename + +# Set an initial ACL while the subvolume is writable. +set_acl rwx + +# Attempt to change the ACL once the subvolume is read-only. This must +# fail with EROFS. +$BTRFS_UTIL_PROG property set $SCRATCH_MNT ro true +$BTRFS_UTIL_PROG property get $SCRATCH_MNT ro + +set_acl r-- + +# The ACL must not have changed. +get_acl + +# Attempt to remove the ACL from the read-only subvolume. This must +# fail with EROFS as well. +del_acl + +# The ACL must still be present. +get_acl + +# Make the subvolume writable again. +$BTRFS_UTIL_PROG property set $SCRATCH_MNT ro false +$BTRFS_UTIL_PROG property get $SCRATCH_MNT ro + +# Now changing the ACL must succeed. +set_acl r-- + +get_acl + +# And removing it must succeed too. +del_acl + +# Check the ACL is really gone. +get_acl + +status=0 +exit
tests/btrfs/353.out new file +39 -0
@@ -0,0 +1,39 @@ +QA output created by 353 +ro=true +setfacl: SCRATCH_MNT/foo: Read-only file system +# file: SCRATCH_MNT/foo +# owner: 0 +# group: 0 +user::rw- +user:id2:rwx +group::r-- +mask::rwx +other::r-- + +setfacl: SCRATCH_MNT/foo: Read-only file system +# file: SCRATCH_MNT/foo +# owner: 0 +# group: 0 +user::rw- +user:id2:rwx +group::r-- +mask::rwx +other::r-- + +ro=false +# file: SCRATCH_MNT/foo +# owner: 0 +# group: 0 +user::rw- +user:id2:r-- +group::r-- +mask::rwx +other::r-- + +# file: SCRATCH_MNT/foo +# owner: 0 +# group: 0 +user::rw- +group::r-- +other::r-- +
Signature · 1 line
2.54.0
Re: [PATCH v3] btrfs: test POSIX ACL changes for RO btrfs property
Quoted 13 lines · Sun YangKai
From: Sun YangKai <[email protected]>
Test creation, modification and deletion of POSIX ACLs on a btrfs filesystem that has the read-only property set to true.
This exercises a bug fixed by the kernel patch with subject:
"btrfs: check if root is readonly when setting posix acl"Signed-off-by Sun YangKai <[email protected]>Reviewed-by Filipe Manana <[email protected]>---
Changes since v2:
Quoted 7 lines
- updated commit message
- proper format forfixed_by_kernel_commit
- lower case variable name
- handle mkfs failureSuggested by Filipe Manana
---
This version is good to me, if no more review points form btrfs list, I'll merge it.
Quoted 156 lines
tests/btrfs/353 | 95 +++++++++++++++++++++++++++++++++++++++++++++ tests/btrfs/353.out | 39 +++++++++++++++++++ 2 files changed, 134 insertions(+) create mode 100755 tests/btrfs/353 create mode 100644 tests/btrfs/353.outtests/btrfs/353 new file +95
-0@@ -0,0 +1,95 @@ +#! /bin/bash +# SPDX-License-Identifier: GPL-2.0 +# Copyright (C) 2026 Fygo OS. All Rights Reserved. +# +# FS QA Test No. 353 +# +# Test that POSIX ACLs cannot be changed once a btrfs subvolume has the +# read-only property set. +# +# Setting or removing a POSIX ACL goes through the ->set_acl inode +# operation, which is a different code path from the generic ->setxattr +# one covered by btrfs/275. It used to be allowed on a read-only +# subvolume and thus bypassed the RO protection. Such modifications must +# fail with EROFS, just like any other xattr. +# +. ./common/preamble +_begin_fstest auto quick acl attr + +. ./common/filter +. ./common/attr + +_fixed_by_kernel_commit xxxxxxxxxxxx \ + "btrfs: check if root is readonly when setting posix acl" + +_require_acls +_require_btrfs_command "property" +_require_scratch + +_scratch_mkfs >> $seqres.full 2>&1 || _fail "mkfs failed" +_scratch_mount + +filename=$SCRATCH_MNT/foo + +set_acl() +{ + local perm=$1 + + # Use -n so setfacl does not recalculate the mask, keeping the + # golden output deterministic regardless of the named user's + # permissions. + setfacl -n -m u:$acl2:$perm,m::rwx $filename 2>&1 | _filter_scratch +} + +get_acl() +{ + getfacl --absolute-names -n $filename | _filter_scratch | _getfacl_filter_id +} + +del_acl() +{ + setfacl -b $filename 2>&1 | _filter_scratch +} + +_acl_setup_ids + +# Create a test file. +echo "hello world" > $filename + +# Set an initial ACL while the subvolume is writable. +set_acl rwx + +# Attempt to change the ACL once the subvolume is read-only. This must +# fail with EROFS. +$BTRFS_UTIL_PROG property set $SCRATCH_MNT ro true +$BTRFS_UTIL_PROG property get $SCRATCH_MNT ro + +set_acl r-- + +# The ACL must not have changed. +get_acl + +# Attempt to remove the ACL from the read-only subvolume. This must +# fail with EROFS as well. +del_acl + +# The ACL must still be present. +get_acl + +# Make the subvolume writable again. +$BTRFS_UTIL_PROG property set $SCRATCH_MNT ro false +$BTRFS_UTIL_PROG property get $SCRATCH_MNT ro + +# Now changing the ACL must succeed. +set_acl r-- + +get_acl + +# And removing it must succeed too. +del_acl + +# Check the ACL is really gone. +get_acl + +status=0 +exittests/btrfs/353.out new file +39
-0@@ -0,0 +1,39 @@ +QA output created by 353 +ro=true +setfacl: SCRATCH_MNT/foo: Read-only file system +# file: SCRATCH_MNT/foo +# owner: 0 +# group: 0 +user::rw- +user:id2:rwx +group::r-- +mask::rwx +other::r-- + +setfacl: SCRATCH_MNT/foo: Read-only file system +# file: SCRATCH_MNT/foo +# owner: 0 +# group: 0 +user::rw- +user:id2:rwx +group::r-- +mask::rwx +other::r-- + +ro=false +# file: SCRATCH_MNT/foo +# owner: 0 +# group: 0 +user::rw- +user:id2:r-- +group::r-- +mask::rwx +other::r-- + +# file: SCRATCH_MNT/foo +# owner: 0 +# group: 0 +user::rw- +group::r-- +other::r-- +Signature · 1 line
2.54.0