linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 1/1] io_uring: fix lockup with timeouts
@ 2020-03-06 22:15 Pavel Begunkov
  2020-03-07 15:36 ` Jens Axboe
  0 siblings, 1 reply; 2+ messages in thread
From: Pavel Begunkov @ 2020-03-06 22:15 UTC (permalink / raw)
  To: Jens Axboe, io-uring, linux-kernel

There is a recipe to deadlock the kernel: submit a timeout sqe with a
linked_timeout (e.g.  test_single_link_timeout_ception() from liburing),
and SIGKILL the process.

Then, io_kill_timeouts() takes @ctx->completion_lock, but the timeout
isn't flagged with REQ_F_COMP_LOCKED, and will try to double grab it
during io_put_free() to cancel the linked timeout. Probably, the same
can happen with another io_kill_timeout() call site, that is
io_commit_cqring().

Signed-off-by: Pavel Begunkov <asml.silence@gmail.com>
---
 fs/io_uring.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/fs/io_uring.c b/fs/io_uring.c
index 104f76aace29..94eca92d1354 100644
--- a/fs/io_uring.c
+++ b/fs/io_uring.c
@@ -1089,6 +1089,7 @@ static void io_kill_timeout(struct io_kiocb *req)
 	if (ret != -1) {
 		atomic_inc(&req->ctx->cq_timeouts);
 		list_del_init(&req->list);
+		req->flags |= REQ_F_COMP_LOCKED;
 		io_cqring_fill_event(req, 0);
 		io_put_req(req);
 	}
-- 
2.24.0


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

* Re: [PATCH 1/1] io_uring: fix lockup with timeouts
  2020-03-06 22:15 [PATCH 1/1] io_uring: fix lockup with timeouts Pavel Begunkov
@ 2020-03-07 15:36 ` Jens Axboe
  0 siblings, 0 replies; 2+ messages in thread
From: Jens Axboe @ 2020-03-07 15:36 UTC (permalink / raw)
  To: Pavel Begunkov, io-uring, linux-kernel

On 3/6/20 3:15 PM, Pavel Begunkov wrote:
> There is a recipe to deadlock the kernel: submit a timeout sqe with a
> linked_timeout (e.g.  test_single_link_timeout_ception() from liburing),
> and SIGKILL the process.
> 
> Then, io_kill_timeouts() takes @ctx->completion_lock, but the timeout
> isn't flagged with REQ_F_COMP_LOCKED, and will try to double grab it
> during io_put_free() to cancel the linked timeout. Probably, the same
> can happen with another io_kill_timeout() call site, that is
> io_commit_cqring().

Thanks, looks good, applied.

-- 
Jens Axboe


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

end of thread, other threads:[~2020-03-07 15:36 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-03-06 22:15 [PATCH 1/1] io_uring: fix lockup with timeouts Pavel Begunkov
2020-03-07 15:36 ` Jens Axboe

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).