All of lore.kernel.org
 help / color / mirror / Atom feed
From: Petr Vorel <pvorel@suse.cz>
To: Kent Overstreet <kent.overstreet@linux.dev>
Cc: Andrea Cervesato <andrea.cervesato@suse.de>,
	ltp@lists.linux.it, linux-bcachefs@vger.kernel.org,
	linux-fsdevel@vger.kernel.org, Li Wang <liwang@redhat.com>,
	Cyril Hrubis <chrubis@suse.cz>
Subject: Re: [LTP] [PATCH] ioctl_ficlone03: fix capabilities on immutable files
Date: Wed, 26 Mar 2025 19:42:08 +0100	[thread overview]
Message-ID: <20250326184208.GA53635@pevik> (raw)
In-Reply-To: <7ry7netcdqchal5pyoa5qdiris5klyxg6pqnz3qj6toodfgyuw@zder35svbr7v>

Hi Kent,

> 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?

I'm sorry, to put more info: this is an attempt to fix of LTP test
ioctl_ficlone03.c [1], which is failing on 32 bit compatibility mode:

# ./ioctl_ficlone03
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)

Original thread of this is on LTP ML [2].

Kind regards,
Petr

[1] https://github.com/linux-test-project/ltp/tree/master/testcases/kernel/syscalls/ioctl/ioctl_ficlone03.c
[2] https://lore.kernel.org/ltp/20250326-fix_ioctl_ficlone03_32bit_bcachefs-v1-1-554a0315ebf5@suse.com/

> > > From: Andrea Cervesato <andrea.cervesato@suse.com>

> > > 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@suse.com>
> > > ---
> > >  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@suse.cz>

> > 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,

WARNING: multiple messages have this Message-ID (diff)
From: Petr Vorel <pvorel@suse.cz>
To: Kent Overstreet <kent.overstreet@linux.dev>
Cc: linux-bcachefs@vger.kernel.org, linux-fsdevel@vger.kernel.org,
	ltp@lists.linux.it
Subject: Re: [LTP] [PATCH] ioctl_ficlone03: fix capabilities on immutable files
Date: Wed, 26 Mar 2025 19:42:08 +0100	[thread overview]
Message-ID: <20250326184208.GA53635@pevik> (raw)
In-Reply-To: <7ry7netcdqchal5pyoa5qdiris5klyxg6pqnz3qj6toodfgyuw@zder35svbr7v>

Hi Kent,

> 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?

I'm sorry, to put more info: this is an attempt to fix of LTP test
ioctl_ficlone03.c [1], which is failing on 32 bit compatibility mode:

# ./ioctl_ficlone03
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)

Original thread of this is on LTP ML [2].

Kind regards,
Petr

[1] https://github.com/linux-test-project/ltp/tree/master/testcases/kernel/syscalls/ioctl/ioctl_ficlone03.c
[2] https://lore.kernel.org/ltp/20250326-fix_ioctl_ficlone03_32bit_bcachefs-v1-1-554a0315ebf5@suse.com/

> > > From: Andrea Cervesato <andrea.cervesato@suse.com>

> > > 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@suse.com>
> > > ---
> > >  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@suse.cz>

> > 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,

-- 
Mailing list info: https://lists.linux.it/listinfo/ltp

  reply	other threads:[~2025-03-26 18:42 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-03-26 12:42 [LTP] [PATCH] ioctl_ficlone03: fix capabilities on immutable files Andrea Cervesato
2025-03-26 13:47 ` Petr Vorel
2025-03-26 13:47   ` Petr Vorel
2025-03-26 14:12   ` Kent Overstreet
2025-03-26 14:12     ` Kent Overstreet
2025-03-26 18:42     ` Petr Vorel [this message]
2025-03-26 18:42       ` Petr Vorel
2025-03-27  0:49   ` Dave Chinner
2025-03-27  0:49     ` Dave Chinner via ltp
2025-03-28 16:26     ` Kent Overstreet
2025-03-28 16:26       ` Kent Overstreet

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20250326184208.GA53635@pevik \
    --to=pvorel@suse.cz \
    --cc=andrea.cervesato@suse.de \
    --cc=chrubis@suse.cz \
    --cc=kent.overstreet@linux.dev \
    --cc=linux-bcachefs@vger.kernel.org \
    --cc=linux-fsdevel@vger.kernel.org \
    --cc=liwang@redhat.com \
    --cc=ltp@lists.linux.it \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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.