Skip to content

Commit 67e0870

Browse files
isilencegregkh
authored andcommitted
io_uring: fix cancellation overwriting req->flags
commit f4a1254 upstream. Only the current owner of a request is allowed to write into req->flags. Hence, the cancellation path should never touch it. Add a new field instead of the flag, move it into the 3rd cache line because it should always be initialised. poll_refs can move further as polling is an involved process anyway. It's a minimal patch, in the future we can and should find a better place for it and remove now unused REQ_F_CANCEL_SEQ. Fixes: 521223d ("io_uring/cancel: don't default to setting req->work.cancel_seq") Cc: [email protected] Reported-by: Li Shi <[email protected]> Signed-off-by: Pavel Begunkov <[email protected]> Link: https://lore.kernel.org/r/6827b129f8f0ad76fa9d1f0a773de938b240ffab.1718323430.git.asml.silence@gmail.com Signed-off-by: Jens Axboe <[email protected]> Signed-off-by: Greg Kroah-Hartman <[email protected]>
1 parent 4429c6c commit 67e0870

File tree

3 files changed

+5
-3
lines changed

3 files changed

+5
-3
lines changed

include/linux/io_uring_types.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -653,7 +653,7 @@ struct io_kiocb {
653653
struct io_rsrc_node *rsrc_node;
654654

655655
atomic_t refs;
656-
atomic_t poll_refs;
656+
bool cancel_seq_set;
657657
struct io_task_work io_task_work;
658658
/* for polled requests, i.e. IORING_OP_POLL_ADD and async armed poll */
659659
struct hlist_node hash_node;
@@ -662,6 +662,7 @@ struct io_kiocb {
662662
/* opcode allocated if it needs to store data for async defer */
663663
void *async_data;
664664
/* linked requests, IFF REQ_F_HARDLINK or REQ_F_LINK are set */
665+
atomic_t poll_refs;
665666
struct io_kiocb *link;
666667
/* custom credentials, valid IFF REQ_F_CREDS is set */
667668
const struct cred *creds;

io_uring/cancel.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,10 +27,10 @@ bool io_cancel_req_match(struct io_kiocb *req, struct io_cancel_data *cd);
2727

2828
static inline bool io_cancel_match_sequence(struct io_kiocb *req, int sequence)
2929
{
30-
if ((req->flags & REQ_F_CANCEL_SEQ) && sequence == req->work.cancel_seq)
30+
if (req->cancel_seq_set && sequence == req->work.cancel_seq)
3131
return true;
3232

33-
req->flags |= REQ_F_CANCEL_SEQ;
33+
req->cancel_seq_set = true;
3434
req->work.cancel_seq = sequence;
3535
return false;
3636
}

io_uring/io_uring.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2211,6 +2211,7 @@ static int io_init_req(struct io_ring_ctx *ctx, struct io_kiocb *req,
22112211
req->file = NULL;
22122212
req->rsrc_node = NULL;
22132213
req->task = current;
2214+
req->cancel_seq_set = false;
22142215

22152216
if (unlikely(opcode >= IORING_OP_LAST)) {
22162217
req->opcode = 0;

0 commit comments

Comments
 (0)