Skip to contentSkip to conversation

io_uring: fix truncated async read/readv and write/writev retry

PATCH In review Jens Axboe 2 participants 3 messages Mar 11, 2020 – Mar 12, 2020

Subsystems (2)
lore
Share & tools
lore

Jens Axboe

author maintainer
#0 lore raw

PATCH 1/1 io_uring: fix truncated async read/readv and write/writev retry

Ensure we keep the truncated value, if we did truncate it. If not, we might read/write more than the registered buffer size.

Also for retry, ensure that we return the truncated mapped value for the vectorized versions of the read/write commands.

---

fs/io_uring.c +5 -2
index 9f1a462eb780..55afae6f0cf4 100644
@@ -2360,6 +2360,7 @@ static ssize_t io_import_iovec(int rw, struct io_kiocb *req,
 				*iovec = NULL;
 				return PTR_ERR(buf);
 			}
+			req->rw.len = sqe_len;
 		}
 
 		ret = import_single_range(rw, buf, sqe_len, *iovec, iter);
@@ -2379,8 +2380,10 @@ static ssize_t io_import_iovec(int rw, struct io_kiocb *req,
 
 	if (req->flags & REQ_F_BUFFER_SELECT) {
 		ret = io_iov_buffer_select(req, *iovec, needs_lock);
-		if (!ret)
-			iov_iter_init(iter, rw, *iovec, 1, (*iovec)->iov_len);
+		if (!ret) {
+			ret = (*iovec)->iov_len;
+			iov_iter_init(iter, rw, *iovec, 1, ret);
+		}
 		*iovec = NULL;
 		return ret;
 	}
Signature · 1 line
Jens Axboe
#1 lore raw

Hi Jens,

I haven't looked at the change in detail, but I'm wondering if this would be needed in stable too?

metze

Am 11.03.20 um 19:30 schrieb Jens Axboe:

Quoted 36 lines

Ensure we keep the truncated value, if we did truncate it. If not, we might read/write more than the registered buffer size.

Also for retry, ensure that we return the truncated mapped value for the vectorized versions of the read/write commands.

---

fs/io_uring.c +5 -2
index 9f1a462eb780..55afae6f0cf4 100644
@@ -2360,6 +2360,7 @@ static ssize_t io_import_iovec(int rw, struct io_kiocb *req,
 				*iovec = NULL;
 				return PTR_ERR(buf);
 			}
+			req->rw.len = sqe_len;
 		}
 
 		ret = import_single_range(rw, buf, sqe_len, *iovec, iter);
@@ -2379,8 +2380,10 @@ static ssize_t io_import_iovec(int rw, struct io_kiocb *req,
 
 	if (req->flags & REQ_F_BUFFER_SELECT) {
 		ret = io_iov_buffer_select(req, *iovec, needs_lock);
-		if (!ret)
-			iov_iter_init(iter, rw, *iovec, 1, (*iovec)->iov_len);
+		if (!ret) {
+			ret = (*iovec)->iov_len;
+			iov_iter_init(iter, rw, *iovec, 1, ret);
+		}
 		*iovec = NULL;
 		return ret;
 	}
author maintainer
#2 lore raw
Quoted 4 lines · Stefan Metzmacher

Hi Jens,

I haven't looked at the change in detail, but I'm wondering if this would be needed in stable too?

It's just for the buffer select stuff, so won't impact 5.6 or earlier.

Signature · 1 line
Jens Axboe