๐Ÿš€ go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: linux.kernel.netdev
Article #5309

Re: [PATCH net-next v1 2/4] net/mlx5: Don't free the WC test CQ if destroying it fails

#5309
From: netdev-bot+sashiko
Date: Tue, 20 Oct 2026 05:24
122 lines
12927 bytes
Thank you for your contribution! Sashiko AI review found 2 potential
issue(s) to consider.

Critical: 0 ยท High: 1 ยท Medium: 0 ยท Low: 1

If you believe none of the issues are legitimate, please reply to each
issue of Medium severity or higher and explain why the AI is wrong.
If any of them are legitimate and you plan to respin, please let patchwork
know by including "pw-bot: cr" as a separate line at the end of your reply
(one such reply per series is enough).

- [High] net/mlx5: SQ DMA use-after-free due to dropped DESTROY_SQ error
- [Low] When DESTROY_CQ fails, mlx5_core_test_wc() now deliberately leaks
  the struct mlx5_wc_sq, the CQ frag buffer and the CQ doorbell record.

--

net/mlx5: Don't free the WC test CQ if destroying it fails

This patch makes mlx5_wc_destroy_cq() return the result of
mlx5_core_destroy_cq() and skip freeing the CQ buffer and doorbell record
when DESTROY_CQ fails. mlx5_core_test_wc() then also keeps the struct
mlx5_wc_sq that embeds the CQ instead of freeing it.

> diff --git a/drivers/net/ethernet/mellanox/mlx5/core/wc.c b/drivers/net/ethernet/mellanox/mlx5/core/wc.c
> index 7d3d4d739e2cd..01e9800ff6fd9 100644
> --- a/drivers/net/ethernet/mellanox/mlx5/core/wc.c
> +++ b/drivers/net/ethernet/mellanox/mlx5/core/wc.c

[ ... ]

> @@ -396,11 +401,13 @@ static void mlx5_core_test_wc(struct mlx5_core_dev *mdev)
>  	mlx5_wc_destroy_sq(sq);
>  
>  err_create_sq:
> -	mlx5_wc_destroy_cq(&sq->cq);
> +	/* An undestroyed CQ may still be in use; keep the SQ that holds it. */
> +	keep_sq = mlx5_wc_destroy_cq(&sq->cq);
>  err_create_cq:
>  	mlx5_free_bfreg(mdev, &sq->bfreg);
>  err_alloc_bfreg:
> -	kfree(sq);
> +	if (!keep_sq)
> +		kfree(sq);
>  
>  	if (mdev->wc_state == MLX5_WC_STATE_UNSUPPORTED)
>  		mlx5_core_warn(mdev, "Write combining is not supported\n");

[Severity: High]
The commit message argues that a failed DESTROY_CQ can leave the CQ
alive in firmware with access to its buffer and doorbell record. Does
the same argument not apply to the SQ that is torn down just before
this?

mlx5_wc_destroy_sq() frees the SQ work queue unconditionally after
asking firmware to destroy it:

	mlx5_core_destroy_sq(sq->cq.mdev, sq->sqn);
	mlx5_wq_destroy(&sq->wq_ctrl);

mlx5_core_destroy_sq() in transobj.c returns void and discards the
result of mlx5_cmd_exec_in(). A DESTROY_SQ failure, such as a command
timeout, is therefore never visible here.

sq->wq_ctrl.buf and sq->wq_ctrl.db are then freed while the SQ may
still be live in the device. Once that memory is reused, the device
could read whatever lands there as WQEs or doorbell values and issue
DMA based on it.

The err_modify_sq path in create_wc_sq() has the same shape. It calls
mlx5_core_destroy_sq(), and the SQ buffer is freed on the error return
whether or not the destroy succeeded.

This also seems to weaken the new keep_sq handling. The struct
mlx5_wc_sq is kept when DESTROY_CQ fails, but mlx5_wc_destroy_sq()
has already released its SQ buffer.

If DESTROY_SQ failed silently, an SQ still bound to the CQ might even
be what makes DESTROY_CQ fail. In that case the CQ buffer would be
carefully kept while the SQ buffer that firmware still references has
already been freed.

Fixing this properly looks like it needs mlx5_core_destroy_sq() to
return an error, which affects callers outside wc.c. Would you be
willing to cover that in this series, so mlx5_wc_destroy_sq() can keep
sq->wq_ctrl on failure the same way mlx5_wc_destroy_cq() now keeps
cq->wq_ctrl? Or should that be a separate fix?

[Severity: Low]
Could this leak the struct mlx5_wc_sq, the CQ frag buffer and the CQ
doorbell record again on every retry?

When mlx5_wc_destroy_cq() fails, sq, cq->wq_ctrl.buf and cq->wq_ctrl.db
are kept. Nothing records this, and mdev->wc_state is not changed.

wc_state is only set in mlx5_wc_poll_cq() when a REQ CQE arrives. If the
poll times out, or if mlx5_wc_create_sq() fails, it stays
MLX5_WC_STATE_UNINITIALIZED. The create_sq failure path is also where
DESTROY_CQ is most likely to fail.

mlx5_wc_support_get() only skips the test when wc_state has been set:

	if (mdev->wc_state != MLX5_WC_STATE_UNINITIALIZED)
		goto unlock;

So the next call runs mlx5_core_test_wc() again.

Userspace can reach mlx5_wc_support_get() repeatedly through mlx5_ib.
Examples are mlx5_ib_alloc_ucontext(), the WC page mmap path and the UAR
alloc uverbs method.

Suppose firmware keeps rejecting DESTROY_CQ while the create commands
still succeed. Would each of those calls then leak another sq struct,
another DMA-coherent CQ buffer and another doorbell slot, with no upper
bound? Before this patch these were freed, unsafely, on each run.

Would it make sense to latch wc_state when the CQ has to be kept, for
example to MLX5_WC_STATE_UNSUPPORTED, so the test is not retried?

-- 
Sashiko AI review ยท https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261016045849.813696-6-oss.patchbox%40gmail.com
Technical Details
Message-ID: <179247389536.3135.6864822792166805555@kernel.org>
Path: mbox-mo1.pugleaf.net!archive.usenet.blueworldhosting.com!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-349043-linux-kernel-netdev=dewy.ru
References: <20261016045849.813696-8-oss.patchbox@gmail.com>

Show Full Headers
Complete Article Headers
Path: mbox-mo1.pugleaf.net!archive.usenet.blueworldhosting.com!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-349043-linux-kernel-netdev=dewy.ru
From: netdev-bot+sashiko@kernel.org
Newsgroups: linux.kernel.netdev
Subject: Re: [PATCH net-next v1 2/4] net/mlx5: Don't free the WC test CQ if
 destroying it fails
Date: Tue, 20 Oct 2026 05:24:55 +0000
Organization: Usenet Network
Message-ID: <179247389536.3135.6864822792166805555@kernel.org>
References: <20261016045849.813696-8-oss.patchbox@gmail.com>
MIME-Version: 1.0
Content-Type: text/plain; charset="utf-8"
Content-Transfer-Encoding: 8bit
Injection-Info: usenet.network;
	logging-data="3787385"; mail-complaints-to="abuse@usenet.network"
Cancel-Lock: sha1:KkQRTN/apKLlWyywuNueIbXZ/X8= sha256:IWDZMB46uV4LAm+FIIWzD9u2rgR++YulYu5xtX8Jano=
	sha1:3xUfd+KWdCnaENVzJSlJEJQBVyc= sha256:hRAjWDA6XEvy/QdSkKNqba5GSGg4cFTgX3ucNJHAXek=
List-ID: <netdev.vger.kernel.org>
X-Mailpost-Empty-Hdrs: X-Spam-Level
X-Received: from localhost (localhost [127.0.0.1])
	by mail.dewy.ru (Postfix) with ESMTP id EDF67110C01; Tue, 20 Oct 2026 08:25:32 +0300 (MSK)
X-Virus-Scanned: Debian amavisd-new at usenet.network
X-Spam-Flag: NO
X-Spam-Score: -3.728
X-Spam-Status: No, score=-3.728 tagged_above=-9999 required=6.31
	tests=[DCC_REPUT_70_89=0.1, DKIMWL_WL_HIGH=-0.329, DKIM_SIGNED=0.1,
	DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1,
	MAILING_LIST_MULTI=-1, RCVD_IN_DNSWL_MED=-2.3, SPF_HELO_NONE=0.001,
	SPF_PASS=-0.001, URIBL_BLOCKED=0.001] autolearn=ham autolearn_force=no
X-Authentication-Results: mail.dewy.ru (amavisd-new); dkim=pass (2048-bit key)
	header.d=kernel.org
X-Received: from mail.dewy.ru ([127.0.0.1])
	by localhost (mail.dewy.ru [127.0.0.1]) (amavisd-new, port 10024)
	with ESMTP id ZGoCh0auyten;
	Tue, 20 Oct 2026 08:25:24 +0300 (MSK)
X-Received-SPF: Pass (mailfrom) identity=mailfrom; client-ip=172.105.105.114; helo=tor.lore.kernel.org; envelope-from=netdev+bounces-349043-linux-kernel-netdev=dewy.ru@vger.kernel.org; receiver=<UNKNOWN> 
X-Authentication-Results: OpenDMARC; dmarc=pass (p=quarantine dis=none) header.from=kernel.org
X-Received: from tor.lore.kernel.org (tor.lore.kernel.org [172.105.105.114])
	by mail.dewy.ru (Postfix) with ESMTPS id 73D43110BF4; Tue, 20 Oct 2026 08:25:15 +0300 (MSK)
X-Received: from smtp.subspace.kernel.org (conduit.subspace.kernel.org [100.77.114.92])
	by tor.lore.kernel.org (Postfix) with ESMTP id A33D4359C6; Tue, 20 Oct 2026 05:25:02 +0000 (UTC)
X-Authentication-Results: smtp.subspace.kernel.org; arc=pass header.oldest-pass=0 smtp.remote-ip=127.0.0.1
X-ARC-Seal: i=2; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=pass;
	t=1792473901;
	b=Y/tlqD5qVjsWpYD6iWoR8upa0feMIc28WsztnkE4T3wiLR3xyp2Qz3XNGZZCyg4KVPvX
	 ulmiZQTANV5Kg7iWdbDBkV/uGAke5y0jvGPRZYMwcYkoY3LuHsgYSr1ImUkt72uiUNmEz
	 WieJKn5dt5rv5B4ryPh8Z1h+5QbsvXXBASbVKcZpVT58TketYl8lbslH3qeTjGPQI4u6b
	 7/uCLFm1hY5GxHQ2HjQAUXgXquBmlDPMtWzXzUo8Unkg9g1XT61zqJC1qoQHQ9fRa7zRd
	 9wNvY1247uma8O04Dyls0/atUJjoqeUl8pRtECff7m3dqe2bWDXwd5wEW3geoYk4/ug==
X-ARC-Message-Signature: i=2; d=subspace.kernel.org; s=arc20261015;
	a=rsa-sha256; c=relaxed/relaxed; t=1792473901;
	h=X-Original-To:Received:Received:DKIM-Signature:Subject:From:To:Cc:
	 Date:Message-ID:In-Reply-To:References:X-sashiko-severity:
	 Content-Type:Content-Transfer-Encoding:X-Mailing-List:List-Id:
	 List-Post:List-Help:List-Subscribe:List-Unsubscribe:List-Owner:
	 Precedence:MIME-Version;
	bh=WgU3tTWV6lbRlYg7TAKMkx9YxxtM8QnErb6eOW1atQA=;
	b=KaFy/HQWLDVDbQFd2ShCmIOacQh7ugkSBB3rk0sayYhvIaa077QaC8V/eFgfl4jsWXf4
	 Q2qHqfFwL6oPYwA2aaobWRf9uFhLhV0819tgKOy2t8C+TbpY3c2e2RnTpWJcSLjjdAFKY
	 twVAS7boXQSHA2zOM8/HS47WxS3E4B5n0cWCExEXRJ/oKnQbjgvKFmnuP2YvTp+73Ypb4
	 GCNIm7XWPo27G6OYaYVrvWmfcZK/LA9n3mmAJkCBjwEiU49p/H9hzK/X6e/tpM4MIPT+p
	 qkNCfvWw3DMKArg4dWamg8wXzqK1IIri6DDd67qn88S2rW4/gVZ6T6i/NaxSi2B29kQ==
X-ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; 
	dkim=pass header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=ZcJNfbQe;
	arc=pass header.oldest-pass=0 smtp.remote-ip=127.0.0.1
X-Received: from localhost.localdomain (localhost [127.0.0.1])
	by smtp.subspace.kernel.org (Postfix) with ESMTP id 911F1606A31E;
	Tue, 20 Oct 2026 05:25:01 +0000 (UTC)
X-Authentication-Results: smtp.subspace.kernel.org;
	dkim=pass (2048-bit key, unprotected) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=ZcJNfbQe
X-Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=100.103.45.18
X-ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none;
	t=1792473897;
	b=So1JUodSndUFwqdzt+A4Oklfi1Nt978r6NX8Dcf3qrEXq92zBDhwJHeKBvCYaDUlwmo6
	 u3yICCDL66R79ldBB0OBokEkF9a1L2+iPL5aSaFCQocxRy8w8IxXKVS3yGCHpWZaUDtoG
	 URhetu9dZGOC4YR2nv1rCaFXt0JsPDv+dW1AaCR5xyd2mJHNIwMpOLtcdc9l3nF5WuyVO
	 Wk/VoLOSEJwYqhuHJ+VNHSXIyhQ+2s87T6PBu+TVm3WmP73lLh3NgzOGSArsLkhPug+uk
	 YuaSeUBLX5+Dl/MtJAUSs78vLXqLBFWfJIXsJEqT0Jn2ZNewchnZxKHW6irCOEdtrZg==
X-ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015;
	a=rsa-sha256; c=relaxed/relaxed; t=1792473897;
	h=Received:DKIM-Signature:Subject:From:To:Cc:Date:Message-ID:
	 In-Reply-To:References:X-sashiko-severity:Content-Type:
	 Content-Transfer-Encoding:MIME-Version;
	bh=WgU3tTWV6lbRlYg7TAKMkx9YxxtM8QnErb6eOW1atQA=;
	b=wR14XIgfsug2KyBOz+Gdy0ea0ncozzuyjWJ0HwMS6DTtchWYeIfNi2DP+B+qBOxUx6lS
	 +AMyNLN6kM/a7CXSl0gcV7i3VzjpG0vPEIBxi+ChcLtB03Y9jTWhH6CoGZbQn0Kah7IYP
	 Pswy8WXY0L0blav7jzWPTFy+E8XfM/8LVbgLzBqOq/fwOq7WmtoakwIQ6qWS3mB5kGBFL
	 vrvhRMv+d5NKsge+iU8V0zAKLaYQl2a/qp5E6kcHvrK2Em0v6v8PO89IlY2Y+UaI+3r0N
	 9Zifb2zfTUYZCFS9qBGTSQlKaAwl7Ob6fknHxWd8HVj0DP6uqBx5ObUD53T2dyfuYbw==
X-ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; 
	dkim=pass header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=ZcJNfbQe;
	arc=none smtp.remote-ip=100.103.45.18
X-Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18])
	(using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)
	 key-exchange X25519 server-signature ECDSA (prime256v1))
	(No client certificate requested)
	by smtp.subspace.kernel.org (Postfix) with ESMTPS id 3DFCB606A323;
	Tue, 20 Oct 2026 05:24:57 +0000 (UTC)
X-Received: by smtp.kernel.org (Postfix) with ESMTPSA id CD82E1F000C4;
	Tue, 20 Oct 2026 05:24:55 +0000 (UTC)
X-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org;
	s=k20260515; t=1792473896;
	bh=WgU3tTWV6lbRlYg7TAKMkx9YxxtM8QnErb6eOW1atQA=;
	h=Subject:From:To:Cc:Date:In-Reply-To:References;
	b=ZcJNfbQeyLYuPCmogWo3MrvvThz3FwNrQTHxARegZ78meZEgrgW90wibqiMnS/0+N
	 gnpp/0yYS/k1LVcYoyIuzv7iN1PvdRJunPVftDuTdfxAdzgdt0ksYeKIsoVoOs6tQa
	 g+OI1QJdC7anLPaZ/Cuo5btD5F5WZb9e2w550dZb5VNJPRL5UMcKssU+GOdRlt6IhF
	 zTuVCFtzhgnKz1AgXg+HXalMY9KW+EvgANBGWqPL3XAdv7cHhrcUDX3arF63LWvr2M
	 3hf0Df+A2eqjebl6dE6iWIUDmkfDUBfTE4MUv6PftGDX14M97l5KsS3rTw3JPEAG2F
	 /XN2/pNBUMq6g==
X-Cc: saeedm@nvidia.com, leon@kernel.org, tariqt@nvidia.com, mbloch@nvidia.com,
 andrew+netdev@lunn.ch, davem@davemloft.net, edumazet@kernel.org,
 kuba@kernel.org, pabeni@redhat.com, lariel@nvidia.com, jianbol@nvidia.com,
 valex@nvidia.com, kliteyn@nvidia.com, igozlan@nvidia.com,
 netdev@vger.kernel.org, linux-rdma@vger.kernel.org,
 linux-kernel@vger.kernel.org
X-In-Reply-To: <20261016045849.813696-8-oss.patchbox@gmail.com>
X-sashiko-severity: High
X-Mailing-List: netdev@vger.kernel.org
X-List-Post: <mailto:netdev@vger.kernel.org>
X-List-Help: <mailto:netdev+help@vger.kernel.org>
X-List-Subscribe: <mailto:netdev+subscribe@vger.kernel.org>
X-List-Unsubscribe: <mailto:netdev+unsubscribe@vger.kernel.org>
X-List-Owner: <mailto:netdev+owner@vger.kernel.org>
X-Precedence: list