mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Jijie Shao <shaojijie@huawei.com>
To: <netdev-bot+sashiko@kernel.org>
Cc: <shaojijie@huawei.com>, <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 v3 net 1/4] net: hns3: fix vector resource leak in hns3_nic_alloc_vector_data
Date: Wed, 4 Nov 2026 19:49:54 +0800	[thread overview]
Message-ID: <db8134db-5e14-4669-ba16-126b45e77cb2@huawei.com> (raw)
In-Reply-To: <179370110586.488856.5999411563039166781@kernel.org>


on 2026/11/3 18:18, netdev-bot+sashiko@kernel.org wrote:
> 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 commit message does not give the real reason for one line of
>    the fix.
>
> --
>
> net: hns3: fix vector resource leak in hns3_nic_alloc_vector_data
>
> This patch fixes the error path in hns3_nic_alloc_vector_data() for when
> devm_kcalloc() of priv->tqp_vector fails. The new path calls put_vector()
> for every vector that get_vector() acquired, and resets priv->vector_num
> to 0 before returning.
>
>> Call put_vector() for every acquired vector before returning the
>> error, and reset priv->vector_num to 0 to avoid a NULL deref in the
>> subsequent hns3_nic_dealloc_vector_data(), which iterates
>> priv->tqp_vector (still NULL after the kcalloc failure) using
>> priv->vector_num.
> [Severity: Low]
> Is this the right reason for the priv->vector_num reset? As far as I can
> tell, no path calls hns3_nic_dealloc_vector_data() after
> hns3_nic_alloc_vector_data() fails.
>
> In hns3_client_init(), the failure jumps to a label that comes after the
> dealloc call:
>
> drivers/net/ethernet/hisilicon/hns3/hns3_enet.c:hns3_client_init() {
>      ...
> 	ret = hns3_nic_alloc_vector_data(priv);
> 	if (ret) {
> 		ret = -ENOMEM;
> 		goto out_alloc_vector_data;
> 	}
>      ...
> out_init_vector_data:
> 	hns3_nic_dealloc_vector_data(priv);
> out_alloc_vector_data:
>      ...
> }
>
> hns3_reset_notify_init_enet() works the same way:
>
> drivers/net/ethernet/hisilicon/hns3/hns3_enet.c:hns3_reset_notify_init_enet() {
>      ...
> 	ret = hns3_nic_alloc_vector_data(priv);
> 	if (ret)
> 		goto err_put_ring;
>      ...
> err_dealloc_vector:
> 	hns3_nic_dealloc_vector_data(priv);
> err_put_ring:
>      ...
> }
>
> hns3_client_uninit() and hns3_reset_notify_uninit_enet() both start with
> test_and_clear_bit(HNS3_NIC_STATE_INITED, &priv->state). They bail out
> before calling hns3_nic_dealloc_vector_data() if the bit is clear.
>
> HNS3_NIC_STATE_INITED is only set once init succeeds, so it is still
> clear after this failure. That means the NULL deref described above
> cannot happen, with or without this patch.
>
> The reset may still be useful for other code that indexes
> priv->tqp_vector by priv->vector_num while the netdev stays alive after
> a failed reset re-init. One example is hns3_dump_coal_info() in
> hns3_debugfs.c:
>
> 	for (i = 0; i < priv->vector_num; i++) {
> 		tqp_vector = &priv->tqp_vector[i];
>
> Should the commit message name the code that actually depends on
> priv->vector_num being 0, rather than hns3_nic_dealloc_vector_data()?

Acked. The NULL deref in hns3_nic_dealloc_vector_data() cannot
happen because the failure path jumps past it. The real reason
for the reset is to protect code that indexes priv->tqp_vector
by priv->vector_num while the netdev stays alive after a failed
reset re-init (e.g. hns3_dump_coal_info()). Will adjust the
commit message in v4.



  reply	other threads:[~2026-11-04 11:50 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-10-30  9:56 [PATCH v3 net 0/4] net: hns3: fix multiple bugs in reset/error paths Jijie Shao
2026-10-30  9:56 ` [PATCH v3 net 1/4] net: hns3: fix vector resource leak in hns3_nic_alloc_vector_data Jijie Shao
2026-11-03 10:18   ` netdev-bot+sashiko
2026-11-04 11:49     ` Jijie Shao [this message]
2026-10-30  9:56 ` [PATCH v3 net 2/4] net: hns3: fix page_pool leak in hns3_alloc_ring_memory error path Jijie Shao
2026-11-03 10:18   ` netdev-bot+sashiko
2026-11-04 11:51     ` Jijie Shao
2026-10-30  9:56 ` [PATCH v3 net 3/4] net: hns3: fix interface stuck after OOM with full hardware rx queue Jijie Shao
2026-11-03 10:18   ` netdev-bot+sashiko
2026-11-04 12:03     ` Jijie Shao
2026-10-30  9:56 ` [PATCH v3 net 4/4] net: hns3: fix use-after-free in debugfs read during reset/unload Jijie Shao
2026-11-03 10:18   ` netdev-bot+sashiko
2026-11-04 12:29     ` Jijie Shao
2026-10-30 10:00 ` [PATCH v3 net 0/4] net: hns3: fix multiple bugs in reset/error paths netdev-bot+sinfo

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=db8134db-5e14-4669-ba16-126b45e77cb2@huawei.com \
    --to=shaojijie@huawei.com \
    --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-bot+sashiko@kernel.org \
    --cc=netdev@vger.kernel.org \
    --cc=ningwei15@huawei.com \
    --cc=pabeni@redhat.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®