public inbox for [email protected]
 help / color / mirror / Atom feed
* [PATCH 1/1] io_uring: sqpoll: zero sqd->thread on tctx errors
@ 2025-01-10 14:31 Pavel Begunkov
  2025-01-10 14:34 ` Jens Axboe
  0 siblings, 1 reply; 2+ messages in thread
From: Pavel Begunkov @ 2025-01-10 14:31 UTC (permalink / raw)
  To: io-uring; +Cc: asml.silence, syzbot+3d92cfcfa84070b0a470

Syzkeller reports:

BUG: KASAN: slab-use-after-free in thread_group_cputime+0x409/0x700 kernel/sched/cputime.c:341
Read of size 8 at addr ffff88803578c510 by task syz.2.3223/27552
 Call Trace:
  <TASK>
  ...
  kasan_report+0x143/0x180 mm/kasan/report.c:602
  thread_group_cputime+0x409/0x700 kernel/sched/cputime.c:341
  thread_group_cputime_adjusted+0xa6/0x340 kernel/sched/cputime.c:639
  getrusage+0x1000/0x1340 kernel/sys.c:1863
  io_uring_show_fdinfo+0xdfe/0x1770 io_uring/fdinfo.c:197
  seq_show+0x608/0x770 fs/proc/fd.c:68
  ...

That's due to sqd->task not being cleared properly in cases where
SQPOLL task tctx setup fails.

Cc: [email protected]
Fixes: 1251d2025c3e1 ("io_uring/sqpoll: early exit thread if task_context wasn't allocated")
Reported-by: [email protected]
Signed-off-by: Pavel Begunkov <[email protected]>
---
 io_uring/sqpoll.c | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)

diff --git a/io_uring/sqpoll.c b/io_uring/sqpoll.c
index 6df5e649c413..5768e31e99b1 100644
--- a/io_uring/sqpoll.c
+++ b/io_uring/sqpoll.c
@@ -268,8 +268,12 @@ static int io_sq_thread(void *data)
 	DEFINE_WAIT(wait);
 
 	/* offload context creation failed, just exit */
-	if (!current->io_uring)
+	if (!current->io_uring) {
+		mutex_lock(&sqd->lock);
+		sqd->thread = NULL;
+		mutex_unlock(&sqd->lock);
 		goto err_out;
+	}
 
 	snprintf(buf, sizeof(buf), "iou-sqp-%d", sqd->task_pid);
 	set_task_comm(current, buf);
-- 
2.47.1


^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH 1/1] io_uring: sqpoll: zero sqd->thread on tctx errors
  2025-01-10 14:31 [PATCH 1/1] io_uring: sqpoll: zero sqd->thread on tctx errors Pavel Begunkov
@ 2025-01-10 14:34 ` Jens Axboe
  0 siblings, 0 replies; 2+ messages in thread
From: Jens Axboe @ 2025-01-10 14:34 UTC (permalink / raw)
  To: io-uring, Pavel Begunkov; +Cc: syzbot+3d92cfcfa84070b0a470


On Fri, 10 Jan 2025 14:31:23 +0000, Pavel Begunkov wrote:
> Syzkeller reports:
> 
> BUG: KASAN: slab-use-after-free in thread_group_cputime+0x409/0x700 kernel/sched/cputime.c:341
> Read of size 8 at addr ffff88803578c510 by task syz.2.3223/27552
>  Call Trace:
>   <TASK>
>   ...
>   kasan_report+0x143/0x180 mm/kasan/report.c:602
>   thread_group_cputime+0x409/0x700 kernel/sched/cputime.c:341
>   thread_group_cputime_adjusted+0xa6/0x340 kernel/sched/cputime.c:639
>   getrusage+0x1000/0x1340 kernel/sys.c:1863
>   io_uring_show_fdinfo+0xdfe/0x1770 io_uring/fdinfo.c:197
>   seq_show+0x608/0x770 fs/proc/fd.c:68
>   ...
> 
> [...]

Applied, thanks!

[1/1] io_uring: sqpoll: zero sqd->thread on tctx errors
      commit: 1593ed0d510769514b648e09f8b7b71cc7fc18ec

Best regards,
-- 
Jens Axboe




^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2025-01-10 14:34 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-01-10 14:31 [PATCH 1/1] io_uring: sqpoll: zero sqd->thread on tctx errors Pavel Begunkov
2025-01-10 14:34 ` Jens Axboe

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox