Re: [PATCH v5 net 4/4] net: hns3: fix use-after-free in debugfs read during reset/unload
From: netdev-bot+sashiko
Date: Sun Nov 22 2026 - 08:24:17 EST
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@xxxxxxxxxx/
> 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