🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: linux.kernel.netdev
Article #20425

Re: [PATCH v5 net 4/4] net: hns3: fix use-after-free in debugfs read during reset/unload

#20425
From: netdev-bot+sashiko
Date: Sun, 22 Nov 2026 13:24
72 lines
11020 bytes
Thank you for your contribution! Sashiko AI review found more severe
issue(s) in other patches of this series. This mail is only an FYI, in case
you want to address the nit picks below when you respin.

Low priority / nit picks for your consideration:

- [Low] The comment on the new `struct hnae3_handle::dbg_mutex` field in
  drivers/net/ethernet/hisilicon/hns3/hnae3.h reads "protect debugfs…

--

net: hns3: fix use-after-free in debugfs read during reset/unload

This patch adds a dbg_mutex to struct hnae3_handle. The enet-layer debugfs
show callbacks take it, and so do the reset, driver unload and ethtool ring
resize paths, which keeps the readers away from priv->ring, priv->tqp_vector
and ring->desc while those are being freed. The readers also check the
device state on every iteration and return -EBUSY when the device is busy.

Closes: https://lore.kernel.org/all/a0853cd9-cab5-441d-b181-8ba97f2f58b0@huawei.com/

> diff --git a/drivers/net/ethernet/hisilicon/hns3/hnae3.h b/drivers/net/ethernet/hisilicon/hns3/hnae3.h
> index 4286af9239b01..e94cc33da8643 100644
> --- a/drivers/net/ethernet/hisilicon/hns3/hnae3.h
> +++ b/drivers/net/ethernet/hisilicon/hns3/hnae3.h
> @@ -944,6 +944,7 @@ struct hnae3_handle {
>  
>  	u8 netdev_flags;
>  	struct dentry *hnae3_dbgfs;
> +	struct mutex dbg_mutex;	/* protect debugfs against reset/unload */

[Severity: Low]
This isn't a bug, but is this comment a little narrower and a little
broader than what the lock actually does?

On the writer side, hns3_set_ringparam() also takes h->dbg_mutex around
hns3_init_all_ring(), the memcpy() restore and hns3_fini_ring() on the
backup rings:

> diff --git a/drivers/net/ethernet/hisilicon/hns3/hns3_ethtool.c b/drivers/net/ethernet/hisilicon/hns3/hns3_ethtool.c
> --- a/drivers/net/ethernet/hisilicon/hns3/hns3_ethtool.c
> +++ b/drivers/net/ethernet/hisilicon/hns3/hns3_ethtool.c
> @@ -1252,6 +1252,7 @@ static int hns3_set_ringparam(struct net_device *ndev,
>  	if (if_running)
>  		ndev->netdev_ops->ndo_stop(ndev);
>  
> +	mutex_lock(&h->dbg_mutex);
>  	hns3_change_all_ring_bd_num(priv, new_ringparam.tx_desc_num,
>  				    new_ringparam.rx_desc_num);

Ring resize is neither a reset nor an unload, so the field comment does
not mention it.

On the reader side, only the enet-layer seq_file callbacks take the
mutex (coal_info, rx/tx_queue_info, queue_map, page_pool_info, bd_info).
The hclge-layer readers that hns3_dbg_common_init_t2() registers through
ops->dbg_get_read_func() live under the same handle->hnae3_dbgfs tree,
and they never take it.

The commit message says the mutex is "used by enet-layer debugfs
callbacks", but this comment is the only place in the tree that
describes the lock's scope.

Could the comment say that the lock serializes the enet-layer debugfs
readers against the paths that free or rebuild priv->ring,
priv->tqp_vector and ring->desc (reset, unload and ring resize)? Then a
future writer would know it has to take the lock, and an hclge-layer
reader would not assume it is protected.

-- 
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261118130330.3026625-1-shaojijie%40huawei.com
Technical Details
Message-ID: <179535384216.3135.13172932788054177257@kernel.org>
Path: mbox-mo1.pugleaf.net!srv.newsdeef.eu!news.mb-net.net!open-news-network.org!news.nntp4.net!nntp.xenet.de!news.neodome.net!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-368694-linux-kernel-netdev=dewy.ru
References: <20261118130330.3026625-5-shaojijie@huawei.com>

Show Full Headers
Complete Article Headers
Path: mbox-mo1.pugleaf.net!srv.newsdeef.eu!news.mb-net.net!open-news-network.org!news.nntp4.net!nntp.xenet.de!news.neodome.net!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-368694-linux-kernel-netdev=dewy.ru
From: netdev-bot+sashiko@kernel.org
Newsgroups: linux.kernel.netdev
Subject: Re: [PATCH v5 net 4/4] net: hns3: fix use-after-free in debugfs read
 during reset/unload
Date: Sun, 22 Nov 2026 13:24:02 +0000
Organization: Usenet Network
Message-ID: <179535384216.3135.13172932788054177257@kernel.org>
References: <20261118130330.3026625-5-shaojijie@huawei.com>
MIME-Version: 1.0
Content-Type: text/plain; charset="utf-8"
Content-Transfer-Encoding: 8bit
Injection-Info: usenet.network;
	logging-data="3641364"; mail-complaints-to="abuse@usenet.network"
Cancel-Lock: sha1:JtseRnLcJc/kK25lotnQZ9bvNdM= sha256:0KoDkS8L+mPvBG7O4WYxFIw6xUcob9A9y+EP3D3V8fw=
	sha1:M02kWjjzFAy0PhKfbKKQLrMmWoY= sha256:zp0dApAk/jz9Jf9Xjun5q86MHC3bBlBncrKTeRk+ZAY=
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 41576125D77; Sun, 22 Nov 2026 16:24:25 +0300 (MSK)
X-Virus-Scanned: Debian amavisd-new at usenet.network
X-Spam-Flag: NO
X-Spam-Score: -3.4
X-Spam-Status: No, score=-3.4 tagged_above=-9999 required=6.31
	tests=[DCC_REPUT_70_89=0.1, DKIMWL_WL_HIGH=-0.001, 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 P-5o0cUvIf2z;
	Sun, 22 Nov 2026 16:24:21 +0300 (MSK)
X-Received-SPF: Pass (mailfrom) identity=mailfrom; client-ip=172.234.253.10; helo=sea.lore.kernel.org; envelope-from=netdev+bounces-368694-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 sea.lore.kernel.org (sea.lore.kernel.org [172.234.253.10])
	by mail.dewy.ru (Postfix) with ESMTPS id 408C8125D78; Sun, 22 Nov 2026 16:24:12 +0300 (MSK)
X-Received: from smtp.subspace.kernel.org (conduit.subspace.kernel.org [100.77.114.92])
	by sea.lore.kernel.org (Postfix) with ESMTP id A8BB130D1C; Sun, 22 Nov 2026 13:24:06 +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=1795353844;
	b=AUOltpIRozG6/EdDFVeq9KMjJSHOPDiwVVf5+9c3oG7ltziTpxKZEForxgnZPNbpkpw3
	 dI87XmWeOUDBY3h5llwfmc8havRxd+04IpP4tcXXAcrSPFROmUXs+LbQQZkOuDt9oLxkv
	 fwxy7DoSGty0CyuyB0lIrJh3G7bFRbXH0wIDyk4ZLZHRay8x35qtHWb7d7sAAFrAK5Ruh
	 3d/oMcD6vCqoXNrG992iOOGll3OEorO//h0arHrcPanWRiXZv34pxPA/ksvpqXJsexYI3
	 BZqm04Zrx/rYEiEWmcHeWnSEJnw0gxjiTEn/qFFavqGtRKV4ZdEho0tgyR0nZcK0ytQ==
X-ARC-Message-Signature: i=2; d=subspace.kernel.org; s=arc20261015;
	a=rsa-sha256; c=relaxed/relaxed; t=1795353844;
	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=LX1er8W69gZNUPbY/pjrjgdNZyTT7gzY53mg2yQt6WE=;
	b=Ey8gW8w9LKuRXvScLy2+uoxaV+rNhIh+kVAKwXHIYf9K1XDU0pGPsGrx1mAgVz4Z5fHb
	 qKDzeI6FVYfx/6sR2JFaCjQxwL1EQ7eTmjU+bqDxLHXmpr3Cf9AAPGXtbUb8PunOjCDdT
	 0JLKfT1kaCTsL0xP/ZB78C8zqX5EgvkMce/dGpuLzd3g3zDN+aeEb43kUOCfoJJTiaxxl
	 4dAJDsG5yniUQ2NUaO4jI8DRwNoZ4H8d3W16h4nT3tMBGRaHvVYSfSAOa4+M5IQMrmwSN
	 BMm7Kj4QTUsix23GItzJoBQkkfDZFsMW38lXdka/HvkpvaPuQqtsBu+O5hrRZauF7DQ==
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=Qw67LtmK;
	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 9D903606A68E;
	Sun, 22 Nov 2026 13:24:04 +0000 (UTC)
X-Authentication-Results: smtp.subspace.kernel.org;
	dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=Qw67LtmK
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=1795353843;
	b=W8zxcYHc2MRDFRWBPRkBKRw5iEnTr+WmhBngk4V/MKNqx15JhdXKWRaMrf7OMSMiHQLC
	 c35Cj4Xo5k2ax4D7CmuJzlZGbL4jfcwwxpS0Bt3crtB+RcllYO55qxekXsTqqsH/82nU/
	 YUr/i4tuTXb34+v+iPXwiJKQl8Igo1b5Mw6pmd3TSr8ijcHgIE54QOSZ4+yrDvgog6HmN
	 mcVjbZSAmlVRvs7HFKKNH8zPA9rpathtn0WGQzqDLbxAhUwrvbxOse+d8BPHq7L67aKRK
	 Q8sNYMZV9fAi4U0Jl25tzUwPDoJ2L8BS9yMQxTm1As0U7DSVg3AjOoMaLWamwkpttPA==
X-ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015;
	a=rsa-sha256; c=relaxed/relaxed; t=1795353843;
	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=LX1er8W69gZNUPbY/pjrjgdNZyTT7gzY53mg2yQt6WE=;
	b=B0ea35cqhLujNEQYiD1yPLjv6VjQ07w3Toon4yhiINH1177T+FUBQmaE9jEIRgzNZdFc
	 N6Zv/mB/YqQMJOU0RRXB+aCFhHd35i5laOj5CZ0CLOcLPtV+5HSIxrEqVrVbV+uOgSBZY
	 Hsw3UZ77elCjhCSCIwe2Q9K02Wi5Zt5e4Vygb6oOU7U+c6Qtp7Og4Fl6aGo+y1g4YG52J
	 VbpMdlsmVUvd1woy0IZJRxoWbEYk2ShhpuxWxZX099EjlCWGH+jdyZuqBT7W9l9NQalXm
	 ADruG1nxPvd/40QxqVq28oDCc3eTrhnWvJxeYLXhtHRHCuut76IKGp0V9H9zkOxMQWQ==
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=Qw67LtmK;
	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 BF631606A33E;
	Sun, 22 Nov 2026 13:24:03 +0000 (UTC)
X-Received: by smtp.kernel.org (Postfix) with ESMTPSA id 972EA1F000C0;
	Sun, 22 Nov 2026 13:24:02 +0000 (UTC)
X-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org;
	s=k20260515; t=1795353843;
	bh=LX1er8W69gZNUPbY/pjrjgdNZyTT7gzY53mg2yQt6WE=;
	h=Subject:From:To:Cc:Date:In-Reply-To:References;
	b=Qw67LtmKJYCm1KNf4wobrqCnjN3Sq6JXdFKCGKWb9g1dVaOghe6vzsuebugpsn0tA
	 a8kxJvBKL18Z+ZR66Sv5NZ9bDUg0a/OADpdMKtHJh4cy9+jEA+oXQFg+EcEGn5aIqa
	 LHFCaSbzcxu4tQDT/+Z1Yao0S/5byPs88FyMLkxslOx7W/6v2RVHZ3G9EVmVhcz71g
	 8YCVzsqaP+GXGxa2hm4aC9CtdvgXyfhQtcZU+Qs5Pi1b+R4K/aQhdrjkWQNSr97lUt
	 yVWPXC5jJZI1dHEaCvzAIViHYrSV70QCgt2ObD4xGPQu4MhXMv5VfekDN3kbo+AVOn
	 P6WIBMqOcNcZQ==
X-Cc: davem@davemloft.net, edumazet@kernel.org, kuba@kernel.org,
 pabeni@redhat.com, andrew+netdev@lunn.ch, shenjian15@huawei.com,
 liuyonglong@huawei.com, chenhao418@huawei.com, yangshuaisong@h-partners.com,
 ningwei15@huawei.com, netdev@vger.kernel.org, linux-kernel@vger.kernel.org
X-In-Reply-To: <20261118130330.3026625-5-shaojijie@huawei.com>
X-sashiko-severity: Low
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