From: Dave Chinner <david@fromorbit.com>
To: Petr Vorel <pvorel@suse.cz>
Cc: Andrea Cervesato <andrea.cervesato@suse.de>,
ltp@lists.linux.it, Kent Overstreet <kent.overstreet@linux.dev>,
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: Thu, 27 Mar 2025 11:49:19 +1100 [thread overview]
Message-ID: <Z-Sgj_XOVar8myLw@dread.disaster.area> (raw)
In-Reply-To: <20250326134749.GA45449@pevik>
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 ]
>
> > 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)
None of these are -EPERM, so how is a missing capability that
results in -EPERM being returned cause -ENOTTY or -EBADF failures?
ohhhhh. ENOTTY is a result of a kernel side compat ioctl handling bug
w/ bcachefs.
bcachefs doesn't implement ->fileattr_set().
sys_compat_ioctl() does:
case FS_IOC32_GETFLAGS:
case FS_IOC32_SETFLAGS:
cmd = (cmd == FS_IOC32_GETFLAGS) ?
FS_IOC_GETFLAGS : FS_IOC_SETFLAGS;
and then calls do_vfs_ioctl().
This then ends up in vfs_fileattr_set(), which does:
if (!inode->i_op->fileattr_set)
return -ENOIOCTLCMD;
which means sys_compat_ioctl() then falls back to calling
->compat_ioctl().
However, cmd has been overwritten to FS_IOC_SETFLAGS and
bch2_compat_fs_ioctl() looks for FS_IOC32_SETFLAGS, so it returns
-ENOIOCTLCMD as it doesn't handle the ioctl command passed in.
sys_compat_ioctl() then converts the -ENOIOCTLCMD to -ENOTTY, and
there's the error being reported.
OK, this is a bcachefs compat ioctl handling bug, triggered by not
implementing ->fileattr_set and implementing FS_IOC_SETFLAGS
directly itself via ->unlocked_ioctl.
Yeah, fixes to bcachefs needed here, not LTP.
> I wonder why it does not fail for generic VFS fs/ioctl.c used by Btrfs and XFS:
Because they implement ->fileattr_set() and so all the compat ioctl
FS_IOC32_SETFLAGS handling works as expected.
-Dave.
--
Dave Chinner
david@fromorbit.com
next prev parent reply other threads:[~2025-03-27 0:49 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <20250326-fix_ioctl_ficlone03_32bit_bcachefs-v1-1-554a0315ebf5@suse.com>
2025-03-26 13:47 ` [LTP] [PATCH] ioctl_ficlone03: fix capabilities on immutable files Petr Vorel
2025-03-26 14:12 ` Kent Overstreet
2025-03-26 18:42 ` Petr Vorel
2025-03-27 0:49 ` Dave Chinner [this message]
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=Z-Sgj_XOVar8myLw@dread.disaster.area \
--to=david@fromorbit.com \
--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 \
--cc=pvorel@suse.cz \
/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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox