Skip to content

Commit dddca22

Browse files
isilenceaxboe
authored andcommitted
io_uring: dont overlap internal and user req flags
CQE flags take one byte that we store in req->flags together with other REQ_F_* internal flags. CQE flags are copied directly into req and then verified that requires some handling on failures, e.g. to make sure that that copy doesn't set some of the internal flags. Move all internal flags to take bits after the first byte, so we don't need extra handling and make it safer overall. Signed-off-by: Pavel Begunkov <asml.silence@gmail.com> Link: https://lore.kernel.org/r/b8b5b02d1ab9d786fcc7db4a3fe86db6b70b8987.1619536280.git.asml.silence@gmail.com Signed-off-by: Jens Axboe <axboe@kernel.dk>
1 parent 2840f71 commit dddca22

1 file changed

Lines changed: 3 additions & 6 deletions

File tree

fs/io_uring.c

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -702,7 +702,8 @@ enum {
702702
REQ_F_FORCE_ASYNC_BIT = IOSQE_ASYNC_BIT,
703703
REQ_F_BUFFER_SELECT_BIT = IOSQE_BUFFER_SELECT_BIT,
704704

705-
REQ_F_FAIL_LINK_BIT,
705+
/* first byte is taken by user flags, shift it to not overlap */
706+
REQ_F_FAIL_LINK_BIT = 8,
706707
REQ_F_INFLIGHT_BIT,
707708
REQ_F_CUR_POS_BIT,
708709
REQ_F_NOWAIT_BIT,
@@ -6503,14 +6504,10 @@ static int io_init_req(struct io_ring_ctx *ctx, struct io_kiocb *req,
65036504
req->work.creds = NULL;
65046505

65056506
/* enforce forwards compatibility on users */
6506-
if (unlikely(sqe_flags & ~SQE_VALID_FLAGS)) {
6507-
req->flags = 0;
6507+
if (unlikely(sqe_flags & ~SQE_VALID_FLAGS))
65086508
return -EINVAL;
6509-
}
6510-
65116509
if (unlikely(req->opcode >= IORING_OP_LAST))
65126510
return -EINVAL;
6513-
65146511
if (unlikely(!io_check_restriction(ctx, req, sqe_flags)))
65156512
return -EACCES;
65166513

0 commit comments

Comments
 (0)