* [PATCHSET 0/2] Fix SQPOLL tctx allocation failure handling
@ 2025-06-17 12:48 Jens Axboe
2025-06-17 12:48 ` [PATCH 1/2] io_uring: remove duplicate io_uring_alloc_task_context() definition Jens Axboe
2025-06-17 12:48 ` [PATCH 2/2] io_uring/sqpoll: don't put task_struct on tctx setup failure Jens Axboe
0 siblings, 2 replies; 3+ messages in thread
From: Jens Axboe @ 2025-06-17 12:48 UTC (permalink / raw)
To: io-uring
Hi,
Just a basic prep patch cleaning up something I spotted while looking
at the report, and then patch 2 that fixes a recent regression due to
missing the sqpoll.c error handling.
--
Jens Axboe
^ permalink raw reply [flat|nested] 3+ messages in thread
* [PATCH 1/2] io_uring: remove duplicate io_uring_alloc_task_context() definition
2025-06-17 12:48 [PATCHSET 0/2] Fix SQPOLL tctx allocation failure handling Jens Axboe
@ 2025-06-17 12:48 ` Jens Axboe
2025-06-17 12:48 ` [PATCH 2/2] io_uring/sqpoll: don't put task_struct on tctx setup failure Jens Axboe
1 sibling, 0 replies; 3+ messages in thread
From: Jens Axboe @ 2025-06-17 12:48 UTC (permalink / raw)
To: io-uring; +Cc: Jens Axboe
This function exists in both tctx.h (where it belongs) and in io_uring.h
as a remnant of before the tctx handling code got split out. Remove the
io_uring.h definition and ensure that sqpoll.c includes the tctx.h
header to get the definition.
Signed-off-by: Jens Axboe <axboe@kernel.dk>
---
io_uring/io_uring.h | 2 --
io_uring/sqpoll.c | 1 +
2 files changed, 1 insertion(+), 2 deletions(-)
diff --git a/io_uring/io_uring.h b/io_uring/io_uring.h
index d59c12277d58..66c1ca73f55e 100644
--- a/io_uring/io_uring.h
+++ b/io_uring/io_uring.h
@@ -98,8 +98,6 @@ struct llist_node *io_handle_tw_list(struct llist_node *node, unsigned int *coun
struct llist_node *tctx_task_work_run(struct io_uring_task *tctx, unsigned int max_entries, unsigned int *count);
void tctx_task_work(struct callback_head *cb);
__cold void io_uring_cancel_generic(bool cancel_all, struct io_sq_data *sqd);
-int io_uring_alloc_task_context(struct task_struct *task,
- struct io_ring_ctx *ctx);
int io_ring_add_registered_file(struct io_uring_task *tctx, struct file *file,
int start, int end);
diff --git a/io_uring/sqpoll.c b/io_uring/sqpoll.c
index 268d2fbe6160..fa5a6750ee52 100644
--- a/io_uring/sqpoll.c
+++ b/io_uring/sqpoll.c
@@ -16,6 +16,7 @@
#include <uapi/linux/io_uring.h>
#include "io_uring.h"
+#include "tctx.h"
#include "napi.h"
#include "sqpoll.h"
--
2.50.0
^ permalink raw reply related [flat|nested] 3+ messages in thread
* [PATCH 2/2] io_uring/sqpoll: don't put task_struct on tctx setup failure
2025-06-17 12:48 [PATCHSET 0/2] Fix SQPOLL tctx allocation failure handling Jens Axboe
2025-06-17 12:48 ` [PATCH 1/2] io_uring: remove duplicate io_uring_alloc_task_context() definition Jens Axboe
@ 2025-06-17 12:48 ` Jens Axboe
1 sibling, 0 replies; 3+ messages in thread
From: Jens Axboe @ 2025-06-17 12:48 UTC (permalink / raw)
To: io-uring; +Cc: Jens Axboe, syzbot+763e12bbf004fb1062e4
A recent commit moved the error handling of sqpoll thread and tctx
failures into the thread itself, as part of fixing an issue. However, it
missed that tctx allocation may also fail, and that
io_sq_offload_create() does its own error handling for the task_struct
in that case.
Remove the manual task putting in io_sq_offload_create(), as
io_sq_thread() will notice that the tctx did not get setup and hence it
should put itself and exit.
Reported-by: syzbot+763e12bbf004fb1062e4@syzkaller.appspotmail.com
Fixes: ac0b8b327a56 ("io_uring: fix use-after-free of sq->thread in __io_uring_show_fdinfo()")
Signed-off-by: Jens Axboe <axboe@kernel.dk>
---
io_uring/sqpoll.c | 5 +----
1 file changed, 1 insertion(+), 4 deletions(-)
diff --git a/io_uring/sqpoll.c b/io_uring/sqpoll.c
index fa5a6750ee52..a3f11349ce06 100644
--- a/io_uring/sqpoll.c
+++ b/io_uring/sqpoll.c
@@ -420,7 +420,6 @@ void io_sqpoll_wait_sq(struct io_ring_ctx *ctx)
__cold int io_sq_offload_create(struct io_ring_ctx *ctx,
struct io_uring_params *p)
{
- struct task_struct *task_to_put = NULL;
int ret;
/* Retain compatibility with failing for an invalid attach attempt */
@@ -499,7 +498,7 @@ __cold int io_sq_offload_create(struct io_ring_ctx *ctx,
rcu_assign_pointer(sqd->thread, tsk);
mutex_unlock(&sqd->lock);
- task_to_put = get_task_struct(tsk);
+ get_task_struct(tsk);
ret = io_uring_alloc_task_context(tsk, ctx);
wake_up_new_task(tsk);
if (ret)
@@ -514,8 +513,6 @@ __cold int io_sq_offload_create(struct io_ring_ctx *ctx,
complete(&ctx->sq_data->exited);
err:
io_sq_thread_finish(ctx);
- if (task_to_put)
- put_task_struct(task_to_put);
return ret;
}
--
2.50.0
^ permalink raw reply related [flat|nested] 3+ messages in thread
end of thread, other threads:[~2025-06-17 12:49 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-06-17 12:48 [PATCHSET 0/2] Fix SQPOLL tctx allocation failure handling Jens Axboe
2025-06-17 12:48 ` [PATCH 1/2] io_uring: remove duplicate io_uring_alloc_task_context() definition Jens Axboe
2025-06-17 12:48 ` [PATCH 2/2] io_uring/sqpoll: don't put task_struct on tctx setup failure Jens Axboe
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox