mirror of
https://git.kernel.org/pub/scm/linux/kernel/git/chenhuacai/linux-loongson
synced 2025-08-27 15:36:48 +00:00
loop: Add sanity check for read/write_iter
Some file systems do not support read_iter/write_iter, such as selinuxfs
in this issue.
So before calling them, first confirm that the interface is supported and
then call it.
It is releavant in that vfs_iter_read/write have the check, and removal
of their used caused szybot to be able to hit this issue.
Fixes: f2fed441c6
("loop: stop using vfs_iter__{read,write} for buffered I/O")
Reported-by: syzbot+6af973a3b8dfd2faefdc@syzkaller.appspotmail.com
Closes: https://syzkaller.appspot.com/bug?extid=6af973a3b8dfd2faefdc
Signed-off-by: Lizhi Xu <lizhi.xu@windriver.com>
Reviewed-by: Christoph Hellwig <hch@lst.de>
Link: https://lore.kernel.org/r/20250428143626.3318717-1-lizhi.xu@windriver.com
Signed-off-by: Jens Axboe <axboe@kernel.dk>
This commit is contained in:
parent
6d732e8d1e
commit
f5c84eff63
@ -505,6 +505,17 @@ static void loop_assign_backing_file(struct loop_device *lo, struct file *file)
|
|||||||
lo->lo_min_dio_size = loop_query_min_dio_size(lo);
|
lo->lo_min_dio_size = loop_query_min_dio_size(lo);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static int loop_check_backing_file(struct file *file)
|
||||||
|
{
|
||||||
|
if (!file->f_op->read_iter)
|
||||||
|
return -EINVAL;
|
||||||
|
|
||||||
|
if ((file->f_mode & FMODE_WRITE) && !file->f_op->write_iter)
|
||||||
|
return -EINVAL;
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* loop_change_fd switched the backing store of a loopback device to
|
* loop_change_fd switched the backing store of a loopback device to
|
||||||
* a new file. This is useful for operating system installers to free up
|
* a new file. This is useful for operating system installers to free up
|
||||||
@ -526,6 +537,10 @@ static int loop_change_fd(struct loop_device *lo, struct block_device *bdev,
|
|||||||
if (!file)
|
if (!file)
|
||||||
return -EBADF;
|
return -EBADF;
|
||||||
|
|
||||||
|
error = loop_check_backing_file(file);
|
||||||
|
if (error)
|
||||||
|
return error;
|
||||||
|
|
||||||
/* suppress uevents while reconfiguring the device */
|
/* suppress uevents while reconfiguring the device */
|
||||||
dev_set_uevent_suppress(disk_to_dev(lo->lo_disk), 1);
|
dev_set_uevent_suppress(disk_to_dev(lo->lo_disk), 1);
|
||||||
|
|
||||||
@ -963,6 +978,14 @@ static int loop_configure(struct loop_device *lo, blk_mode_t mode,
|
|||||||
|
|
||||||
if (!file)
|
if (!file)
|
||||||
return -EBADF;
|
return -EBADF;
|
||||||
|
|
||||||
|
if ((mode & BLK_OPEN_WRITE) && !file->f_op->write_iter)
|
||||||
|
return -EINVAL;
|
||||||
|
|
||||||
|
error = loop_check_backing_file(file);
|
||||||
|
if (error)
|
||||||
|
return error;
|
||||||
|
|
||||||
is_loop = is_loop_device(file);
|
is_loop = is_loop_device(file);
|
||||||
|
|
||||||
/* This is safe, since we have a reference from open(). */
|
/* This is safe, since we have a reference from open(). */
|
||||||
|
Loading…
Reference in New Issue
Block a user