From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 6E9D1330B00; Fri, 17 Oct 2025 15:48:46 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1760716126; cv=none; b=TxW4NkNuvi9YajfrZKQAj3fOFVoBKMeEOe+PdsDGHaWvgDDfMyJK2h1eSfmfskwoAJtIcT17ANPCkSmiHkXDla4D9b+C8S6j7LgsCcNwI1k4ugXvUlsgHB0mSQhy3IHum/POJ+KgI0U6DNC67TdH+qgewY0uzZgAsK/KaKA9tgE= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1760716126; c=relaxed/simple; bh=YO34k4xF9iAhAP9CvBrInnQ0B/4VOjjoYMjB5WWJp0U=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=TouE810PM3jv3W9aLMfyi4MHU9d/70HVt+9QF8TeZ+rh83stam1gEJRJO6pskK5ZFqpAPrR8m1gU3KK7gecz8P3ArDDOATD43+e9/o/fCZwW4xYR25sWwRST0gSg8x0HP11QvVALbOAp1SNTlisql2TTgYy+3ESDmbdvGg/t4oA= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b=CtLxEYiD; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b="CtLxEYiD" Received: by smtp.kernel.org (Postfix) with ESMTPSA id E11A5C4CEE7; Fri, 17 Oct 2025 15:48:45 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1760716126; bh=YO34k4xF9iAhAP9CvBrInnQ0B/4VOjjoYMjB5WWJp0U=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=CtLxEYiD2kGyvJ3P7eYH4tlZGcRGf6UVCCcbc5rjKAgMoI6b1NGUfsf0tQkISSnSk tLh8RQUEZS9kPrdpZ74echE5dZpdKjNAw70ZLNfhvGfXi4D7g6PE0iMWF4U9XoxKZJ V0FlRmD1jD3AX6O83BXq5/MwRlGbXaEW2HHsyVvM= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, Vlad Dumitrescu , Mark Zhang , Edward Srouji , Leon Romanovsky , Sasha Levin Subject: [PATCH 5.15 083/276] IB/sa: Fix sa_local_svc_timeout_ms read race Date: Fri, 17 Oct 2025 16:52:56 +0200 Message-ID: <20251017145145.515813253@linuxfoundation.org> X-Mailer: git-send-email 2.51.0 In-Reply-To: <20251017145142.382145055@linuxfoundation.org> References: <20251017145142.382145055@linuxfoundation.org> User-Agent: quilt/0.69 X-stable: review X-Patchwork-Hint: ignore Precedence: bulk X-Mailing-List: stable@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 5.15-stable review patch. If anyone has any objections, please let me know. ------------------ From: Vlad Dumitrescu [ Upstream commit 1428cd764cd708d53a072a2f208d87014bfe05bc ] When computing the delta, the sa_local_svc_timeout_ms is read without ib_nl_request_lock held. Though unlikely in practice, this can cause a race condition if multiple local service threads are managing the timeout. Fixes: 2ca546b92a02 ("IB/sa: Route SA pathrecord query through netlink") Signed-off-by: Vlad Dumitrescu Reviewed-by: Mark Zhang Signed-off-by: Edward Srouji Link: https://patch.msgid.link/20250916163112.98414-1-edwards@nvidia.com Signed-off-by: Leon Romanovsky Signed-off-by: Sasha Levin --- drivers/infiniband/core/sa_query.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/drivers/infiniband/core/sa_query.c b/drivers/infiniband/core/sa_query.c index 1557c71dd152f..2b13cf6e827c6 100644 --- a/drivers/infiniband/core/sa_query.c +++ b/drivers/infiniband/core/sa_query.c @@ -982,6 +982,8 @@ int ib_nl_handle_set_timeout(struct sk_buff *skb, if (timeout > IB_SA_LOCAL_SVC_TIMEOUT_MAX) timeout = IB_SA_LOCAL_SVC_TIMEOUT_MAX; + spin_lock_irqsave(&ib_nl_request_lock, flags); + delta = timeout - sa_local_svc_timeout_ms; if (delta < 0) abs_delta = -delta; @@ -989,7 +991,6 @@ int ib_nl_handle_set_timeout(struct sk_buff *skb, abs_delta = delta; if (delta != 0) { - spin_lock_irqsave(&ib_nl_request_lock, flags); sa_local_svc_timeout_ms = timeout; list_for_each_entry(query, &ib_nl_request_list, list) { if (delta < 0 && abs_delta > query->timeout) @@ -1007,9 +1008,10 @@ int ib_nl_handle_set_timeout(struct sk_buff *skb, if (delay) mod_delayed_work(ib_nl_wq, &ib_nl_timed_work, (unsigned long)delay); - spin_unlock_irqrestore(&ib_nl_request_lock, flags); } + spin_unlock_irqrestore(&ib_nl_request_lock, flags); + settimeout_out: return 0; } -- 2.51.0