Skip to contentSkip to conversation

io_uring: gate personality per opcode to fix TOCTOU check in io_msg_ring_prep

PATCH In review clingfei 2 participants 5 messages Jan 25 – Jan 27 io_uring

lore
Share & tools
lore

clingfei

author
#0 lore raw

PATCH 1/1 io_uring: gate personality per opcode to fix TOCTOU check in io_msg_ring_prep

From: Cheng Lingfei <[email protected]>

Add allow_personality io_issue_def and reject personality use in io_init_req for opcodes that do not permit it. This fixes a TOCTOU window in the prior implementation: userspace could race-update sqe->personality and bypass the __io_msg_ring_prep personality check.

---
 io_uring/io_uring.c |  2 ++
 io_uring/msg_ring.c |  2 +-
 io_uring/opdef.c    | 64 +++++++++++++++++++++++++++++++++++++++++++++
 io_uring/opdef.h    |  2 ++
 4 files changed, 69 insertions(+), 1 deletion(-)
io_uring/io_uring.c +2 -0
index b7a077c11c21..7a898b19a340 100644
@@ -2219,6 +2219,8 @@ static int io_init_req(struct io_ring_ctx *ctx, struct io_kiocb *req,
 	personality = READ_ONCE(sqe->personality);
 	if (personality) {
 		int ret;
+		if (unlikely(!def->allow_personality))
+			return -EINVAL;
 
 		req->creds = xa_load(&ctx->personalities, personality);
 		if (!req->creds)
io_uring/msg_ring.c +1 -1
index 7063ea7964e7..758635753da6 100644
@@ -260,7 +260,7 @@ static int io_msg_send_fd(struct io_kiocb *req, unsigned int issue_flags)
 
 static int __io_msg_ring_prep(struct io_msg *msg, const struct io_uring_sqe *sqe)
 {
-	if (unlikely(sqe->buf_index || sqe->personality))
+	if (unlikely(sqe->buf_index))
 		return -EINVAL;
 
 	msg->src_file = NULL;
io_uring/opdef.c +64 -0

420 lines not on this page · raw message

io_uring/opdef.h +2 -0
index aa37846880ff..f4a98339aa79 100644
@@ -29,6 +29,8 @@ struct io_issue_def {
 	unsigned		vectored : 1;
 	/* set to 1 if this opcode uses 128b sqes in a mixed sq */
 	unsigned		is_128 : 1;
+	/* set to 1 if this opcode allows using personality */
+	unsigned    allow_personality : 1;
 
 	/* size of async data needed, if any */
 	unsigned short		async_size;
Signature · 1 line
2.34.1
maintainer
#1 lore raw
Quoted 6 lines · clingfei

From: Cheng Lingfei <[email protected]>

Add allow_personality io_issue_def and reject personality use in io_init_req for opcodes that do not permit it. This fixes a TOCTOU window in the prior implementation: userspace could race-update sqe->personality and bypass the __io_msg_ring_prep personality check.

Please do detail what the bug is here, this looks like some kind of AI hallucination. The check in msg_ring prep exists just to reject commands with it set, for future expansion. The only thing that matters is the ordering and use in io_init_req(), which is fine.

Signature · 1 line
Jens Axboe
author
#2 lore raw
Quoted 9 lines · Jens Axboe <[email protected]> 于2026年1月25日周日 22:16写道:
Quoted 6 lines · clingfei

From: Cheng Lingfei <[email protected]>

Add allow_personality io_issue_def and reject personality use in io_init_req for opcodes that do not permit it. This fixes a TOCTOU window in the prior implementation: userspace could race-update sqe->personality and bypass the __io_msg_ring_prep personality check.

Quoted 8 lines

Please do detail what the bug is here, this looks like some kind of AI hallucination. The check in msg_ring prep exists just to reject commands with it set, for future expansion. The only thing that matters is the ordering and use in io_init_req(), which is fine.

--
Jens Axboe

Sorry, I forgot to reply to all in the previous email.

The io_init_req checks sqe->personality; if personality is not zero, req->creds is initialized based on personality. The msg_ring prep also checks sqe->personality and rejects non-zero personality values. However, sqe is shared between the kernel and userspace. This means a user can submit a msg_ring SQE with a non-zero personality. After passing the check in io_init_req, the user process can concurrently modify personality to set it to 0,
thus enabling it to pass the check in msg_ring prep and invalidating its rejection
of non-zero personality values.

This is not an AI hallucination, and it can be demonstrated by a userspace PoC.

maintainer
#3 lore raw
Quoted 20 lines · clingfei

Jens Axboe <[email protected]> ?2026?1?25??? 22:16???

Quoted 9 lines · clingfei
Quoted 6 lines

From: Cheng Lingfei <[email protected]>

Add allow_personality io_issue_def and reject personality use in io_init_req for opcodes that do not permit it. This fixes a TOCTOU window in the prior implementation: userspace could race-update sqe->personality and bypass the __io_msg_ring_prep personality check.

Quoted 8 lines

Please do detail what the bug is here, this looks like some kind of AI hallucination. The check in msg_ring prep exists just to reject commands with it set, for future expansion. The only thing that matters is the ordering and use in io_init_req(), which is fine.

--
Jens Axboe

Sorry, I forgot to reply to all in the previous email.

Quoted 10 lines

The io_init_req checks sqe->personality; if personality is not zero, req->creds is initialized based on personality. The msg_ring prep also checks sqe->personality and rejects non-zero personality values. However, sqe is shared between the kernel and userspace. This means a user can submit a msg_ring SQE with a non-zero personality. After passing the check in io_init_req, the user process can concurrently modify personality to set it to 0,
thus enabling it to pass the check in msg_ring prep and invalidating its rejection
of non-zero personality values.

I'm not disputing you can't change ->personality between io_init_req() and __io_msg_ring_prep(), that's obviously possible. I'm saying that it doesn't matter one bit at all, as the check in __io_msg_ring_prep() is just there for future proofing. If the application knowingly changes the SQE post submit to defeat an -EINVAL return, then yes it'll defeat the future proofing. But so what? If you look at other prep handlers, the -EINVAL checks never made any attempts at protecting against this scenario, as it's only there for future proofing.

IOW, you could just remove this check in __io_msg_ring_prep() and it'd be fine. Or just leave it alone, because it really doesn't serve a purpose.

Quoted 2 lines

This is not an AI hallucination, and it can be demonstrated by a userspace PoC.

It does read like one, however... Including this reply.

Signature · 1 line
Jens Axboe
author
#4 lore raw
Quoted 42 lines · Jens Axboe <[email protected]> 于2026年1月26日周一 20:36写道:
Quoted 20 lines · clingfei

Jens Axboe <[email protected]> ?2026?1?25??? 22:16???

Quoted 9 lines · clingfei
Quoted 6 lines

From: Cheng Lingfei <[email protected]>

Add allow_personality io_issue_def and reject personality use in io_init_req for opcodes that do not permit it. This fixes a TOCTOU window in the prior implementation: userspace could race-update sqe->personality and bypass the __io_msg_ring_prep personality check.

Quoted 8 lines

Please do detail what the bug is here, this looks like some kind of AI hallucination. The check in msg_ring prep exists just to reject commands with it set, for future expansion. The only thing that matters is the ordering and use in io_init_req(), which is fine.

--
Jens Axboe

Sorry, I forgot to reply to all in the previous email.

Quoted 10 lines

The io_init_req checks sqe->personality; if personality is not zero, req->creds is initialized based on personality. The msg_ring prep also checks sqe->personality and rejects non-zero personality values. However, sqe is shared between the kernel and userspace. This means a user can submit a msg_ring SQE with a non-zero personality. After passing the check in io_init_req, the user process can concurrently modify personality to set it to 0,
thus enabling it to pass the check in msg_ring prep and invalidating its rejection
of non-zero personality values.

I'm not disputing you can't change ->personality between io_init_req() and __io_msg_ring_prep(), that's obviously possible. I'm saying that it doesn't matter one bit at all, as the check in __io_msg_ring_prep() is just there for future proofing. If the application knowingly changes the SQE post submit to defeat an -EINVAL return, then yes it'll defeat the future proofing. But so what? If you look at other prep handlers, the -EINVAL checks never made any attempts at protecting against this scenario, as it's only there for future proofing.

Quoted 4 lines

IOW, you could just remove this check in __io_msg_ring_prep() and it'd be fine. Or just leave it alone, because it really doesn't serve a purpose.

Thanks for your patient reply.

I agree that this does not matter since it cannot be leveraged for further exploitation.
Initially, I read the Linux 6.6 version of the code, which can only affect fpl->user
in __io_scm_file_account when the cred is substituted with another process's. However, I found that this portion has been removed in the latest kernel version...

By the way, I did read other prep handlers’ code, but almost none included a similar double-check that could be bypassed in the same manner, which is why I find this a bit strange.

Quoted 7 lines
Quoted 2 lines

This is not an AI hallucination, and it can be demonstrated by a userspace PoC.

It does read like one, however... Including this reply.

--
Jens Axboe