Skip to content

Commit 193155c

Browse files
committed
io_uring: handle multiple personalities in link chains
If we have a chain of requests and they don't all use the same credentials, then the head of the chain will be issued with the credentails of the tail of the chain. Ensure __io_queue_sqe() overrides the credentials, if they are different. Once we do that, we can clean up the creds handling as well, by only having io_submit_sqe() do the lookup of a personality. It doesn't need to assign it, since __io_queue_sqe() now always does the right thing. Fixes: 75c6a03 ("io_uring: support using a registered personality for commands") Reported-by: Pavel Begunkov <[email protected]> Signed-off-by: Jens Axboe <[email protected]>
1 parent f8788d8 commit 193155c

File tree

1 file changed

+15
-10
lines changed

1 file changed

+15
-10
lines changed

fs/io_uring.c

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4705,11 +4705,21 @@ static void __io_queue_sqe(struct io_kiocb *req, const struct io_uring_sqe *sqe)
47054705
{
47064706
struct io_kiocb *linked_timeout;
47074707
struct io_kiocb *nxt = NULL;
4708+
const struct cred *old_creds = NULL;
47084709
int ret;
47094710

47104711
again:
47114712
linked_timeout = io_prep_linked_timeout(req);
47124713

4714+
if (req->work.creds && req->work.creds != current_cred()) {
4715+
if (old_creds)
4716+
revert_creds(old_creds);
4717+
if (old_creds == req->work.creds)
4718+
old_creds = NULL; /* restored original creds */
4719+
else
4720+
old_creds = override_creds(req->work.creds);
4721+
}
4722+
47134723
ret = io_issue_sqe(req, sqe, &nxt, true);
47144724

47154725
/*
@@ -4759,6 +4769,8 @@ static void __io_queue_sqe(struct io_kiocb *req, const struct io_uring_sqe *sqe)
47594769
goto punt;
47604770
goto again;
47614771
}
4772+
if (old_creds)
4773+
revert_creds(old_creds);
47624774
}
47634775

47644776
static void io_queue_sqe(struct io_kiocb *req, const struct io_uring_sqe *sqe)
@@ -4803,7 +4815,6 @@ static inline void io_queue_link_head(struct io_kiocb *req)
48034815
static bool io_submit_sqe(struct io_kiocb *req, const struct io_uring_sqe *sqe,
48044816
struct io_submit_state *state, struct io_kiocb **link)
48054817
{
4806-
const struct cred *old_creds = NULL;
48074818
struct io_ring_ctx *ctx = req->ctx;
48084819
unsigned int sqe_flags;
48094820
int ret, id;
@@ -4818,14 +4829,12 @@ static bool io_submit_sqe(struct io_kiocb *req, const struct io_uring_sqe *sqe,
48184829

48194830
id = READ_ONCE(sqe->personality);
48204831
if (id) {
4821-
const struct cred *personality_creds;
4822-
4823-
personality_creds = idr_find(&ctx->personality_idr, id);
4824-
if (unlikely(!personality_creds)) {
4832+
req->work.creds = idr_find(&ctx->personality_idr, id);
4833+
if (unlikely(!req->work.creds)) {
48254834
ret = -EINVAL;
48264835
goto err_req;
48274836
}
4828-
old_creds = override_creds(personality_creds);
4837+
get_cred(req->work.creds);
48294838
}
48304839

48314840
/* same numerical values with corresponding REQ_F_*, safe to copy */
@@ -4837,8 +4846,6 @@ static bool io_submit_sqe(struct io_kiocb *req, const struct io_uring_sqe *sqe,
48374846
err_req:
48384847
io_cqring_add_event(req, ret);
48394848
io_double_put_req(req);
4840-
if (old_creds)
4841-
revert_creds(old_creds);
48424849
return false;
48434850
}
48444851

@@ -4899,8 +4906,6 @@ static bool io_submit_sqe(struct io_kiocb *req, const struct io_uring_sqe *sqe,
48994906
}
49004907
}
49014908

4902-
if (old_creds)
4903-
revert_creds(old_creds);
49044909
return true;
49054910
}
49064911

0 commit comments

Comments
 (0)