From patchwork Fri Sep 27 06:37:51 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chengen Du X-Patchwork-Id: 1990142 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 4XFLPy49Hhz1xst for ; Fri, 27 Sep 2024 16:38:14 +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 1su4cB-0005Dz-5S; Fri, 27 Sep 2024 06:38:07 +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 1su4c8-0005CK-5H for kernel-team@lists.ubuntu.com; Fri, 27 Sep 2024 06:38:04 +0000 Received: from mail-pf1-f199.google.com (mail-pf1-f199.google.com [209.85.210.199]) (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 667313F180 for ; Fri, 27 Sep 2024 06:38:03 +0000 (UTC) Received: by mail-pf1-f199.google.com with SMTP id d2e1a72fcca58-7177906db91so2082002b3a.3 for ; Thu, 26 Sep 2024 23:38:03 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1727419081; x=1728023881; 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=kLAlK/i6uI9Q5y7s5/OAuTzBWVLCVmp2zat2hJx+MVrkS75pBLb5LYtK71lJ0DIbUk mtoXUbJuJbU7cLvEE+Oz7+VD7wGOjm6/sE+kDHg8ZRkTiXc8lvWNOR2Ro6Qw9CKLPzc9 n94CmUOFg0oO48sm7dyRf2r8OzDThGgR14hcQitdautvH1pXEfTcED2TaqJaPgNmAROr OmhCcNP49N9H46wus1OFVBmmQ6+sce8AoGsUOOSpB0A2lTBBCFIGNlCcdCVu+zeGX7kh q0zCQZOtqkGJMfGFogJZyJswuPhF7OdAAOYyCRhedcsWGG3jgqGy6Bsplu1iTSLnBNrX 8l3Q== X-Gm-Message-State: AOJu0Yx9pYG24sc1HT4cOBOuG9HjwbAO4P2KiRFtWH8S0PQ75CIdhEfa G2N8a+Vd1354V+M8+iB3jrchMf3dhMbMttAHly6cDzwggtRwhE59gLK7AFw/9HkjXBfMnh5Q6Zz 9VWApba4VfWlBIRobawZTD0Wo6BwtZeCOARsLbhHOagLQKuuRGwBaOIUmADHyrzrO1JoLyldvPv 8WoZugB+anrrsA X-Received: by 2002:a05:6a00:cc1:b0:717:9120:35f with SMTP id d2e1a72fcca58-71b26072ecdmr3378318b3a.27.1727419081509; Thu, 26 Sep 2024 23:38:01 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGF548+YNViVOwQxdvizcbf32cRirJNK0yDZqL5fsKcOlKuTDXgz5UObrbBa1xdo2Bkd0cwmw== X-Received: by 2002:a05:6a00:cc1:b0:717:9120:35f with SMTP id d2e1a72fcca58-71b26072ecdmr3378296b3a.27.1727419080981; Thu, 26 Sep 2024 23:38:00 -0700 (PDT) Received: from chengendu.. (2001-b011-381c-11cc-d91b-fa79-21a5-98b6.dynamic-ip6.hinet.net. [2001:b011:381c:11cc:d91b:fa79:21a5:98b6]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-71b2649c2bfsm894562b3a.28.2024.09.26.23.37.59 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 26 Sep 2024 23:38:00 -0700 (PDT) From: Chengen Du To: kernel-team@lists.ubuntu.com Subject: [SRU][F][PATCH 1/1] io_uring: ensure IOPOLL locks around deferred work Date: Fri, 27 Sep 2024 14:37:51 +0800 Message-ID: <20240927063755.112103-2-chengen.du@canonical.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240927063755.112103-1-chengen.du@canonical.com> References: <20240927063755.112103-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); }