🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: linux.kernel.netdev
Article #27501

Re: [PATCH net v2 3/6] idpf: ignore link events once removal has started

#27501
From: netdev-bot+sashiko
Date: Sat, 05 Dec 2026 20:47
210 lines
15919 bytes
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] On remove, the fix only works together with the mbx_task drain
  added by the previous patch in the series ("idpf: ignore Tx timestamp…

Pre-existing issues:
- [High] This patch did not introduce the problem: the same link-event
  use-after-free stays reachable on teardown paths that do not set…
- [High] This patch did not introduce the problem: a link event can see a
  vport before its netdev is set.
- [High] This patch did not introduce the problem:
  idpf_handle_event_link() can wake the TX queues of a vport whose…

--

idpf: ignore link events once removal has started

This patch makes idpf_handle_event_link() return early once
IDPF_REMOVE_IN_PROG is set. On remove, it relies on the mbx_task drain
added by the previous patch, so a link event is either handled before the
vports are torn down or ignored. The commit message notes that hard reset
still has the window and that shutdown is handled later in the series.

> diff --git a/drivers/net/ethernet/intel/idpf/idpf_virtchnl.c b/drivers/net/ethernet/intel/idpf/idpf_virtchnl.c
> index 348c7875134ad..854eb1f1ada4c 100644
> --- a/drivers/net/ethernet/intel/idpf/idpf_virtchnl.c
> +++ b/drivers/net/ethernet/intel/idpf/idpf_virtchnl.c
> @@ -41,6 +41,10 @@ static void idpf_handle_event_link(struct idpf_adapter *adapter,
>  	struct idpf_netdev_priv *np;
>  	struct idpf_vport *vport;
>  
> +	/* The vports are released on remove and shutdown */
> +	if (test_bit(IDPF_REMOVE_IN_PROG, adapter->flags))
> +		return;
> +

[Severity: Low]

On remove, this check only closes the window when combined with the
mbx_task drain from the previous patch in the series ("idpf: ignore Tx
timestamp replies once removal has started"). That drain is in
idpf_vc_core_deinit():

	} else {
		...
		cancel_delayed_work_sync(&adapter->mbx_task);
		queue_delayed_work(adapter->mbx_wq, &adapter->mbx_task, 0);
	}

Without the drain, this test_bit() is check-then-act. Suppose an mbx_task
passed the check before idpf_remove() set IDPF_REMOVE_IN_PROG. It can still
be inside idpf_handle_event_link() when
idpf_deinit_task()->idpf_vport_dealloc() frees the vport.

The previous patch has Fixes: 1a49cf814fe1. This patch has
Fixes: 02cbfba1add5 and a plain Cc: stable, with no note about the
prerequisite. Some stable trees have 02cbfba1add5 but not 1a49cf814fe1
(6.12.y, for example). Those trees would not pick up the previous patch,
and its context (idpf_ptp_release()) does not exist there.

In those trees this statement from the commit message would not hold:

  "on remove a link event is either handled before the vports are torn
  down or ignored"

The race would only be narrowed.

Could the stable tag get a "# depends on" note? Alternatively, the drain
could be split out with a Fixes tag that covers 02cbfba1add5.

>  	vport = idpf_vid_to_vport(adapter, le32_to_cpu(v2e->vport_id));

[Severity: High]

This is a pre-existing issue and was not introduced by this patch. The
same use-after-free can still happen on teardown paths that never set
IDPF_REMOVE_IN_PROG.

The commit message already mentions hard reset. idpf_init_hard_reset()
calls idpf_vc_core_deinit() with remove_in_prog false. So mbx_task is not
drained before idpf_deinit_task(), and it is only cancelled afterwards:

	idpf_ptp_release(adapter);
	idpf_deinit_task(adapter);
	...
	cancel_delayed_work_sync(&adapter->serv_task);
	cancel_delayed_work_sync(&adapter->mbx_task);

The commit message does not mention the unwind_vports error path in
idpf_init_task(), which has the same problem. It frees the vports while
mbx_task is live and cancels mbx_task only afterwards:

unwind_vports:
	if (default_vport) {
		for (index = 0; index < adapter->max_vports; index++) {
			if (adapter->vports[index])
				idpf_vport_dealloc(adapter->vports[index]);
		}
	}
	...
	if (test_and_clear_bit(IDPF_HR_DRV_LOAD, adapter->flags)) {
		cancel_delayed_work_sync(&adapter->serv_task);
		cancel_delayed_work_sync(&adapter->mbx_task);
	}

libie_ctlq_xn_shutdown() does not stop these events. libie_ctlq_xn_recv()
still passes any message that libie_ctlq_xn_process_recv() does not claim
to params->ctlq_msg_handler. So unsolicited VIRTCHNL2_EVENT_LINK_CHANGE
messages keep arriving.

IDPF_HR_RESET_IN_PROG is set on both paths, so idpf_vport_dealloc() skips
idpf_decfg_netdev(). It then frees the vport before clearing its slot:

	idpf_vport_rel(vport);      <-- kfree(vport)

	adapter->vports[i] = NULL;

Can a concurrent link event get the vport from idpf_vid_to_vport() and
then read vport->netdev and read/write vport->link_up after the kfree()?

This could be triggered by a driver-initiated function reset (for example
after a Tx timeout). It could also be triggered by an idpf_init_task()
failure after at least one vport was allocated.

The shutdown part of this is fixed later in the series by "idpf: keep the
mailbox up while tearing down vports on shutdown". That patch sets
IDPF_REMOVE_IN_PROG at the start of idpf_shutdown().

>  	if (!vport) {
>  		dev_err_ratelimited(&adapter->pdev->dev, "Failed to find vport_id %d for link event\n",

[Severity: High]

This is also a pre-existing issue and was not introduced by this patch.
Can a link event see a vport before its netdev has been set?

idpf_vport_alloc() publishes the vport with plain stores:

	adapter->vports[idx] = vport;
	adapter->vport_ids[idx] = idpf_get_vport_id(vport);

vport->netdev is only assigned later, when idpf_init_task() calls
idpf_cfg_netdev():

	if (idpf_cfg_netdev(vport))
		goto unwind_vports;

At that point mbx_task is already running and IDPF_REMOVE_IN_PROG is
clear. Suppose a VIRTCHNL2_EVENT_LINK_CHANGE for the new vport_id arrives
in that window. idpf_vid_to_vport() returns a vport whose netdev is still
NULL, and idpf_handle_event_link() then does:

	np = netdev_priv(vport->netdev);

	np->link_speed_mbps = le32_to_cpu(v2e->link_speed);

Would this write through netdev_priv(NULL) and oops?

The window is open on every probe and after every hard reset. On the first
probe it also includes the sleeping alloc_etherdev_mqs().

[Severity: High]

This is another pre-existing race in this handler and was not introduced
by this patch. Can a link event wake the TX queues of a vport while it is
being stopped?

idpf_handle_event_link() runs without rtnl or vport_ctrl_lock and does:

	vport->link_up = v2e->link_status;

	if (!test_bit(IDPF_VPORT_UP, np->state))
		return;

	if (vport->link_up) {
		netif_tx_start_all_queues(vport->netdev);
		netif_carrier_on(vport->netdev);

idpf_vport_stop() clears IDPF_VPORT_UP only after the queues are freed:

	vport->link_up = false;
	idpf_vport_intr_deinit(vport, rsrc);
	idpf_xdp_rxq_info_deinit_all(rsrc);
	idpf_vport_queues_rel(vport, rsrc);
	idpf_vport_intr_rel(rsrc);
	clear_bit(IDPF_VPORT_UP, np->state);

Consider a link-up event handled between the link_up = false store and the
clear_bit(). It would see link_up change and pass the IDPF_VPORT_UP test.
It would then restart all TX queues and turn the carrier on.

On the soft reset path (ethtool -L/-G or an MTU change on an up
interface), the stack can then call idpf_tx_start(), which does:

	tx_q = vport->txqs[skb_get_queue_mapping(skb)];

After idpf_vport_queues_rel() that pointer is NULL. After this memcpy() in
idpf_initiate_soft_reset() it is the stale, freed pointer:

	memcpy(vport, new_vport, offsetof(struct idpf_vport, link_up));

It stays that way until idpf_vport_open() reallocates the queues.

-- 
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261204194642.3048406-1-anthony.l.nguyen%40intel.com
Technical Details
Message-ID: <179650363281.3148.9057377963791505666@kernel.org>
Path: mbox-mo1.pugleaf.net!news-wdc.pugleaf.net!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!peer04.iad!feed-me.highwinds-media.com!peer05.ams4!peer.am4.highwinds-media.com!news.highwinds-media.com!feeder.usenetexpress.com!tr3.eu1.usenetexpress.com!news.neodome.net!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-378124-linux-kernel-netdev=dewy.ru
References: <20261204194642.3048406-4-anthony.l.nguyen@intel.com>

Show Full Headers
Complete Article Headers
Path: mbox-mo1.pugleaf.net!news-wdc.pugleaf.net!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!peer04.iad!feed-me.highwinds-media.com!peer05.ams4!peer.am4.highwinds-media.com!news.highwinds-media.com!feeder.usenetexpress.com!tr3.eu1.usenetexpress.com!news.neodome.net!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-378124-linux-kernel-netdev=dewy.ru
From: netdev-bot+sashiko@kernel.org
Newsgroups: linux.kernel.netdev
Subject: Re: [PATCH net v2 3/6] idpf: ignore link events once removal has started
Date: Sat, 05 Dec 2026 20:47:12 +0000
Organization: Usenet Network
Message-ID: <179650363281.3148.9057377963791505666@kernel.org>
References: <20261204194642.3048406-4-anthony.l.nguyen@intel.com>
MIME-Version: 1.0
Content-Type: text/plain; charset="utf-8"
Content-Transfer-Encoding: 8bit
Injection-Info: usenet.network; logging-data="3117247"; mail-complaints-to="abuse@usenet.network"
Cancel-Lock: sha1:s7Fyn37geQU2r7dlTFEupzFkJuE= sha256:M/Omfrzpp2bOezbvLldn8tPsVm1KoLmxYkiXydQupEY= sha1:A7tZExvXNcQwle0d1dVmYm8iuiE= sha256:bwwBdB3u4tonkr74+DQsIO0CdTmlJPk44Z8tZRxWAKc=
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 86968117EAD; Sat,  5 Dec 2026 23:47:37 +0300 (MSK)
X-Virus-Scanned: Debian amavisd-new at usenet.network
X-Spam-Flag: NO
X-Spam-Score: -3.539
X-Spam-Status: No, score=-3.539 tagged_above=-9999 required=6.31 tests=[DCC_REPUT_70_89=0.1, DKIMWL_WL_HIGH=-0.14, 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, URIBL_BLOCKED=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 BJ2ZgZjBLGGb; Sat,  5 Dec 2026 23:47:34 +0300 (MSK)
X-Received-SPF: Pass (mailfrom) identity=mailfrom; client-ip=172.234.253.10; helo=sea.lore.kernel.org; envelope-from=netdev+bounces-378124-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 9FF4A117EA6; Sat,  5 Dec 2026 23:47:23 +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 758042613E; Sat,  5 Dec 2026 20:47:15 +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=1796503635; b=gUVDtroNn16Puu5Fy2iJF15TnI1nYdBfoa+PYgwyF/ZMV6fivXOxKJ3wts+osCbhsXPX noy3l6bIGb30S3DK0D/xbYfFRBedKfGRgikpAUiDKvwX9MFn9dS4xZ8CQlVO14Yd+BMdx DRWUVIPWxnZ3NRhxdaFqNeAQuGvETeYOAZDxchvXWOsxHxEndZ/tC51i4F1WluXqMbGkt XIjxMKQTPjH9yjEt13q/ogb2PkCUElicY10JmjkrVZ9pPLuSoWHGhjVsl8asWzmm6Bd4C bZolM6puMSvAYJUCd0BX7QQySOzQk86PyY84MYo9exx2wDCGDH0bEKfIGo+OrlTUcuQ==
X-ARC-Message-Signature: i=2; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796503635; h=X-Original-To:Received:Received:DKIM-Signature:Subject:From:To:Cc: Date:Message-ID:In-Reply-To:References:X-sashiko-severity: Content-Type:Content-Transfer-Encoding:X-Mailing-List:List-Id: List-Post:List-Help:List-Subscribe:List-Unsubscribe:List-Owner: Precedence:MIME-Version; bh=3oAmjRNf+eHHyQBrEzvJ5JH6MT1ZMhwapDbYyk7gyo4=; b=Qx9LZ65h5KDOhlBjfa8llF4uPItXRPk0r8fYXW2eAsgAqTUSHYkZx/92MyqciToq9tUz VjGrLU1YbUQ6chZPLmlEN+mg6SqoLugyhPiJbWEX196VI9071Nr/HmNRsgoXYaHluk3XG ojgjn8RvgVd5HpLLJqTY16El/MJe62U6K0D7xXt0JxbB+S80xHQ4tbKco9lkYV5/WkNlO UAqfGTdlq+uGZV5+tZfDE5/UC5bvQ8Viavl3EykakC4oFFOO2CnMBJTGvbsYJUDBY/pWr 1JR9KJ5nnVdfPTj5DGIfz+nMgTy89naVXkGUL+vc3qoY+gVdHc3LkRefLuqKpjI1Yzw==
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=IvkuZs6c; 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 44B37606A334; Sat,  5 Dec 2026 20:47:15 +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=IvkuZs6c
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=1796503634; b=GRCoS4Xvf7V3PtfASo1GvRXBakJU7aHk0l3idspGBWEBGmpHT21KUBI93qMPDRdZjOvx PeXfvC+oRWc8O1Tp13Qew90AaJ0QgKQte92R06Fe8b/59+gSTxgbEaYyfrWzBGsxV8fwZ StK9k9xpgNEsVVSwBNoyYjkucR8r0J53aPuwFKx4lpPIFmP8/B+EmmJeNA8b1Wg/eRKPZ 3LooqmdIPUli2oFVrACHBMIZga3Te5li5400/AesfYD3TxAWtzHjjtJ+gUtDid3kbDVYN XiBEL5rlsgCHepSjbZAphnF6pOc/xVFOfXiktYFz/g2rDAFAjgq2oaY745VXYYh+KXg==
X-ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796503634; h=Received:DKIM-Signature:Subject:From:To:Cc:Date:Message-ID: In-Reply-To:References:X-sashiko-severity:Content-Type: Content-Transfer-Encoding:MIME-Version; bh=3oAmjRNf+eHHyQBrEzvJ5JH6MT1ZMhwapDbYyk7gyo4=; b=kjzzASdmLB8wlhrgTUCaX3TRD7AuR+PPJ+65rESdxP9nwW5P8sGCFA1Vtx55nKFLJsm1 Elawo4CFq0JFIIZKS0V44r13uR7JxcVP8Hq0votsZxD4uJu2YOmad74KzOZh9EE33IPV6 VMnlh7v5yYB6jEcBOMBXgnEIfno1Y8Iv3jvGWigHjOt0tQlLwHEoIXLth7mO7DL2h3S4U lKrHmsIiL+BXYxGY5zvIGhXw0cl9OoxAPiaxZs8eIGsWBn4yj22ijDqRMB9a131yl3opw xulG+6ydnyVlyYqHVqdK0fVV8KqLiGzJ3eJJp3ltyegNhjB0JbghipCxq4bMUMC2LPw==
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=IvkuZs6c; 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 67096606A339; Sat,  5 Dec 2026 20:47:14 +0000 (UTC)
X-Received: by smtp.kernel.org (Postfix) with ESMTPSA id 43BE51F0092B; Sat,  5 Dec 2026 20:47:13 +0000 (UTC)
X-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1796503634; bh=3oAmjRNf+eHHyQBrEzvJ5JH6MT1ZMhwapDbYyk7gyo4=; h=Subject:From:To:Cc:Date:In-Reply-To:References; b=IvkuZs6cYNz1jJx9CAvgYZ94JASLDv69m0x2bfx9OpHT4FiFGDJLrYsG99nYK6m8k m2fzXSlRJpbTNQRAAUbJjiWNXghAMjQrb5oqjywLjHG9FmOr7lnCCNPkZmxU9WyIrv /oMhPvqAm1mGl+oiTnQb5yUW3xuHi6hGwo4jZlYAsk5JYR8orRKEEuj8WNp/GDwBzL M2mnacfjpzGSSAQWvwkLTB/avEk7FyH1h7JjesJUNsCvhWkXf6NlW5OuxZAEGCzev/ VYT49T4HpDTNX/0I/tvky0mwBtXlUnAxWEh7ZmpbYSsVVbJg14F3MF38oFTrJJFHre vyXGX5z6zvpTQ==
X-Cc: davem@davemloft.net, kuba@kernel.org, pabeni@redhat.com, edumazet@kernel.org, andrew+netdev@lunn.ch, willemb@google.com, netdev@vger.kernel.org, tianxun.ng@bytedance.com, oss.patchbox@gmail.com, luckilystar08@gmail.com, emil.s.tantilov@intel.com, richardcochran@gmail.com, milena.olech@intel.com, konstantin.ilichev@intel.com, stable@vger.kernel.org, Samuel.salin@intel.com
X-In-Reply-To: <20261204194642.3048406-4-anthony.l.nguyen@intel.com>
X-sashiko-severity: Low
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-Received-Bytes: 15722