Article View: linux.kernel.netdev
Article #22462Re: [PATCH v5 net 4/4] net: hns3: fix use-after-free in debugfs read during reset/unload
From: Simon Horman
Date: Wed, 25 Nov 2026 10:39
Date: Wed, 25 Nov 2026 10:39
46 lines
10132 bytes
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>
Technical Details
Message-ID:
<20261125103909.GR31322@horms.kernel.org>Path:
mbox-mo1.pugleaf.net!srv.newsdeef.eu!newsfeed.bofh.team!news.nntp4.net!nntp.xenet.de!news.neodome.net!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-371237-linux-kernel-netdev=dewy.ruReferences:
<20261118130330.3026625-1-shaojijie@huawei.com> <20261118130330.3026625-5-shaojijie@huawei.com>Show Full Headers
Complete Article Headers
Path: mbox-mo1.pugleaf.net!srv.newsdeef.eu!newsfeed.bofh.team!news.nntp4.net!nntp.xenet.de!news.neodome.net!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-371237-linux-kernel-netdev=dewy.ru From: horms@kernel.org (Simon Horman) Newsgroups: linux.kernel.netdev 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 Organization: Usenet Network Message-ID: <20261125103909.GR31322@horms.kernel.org> References: <20261118130330.3026625-1-shaojijie@huawei.com> <20261118130330.3026625-5-shaojijie@huawei.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Injection-Info: usenet.network; logging-data="183784"; mail-complaints-to="abuse@usenet.network" Cancel-Lock: sha1:1OpfTfppx74N6nYTCb6DP8uukR4= sha256:T2cHzmcPf8oxvvkzeTCTvabW/lfxQP1RqIjoTBiobus= sha1:Dsbf/bzzaQmBLrP2/NeFdKGn44o= sha256:OxFb1ylW5GyZXeJ4mqMaT2wCVBV7HkhddADvrEaEkA0= Content-Disposition: inline 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 13292125E55; Wed, 25 Nov 2026 13:39:37 +0300 (MSK) X-Virus-Scanned: Debian amavisd-new at usenet.network X-Spam-Flag: NO X-Spam-Score: -3.401 X-Spam-Status: No, score=-3.401 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] 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 2Ot6uhxXlAYi; Wed, 25 Nov 2026 13:39:33 +0300 (MSK) X-Received-SPF: Pass (mailfrom) identity=mailfrom; client-ip=172.234.253.10; helo=sea.lore.kernel.org; envelope-from=netdev+bounces-371237-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 27FF0125E54; Wed, 25 Nov 2026 13:39:25 +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 83E1C3D875; Wed, 25 Nov 2026 10:39:20 +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=1795603160; b=stVFLLQDFUOZ5V8tsrjHMsqyUUfbKT6RdZ9N5XyRKBpGXwUzQvnj0a6/APPDQYvPcM4h +tof8ZmtEAaBrlQUuQR4qJLIepUYB5hGUnyOrX2C8plQAKrf5UbTB/Zw42+6RV4v91TRU W5qONZQNebXDEajWSwZ+6sVvIsJlCJrWewGjQpeMstIpXOv2w/YvXqUz5UuZb/ftGGk3f UHQMzfr/1B5tnHGDg1b/lCBmB4mqLO10LZRo2ZZLD3Taax0LMEWMDx+WKaGYW08HfVwWD hMYB6sV1AYEKMsLXf0csrH/fx4GMG20KKlR7vKPaRpYqongD1Kh4JjglvJSMSlEuQsw== X-ARC-Message-Signature: i=2; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1795603160; h=X-Original-To:Received:Received:DKIM-Signature:Date:From:To:Cc: Subject:Message-ID:References:X-Mailing-List:List-Id:List-Post: List-Help:List-Subscribe:List-Unsubscribe:List-Owner:Precedence: MIME-Version:Content-Type:Content-Disposition:In-Reply-To; bh=99+nx5kiE5SfUzLb8n+CdHLxKeAXEkt8ftQI5zT19Zw=; b=FzvpwfWN9UetXbDZ+qwg6b7G6jCjgjNRmjWmbGJ3PoOW7t3tkC5qWg9BYoIuylQtGs7n bSsadbxKy+kI4jy/5KfaGNYvH8wKhRT3unvXRx0sN/3lkPVJeQyrzBYtpjQl67oRX8vDG n3WqCdWASoK4U/Of/1uGgYklCFgcWLfT2Q1ugOtO22mJUtOsUWh5dj/HUPQY0AO5xmw5N XkwDlLSesYvOe21j0G7dfxpAn/6h6aa8kU7xn+xgIMQ5lbhp0R2Qzxq0YebFnxz/codjB 5d3IwInfKMLiHuh9e2QLr4AqXqveZlKJpxk8MkO0w1XKyyakRR5iOM0xvOSrwQ6sr9g== 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=TQGC8C0e; 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 5BED3606A329; Wed, 25 Nov 2026 10:39:20 +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=TQGC8C0e 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=1795603154; b=X/AMEHcxW5e1CHKL6540DPLfSHhGBxs1Q1uOF9qu5wliIeoFsPx1X7FmJcSywiuLJ8zZ md0jJH3JMNfOwolaAJsJxwSZ8+rHCj1GxD0WPrUAxcvwrtKYajKvCXcT5zrLt1tnx6ErV apyqZy4z1bJxEjB1T8xijtvAZekk5HaqMWbwrG256f8tEuuHuIUQl72KDWETlp4Grk37N 1ExKX+I08quh55XvS7L5fWacjnFRFd93OVbt7ZkRlf/iMrBbJcaN2oICUUJtE+LtOwNob dDs4UO8AV7j0qkUvsWT9clorMsIoEvw/FwTEUQjVvj9bwa6zlIYuhnS2QqIIYmPJQFw== X-ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1795603154; h=Received:DKIM-Signature:Date:From:To:Cc:Subject:Message-ID: References:MIME-Version:Content-Type:Content-Disposition:In-Reply-To; bh=99+nx5kiE5SfUzLb8n+CdHLxKeAXEkt8ftQI5zT19Zw=; b=opdO4U/F5sWAZe9LkaW2br/wrSg8+avv2o6CaY5cfAWTMpHUBlVikBCSH5BY5nTNV5T9 1FCobUiviMogInlYmWpJNtYIbtc5wPI4+2QMN3+VgX92UCiiXlYeXgp1c+eAMYBdupt+v OfsDPxxGkGdCdtbE2VK6u9uBmKAwzuDrCUNGNva1NK/pO9qt/59kBIFv8sQAB3XiUbDPF Dx2FuftjPlvQSv9fzFQkYvEGWYj6BY3+XCA+JzFhsgBv8beZoGnRId4bh+DZZQECeNopt IFw2E2JjW6cYbLdMpyK1Jf162yofVmENqSqDiY3y+tystp+I6G7yUsl8tKXmns3CPkA== 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=TQGC8C0e; 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 78BE7606A31E; Wed, 25 Nov 2026 10:39:14 +0000 (UTC) X-Received: by smtp.kernel.org (Postfix) with ESMTPSA id B4AE71F000CA; Wed, 25 Nov 2026 10:39:11 +0000 (UTC) X-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1795603154; bh=99+nx5kiE5SfUzLb8n+CdHLxKeAXEkt8ftQI5zT19Zw=; h=Date:From:To:Cc:Subject:References:In-Reply-To; b=TQGC8C0e1Ga8ccjLSzibaFfQj3GiF6rJbsRzuQr2T59I6btPjsEQVOshe/GGh5AYM Y6wUSmCY9hZ1lBAIas6UNT8Be96ljiNi0akdC4MgktXljS0JXM0ZskC0MsKFw/q60J VWfqeGkI0ZUgNZbuRLlUSv5b52DIsxyNXnI6sm1rLix6zdaPTAKTlY3j7zlP794nL3 tyDB94SJvEJj0+Z6qEnZ0Kaye/0U3F8RDknMnlcNE4amyLewXI9/X49RYDlTBpfR+Z SIAB/F6wx+dqyITCaTvJRM8/VVpcugQonO0BMeXwtVKiAszuy60YUWfN9d68F13Gkx di881NMx08FkA== 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-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 X-In-Reply-To: <20261118130330.3026625-5-shaojijie@huawei.com>