Skip to content

Commit dea3b49

Browse files
isilenceaxboe
authored andcommitted
io_uring: keep all sqe->flags in req->flags
It's a good idea to not read sqe->flags twice, as it's prone to security bugs. Instead of passing it around, embeed them in req->flags. It's already so except for IOSQE_IO_LINK. 1. rename former REQ_F_LINK -> REQ_F_LINK_HEAD 2. introduce and copy REQ_F_LINK, which mimics IO_IOSQE_LINK And leave req_set_fail_links() using new REQ_F_LINK, because it's more sensible. Signed-off-by: Pavel Begunkov <[email protected]> Signed-off-by: Jens Axboe <[email protected]>
1 parent 1d4240c commit dea3b49

File tree

1 file changed

+13
-10
lines changed

1 file changed

+13
-10
lines changed

fs/io_uring.c

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -508,6 +508,7 @@ enum {
508508
REQ_F_FORCE_ASYNC_BIT = IOSQE_ASYNC_BIT,
509509
REQ_F_BUFFER_SELECT_BIT = IOSQE_BUFFER_SELECT_BIT,
510510

511+
REQ_F_LINK_HEAD_BIT,
511512
REQ_F_LINK_NEXT_BIT,
512513
REQ_F_FAIL_LINK_BIT,
513514
REQ_F_INFLIGHT_BIT,
@@ -543,6 +544,8 @@ enum {
543544
/* IOSQE_BUFFER_SELECT */
544545
REQ_F_BUFFER_SELECT = BIT(REQ_F_BUFFER_SELECT_BIT),
545546

547+
/* head of a link */
548+
REQ_F_LINK_HEAD = BIT(REQ_F_LINK_HEAD_BIT),
546549
/* already grabbed next link */
547550
REQ_F_LINK_NEXT = BIT(REQ_F_LINK_NEXT_BIT),
548551
/* fail rest of links */
@@ -1437,7 +1440,7 @@ static bool io_link_cancel_timeout(struct io_kiocb *req)
14371440
if (ret != -1) {
14381441
io_cqring_fill_event(req, -ECANCELED);
14391442
io_commit_cqring(ctx);
1440-
req->flags &= ~REQ_F_LINK;
1443+
req->flags &= ~REQ_F_LINK_HEAD;
14411444
io_put_req(req);
14421445
return true;
14431446
}
@@ -1473,7 +1476,7 @@ static void io_req_link_next(struct io_kiocb *req, struct io_kiocb **nxtptr)
14731476

14741477
list_del_init(&req->link_list);
14751478
if (!list_empty(&nxt->link_list))
1476-
nxt->flags |= REQ_F_LINK;
1479+
nxt->flags |= REQ_F_LINK_HEAD;
14771480
*nxtptr = nxt;
14781481
break;
14791482
}
@@ -1484,7 +1487,7 @@ static void io_req_link_next(struct io_kiocb *req, struct io_kiocb **nxtptr)
14841487
}
14851488

14861489
/*
1487-
* Called if REQ_F_LINK is set, and we fail the head request
1490+
* Called if REQ_F_LINK_HEAD is set, and we fail the head request
14881491
*/
14891492
static void io_fail_links(struct io_kiocb *req)
14901493
{
@@ -1517,7 +1520,7 @@ static void io_fail_links(struct io_kiocb *req)
15171520

15181521
static void io_req_find_next(struct io_kiocb *req, struct io_kiocb **nxt)
15191522
{
1520-
if (likely(!(req->flags & REQ_F_LINK)))
1523+
if (likely(!(req->flags & REQ_F_LINK_HEAD)))
15211524
return;
15221525

15231526
/*
@@ -1669,7 +1672,7 @@ static inline unsigned int io_sqring_entries(struct io_ring_ctx *ctx)
16691672

16701673
static inline bool io_req_multi_free(struct req_batch *rb, struct io_kiocb *req)
16711674
{
1672-
if ((req->flags & REQ_F_LINK) || io_is_fallback_req(req))
1675+
if ((req->flags & REQ_F_LINK_HEAD) || io_is_fallback_req(req))
16731676
return false;
16741677

16751678
if (!(req->flags & REQ_F_FIXED_FILE) || req->io)
@@ -2562,7 +2565,7 @@ static int io_read(struct io_kiocb *req, bool force_nonblock)
25622565

25632566
req->result = 0;
25642567
io_size = ret;
2565-
if (req->flags & REQ_F_LINK)
2568+
if (req->flags & REQ_F_LINK_HEAD)
25662569
req->result = io_size;
25672570

25682571
/*
@@ -2653,7 +2656,7 @@ static int io_write(struct io_kiocb *req, bool force_nonblock)
26532656

26542657
req->result = 0;
26552658
io_size = ret;
2656-
if (req->flags & REQ_F_LINK)
2659+
if (req->flags & REQ_F_LINK_HEAD)
26572660
req->result = io_size;
26582661

26592662
/*
@@ -5476,7 +5479,7 @@ static struct io_kiocb *io_prep_linked_timeout(struct io_kiocb *req)
54765479
{
54775480
struct io_kiocb *nxt;
54785481

5479-
if (!(req->flags & REQ_F_LINK))
5482+
if (!(req->flags & REQ_F_LINK_HEAD))
54805483
return NULL;
54815484
/* for polled retry, if flag is set, we already went through here */
54825485
if (req->flags & REQ_F_POLLED)
@@ -5636,7 +5639,7 @@ static int io_submit_sqe(struct io_kiocb *req, const struct io_uring_sqe *sqe,
56365639
/* same numerical values with corresponding REQ_F_*, safe to copy */
56375640
req->flags |= sqe_flags & (IOSQE_IO_DRAIN | IOSQE_IO_HARDLINK |
56385641
IOSQE_ASYNC | IOSQE_FIXED_FILE |
5639-
IOSQE_BUFFER_SELECT);
5642+
IOSQE_BUFFER_SELECT | IOSQE_IO_LINK);
56405643

56415644
fd = READ_ONCE(sqe->fd);
56425645
ret = io_req_set_file(state, req, fd, sqe_flags);
@@ -5687,7 +5690,7 @@ static int io_submit_sqe(struct io_kiocb *req, const struct io_uring_sqe *sqe,
56875690
req->ctx->drain_next = 0;
56885691
}
56895692
if (sqe_flags & (IOSQE_IO_LINK|IOSQE_IO_HARDLINK)) {
5690-
req->flags |= REQ_F_LINK;
5693+
req->flags |= REQ_F_LINK_HEAD;
56915694
INIT_LIST_HEAD(&req->link_list);
56925695

56935696
if (io_alloc_async_ctx(req))

0 commit comments

Comments
 (0)