From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-10.1 required=3.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,INCLUDES_PATCH,MAILING_LIST_MULTI,SIGNED_OFF_BY, SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 4DDA1C18E5B for ; Mon, 16 Mar 2020 02:40:12 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 16D2E205C9 for ; Mon, 16 Mar 2020 02:40:12 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1584326412; bh=cCg0M0loROU58Zt2BRB0MoP92hqsihIZYRkM3zwyyRk=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-ID:From; b=V0zLNDfSryoLudRKKSSdUpb1Xd46jfGwYMOJA4lJSn1uuVDp8JOkctZci8fHxKPiv BasLzjZe88tpKiM5T2of0Xn9WJHFP86v3hbk5x000hjM1PEslxatUI1zyX/7mjD3fM QER2Im8+GMX0M8pSaoX3fw1mpCUszdaKD7QnIxG0= Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729783AbgCPCeK (ORCPT ); Sun, 15 Mar 2020 22:34:10 -0400 Received: from mail.kernel.org ([198.145.29.99]:37370 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729777AbgCPCeJ (ORCPT ); Sun, 15 Mar 2020 22:34:09 -0400 Received: from sasha-vm.mshome.net (c-73-47-72-35.hsd1.nh.comcast.net [73.47.72.35]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 7030120726; Mon, 16 Mar 2020 02:34:08 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1584326049; bh=cCg0M0loROU58Zt2BRB0MoP92hqsihIZYRkM3zwyyRk=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=KWL3pWbjXJfFfFs+oJnvQLlToapXO9JKU6+KSTFIMbNLLfYcJCQ5lxyTkl3J7J+ae RFbT65nzR1DX93pmt6vjUiEs7yZRBmHkABjh9Ax3Ct8iUIPsm8VssQJPRYulEqZqqy wvIctqijqI48aXudkADLDrEND9hnUSymkxF4ADHs= From: Sasha Levin To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: Pavel Begunkov , Jens Axboe , Sasha Levin , linux-fsdevel@vger.kernel.org, io-uring@vger.kernel.org Subject: [PATCH AUTOSEL 5.5 41/41] io_uring: fix lockup with timeouts Date: Sun, 15 Mar 2020 22:33:19 -0400 Message-Id: <20200316023319.749-41-sashal@kernel.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20200316023319.749-1-sashal@kernel.org> References: <20200316023319.749-1-sashal@kernel.org> MIME-Version: 1.0 X-stable: review X-Patchwork-Hint: Ignore Content-Transfer-Encoding: 8bit Sender: io-uring-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: io-uring@vger.kernel.org From: Pavel Begunkov [ Upstream commit f0e20b8943509d81200cef5e30af2adfddba0f5c ] 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 Signed-off-by: Jens Axboe Signed-off-by: Sasha Levin --- fs/io_uring.c | 1 + 1 file changed, 1 insertion(+) diff --git a/fs/io_uring.c b/fs/io_uring.c index 60a4832089982..fd28f85677225 100644 --- a/fs/io_uring.c +++ b/fs/io_uring.c @@ -688,6 +688,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.20.1