* io_msg_remote_post() sets up dangling pointer (but it is never accessed)?
@ 2025-01-21 23:41 Jann Horn
2025-01-21 23:44 ` Jann Horn
2025-01-22 23:56 ` Jens Axboe
0 siblings, 2 replies; 3+ messages in thread
From: Jann Horn @ 2025-01-21 23:41 UTC (permalink / raw)
To: Jens Axboe; +Cc: io-uring, kernel list
Hi!
I think the following statement in io_msg_remote_post():
req->tctx = READ_ONCE(ctx->submitter_task->io_uring);
sets req->tctx to a pointer that may immediately become dangling if
the ctx->submitter_task concurrently goes through execve() including
the call path:
begin_new_exec -> io_uring_task_cancel -> __io_uring_cancel(true) ->
io_uring_cancel_generic(true, ...) -> __io_uring_free()
However, I can't find any codepath that can actually dereference the
req->tctx of such a ring message; and I did some quick test under
KASAN, and that also did not reveal any issue.
I think the current code is probably fine, but it would be nice if we
could avoid having a potentially dangling pointer here. Can we NULL
out the req->tctx in io_msg_remote_post(), or is that actually used
for some pointer comparison or such?
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: io_msg_remote_post() sets up dangling pointer (but it is never accessed)?
2025-01-21 23:41 io_msg_remote_post() sets up dangling pointer (but it is never accessed)? Jann Horn
@ 2025-01-21 23:44 ` Jann Horn
2025-01-22 23:56 ` Jens Axboe
1 sibling, 0 replies; 3+ messages in thread
From: Jann Horn @ 2025-01-21 23:44 UTC (permalink / raw)
To: Jens Axboe; +Cc: io-uring, kernel list
On Wed, Jan 22, 2025 at 12:41 AM Jann Horn <[email protected]> wrote:
> I think the following statement in io_msg_remote_post():
>
> req->tctx = READ_ONCE(ctx->submitter_task->io_uring);
>
> sets req->tctx to a pointer that may immediately become dangling if
> the ctx->submitter_task concurrently goes through execve() including
> the call path:
>
> begin_new_exec -> io_uring_task_cancel -> __io_uring_cancel(true) ->
> io_uring_cancel_generic(true, ...) -> __io_uring_free()
>
> However, I can't find any codepath that can actually dereference the
> req->tctx of such a ring message; and I did some quick test under
> KASAN, and that also did not reveal any issue.
>
> I think the current code is probably fine, but it would be nice if we
> could avoid having a potentially dangling pointer here. Can we NULL
> out the req->tctx in io_msg_remote_post(), or is that actually used
> for some pointer comparison or such?
This seems to have been the case since commit
b6f58a3f4aa8dba424356c7a69388a81f4459300 ("io_uring: move struct
io_kiocb from task_struct to io_uring_task").
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: io_msg_remote_post() sets up dangling pointer (but it is never accessed)?
2025-01-21 23:41 io_msg_remote_post() sets up dangling pointer (but it is never accessed)? Jann Horn
2025-01-21 23:44 ` Jann Horn
@ 2025-01-22 23:56 ` Jens Axboe
1 sibling, 0 replies; 3+ messages in thread
From: Jens Axboe @ 2025-01-22 23:56 UTC (permalink / raw)
To: Jann Horn; +Cc: io-uring, kernel list
On 1/21/25 4:41 PM, Jann Horn wrote:
> Hi!
>
> I think the following statement in io_msg_remote_post():
>
> req->tctx = READ_ONCE(ctx->submitter_task->io_uring);
>
> sets req->tctx to a pointer that may immediately become dangling if
> the ctx->submitter_task concurrently goes through execve() including
> the call path:
>
> begin_new_exec -> io_uring_task_cancel -> __io_uring_cancel(true) ->
> io_uring_cancel_generic(true, ...) -> __io_uring_free()
>
> However, I can't find any codepath that can actually dereference the
> req->tctx of such a ring message; and I did some quick test under
> KASAN, and that also did not reveal any issue.
>
> I think the current code is probably fine, but it would be nice if we
> could avoid having a potentially dangling pointer here. Can we NULL
> out the req->tctx in io_msg_remote_post(), or is that actually used
> for some pointer comparison or such?
Yep that should just go away, I'll send out a patch.
--
Jens Axboe
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2025-01-22 23:56 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-01-21 23:41 io_msg_remote_post() sets up dangling pointer (but it is never accessed)? Jann Horn
2025-01-21 23:44 ` Jann Horn
2025-01-22 23:56 ` Jens Axboe
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox