History

io_uring: fix races with buffer table unregister

Fixed buffer table quiesce might unlock ->uring_lock, potentially letting new requests to be submitted, don't allow those requests to use the table as they will race with unregistration.

Pavel Begunkov committed 4 years ago

Commit d11d31f1 parent b0380bf1 file · +7 −0Browse files

Unified · Split

fs/io_uring.c+7−0
@@ -10680,12 +10680,19 @@ static void __io_sqe_buffers_unregister(struct io_ring_ctx *ctx) · 10679 unmodified lines
1068010680
1068110681 static int io_sqe_buffers_unregister(struct io_ring_ctx *ctx)
1068210682 {
10683+ unsigned nr = ctx->nr_user_bufs;
1068310684 int ret;
1068410685
1068510686 if (!ctx->buf_data)
1068610687 return -ENXIO;
1068710688
10689+ /*
10690+ * Quiesce may unlock ->uring_lock, and while it's not held
10691+ * prevent new requests using the table.
10692+ */
10693+ ctx->nr_user_bufs = 0;
1068810694 ret = io_rsrc_ref_quiesce(ctx->buf_data, ctx);
10695+ ctx->nr_user_bufs = nr;
1068910696 if (!ret)
1069010697 __io_sqe_buffers_unregister(ctx);
1069110698 return ret;