From: "Arnd Bergmann" <arnd@arndb.de>
To: "Darrick J. Wong" <djwong@kernel.org>, "Arnd Bergmann" <arnd@kernel.org>
Cc: linux-fsdevel@vger.kernel.org, linux-block@vger.kernel.org,
"Anuj Gupta" <anuj20.g@samsung.com>,
"Martin K. Petersen" <martin.petersen@oracle.com>,
"Kanchan Joshi" <joshi.k@samsung.com>,
"LTP List" <ltp@lists.linux.it>,
"Dan Carpenter" <dan.carpenter@linaro.org>,
"Benjamin Copeland" <benjamin.copeland@linaro.org>,
rbm@suse.com, "Naresh Kamboju" <naresh.kamboju@linaro.org>,
"Anders Roxell" <anders.roxell@linaro.org>,
"Jens Axboe" <axboe@kernel.dk>,
"Pavel Begunkov" <asml.silence@gmail.com>,
"Christian Brauner" <brauner@kernel.org>,
"Alexey Dobriyan" <adobriyan@gmail.com>,
"Eric Biggers" <ebiggers@google.com>,
linux-kernel@vger.kernel.org
Subject: Re: [PATCH] block: fix FS_IOC_GETLBMD_CAP parsing in blkdev_common_ioctl()
Date: Wed, 09 Jul 2025 22:30:40 +0200 [thread overview]
Message-ID: <290c17df-1bf2-45b8-b0c2-7a1865585d0a@app.fastmail.com> (raw)
In-Reply-To: <20250709182706.GF2672070@frogsfrogsfrogs>
On Wed, Jul 9, 2025, at 20:27, Darrick J. Wong wrote:
> On Wed, Jul 09, 2025 at 08:10:14PM +0200, Arnd Bergmann wrote:
> though we probably want a helper or something to encapsulate those three
> comparisons to avoid the SOMETHING_SOMETHING part:
>
> #define IOC_DISPATCH(c) \
> ((c) & ~(_IOC(0, 0, 0, _IOC_SIZE(_IOC_SIZEMASK))))
>
> switch (IOC_DISPATCH(cmd)) {
> case IOC_DISPATCH(FS_IOC_FSGETXATTR):
> return ioctl_fsgetxattr(filp, cmd, argp);
>
> Assuming that ioctl_fsgetxattr derives size from @cmd and rejects values
> that it doesn't like. Hrm?
This may work in specific cases, but it adds a lot of complexity
and room for error if we try to do this in more places:
Ignoring the 'size' argument as above would mean that
each case now has to add an extra size check in each 'case',
which then defeats the entire purpose.
I should maybe dig out my notes for table-driver ioctl
handlers, if we want to improve the way that drivers define
their ioctl implementations, I'm sure there is some
infrastructure we can come up with that can help here,
but I don't think 'same as before but more macros' is the
answer.
joydev_ioctl_common() is an existing example doing something
like it and gets it right, while snd_compr_ioctl() is an
example that looks completely broken to me.
>> + _IOC_SIZE(cmd) >= LBMD_SIZE_VER0 &&
>> + _IOC_SIZE(cmd) <= _IOC_SIZE(FS_IOC_GETLBMD_CAP))
>
> blk_get_meta_cap already checks this.
I had thought about removing it there, but decided against that.
Maybe a better way would be to have the full check inside of
blk_get_meta_cap() and use the -ENOIOCTLCMD return code
to keep the caller simple:
switch(cmd) {
...
default:
break;
}
ret = blk_get_meta_cap(bdev, cmd, argp);
if (ret != -ENOIOCTLCMD)
return ret;
...
return -ENOIOCTLCMD;
Arnd
next prev parent reply other threads:[~2025-07-09 20:31 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-07-09 18:10 [PATCH] block: fix FS_IOC_GETLBMD_CAP parsing in blkdev_common_ioctl() Arnd Bergmann
2025-07-09 18:27 ` Darrick J. Wong
2025-07-09 20:30 ` Arnd Bergmann [this message]
2025-07-10 8:00 ` Christian Brauner
2025-07-10 8:14 ` Christoph Hellwig
2025-07-10 10:50 ` Arnd Bergmann
2025-07-10 10:59 ` Christoph Hellwig
2025-07-10 11:52 ` Arnd Bergmann
2025-07-10 12:11 ` Christian Brauner
2025-07-10 10:11 ` Arnd Bergmann
2025-07-10 12:03 ` Christian Brauner
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=290c17df-1bf2-45b8-b0c2-7a1865585d0a@app.fastmail.com \
--to=arnd@arndb.de \
--cc=adobriyan@gmail.com \
--cc=anders.roxell@linaro.org \
--cc=anuj20.g@samsung.com \
--cc=arnd@kernel.org \
--cc=asml.silence@gmail.com \
--cc=axboe@kernel.dk \
--cc=benjamin.copeland@linaro.org \
--cc=brauner@kernel.org \
--cc=dan.carpenter@linaro.org \
--cc=djwong@kernel.org \
--cc=ebiggers@google.com \
--cc=joshi.k@samsung.com \
--cc=linux-block@vger.kernel.org \
--cc=linux-fsdevel@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=ltp@lists.linux.it \
--cc=martin.petersen@oracle.com \
--cc=naresh.kamboju@linaro.org \
--cc=rbm@suse.com \
/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