All of lore.kernel.org
 help / color / mirror / Atom feed
From: Simon Horman <horms@kernel.org>
To: Jijie Shao <shaojijie@huawei.com>
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
Subject: Re: [PATCH v5 net 4/4] net: hns3: fix use-after-free in debugfs read during reset/unload
Date: Wed, 25 Nov 2026 10:39:09 +0000	[thread overview]
Message-ID: <20261125103909.GR31322@horms.kernel.org> (raw)
In-Reply-To: <20261118130330.3026625-5-shaojijie@huawei.com>

On Wed, Nov 18, 2026 at 09:03:30PM +0800, Jijie Shao wrote:
> The seq_file refactoring of hns3 debugfs removed the per-file entry
> state checks. Without them, debugfs show callbacks can access
> priv->ring, priv->tqp_vector, and ring->desc while these resources
> are being freed by reset, driver unload, or ethtool ring resize.
> 
> Plain state-bit checks leave a TOCTOU window between check and use.
> 
> Fix by adding a mutex (dbg_mutex) to struct hnae3_handle, used by
> enet-layer debugfs callbacks. Readers acquire the mutex, then check
> device state per iteration -- this lets an in-flight reader exit
> promptly when reset begins mid-dump, keeping reset latency bounded
> by one iteration, and also rejects a reader that arrives after the
> writer has finished tearing down resources (priv->ring is NULL by
> then). The dbg_uninit() call stays outside the mutex to avoid
> deadlock with debugfs_remove_recursive().
> 
> Two kinds of writer paths are protected:
> 
>   * hns3_client_uninit() and hns3_reset_notify_uninit_enet() clear
>     HNS3_NIC_STATE_INITED first so that readers running outside the
>     mutex see the device as busy and return -EBUSY early, then take
>     dbg_mutex before freeing resources.
> 
>   * hns3_set_ringparam() calls ndo_stop() first (which sets
>     HNS3_NIC_STATE_DOWN) and then takes dbg_mutex around the ring
>     re-allocation. The busy check does not test the DOWN bit, so
>     readers that arrive here are blocked by the mutex itself rather
>     than by the INITED signal.
> 
> Userspace-visible changes: debugfs reads under
> /sys/kernel/debug/hns3/*/ that race with reset, driver unload, or
> ethtool ring resize now return -EBUSY instead of potentially reading
> freed or zero-filled memory. The per-iteration busy error is -EBUSY
> instead of -EPERM, and a NULL priv->ring now returns -EBUSY instead
> of -EFAULT. Reading page_pool_info when page pools are not
> initialized now succeeds and prints "page pool not initialized" per
> queue instead of failing with -EFAULT.
> 
> Fixes: a723fb8efe29d3 ("net: hns3: refine for set ring parameters")
> Fixes: eced3d1c41db ("net: hns3: use seq_file for files in queue/ in debugfs")
> Closes: https://lore.kernel.org/all/a0853cd9-cab5-441d-b181-8ba97f2f58b0@huawei.com/
> Signed-off-by: Jijie Shao <shaojijie@huawei.com>

Reviewed-by: Simon Horman <horms@kernel.org>


  parent reply	other threads:[~2026-11-25 10:39 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-18 13:03 [PATCH net v5 0/4] net: hns3: fix multiple bugs in reset/error paths Jijie Shao
2026-11-18 13:03 ` [PATCH v5 net 1/4] net: hns3: fix vector resource leak in hns3_nic_alloc_vector_data Jijie Shao
2026-11-25 10:38   ` Simon Horman
2026-11-18 13:03 ` [PATCH v5 net 2/4] net: hns3: fix page_pool leak in hns3_alloc_ring_memory error path Jijie Shao
2026-11-25 10:38   ` Simon Horman
2026-11-18 13:03 ` [PATCH v5 net 3/4] net: hns3: fix interface stuck after OOM with full hardware rx queue Jijie Shao
2026-11-22 13:24   ` netdev-bot+sashiko
2026-11-23  7:33     ` Jijie Shao
2026-11-25 14:31       ` Paolo Abeni
2026-11-26  3:58         ` Jijie Shao
2026-11-25 10:38   ` Simon Horman
2026-11-18 13:03 ` [PATCH v5 net 4/4] net: hns3: fix use-after-free in debugfs read during reset/unload Jijie Shao
2026-11-22 13:24   ` netdev-bot+sashiko
2026-11-23  7:43     ` Jijie Shao
2026-11-25 10:39   ` Simon Horman [this message]
2026-11-26  9:10 ` [PATCH net v5 0/4] net: hns3: fix multiple bugs in reset/error paths patchwork-bot+netdevbpf

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20261125103909.GR31322@horms.kernel.org \
    --to=horms@kernel.org \
    --cc=andrew+netdev@lunn.ch \
    --cc=chenhao418@huawei.com \
    --cc=davem@davemloft.net \
    --cc=edumazet@kernel.org \
    --cc=kuba@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=liuyonglong@huawei.com \
    --cc=netdev@vger.kernel.org \
    --cc=ningwei15@huawei.com \
    --cc=pabeni@redhat.com \
    --cc=shaojijie@huawei.com \
    --cc=shenjian15@huawei.com \
    --cc=yangshuaisong@h-partners.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.