io_uring: fix io_req_prep_async with provided buffers
io_req_prep_async() can import provided buffers, commit the ring state
by giving up on that before, it'll be reimported later if needed.
BUG=b/397181083
TEST=None
RELEASE_NOTE=None
cos-patch: security-high
Reported-by: Muhammad Ramdhan <ramdhan@starlabs.sg>
Reported-by: Bing-Jhong Billy Jheng <billy@starlabs.sg>
Reported-by: Jacob Soo <jacob.soo@starlabs.sg>
Fixes: c7fb19428d67d ("io_uring: add support for ring mapped supplied buffers")
Change-Id: I6cba13e5583da45b772b8b42e3d7fe380be9d243
Signed-off-by: Pavel Begunkov <asml.silence@gmail.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Reviewed-on: https://cos-review.googlesource.com/c/third_party/kernel/+/93820
Main-Branch-Verified: Cusky Presubmit Bot <presubmit@cos-infra-prod.iam.gserviceaccount.com>
Tested-by: Cusky Presubmit Bot <presubmit@cos-infra-prod.iam.gserviceaccount.com>
Reviewed-by: Anil Altinay <aaltinay@google.com>
diff --git a/io_uring/io_uring.c b/io_uring/io_uring.c
index a882415..45896fc 100644
--- a/io_uring/io_uring.c
+++ b/io_uring/io_uring.c
@@ -1633,6 +1633,7 @@ bool io_alloc_async_data(struct io_kiocb *req)
int io_req_prep_async(struct io_kiocb *req)
{
const struct io_op_def *def = &io_op_defs[req->opcode];
+ int ret;
/* assign early for deferred execution for non-fixed file */
if (def->needs_file && !(req->flags & REQ_F_FIXED_FILE) && !req->file)
@@ -1645,7 +1646,9 @@ int io_req_prep_async(struct io_kiocb *req)
if (io_alloc_async_data(req))
return -EAGAIN;
}
- return def->prep_async(req);
+ ret = def->prep_async(req);
+ io_kbuf_recycle(req, 0);
+ return ret;
}
static u32 io_get_sequence(struct io_kiocb *req)