From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=100.103.45.18 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== 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== 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 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) 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 Received: by smtp.kernel.org (Postfix) with ESMTPSA id 43BE51F0092B; Sat, 5 Dec 2026 20:47:13 +0000 (UTC) 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== Subject: Re: [PATCH net v2 3/6] idpf: ignore link events once removal has started From: netdev-bot+sashiko@kernel.org To: anthony.l.nguyen@intel.com 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 Date: Sat, 05 Dec 2026 20:47:12 +0000 Message-ID: <179650363281.3148.9057377963791505666@kernel.org> In-Reply-To: <20261204194642.3048406-4-anthony.l.nguyen@intel.com> References: <20261204194642.3048406-4-anthony.l.nguyen@intel.com> X-sashiko-severity: Low Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 8bit X-Mailing-List: netdev@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 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