From patchwork Mon Sep 19 17:58:06 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Thadeu Lima de Souza Cascardo X-Patchwork-Id: 1679594 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.ubuntu.com (client-ip=91.189.94.19; helo=huckleberry.canonical.com; envelope-from=kernel-team-bounces@lists.ubuntu.com; receiver=) Authentication-Results: legolas.ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=canonical.com header.i=@canonical.com header.a=rsa-sha256 header.s=20210705 header.b=REj3akQ/; dkim-atps=neutral Received: from huckleberry.canonical.com (huckleberry.canonical.com [91.189.94.19]) (using TLSv1.2 with cipher ECDHE-ECDSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4MWXVX5wv3z1yp7 for ; Tue, 20 Sep 2022 03:59:00 +1000 (AEST) Received: from localhost ([127.0.0.1] helo=huckleberry.canonical.com) by huckleberry.canonical.com with esmtp (Exim 4.86_2) (envelope-from ) id 1oaL2h-00072O-Ak; Mon, 19 Sep 2022 17:58:51 +0000 Received: from smtp-relay-canonical-1.internal ([10.131.114.174] helo=smtp-relay-canonical-1.canonical.com) by huckleberry.canonical.com with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.86_2) (envelope-from ) id 1oaL2Z-0006pY-5g for kernel-team@lists.ubuntu.com; Mon, 19 Sep 2022 17:58:43 +0000 Received: from quatroqueijos.. (unknown [179.93.171.162]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by smtp-relay-canonical-1.canonical.com (Postfix) with ESMTPSA id 6812B3FDEB for ; Mon, 19 Sep 2022 17:58:41 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=canonical.com; s=20210705; t=1663610322; bh=A0/oVOPPEpj40k3lFKTeyxX7mrkK71JQ412GYgHh+hE=; h=From:To:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=REj3akQ/d2Xb7oSingCy80lEAYPUZEa+qWxv2yy72l1WZNAvjeJwdEdFiRqv+LkwI 2o6HiRAnrmaNY3DxS0wRjAXE53WuGXClbD3C8XYvQCaexKqzEzhWvcKZ7LzZT1RVq8 9uib2enenF7R0Zpfd/dfUrfqBeouPp2xsBw9lUfpSLdqjMVS3sTxGyvS03e1Kfa4UJ lDzBl4MXRYzUMKnkEAw7/VJBGEDb4jzcU6Pm4cXCt6158swu0706D4yNZeC2t2/jNv lzoxYU1ENbJk3iH82q83W/dhd323eSw01/tl9du7hyPd/IJbPxBpQlK7FfI3rIb2mc xYs9qg7+Rfa+Q== From: Thadeu Lima de Souza Cascardo To: kernel-team@lists.ubuntu.com Subject: [SRU Jammy 08/12] io_uring: remove poll entry from list when canceling all Date: Mon, 19 Sep 2022 14:58:06 -0300 Message-Id: <20220919175810.689086-10-cascardo@canonical.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220919175810.689086-1-cascardo@canonical.com> References: <20220919175810.689086-1-cascardo@canonical.com> MIME-Version: 1.0 X-BeenThere: kernel-team@lists.ubuntu.com X-Mailman-Version: 2.1.20 Precedence: list List-Id: Kernel team discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: kernel-team-bounces@lists.ubuntu.com Sender: "kernel-team" From: Jens Axboe [ upstream commmit 61bc84c4008812d784c398cfb54118c1ba396dfc ] When the ring is exiting, as part of the shutdown, poll requests are removed. But io_poll_remove_all() does not remove entries when finding them, and since completions are done out-of-band, we can find and remove the same entry multiple times. We do guard the poll execution by poll ownership, but that does not exclude us from reissuing a new one once the previous removal ownership goes away. This can race with poll execution as well, where we then end up seeing req->apoll be NULL because a previous task_work requeue finished the request. Remove the poll entry when we find it and get ownership of it. This prevents multiple invocations from finding it. Fixes: aa43477b0402 ("io_uring: poll rework") Reported-by: Dylan Yudaken Signed-off-by: Jens Axboe [pavel: backport] Signed-off-by: Pavel Begunkov Signed-off-by: Greg Kroah-Hartman (cherry picked from commit 7524ec52caa893a3aeae85488f19dc2f71c8e7b9 linux-5.15.y) CVE-2022-3176 Signed-off-by: Thadeu Lima de Souza Cascardo --- fs/io_uring.c | 1 + 1 file changed, 1 insertion(+) diff --git a/fs/io_uring.c b/fs/io_uring.c index bc4741061258..dd750d6f00fd 100644 --- a/fs/io_uring.c +++ b/fs/io_uring.c @@ -5720,6 +5720,7 @@ static bool io_poll_remove_all(struct io_ring_ctx *ctx, struct task_struct *tsk, list = &ctx->cancel_hash[i]; hlist_for_each_entry_safe(req, tmp, list, hash_node) { if (io_match_task_safe(req, tsk, cancel_all)) { + hlist_del_init(&req->hash_node); io_poll_cancel_req(req); found = true; }