🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: linux.kernel.netdev
Article #12438

Re: [PATCH] net: ixgbe: drop the SA reference if secpath_set() fails

#12438
From: netdev-bot+sashiko
Date: Sat, 07 Nov 2026 11:15
158 lines
13165 bytes
Thank you for your contribution! Sashiko AI review found 1 potential
issue(s) to consider.

Critical: 0 · High: 0 (2) · Medium: 1 · 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).

- [Medium] This patch fixes the SA reference leak in only one of the two
  copies of this Rx code.

Pre-existing issues:
- [High] ixgbe_ipsec_del_sa() unlinks the rx_sa from the RCU hash table
  with hash_del_rcu(&rsa->hlist) (line 783) and then zeroes the same…
- [High] ixgbe_ipsec_find_rx_state() finds rsa->xs only under
  rcu_read_lock() and takes its reference with xfrm_state_hold(), which…

--

net: ixgbe: drop the SA reference if secpath_set() fails

ixgbe_ipsec_find_rx_state() takes a reference on an xfrm_state. With this
patch, ixgbe_ipsec_rx() releases that reference when secpath_set() fails
to allocate the skb extension. Before this patch the reference was leaked
on that error path.

> diff --git a/drivers/net/ethernet/intel/ixgbe/ixgbe_ipsec.c b/drivers/net/ethernet/intel/ixgbe/ixgbe_ipsec.c
> index bd397b3d7deab..e44d5eed9ab59 100644
> --- a/drivers/net/ethernet/intel/ixgbe/ixgbe_ipsec.c
> +++ b/drivers/net/ethernet/intel/ixgbe/ixgbe_ipsec.c
> @@ -1197,8 +1197,10 @@ void ixgbe_ipsec_rx(struct ixgbe_ring *rx_ring,
>  		return;
>  
>  	sp = secpath_set(skb);
> -	if (unlikely(!sp))
> +	if (unlikely(!sp)) {
> +		xfrm_state_put(xs);
>  		return;
> +	}

[Severity: Medium]
Does ixgbevf need the same fix? The VF driver has a copy of this Rx code
in drivers/net/ethernet/intel/ixgbevf/ipsec.c. After this patch,
ixgbevf_ipsec_rx() still returns without dropping the reference:

drivers/net/ethernet/intel/ixgbevf/ipsec.c:ixgbevf_ipsec_rx() {
    ...
	sp = secpath_set(skb);
	if (unlikely(!sp))
		return;
    ...
}

ixgbevf_ipsec_find_rx_state() takes the reference the same way the PF
helper does:

			ret = rsa->xs;
			xfrm_state_hold(ret);
			break;

secpath_set()->skb_ext_add() is a GFP_ATOMIC allocation. Suppose a VF gets
inline-offloaded ESP/AH traffic while memory is tight. Would one
xfrm_state reference leak each time the allocation fails? If so, the state
would never be freed after the SA is deleted.

Could ixgbevf get a matching fix with its own Fixes: tag?

>  
>  	sp->xvec[sp->len++] = xs;
>  	sp->olen++;

[Severity: High]
This isn't a bug introduced by this patch, but is the rx_sa entry walked
by ixgbe_ipsec_find_rx_state() safe against ixgbe_ipsec_del_sa()?

ixgbe_ipsec_del_sa() unlinks the entry and zeroes it straight away. There
is no grace period in between:

drivers/net/ethernet/intel/ixgbe/ixgbe_ipsec.c:ixgbe_ipsec_del_sa() {
    ...
		hash_del_rcu(&rsa->hlist);
    ...
		memset(rsa, 0, sizeof(struct rx_sa));
		ipsec->num_rx_sa--;
    ...
}

The NAPI reader runs under rcu_read_lock() and loads rsa->mode and
rsa->xs with plain loads:

ixgbe_ipsec_find_rx_state() {
    ...
		if (rsa->mode & IXGBE_RXTXMOD_VF)
			continue;
		if (spi == rsa->xs->id.spi &&
		    ((ip4 && *daddr == rsa->xs->id.daddr.a4) ||
    ...
}

Suppose a reader picked up rsa from the bucket before hash_del_rcu(). Can
it then see rsa->mode == 0, pass the VF check, and dereference
rsa->xs == NULL in softirq? If ixgbe_ipsec_add_sa() reuses the slot, the
reader could also see a mix of old and new SA fields.

The trigger would be an SA deletion (XFRM_MSG_DELSA, IKE rekey or
lifetime expiry) racing with Rx traffic whose SPI hashes to the same
bucket.

ixgbevf_ipsec_del_sa() has the same pattern:

		hash_del_rcu(&ipsec->rx_tbl[sa_idx].hlist);
		memset(&ipsec->rx_tbl[sa_idx], 0, sizeof(struct rx_sa));

[Severity: High]
This is a pre-existing issue, but is xfrm_state_hold() safe on an
xfrm_state that was found only under rcu_read_lock()?

ixgbe_ipsec_find_rx_state() does this:

			ret = rsa->xs;
			xfrm_state_hold(ret);

xfrm_state_hold() is an unconditional refcount_inc(). The rx_sa entry
holds no reference of its own on xs. __xfrm_state_delete() calls
xfrm_dev_state_delete() and then drops the reference right away:

net/xfrm/xfrm_state.c:__xfrm_state_delete() {
    ...
		xfrm_dev_state_delete(x);

		xfrm_state_delete_tunnel(x);
		...
		xfrm_state_put(x);
    ...
}

Can the refcount reach zero while a NAPI reader that has already loaded
rsa->xs is still in its RCU section? If so, refcount_inc() would run on 0.
That warns and saturates, but the pointer still ends up in sp->xvec[]
above.

xfrm_state_gc_task() frees the state after synchronize_rcu(). That waits
for RCU readers, but not for skbs that hold the secpath.

Suppose the skb outlives the grace period, for example when RPS queues it
to another CPU's backlog. Would xfrm_input() and
secpath_put()->xfrm_state_put() then touch freed memory?

The xfrm core handles this case with xfrm_state_hold_rcu(), which uses
refcount_inc_not_zero(). Should the driver take its reference with an
inc-not-zero as well? ixgbevf_ipsec_find_rx_state() has the same pattern.

-- 
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261103100534.1310039-1-vulab%40iscas.ac.cn
Technical Details
Message-ID: <179405014554.994134.10719290719575125531@kernel.org>
Path: mbox-mo1.pugleaf.net!archive.usenet.blueworldhosting.com!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-358338-linux-kernel-netdev=dewy.ru
References: <20261103100534.1310039-1-vulab@iscas.ac.cn>

Show Full Headers
Complete Article Headers
Path: mbox-mo1.pugleaf.net!archive.usenet.blueworldhosting.com!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-358338-linux-kernel-netdev=dewy.ru
From: netdev-bot+sashiko@kernel.org
Newsgroups: linux.kernel.netdev
Subject: Re: [PATCH] net: ixgbe: drop the SA reference if secpath_set() fails
Date: Sat, 07 Nov 2026 11:15:45 +0000
Organization: Usenet Network
Message-ID: <179405014554.994134.10719290719575125531@kernel.org>
References: <20261103100534.1310039-1-vulab@iscas.ac.cn>
MIME-Version: 1.0
Content-Type: text/plain; charset="utf-8"
Content-Transfer-Encoding: 8bit
Injection-Info: usenet.network;
	logging-data="4089603"; mail-complaints-to="abuse@usenet.network"
Cancel-Lock: sha1:LvqkA21M0jMlUtNzLuHvnOhpq+s= sha256:e2PCjM5ehdn6b1US2x7erLZknckyFSRQbkX/+9MGYUk=
	sha1:/Fn36SpL87khERTLrSo0RbJWopA= sha256:Tau9EMponVC/sMRQv/MSRX2ecXVzCSGJ0ImZqU7YOE8=
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 8774A1133F6; Sat,  7 Nov 2026 14:19:35 +0300 (MSK)
X-Virus-Scanned: Debian amavisd-new at usenet.network
X-Spam-Flag: NO
X-Spam-Score: -3.5
X-Spam-Status: No, score=-3.5 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,
	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 WKWOp-uyHEG7;
	Sat,  7 Nov 2026 14:19:31 +0300 (MSK)
X-Received-SPF: Pass (mailfrom) identity=mailfrom; client-ip=172.232.135.74; helo=sto.lore.kernel.org; envelope-from=netdev+bounces-358338-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 7E08A112E3D; Sat,  7 Nov 2026 14:19:22 +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 A8D44607BE5; Sat,  7 Nov 2026 11:15:57 +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=1794050148;
	b=u/jdSb5Ta29g+qEiwjSylyaZMq+G3wMFO1lUQyvUEf5+1+cWvVfvZQeX+vNxnDzh3ouy
	 nKxGRuIkCWYPOAPnVqsl6Kf2lzq8T+0cyjVjODFbXCrILeYLDfkCWnGC1cXQVtQwbiQys
	 HMB9YZuPUU2Xtt0bEONC1saal4VzdQOD4yTO53is6kbVEDryRoP/+ro174m7Y0WJJpNx4
	 PeSsjNLCfYjZ6QnCR+JLdDvbKlZ/X+mT5Cwe1EJIoIKTuFI163CdYsMuw52KXnjhblQLx
	 p0pMu/I+FDWpf5OFcwuZE2nfOmgHFySaVC46z8mJHXXl2CJJIBqBuAAVkj/QxFaC80Q==
X-ARC-Message-Signature: i=2; d=subspace.kernel.org; s=arc20261015;
	a=rsa-sha256; c=relaxed/relaxed; t=1794050148;
	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=HlLkPFRA47iYpBWPfJSKGrVGd9XNqqaIsaN822UA81k=;
	b=0yDtyICtnuCwQv2Hb1FMaSYdZp8agDrifuWUGBOtCy4rihF8lACyp8eyPu2dOzLdWPvP
	 R6T7sxyHOt3MRgCVdqgXbLDNLJ6i5TXE0CGIoOAIsYrlE6qATmP02KUa/SO2VhYWa69sR
	 wumpgOetG9FIWpMD2jDlXRiPUq0j49uf6tKg5wFO4nG9xMn03iiHrS9rMhbvzGJsU2vxZ
	 3lU8+OwPNoADn3A0Y0CYhTyZ3CrNjWDy7VSnd5TonuzWuEf8IB5tq/trcEzgH9KMMko6l
	 e7dwHt8CjEatZ7XzMSx7dzosqxP6bL+iDdtZP5s+V8CODG/v4ucR4WRI0HWi+MklliQ==
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=E8yvilQ6;
	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 3941D606D80E;
	Sat,  7 Nov 2026 11:15:48 +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=E8yvilQ6
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=1794050147;
	b=UCQFDz4PzeuULrddYIhhrD+bZe7jEW4V1vCGL3kOk0CKkRuTfZLJoZrHDVwf9MZ9XUN/
	 UqvISYq3VhNB+hderj5JBf+Tg8/fuFt8/WfqNsCWkuKq4vG9ilFP3ap14ilMZe6xrU/CH
	 S91tOQD6yMMOk39eGW5brlA2T8qv6gS7DgA7ithGO9WwwQaE2OsseF5CPGDHZwXoBQWQj
	 5eNPAMRsnTMdEvXdpABOkz/6KKcK8qnMmor8Rzp8LGwnspM+jdBN611zBb0YnupMDoKnB
	 5H5noNGax6p7G5sZc5hz2gjrExISDGoJYqQWaIb84TnHsSJmmjj0fCfi4gyJtNIylyA==
X-ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015;
	a=rsa-sha256; c=relaxed/relaxed; t=1794050147;
	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=HlLkPFRA47iYpBWPfJSKGrVGd9XNqqaIsaN822UA81k=;
	b=GDhWm2ysEpWiLUSj1sclQflcIQjeN4LYq4+bqceN1C1hmZIPwmTmaQ6s02SoJBrj8PW/
	 wDi5bl0mUmRH/BUo/JL5KzmwJT/BZO0dyYUxx70ZqFLG2E7UHTMXclIqvJsZjMhCOyYew
	 ywgw1DpEWdlysiMsAjb016UNd/MFIg8w9fpmEpd+XK0DVtO7GPtmptFQsr2lkEaloq4iS
	 egpq0dex86j28gE4b2owYQpCJowNw655/6m7ucoes9Pa8gJ4GTgw3RF8At8ngec6U0Fqo
	 Iqq9He7YZx/iSagZyHEyXeg5CcLxamHuw47vU7okFV/Horr3jNaf5nLHeE2xY+N6Uaw==
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=E8yvilQ6;
	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 19DCD606D802;
	Sat,  7 Nov 2026 11:15:46 +0000 (UTC)
X-Received: by smtp.kernel.org (Postfix) with ESMTPSA id 04FAF1F0089F;
	Sat,  7 Nov 2026 11:15:45 +0000 (UTC)
X-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org;
	s=k20260515; t=1794050146;
	bh=HlLkPFRA47iYpBWPfJSKGrVGd9XNqqaIsaN822UA81k=;
	h=Subject:From:To:Cc:Date:In-Reply-To:References;
	b=E8yvilQ6bM1/ZFCRN2Aupy3mdGtXi1d07S7K3DERfQLlQTetUnJxAsoMfuMGva9Hl
	 /yNdTK8FcqGwgtPsgIqT/j4OV1sSE/x/EADkVCS40ef4G/qpkCYRKa4/Uaa84EgnQb
	 gVC6t6dvVQnIqBcHvl/bOQ4Mt8Ax7M2duIE8iepjKZQnapKpm1d+m3Zq0fMU0Zubvi
	 FLWppSRyV+URd9AtlXGKBDedzLWfRLk4oAKWLTTrmbMmq8DIju889NrGuFj56uc9aW
	 yMeHS6w7DP0bMzez+Q3sWtM7/iBGPHPDGHgBm0sJUvs16+kS0OnlQ9pTZ5hAjMIjmU
	 1GKxqKehFqeyA==
X-Cc: anthony.l.nguyen@intel.com, przemyslaw.kitszel@intel.com,
 andrew+netdev@lunn.ch, davem@davemloft.net, edumazet@kernel.org,
 kuba@kernel.org, pabeni@redhat.com, intel-wired-lan@lists.osuosl.org,
 netdev@vger.kernel.org, linux-kernel@vger.kernel.org, stable@vger.kernel.org
X-In-Reply-To: <20261103100534.1310039-1-vulab@iscas.ac.cn>
X-sashiko-severity: Medium
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