Skip to contentSkip to conversation

io_uring/rsrc: fix rogue rsrc node grabbing

PATCH Applied Pavel Begunkov 2 participants 2 messages Mar 29, 2023 io_uring

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 io_uring/rsrc: fix rogue rsrc node grabbing

We should not be looking at ctx->rsrc_node and anyhow modifying the node without holding uring_lock, grabbing references in such a way is not safe either.

Fixes 5106dd6e74ab6 ("io_uring: propagate issue_flags state down to file assignment")
---
 io_uring/rsrc.h | 12 +++++-------
 1 file changed, 5 insertions(+), 7 deletions(-)
io_uring/rsrc.h +5 -7
index 2b8743645efc..f27f4975217d 100644
@@ -144,15 +144,13 @@ static inline void io_req_set_rsrc_node(struct io_kiocb *req,
 					unsigned int issue_flags)
 {
 	if (!req->rsrc_node) {
-		req->rsrc_node = ctx->rsrc_node;
+		io_ring_submit_lock(ctx, issue_flags);
 
-		if (!(issue_flags & IO_URING_F_UNLOCKED)) {
-			lockdep_assert_held(&ctx->uring_lock);
+		lockdep_assert_held(&ctx->uring_lock);
 
-			io_charge_rsrc_node(ctx);
-		} else {
-			percpu_ref_get(&req->rsrc_node->refs);
-		}
+		req->rsrc_node = ctx->rsrc_node;
+		io_charge_rsrc_node(ctx);
+		io_ring_submit_unlock(ctx, issue_flags);
 	}
 }
 
Signature · 1 line
2.39.1
maintainer Applied
#1 lore raw
Quoted 5 lines · Pavel Begunkov

We should not be looking at ctx->rsrc_node and anyhow modifying the node without holding uring_lock, grabbing references in such a way is not safe either.

Applied, thanks!

[1/1] io_uring/rsrc: fix rogue rsrc node grabbing

      commit: 4ff0b50de8cabba055efe50bbcb7506c41a69835

Best regards,

Signature · 1 line
Jens Axboe