Skip to content

Commit 7eb75ce

Browse files
committed
io_uring/tctx: work around xa_store() allocation error issue
syzbot triggered the following WARN_ON: WARNING: CPU: 0 PID: 16 at io_uring/tctx.c:51 __io_uring_free+0xfa/0x140 io_uring/tctx.c:51 which is the WARN_ON_ONCE(!xa_empty(&tctx->xa)); sanity check in __io_uring_free() when a io_uring_task is going through its final put. The syzbot test case includes injecting memory allocation failures, and it very much looks like xa_store() can fail one of its memory allocations and end up with ->head being non-NULL even though no entries exist in the xarray. Until this issue gets sorted out, work around it by attempting to iterate entries in our xarray, and WARN_ON_ONCE() if one is found. Reported-by: syzbot+cc36d44ec9f368e443d3@syzkaller.appspotmail.com Link: https://lore.kernel.org/io-uring/673c1643.050a0220.87769.0066.GAE@google.com/ Signed-off-by: Jens Axboe <axboe@kernel.dk>
1 parent 43eef70 commit 7eb75ce

File tree

1 file changed

+12
-1
lines changed

1 file changed

+12
-1
lines changed

io_uring/tctx.c

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,19 @@ static struct io_wq *io_init_wq_offload(struct io_ring_ctx *ctx,
4747
void __io_uring_free(struct task_struct *tsk)
4848
{
4949
struct io_uring_task *tctx = tsk->io_uring;
50+
struct io_tctx_node *node;
51+
unsigned long index;
5052

51-
WARN_ON_ONCE(!xa_empty(&tctx->xa));
53+
/*
54+
* Fault injection forcing allocation errors in the xa_store() path
55+
* can lead to xa_empty() returning false, even though no actual
56+
* node is stored in the xarray. Until that gets sorted out, attempt
57+
* an iteration here and warn if any entries are found.
58+
*/
59+
xa_for_each(&tctx->xa, index, node) {
60+
WARN_ON_ONCE(1);
61+
break;
62+
}
5263
WARN_ON_ONCE(tctx->io_wq);
5364
WARN_ON_ONCE(tctx->cached_refs);
5465

0 commit comments

Comments
 (0)