2024-04-26 03:29:57

by linke li

[permalink] [raw]
Subject: [PATCH] io_uring/msg_ring: reuse ctx->submitter_task read using READ_ONCE instead of re-reading it

In io_msg_exec_remote(), ctx->submitter_task is read using READ_ONCE at
the beginning of the function, checked, and then re-read from
ctx->submitter_task, voiding all guarantees of the checks. Reuse the value
that was read by READ_ONCE to ensure the consistency of the task struct
throughout the function.

Signed-off-by: linke li <[email protected]>
---
io_uring/msg_ring.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/io_uring/msg_ring.c b/io_uring/msg_ring.c
index cd6dcf634ba3..d74670b39ed6 100644
--- a/io_uring/msg_ring.c
+++ b/io_uring/msg_ring.c
@@ -83,7 +83,7 @@ static int io_msg_exec_remote(struct io_kiocb *req, task_work_func_t func)
return -EOWNERDEAD;

init_task_work(&msg->tw, func);
- if (task_work_add(ctx->submitter_task, &msg->tw, TWA_SIGNAL))
+ if (task_work_add(task, &msg->tw, TWA_SIGNAL))
return -EOWNERDEAD;

return IOU_ISSUE_SKIP_COMPLETE;
--
2.39.3 (Apple Git-146)



2024-04-26 13:41:14

by Jens Axboe

[permalink] [raw]
Subject: Re: [PATCH] io_uring/msg_ring: reuse ctx->submitter_task read using READ_ONCE instead of re-reading it


On Fri, 26 Apr 2024 11:24:37 +0800, linke li wrote:
> In io_msg_exec_remote(), ctx->submitter_task is read using READ_ONCE at
> the beginning of the function, checked, and then re-read from
> ctx->submitter_task, voiding all guarantees of the checks. Reuse the value
> that was read by READ_ONCE to ensure the consistency of the task struct
> throughout the function.
>
>
> [...]

Applied, thanks!

[1/1] io_uring/msg_ring: reuse ctx->submitter_task read using READ_ONCE instead of re-reading it
commit: a4d416dc60980f741f0bfa1f34a1059c498c1b4e

Best regards,
--
Jens Axboe