Re: [PATCH V2] loop: Add sanity check for read/write_iter
From: Christoph Hellwig
Date: Fri Apr 25 2025 - 09:30:16 EST
On Fri, Apr 25, 2025 at 01:38:03PM +0800, Lizhi Xu wrote:
> Some file systems do not support read_iter or write_iter, such as selinuxfs
> in this issue.
> So before calling them, first confirm that the interface is supported and
> then call it.
Nit: commit messages should not have lines longer than 73 characters.
Please also add a:
Fixes: f2fed441c69b ("loop: stop using vfs_iter__{read,write} for buffered I/O")
and maybe add a blurb that vfs_iter_read/write had this check.
Now the other interesting bit is why we did not hit this earlier with
direct I/O? I guess it's because we basically have no instances
supporting direct I/O and not using the iter ops.
> @@ -603,6 +603,12 @@ static int loop_change_fd(struct loop_device *lo, struct block_device *bdev,
> if (!file)
> return -EBADF;
>
> + if (unlikely(!file->f_op->read_iter))
> + return -EINVAL;
> +
> + if (file->f_mode & FMODE_WRITE && unlikely(!file->f_op->write_iter))
> + return -EINVAL;
Can we have a common helper for change_fd and configure, please?
Please also drop the unlikelys - this is not a fast path and we don't
need to micro-optimize.
A bit unrelated, but loop-configure actually checks for write_iter
and forces read-only for that. Do we need the same kind of check in
change_fd?