🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Thread View: linux.kernel.netdev
1 messages
1 total messages Started by Simon Horman Wed, 25 Nov 2026 10:39
Re: [PATCH v5 net 4/4] net: hns3: fix use-after-free in debugfs read during reset/unload
#22462
Author: Simon Horman
Date: Wed, 25 Nov 2026 10:39
46 lines
10132 bytes
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>
Thread Navigation

This is a paginated view of messages in the thread with full content displayed inline.

Messages are displayed in chronological order, with the original post highlighted in green.

Use pagination controls to navigate through all messages in large threads.

Back to All Threads