On Wed, Mar 26, 2025 at 02:47:49PM +0100, Petr Vorel wrote: > Hi all, > > [ Cc Kent and other filesystem folks to be sure we don't hide a bug ] I'm missing context here, and the original thread doesn't seem to be on lore? > > > From: Andrea Cervesato <andrea.cervesato@xxxxxxxx> > > > Make sure that capabilities requirements are satisfied when accessing > > immutable files. On OpenSUSE Tumbleweed 32bit bcachefs fails with the > > following error due to missing capabilities: > > > tst_test.c:1833: TINFO: === Testing on bcachefs === > > .. > > ioctl_ficlone03.c:74: TBROK: ioctl .. failed: ENOTTY (25) > > ioctl_ficlone03.c:89: TWARN: ioctl .. failed: ENOTTY (25) > > ioctl_ficlone03.c:91: TWARN: ioctl .. failed: ENOTTY (25) > > ioctl_ficlone03.c:98: TWARN: close(-1) failed: EBADF (9) > > > Introduce CAP_LINUX_IMMUTABLE capability to make sure that test won't > > fail on other systems as well. > > > Signed-off-by: Andrea Cervesato <andrea.cervesato@xxxxxxxx> > > --- > > testcases/kernel/syscalls/ioctl/ioctl_ficlone03.c | 6 +++++- > > 1 file changed, 5 insertions(+), 1 deletion(-) > > > diff --git a/testcases/kernel/syscalls/ioctl/ioctl_ficlone03.c b/testcases/kernel/syscalls/ioctl/ioctl_ficlone03.c > > index 6a9d270d9fb56f3a263f0aed976f62c4576e6a5f..6716423d9c96d9fc1d433f28e0ae1511b912ae2c 100644 > > --- a/testcases/kernel/syscalls/ioctl/ioctl_ficlone03.c > > +++ b/testcases/kernel/syscalls/ioctl/ioctl_ficlone03.c > > @@ -122,5 +122,9 @@ static struct tst_test test = { > > .bufs = (struct tst_buffers []) { > > {&clone_range, .size = sizeof(struct file_clone_range)}, > > {}, > > - } > > + }, > > + .caps = (struct tst_cap []) { > > + TST_CAP(TST_CAP_REQ, CAP_LINUX_IMMUTABLE), > > + {} > > + }, > > Reviewed-by: Petr Vorel <pvorel@xxxxxxx> > > LGTM, obviously it is CAP_LINUX_IMMUTABLE related. > > This looks like fs/bcachefs/fs-ioctl.c > > static int bch2_inode_flags_set(struct btree_trans *trans, > struct bch_inode_info *inode, > struct bch_inode_unpacked *bi, > void *p) > { > ... > if (((newflags ^ oldflags) & (BCH_INODE_append|BCH_INODE_immutable)) && > !capable(CAP_LINUX_IMMUTABLE)) > return -EPERM; > > > We don't test on vfat and exfat. If I try to do it fail the same way (bcachefs, > fat, exfat and ocfs2 use custom handler for FAT_IOCTL_SET_ATTRIBUTES). > > I wonder why it does not fail for generic VFS fs/ioctl.c used by Btrfs and XFS: > > /* > * Generic function to check FS_IOC_FSSETXATTR/FS_IOC_SETFLAGS values and reject > * any invalid configurations. > * > * Note: must be called with inode lock held. > */ > static int fileattr_set_prepare(struct inode *inode, > const struct fileattr *old_ma, > struct fileattr *fa) > { > int err; > > /* > * The IMMUTABLE and APPEND_ONLY flags can only be changed by > * the relevant capability. > */ > if ((fa->flags ^ old_ma->flags) & (FS_APPEND_FL | FS_IMMUTABLE_FL) && > !capable(CAP_LINUX_IMMUTABLE)) > return -EPERM; > > > Kind regards, > Petr > > > }; > > > --- > > base-commit: 753bd13472d4be44eb70ff183b007fe9c5fffa07 > > change-id: 20250326-fix_ioctl_ficlone03_32bit_bcachefs-2ec15bd6c0c6 > > > Best regards,