Skip to content

Commit efd96fb

Browse files
thejhgregkh
authored andcommitted
io_uring/rsrc: require cloned buffers to share accounting contexts
Commit 19d340a upstream. When IORING_REGISTER_CLONE_BUFFERS is used to clone buffers from uring instance A to uring instance B, where A and B use different MMs for accounting, the accounting can go wrong: If uring instance A is closed before uring instance B, the pinned memory counters for uring instance B will be decremented, even though the pinned memory was originally accounted through uring instance A; so the MM of uring instance B can end up with negative locked memory. Cc: stable@vger.kernel.org Closes: https://lore.kernel.org/r/CAG48ez1zez4bdhmeGLEFxtbFADY4Czn3CV0u9d_TMcbvRA01bg@mail.gmail.com Fixes: 7cc2a6e ("io_uring: add IORING_REGISTER_COPY_BUFFERS method") Signed-off-by: Jann Horn <jannh@google.com> Link: https://lore.kernel.org/r/20250114-uring-check-accounting-v1-1-42e4145aa743@google.com Signed-off-by: Jens Axboe <axboe@kernel.dk> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
1 parent 5d114fa commit efd96fb

1 file changed

Lines changed: 7 additions & 0 deletions

File tree

io_uring/rsrc.c

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1153,6 +1153,13 @@ static int io_clone_buffers(struct io_ring_ctx *ctx, struct io_ring_ctx *src_ctx
11531153
struct io_rsrc_data *data;
11541154
int i, ret, nbufs;
11551155

1156+
/*
1157+
* Accounting state is shared between the two rings; that only works if
1158+
* both rings are accounted towards the same counters.
1159+
*/
1160+
if (ctx->user != src_ctx->user || ctx->mm_account != src_ctx->mm_account)
1161+
return -EINVAL;
1162+
11561163
/*
11571164
* Drop our own lock here. We'll setup the data we need and reference
11581165
* the source buffers, then re-grab, check, and assign at the end.

0 commit comments

Comments
 (0)