Skip to content

Commit fd6c2e4

Browse files
committed
io_uring: io_wq_submit_work() should not touch req->rw
I've been chasing a weird and obscure crash that was userspace stack corruption, and finally narrowed it down to a bit flip that made a stack address invalid. io_wq_submit_work() unconditionally flips the req->rw.ki_flags IOCB_NOWAIT bit, but since it's a generic work handler, this isn't valid. Normal read/write operations own that part of the request, on other types it could be something else. Move the IOCB_NOWAIT clear to the read/write handlers where it belongs. Signed-off-by: Jens Axboe <[email protected]>
1 parent 7c504e6 commit fd6c2e4

File tree

1 file changed

+8
-3
lines changed

1 file changed

+8
-3
lines changed

fs/io_uring.c

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1817,6 +1817,10 @@ static int io_read(struct io_kiocb *req, struct io_kiocb **nxt,
18171817
return ret;
18181818
}
18191819

1820+
/* Ensure we clear previously set non-block flag */
1821+
if (!force_nonblock)
1822+
req->rw.ki_flags &= ~IOCB_NOWAIT;
1823+
18201824
file = req->file;
18211825
io_size = ret;
18221826
if (req->flags & REQ_F_LINK)
@@ -1906,6 +1910,10 @@ static int io_write(struct io_kiocb *req, struct io_kiocb **nxt,
19061910
return ret;
19071911
}
19081912

1913+
/* Ensure we clear previously set non-block flag */
1914+
if (!force_nonblock)
1915+
req->rw.ki_flags &= ~IOCB_NOWAIT;
1916+
19091917
file = kiocb->ki_filp;
19101918
io_size = ret;
19111919
if (req->flags & REQ_F_LINK)
@@ -3274,9 +3282,6 @@ static void io_wq_submit_work(struct io_wq_work **workptr)
32743282
struct io_kiocb *nxt = NULL;
32753283
int ret = 0;
32763284

3277-
/* Ensure we clear previously set non-block flag */
3278-
req->rw.ki_flags &= ~IOCB_NOWAIT;
3279-
32803285
if (work->flags & IO_WQ_WORK_CANCEL)
32813286
ret = -ECANCELED;
32823287

0 commit comments

Comments
 (0)