From patchwork Fri Sep 27 05:30:58 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chengen Du X-Patchwork-Id: 1990095 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 4XFJwt0M4Sz1xtJ for ; Fri, 27 Sep 2024 15:31:25 +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 1su3ZM-0007jJ-32; Fri, 27 Sep 2024 05:31:08 +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 1su3ZK-0007j3-UA for kernel-team@lists.ubuntu.com; Fri, 27 Sep 2024 05:31:06 +0000 Received: from mail-pg1-f198.google.com (mail-pg1-f198.google.com [209.85.215.198]) (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 C63253F0B5 for ; Fri, 27 Sep 2024 05:31:06 +0000 (UTC) Received: by mail-pg1-f198.google.com with SMTP id 41be03b00d2f7-7d4f9974c64so1598136a12.1 for ; Thu, 26 Sep 2024 22:31:06 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1727415065; x=1728019865; 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=lnS+cVbbrlNU3WlFcANVJJj0Pz4nN0nGAgXwm82/DCd5JdYyZSjkHU1f6vQW4MKjU8 UuDhrF9gBvClYaf+nyZEEXgZJKPIF+UgO/MnAdcnk482uJLmUFO7Q+4gP1UuQN+Vlxyt NZaBcmzkNMTxoeCiYQ5DPHFH03M3IHNQ7xXgwig1fbGsnVD9kKE5onZ5YKgN3YdK0jwO OgQwIdNwNTIZwFulGMn8KXaSNMV+BmEGLQnnqDSvTHs79emalsNHJ2Cunlh8+p+GjVCX 3YrtEbZFRfsgpKKWaLJn2u19rYXin7ER2Mq++Q2XwuJ1D+It2kMAfkZGfvK0q9lAEOeI t7Sw== X-Gm-Message-State: AOJu0Yw/QZamzKRVSd37l3dPfgjy3qKWffoQVpY/qW7vPaYiLO3cTkzJ qJXnIV3kJJOJqt/8DIk8d0uBqox0ykpIVzp0dgkV1iAdUoyXI963SZQgptxWoHVR0q2nZl+v7Fb sWRVtgUN1d0D4g+6zg+RHeCX2Cr8nij/yIp3jTZK1uQIq0d8jcrVSLuhnl1X4xuHD/z7dNe01LK BNZcu2htZHXSh/ X-Received: by 2002:a05:6a20:1053:b0:1d3:4675:fc02 with SMTP id adf61e73a8af0-1d4fa6bf691mr2683044637.14.1727415065012; Thu, 26 Sep 2024 22:31:05 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHinCyTJJ0ajCk/1rgDK1iwJaP4Gp2gtgiKflEJm+RNXgWv7ylLJwLExxomHxA+R9pgnATkOQ== X-Received: by 2002:a05:6a20:1053:b0:1d3:4675:fc02 with SMTP id adf61e73a8af0-1d4fa6bf691mr2683021637.14.1727415064603; Thu, 26 Sep 2024 22:31:04 -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 41be03b00d2f7-7e6db2c8af2sm805784a12.48.2024.09.26.22.31.03 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 26 Sep 2024 22:31:04 -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 13:30:58 +0800 Message-ID: <20240927053100.106971-2-chengen.du@canonical.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240927053100.106971-1-chengen.du@canonical.com> References: <20240927053100.106971-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); }