Skip to content

Commit ba5ef6d

Browse files
isilenceaxboe
authored andcommitted
io_uring: fortify tctx/io_wq cleanup
We don't want anyone poking into tctx->io_wq awhile it's being destroyed by io_wq_put_and_exit(), and even though it shouldn't even happen, if buggy would be preferable to get a NULL-deref instead of subtle delayed failure or UAF. Signed-off-by: Pavel Begunkov <[email protected]> Link: https://lore.kernel.org/r/827b021de17926fd807610b3e53a5a5fa8530856.1621513214.git.asml.silence@gmail.com Signed-off-by: Jens Axboe <[email protected]>
1 parent 7a27472 commit ba5ef6d

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

fs/io_uring.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9035,15 +9035,15 @@ static void io_uring_del_task_file(unsigned long index)
90359035

90369036
static void io_uring_clean_tctx(struct io_uring_task *tctx)
90379037
{
9038+
struct io_wq *wq = tctx->io_wq;
90389039
struct io_tctx_node *node;
90399040
unsigned long index;
90409041

9042+
tctx->io_wq = NULL;
90419043
xa_for_each(&tctx->xa, index, node)
90429044
io_uring_del_task_file(index);
9043-
if (tctx->io_wq) {
9044-
io_wq_put_and_exit(tctx->io_wq);
9045-
tctx->io_wq = NULL;
9046-
}
9045+
if (wq)
9046+
io_wq_put_and_exit(wq);
90479047
}
90489048

90499049
static s64 tctx_inflight(struct io_uring_task *tctx, bool tracked)

0 commit comments

Comments
 (0)