From patchwork Mon Sep 2 08:09:52 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chengen Du X-Patchwork-Id: 1979559 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=185.125.189.65; helo=lists.ubuntu.com; envelope-from=kernel-team-bounces@lists.ubuntu.com; receiver=patchwork.ozlabs.org) Received: from lists.ubuntu.com (lists.ubuntu.com [185.125.189.65]) (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 4Wy1fB0XpGz1ygs for ; Mon, 2 Sep 2024 18:10:41 +1000 (AEST) Received: from localhost ([127.0.0.1] helo=lists.ubuntu.com) by lists.ubuntu.com with esmtp (Exim 4.86_2) (envelope-from ) id 1sl28s-0000XF-1M; Mon, 02 Sep 2024 08:10:30 +0000 Received: from smtp-relay-internal-1.internal ([10.131.114.114] helo=smtp-relay-internal-1.canonical.com) by lists.ubuntu.com with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.86_2) (envelope-from ) id 1sl28p-0000Wg-LY for kernel-team@lists.ubuntu.com; Mon, 02 Sep 2024 08:10:27 +0000 Received: from mail-pf1-f197.google.com (mail-pf1-f197.google.com [209.85.210.197]) (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-internal-1.canonical.com (Postfix) with ESMTPS id 2B0AC3F327 for ; Mon, 2 Sep 2024 08:10:26 +0000 (UTC) Received: by mail-pf1-f197.google.com with SMTP id d2e1a72fcca58-71439227092so4591441b3a.3 for ; Mon, 02 Sep 2024 01:10:26 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1725264624; x=1725869424; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=UMq2pOXsUX+Bapu7+7QCURQDS8XQp48QDAML3diZKog=; b=FSJUTjidJuusbPw/v+oJ0PrWNnVSwTU9+PbVv17xBirSncxnbwBWS62IHV+EZL5A3D Ang8QQ555B/2qcSTs3rQ8PfpM1EtX6C3SBnsQU9Mgt+I7vfd5G/PoW+USrMBQdMHw0Ft vUlOeXkRqA9g4CAos7AmAaKKaMFqZzPcZjBibjUaC7KOd1oxnBsVo1sp7u8BIxOyQXxV sr89n2G1oLZGkHWHSYCGDSYv+6M2L6RePdPZa4eH35kXOUSTH8/dnwkOPdkRfTVoiRrW 8SZKLASCW7pI/VusDMtY5R8ar9JxSN20VmXqyXLm2rh9A0pTanPDjP9Tw6NiV2HfhFnX H7KA== X-Gm-Message-State: AOJu0YyZUWUBdFL9YLoIbB1Qii5Aj3KbzvGZxXbHdF1eN3LGmfAAYEAm b8JFM4g2OXIslCabScyocXu/mjTJhY4azzocODyMOgyTsrDvizFbGtAY+YfFmq9Nnxsbr9hRsGP oTj/WMtVIWL7M97dMQAK+KaI/KPoWaONrZH6DRn7fFtjsICiuQxOwH65r9CJBTyuxaeZnFzUvSC w7F65743nReQ== X-Received: by 2002:a05:6a00:9293:b0:70d:14d1:1bb7 with SMTP id d2e1a72fcca58-7173b6d09bemr7153204b3a.28.1725264623718; Mon, 02 Sep 2024 01:10:23 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFWqihi6unXpGZe3KfwkLAncvhyt2nG2VszV5EobeHewugWH0o7JG34+U8ZeEk1ukaJpLVcvg== X-Received: by 2002:a05:6a00:9293:b0:70d:14d1:1bb7 with SMTP id d2e1a72fcca58-7173b6d09bemr7153189b3a.28.1725264623200; Mon, 02 Sep 2024 01:10:23 -0700 (PDT) Received: from chengendu.. (2001-b011-381c-bde8-17a3-13f4-f066-2f6b.dynamic-ip6.hinet.net. [2001:b011:381c:bde8:17a3:13f4:f066:2f6b]) by smtp.gmail.com with ESMTPSA id 41be03b00d2f7-7d22e742c7fsm6900377a12.19.2024.09.02.01.10.21 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 02 Sep 2024 01:10:22 -0700 (PDT) From: Chengen Du To: kernel-team@lists.ubuntu.com Subject: [SRU][F][PATCH 1/1] UBUNTU: SAUCE: io_uring: ensure IOPOLL locks around deferred work Date: Mon, 2 Sep 2024 16:09:52 +0800 Message-ID: <20240902081015.113766-2-chengen.du@canonical.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240902081015.113766-1-chengen.du@canonical.com> References: <20240902081015.113766-1-chengen.du@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 CVE-2023-21400 BugLink: https://bugs.launchpad.net/bugs/2078659 No direct upstream commit exists for this issue. It was fixed in 5.18 as part of a larger rework of the completion side. io_commit_cqring() writes the CQ ring tail to make it visible, but it also kicks off any deferred work we have. A ring setup with IOPOLL does not need any locking around the CQ ring updates, as we're always under the ctx uring_lock. But if we have deferred work that needs processing, then io_queue_deferred() assumes that the completion_lock is held, as it is for !IOPOLL. Add a lockdep assertion to check and document this fact, and have io_iopoll_complete() check if we have deferred work and run that separately with the appropriate lock grabbed. Cc: stable@vger.kernel.org # 5.10, 5.15 Reported-by: dghost david Signed-off-by: Jens Axboe Signed-off-by: Greg Kroah-Hartman (backported from commit fb348857e7b67eefe365052f1423427b66dedbf3) [chengen - apply the locking logic to the corresponding functions / use spin_lock_irq because the same lock is used in the timer callback function.] Signed-off-by: Chengen Du --- fs/io_uring.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/fs/io_uring.c b/fs/io_uring.c index 875dd8e0f766..aa75c32f2d16 100644 --- a/fs/io_uring.c +++ b/fs/io_uring.c @@ -512,6 +512,8 @@ static void __io_commit_cqring(struct io_ring_ctx *ctx) { struct io_rings *rings = ctx->rings; + lockdep_assert_held(&ctx->completion_lock); + if (ctx->cached_cq_tail != READ_ONCE(rings->cq.tail)) { /* order cqe stores with ring update */ smp_store_release(&rings->cq.tail, ctx->cached_cq_tail); @@ -841,7 +843,9 @@ static void io_iopoll_complete(struct io_ring_ctx *ctx, unsigned int *nr_events, } } + spin_lock_irq(&ctx->completion_lock); io_commit_cqring(ctx); + spin_unlock_irq(&ctx->completion_lock); io_free_req_many(ctx, reqs, &to_free); }