🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: linux.kernel.netdev
Article #19780

Re: [PATCH net] octeontx2-pf: Fix potential use-after-free in representor teardown

#19780
From: Simon Horman
Date: Fri, 20 Nov 2026 11:06
103 lines
11971 bytes
On Wed, Nov 18, 2026 at 02:13:34PM +0000, netdev-bot+sashiko@kernel.org wrote:
> Thank you for your contribution! Sashiko AI review found 1 potential
> issue(s) to consider.
> 
> Critical: 1 (1) · High: 0 (2) · Medium: 0 · Low: 0
> 
> If you believe none of the issues are legitimate, please reply to each
> issue of Medium severity or higher and explain why the AI is wrong.
> If any of them are legitimate and you plan to respin, please let patchwork
> know by including "pw-bot: cr" as a separate line at the end of your reply
> (one such reply per series is enough).
> 
> - [Critical] The patch is titled "Fix potential use-after-free in
>   representor teardown", but rvu_rep_destroy() still frees rep_dev while…
> 
> Pre-existing issues:
> - [Critical] This problem wasn't introduced by this patch, but
>   rvu_rep_setup_tc_cb() copies per-representor pointers into the long-…
> - [High] This problem wasn't introduced by this patch, but the flow_cfg
>   setup used by representor TC offload has broken locking and error…
> - [High] This problem wasn't introduced by this patch, but
>   rvu_rep_state_evt_handler() runs from the AF->PF up-mbox work on…
> 
> --
> 
> octeontx2-pf: Fix potential use-after-free in representor teardown
> 
> This patch reorders rvu_rep_destroy() so that rep->flow_cfg is freed
> before free_netdev() releases the netdev allocation that holds the
> representor private data.
> 
> > diff --git a/drivers/net/ethernet/marvell/octeontx2/nic/rep.c b/drivers/net/ethernet/marvell/octeontx2/nic/rep.c
> > index 0f5d5642d3f7a..662da7fc39536 100644
> > --- a/drivers/net/ethernet/marvell/octeontx2/nic/rep.c
> > +++ b/drivers/net/ethernet/marvell/octeontx2/nic/rep.c
> > @@ -638,8 +638,8 @@ void rvu_rep_destroy(struct otx2_nic *priv)
> >  		rep = priv->reps[rep_id];
> >  		unregister_netdev(rep->netdev);
> >  		rvu_rep_devlink_port_unregister(rep);
> > -		free_netdev(rep->netdev);
> >  		kfree(rep->flow_cfg);
> > +		free_netdev(rep->netdev);
> 
> [Severity: Critical]
> Can rep->stats_wrk still be pending when free_netdev() releases the
> rep_dev here?
> 
> The rep_dev lives in the netdev private area. Nothing in rep.c ever
> cancels stats_wrk. rvu_rep_get_stats64() re-arms it on every stats read:
> 
> drivers/net/ethernet/marvell/octeontx2/nic/rep.c:rvu_rep_get_stats64() {
>     ...
> 	schedule_delayed_work(&rep->stats_wrk, msecs_to_jiffies(100));
> }
> 
> The unregister_netdev() call just above seems to arm it too:
> 
> unregister_netdev()
>   unregister_netdevice_many_notify()
>     rtmsg_ifinfo_build_skb(RTM_DELLINK, ...)
>       dev_get_stats()
>         rvu_rep_get_stats64()
>           schedule_delayed_work(&rep->stats_wrk, ...)
> 
> When the timer fires about 100ms later, rvu_rep_get_stats() would run on
> the freed allocation:
> 
> 	rep = container_of(del_work, struct rep_dev, stats_wrk);
> 	priv = rep->mdev;
> 
> 	mutex_lock(&priv->mbox.lock);
> 	...
> 	stats = &rep->stats;
> 	stats->rx_bytes = rsp->rx.octs;
> 
> It reads rep->mdev from freed memory, takes a mutex through that pointer,
> and writes into rep->stats. The timer embedded in the delayed_work also
> stays linked in the timer wheel after the free.
> 
> This can happen on devlink eswitch mode set to legacy, PCI remove, or
> module unload, for any representor that has RVU_REP_VF_INITIALIZED set.
> After a module unload, the handler could also run after the module text
> is gone.
> 
> The error unwind in rvu_rep_create() has the same pattern:
> 
> 	while (--rep_id >= 0) {
> 		rep = priv->reps[rep_id];
> 		unregister_netdev(rep->netdev);
> 		rvu_rep_devlink_port_unregister(rep);
> 		free_netdev(rep->netdev);
> 	}
> 
> This patch targets a use-after-free of the rep private data in this loop.
> Should it also add cancel_delayed_work_sync(&rep->stats_wrk) before
> free_netdev() in both teardown paths?

The above does seem to be a legitimate bug.
However, I believe it is also pre-existing and can be handled
separately to this patch.

Reviewed-by: Simon Horman <horms@kernel.org>
Technical Details
Message-ID: <20261120110621.GB860048@horms.kernel.org>
Path: mbox-mo1.pugleaf.net!news-lax.pugleaf.net!srl.newsdeef.eu!newsfeed.bofh.team!news.nntp4.net!nntp.xenet.de!news.neodome.net!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-367890-linux-kernel-netdev=dewy.ru
References: <20261116-c29ba55625-net-otx2-representor@mail.sdu.edu.cn> <179501121429.3136.3547762606402557223@kernel.org>

Show Full Headers
Complete Article Headers
Path: mbox-mo1.pugleaf.net!news-lax.pugleaf.net!srl.newsdeef.eu!newsfeed.bofh.team!news.nntp4.net!nntp.xenet.de!news.neodome.net!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-367890-linux-kernel-netdev=dewy.ru
From: horms@kernel.org (Simon Horman)
Newsgroups: linux.kernel.netdev
Subject: Re: [PATCH net] octeontx2-pf: Fix potential use-after-free in
 representor teardown
Date: Fri, 20 Nov 2026 11:06:21 +0000
Organization: Usenet Network
Message-ID: <20261120110621.GB860048@horms.kernel.org>
References: <20261116-c29ba55625-net-otx2-representor@mail.sdu.edu.cn>
 <179501121429.3136.3547762606402557223@kernel.org>
MIME-Version: 1.0
Content-Type: text/plain; charset=utf-8
Content-Transfer-Encoding: 8bit
Injection-Info: usenet.network;
	logging-data="3140933"; mail-complaints-to="abuse@usenet.network"
Cancel-Lock: sha1:Soy/NMWrmRN/ZODOVeyxmLR0DL8= sha256:49d92HxUV2ii2q48vT4l0e+XKdoRaxCkonb88hBx768=
	sha1://WB5C26EKQmwpaSAWUfbkQ5sZM= sha256:2MRXjtt4lOXfXv6eZAEKb2lUbb1UGyi3DLeqiuK9mys=
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 C4C59115977; Fri, 20 Nov 2026 14:06:47 +0300 (MSK)
X-Virus-Scanned: Debian amavisd-new at usenet.network
X-Spam-Flag: NO
X-Spam-Score: -3.501
X-Spam-Status: No, score=-3.501 tagged_above=-9999 required=6.31
	tests=[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 IQeEGSRegl4M;
	Fri, 20 Nov 2026 14:06:44 +0300 (MSK)
X-Received-SPF: Pass (mailfrom) identity=mailfrom; client-ip=172.232.135.74; helo=sto.lore.kernel.org; envelope-from=netdev+bounces-367890-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 sto.lore.kernel.org (sto.lore.kernel.org [172.232.135.74])
	by mail.dewy.ru (Postfix) with ESMTPS id A06D7115942; Fri, 20 Nov 2026 14:06:35 +0300 (MSK)
X-Received: from smtp.subspace.kernel.org (conduit.subspace.kernel.org [100.77.114.92])
	by sto.lore.kernel.org (Postfix) with ESMTP id 3371068179F; Fri, 20 Nov 2026 11:06:35 +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=1795172793;
	b=vDlrFNnkE8s4hbqm1Y4M/9RHUXGBV5YR24yBYi+cwkM48zEyz/AUb+65GWfDNfzUV4dG
	 PD0SuudySGdj8aAvrVMEZ2H3/mOO8QyqmEVT4D5OCdvxOaNOiisa0vqnRStu80VzQF315
	 wsj4N24Yc7u9VW/lFSv2l1OzC7PmpH/W/y/81OIz6YTZMlLTqr+hXSsTt7g+ClkNBGHTH
	 XM047Hdo+diNZ7wEtwEbB13Ah5WRa46gbLP5g9m/EIx5fSy6LLrANGn2g1cKhS9fVpm/Y
	 Ui8bdXRu5v8o86PYfa2N48GyJJqXtOQnN4PIvU4aQuW86SbDvLhDX4NeDVoxcEZnlow==
X-ARC-Message-Signature: i=2; d=subspace.kernel.org; s=arc20261015;
	a=rsa-sha256; c=relaxed/relaxed; t=1795172793;
	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:
	 Content-Transfer-Encoding:In-Reply-To;
	bh=YYyqqP9Mt+ougXq/u35v5Dw9NG+MQo8EAqZGdlm0Rf8=;
	b=tJCPot85eZf9Um6UzrZQexsEz3dhIWpKDUMnitrepSajkdOli1WlqYIK5VKRMdjWZMKG
	 wnHHHo/0mWaElOv1fGlN4D2oXA2Qwsh1HgGxFsez2Y86KJPGUf6sJ8R2nqDEjrY80JD6E
	 cz5PR8IFIXxOoSRGqERBymoUGCFnOMANW5lw+yYK6Ak1mhehhj9pLQMgXX6CEqCcO1vAO
	 JQn23jnUG9oXmc80ONhX7Uvkt27sVHdtNYoZ8nbr9zgAFJBOHINVV1uYaNy474mflucwP
	 bc81POQ3p9AlkieuLoTt3BHJKKVRw4G2SOBfyN/prGlIzcv1QTYQ23i1U0O0XFBNn8Q==
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="JL/4KeD4";
	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 44BAD606A325;
	Fri, 20 Nov 2026 11:06:33 +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=JL/4KeD4
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=1795172787;
	b=AXntPbJABkzvNGU+Tv7OA42QfnluQ4TIL58AS5xyRNCWPh2cUYhXUDUKXVG18/X0Qy/J
	 P4sK52lJLZmsfLpMPDS5UD8sX0P/AusjqklOvcngl96yQPBNTcNQ4s1g7Wm+C2tc1rpGx
	 O4y40YZKhRMQlebhe0OxS1a7n+nVNDNTdMtayJWN/jWPJvEqQLuV13dIZxLsDJNwtdFtz
	 uwKIV0ZwSWITesrAnl2+m/hDFV5CON//pj1PpVMaHvv0EUZfbKyKijqtwA9t+Ra1n3Kfi
	 tsa+FT0+yjpBYAGauvN8kM7gaRAOK2l5jOG1SGY6eNT8ER40hLsztmOyvGCweAoSEAA==
X-ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015;
	a=rsa-sha256; c=relaxed/relaxed; t=1795172787;
	h=Received:DKIM-Signature:Date:From:To:Cc:Subject:Message-ID:
	 References:MIME-Version:Content-Type:Content-Disposition:
	 Content-Transfer-Encoding:In-Reply-To;
	bh=YYyqqP9Mt+ougXq/u35v5Dw9NG+MQo8EAqZGdlm0Rf8=;
	b=gSr/bDQkg75m6TivUF9qvDfynuN1DxH+4X6wpjVJ4GVPc9dj7tw09nTZ7jyjYodyfKUP
	 yKOZe3fuIDZILw3J7CZ7iuoe2jwS3VsxyoKOHb2HiQxaWvqyoeTitCXEdHMQQy555yVq0
	 kDgCJSUpZcNHvh1y7eCWWeBUxOimyoqceo+PSvIP6kb20ndENc/DJJhqFAA80tN2cMTNM
	 e4AzgaUQl0fQKy8I44nM0r0qykFvKQu9mOMvF1nk9dZ7z/TMJtj5dHpAJYxAH7Yr/xaoi
	 VYpsB+hOGlIQF84FVDSOqLTNXnZXbd/4HCJ7lCeUx4R6s0/1qs6q1t0TwQe05IWSAGA==
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="JL/4KeD4";
	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 64381606A326;
	Fri, 20 Nov 2026 11:06:27 +0000 (UTC)
X-Received: by smtp.kernel.org (Postfix) with ESMTPSA id 6D3501F000CA;
	Fri, 20 Nov 2026 11:06:24 +0000 (UTC)
X-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org;
	s=k20260515; t=1795172786;
	bh=YYyqqP9Mt+ougXq/u35v5Dw9NG+MQo8EAqZGdlm0Rf8=;
	h=Date:From:To:Cc:Subject:References:In-Reply-To;
	b=JL/4KeD4WWm/2Nsak1zGkpqHRgpRQbuvJik+YWthQfGT+QyyIEXm3iAtfJCELrlPD
	 dOaRli640Dwi+kq89s7B710onJaS4CWrb+xOpbet4AsZtiak4jfIJCfhVsuZVORKg3
	 lXo9B+mJcVGeHiCO8rbJwqUpavNTxN9nwEPKxBp1WTI50AKU03wmMyht7AxmkIogmJ
	 l/pNRdMQi565+vFyTlJaT5Zp15JI90y3hb7T+m9iiG+Ks9Po4ya4KJPoFWSUjDXi/M
	 WBlu4UwxX0nHN1u0pSiQ07+E6WHJ/ZZcgHuavnrCy/pQkHWb2ELa+DiqBZbsGrfp92
	 gag/thiP2aSOA==
X-Cc: liguangshuo@mail.sdu.edu.cn, sgoutham@marvell.com, gakula@marvell.com,
	rkannoth@marvell.com, sbhatta@marvell.com, bbhushan2@marvell.com,
	andrew+netdev@lunn.ch, davem@davemloft.net, edumazet@kernel.org,
	kuba@kernel.org, pabeni@redhat.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: <179501121429.3136.3547762606402557223@kernel.org>