summaryrefslogtreecommitdiffstats
path: root/fs/io_uring.c
diff options
context:
space:
mode:
authorPavel Begunkov <asml.silence@gmail.com>2019-11-24 11:58:24 +0300
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>2019-12-13 08:42:27 +0100
commitf246eedbafdbf348c98d49a7891a3fe72118ffc3 (patch)
tree9500243ecbf3ba57de074aa04e18ec4cfbb3b335 /fs/io_uring.c
parent3b2b7b8954218700cdc7e28a172d3dc9fd5e7878 (diff)
downloadlinux-stable-f246eedbafdbf348c98d49a7891a3fe72118ffc3.tar.gz
linux-stable-f246eedbafdbf348c98d49a7891a3fe72118ffc3.tar.bz2
linux-stable-f246eedbafdbf348c98d49a7891a3fe72118ffc3.zip
io_uring: fix dead-hung for non-iter fixed rw
commit 311ae9e159d81a1ec1cf645daf40b39ae5a0bd84 upstream. Read/write requests to devices without implemented read/write_iter using fixed buffers can cause general protection fault, which totally hangs a machine. io_import_fixed() initialises iov_iter with bvec, but loop_rw_iter() accesses it as iovec, dereferencing random address. kmap() page by page in this case Cc: stable@vger.kernel.org Signed-off-by: Pavel Begunkov <asml.silence@gmail.com> Signed-off-by: Jens Axboe <axboe@kernel.dk> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Diffstat (limited to 'fs/io_uring.c')
-rw-r--r--fs/io_uring.c15
1 files changed, 14 insertions, 1 deletions
diff --git a/fs/io_uring.c b/fs/io_uring.c
index cbe8dabb6479..aa05a032fabc 100644
--- a/fs/io_uring.c
+++ b/fs/io_uring.c
@@ -1351,9 +1351,19 @@ static ssize_t loop_rw_iter(int rw, struct file *file, struct kiocb *kiocb,
return -EAGAIN;
while (iov_iter_count(iter)) {
- struct iovec iovec = iov_iter_iovec(iter);
+ struct iovec iovec;
ssize_t nr;
+ if (!iov_iter_is_bvec(iter)) {
+ iovec = iov_iter_iovec(iter);
+ } else {
+ /* fixed buffers import bvec */
+ iovec.iov_base = kmap(iter->bvec->bv_page)
+ + iter->iov_offset;
+ iovec.iov_len = min(iter->count,
+ iter->bvec->bv_len - iter->iov_offset);
+ }
+
if (rw == READ) {
nr = file->f_op->read(file, iovec.iov_base,
iovec.iov_len, &kiocb->ki_pos);
@@ -1362,6 +1372,9 @@ static ssize_t loop_rw_iter(int rw, struct file *file, struct kiocb *kiocb,
iovec.iov_len, &kiocb->ki_pos);
}
+ if (iov_iter_is_bvec(iter))
+ kunmap(iter->bvec->bv_page);
+
if (nr < 0) {
if (!ret)
ret = nr;