提交 4e3d7618 编写于 作者: A Al Viro 提交者: Yang Yingliang

fuse: fix the ->direct_IO() treatment of iov_iter

mainline inclusion
from mainline-5.9-rc7
commit 933a3752
category: bugfix
bugzilla: 42553
CVE: NA

-------------------------------------------------

the callers rely upon having any iov_iter_truncate() done inside
->direct_IO() countered by iov_iter_reexpand().
Reported-by: NQian Cai <cai@redhat.com>
Tested-by: NQian Cai <cai@redhat.com>
Signed-off-by: NAl Viro <viro@zeniv.linux.org.uk>

Conflict: fs/fuse/file.c
commit 5da784cc("fuse: add max_pages to init_out") is not
backported, fuse_round_up only accept one paramater.
Signed-off-by: NYu Kuai <yukuai3@huawei.com>
Reviewed-by: NZhang Yi <yi.zhang@huawei.com>
Signed-off-by: NYang Yingliang <yangyingliang@huawei.com>
上级 807fd773
...@@ -2866,11 +2866,10 @@ fuse_direct_IO(struct kiocb *iocb, struct iov_iter *iter) ...@@ -2866,11 +2866,10 @@ fuse_direct_IO(struct kiocb *iocb, struct iov_iter *iter)
ssize_t ret = 0; ssize_t ret = 0;
struct file *file = iocb->ki_filp; struct file *file = iocb->ki_filp;
struct fuse_file *ff = file->private_data; struct fuse_file *ff = file->private_data;
bool async_dio = ff->fc->async_dio;
loff_t pos = 0; loff_t pos = 0;
struct inode *inode; struct inode *inode;
loff_t i_size; loff_t i_size;
size_t count = iov_iter_count(iter); size_t count = iov_iter_count(iter), shortened = 0;
loff_t offset = iocb->ki_pos; loff_t offset = iocb->ki_pos;
struct fuse_io_priv *io; struct fuse_io_priv *io;
...@@ -2878,17 +2877,9 @@ fuse_direct_IO(struct kiocb *iocb, struct iov_iter *iter) ...@@ -2878,17 +2877,9 @@ fuse_direct_IO(struct kiocb *iocb, struct iov_iter *iter)
inode = file->f_mapping->host; inode = file->f_mapping->host;
i_size = i_size_read(inode); i_size = i_size_read(inode);
if ((iov_iter_rw(iter) == READ) && (offset > i_size)) if ((iov_iter_rw(iter) == READ) && (offset >= i_size))
return 0; return 0;
/* optimization for short read */
if (async_dio && iov_iter_rw(iter) != WRITE && offset + count > i_size) {
if (offset >= i_size)
return 0;
iov_iter_truncate(iter, fuse_round_up(i_size - offset));
count = iov_iter_count(iter);
}
io = kmalloc(sizeof(struct fuse_io_priv), GFP_KERNEL); io = kmalloc(sizeof(struct fuse_io_priv), GFP_KERNEL);
if (!io) if (!io)
return -ENOMEM; return -ENOMEM;
...@@ -2904,15 +2895,22 @@ fuse_direct_IO(struct kiocb *iocb, struct iov_iter *iter) ...@@ -2904,15 +2895,22 @@ fuse_direct_IO(struct kiocb *iocb, struct iov_iter *iter)
* By default, we want to optimize all I/Os with async request * By default, we want to optimize all I/Os with async request
* submission to the client filesystem if supported. * submission to the client filesystem if supported.
*/ */
io->async = async_dio; io->async = ff->fc->async_dio;
io->iocb = iocb; io->iocb = iocb;
io->blocking = is_sync_kiocb(iocb); io->blocking = is_sync_kiocb(iocb);
/* optimization for short read */
if (io->async && !io->write && offset + count > i_size) {
iov_iter_truncate(iter, fuse_round_up(i_size - offset));
shortened = count - iov_iter_count(iter);
count -= shortened;
}
/* /*
* We cannot asynchronously extend the size of a file. * We cannot asynchronously extend the size of a file.
* In such case the aio will behave exactly like sync io. * In such case the aio will behave exactly like sync io.
*/ */
if ((offset + count > i_size) && iov_iter_rw(iter) == WRITE) if ((offset + count > i_size) && io->write)
io->blocking = true; io->blocking = true;
if (io->async && io->blocking) { if (io->async && io->blocking) {
...@@ -2930,6 +2928,7 @@ fuse_direct_IO(struct kiocb *iocb, struct iov_iter *iter) ...@@ -2930,6 +2928,7 @@ fuse_direct_IO(struct kiocb *iocb, struct iov_iter *iter)
} else { } else {
ret = __fuse_direct_read(io, iter, &pos); ret = __fuse_direct_read(io, iter, &pos);
} }
iov_iter_reexpand(iter, iov_iter_count(iter) + shortened);
if (io->async) { if (io->async) {
bool blocking = io->blocking; bool blocking = io->blocking;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册