Received: from smtp.kernel.org (aws-us-west-2-korg-mail-alma10-1.taild15c8.ts.net [100.103.45.18]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 8F613479869 for ; Tue, 22 Sep 2026 17:55:58 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=100.103.45.18 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1790099759; cv=none; b=eQlXMMPLUqkUr5s/zYX0M8bJ96I4J7FAC+7PBFTe5d4x80pLx1IUFYIvvD0xXqnMFTOxyT8JGXkQcsJI1gmWFeIRUQiGwBNijMqiSCjQu9BX8Fo5KwoBbi46qlYqaNxkNLixODOr1jbkrqr8V4V2P+EgFwNvFFgRvLj2azTsToo= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1790099759; c=relaxed/simple; bh=aaJHmBlMa9bGppi8CD4gwexAF9Hx6q9MAkxylI8tJko=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=I0uxZQxjGxo3gZGKHWzp0H8XKC1S/TDoVXR2wDZ3ZWeKogdAzeK9+iA7IIJuUCdYkgcsdWD1v7AACNBHOUS1wUo4LrbZYwZ319FzFkBwvGJao3LD7DExH0ojqF+tHeSEPXNf0D2g1Xvma/YWSMILsSUk22UQgJEkYqIib830vy8= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=DlUuIFxc; arc=none smtp.client-ip=100.103.45.18 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="DlUuIFxc" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 897791F000FF; Tue, 22 Sep 2026 17:55:57 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1790099758; bh=iiIB6HQgs0nPlhlTLcQLC5FQXitZ2tBP6Xp6RGGIuBA=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=DlUuIFxcQdeP7r/VGSLtA/fFcf9Z0EH5YdSAmTrCjsgVf/tR3N1nt1y5P3UrmP6mj iJZvtcXhbMDfHbtQsNUXiLbtQNYuBTNAkoQcmCi1fQw1ve/HVODocAuPZwcIdgnetx DeCKLymdbxd+fkGzWTnNZVKb/pfaItkEu1ZJfsCRHGbxSjeVglOX/7v2bfEqEWUsON araAqLLRnesmIJjTnEecayF5/9sPYfAq3dcoImIDjfzSdQriIsHvMpfc6dgoQX0xOj v46A+jj+jfbdT25VI2dRGKVdsF1AOlGceh/ejjgTbybgpXbXmVUkWbRDHmCvDhlThB cnKThyfkWwURQ== From: Sasha Levin To: stable@vger.kernel.org Cc: Zhiling Zou , Vega , Steffen Klassert , Sasha Levin Subject: [PATCH 6.1.y] xfrm: save input state data before secpath resets Date: Tue, 22 Sep 2026 13:55:56 -0400 Message-ID: <20260922175556.3320692-1-sashal@kernel.org> X-Mailer: git-send-email 2.53.0 In-Reply-To: <2026092227-tutor-surname-a380@gregkh> References: <2026092227-tutor-surname-a380@gregkh> Precedence: bulk X-Mailing-List: stable@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit From: Zhiling Zou [ Upstream commit 3cf5cdecd99c9c186a5ea518d93bbf3045b6e3aa ] xfrm_input() stores the current xfrm_state in the skb secpath while it continues receive-side processing. Some input paths can reset that secpath before xfrm_input() has finished dereferencing the state. Receive callback users such as VTI and XFRM interfaces can reset the secpath. The VTI receive path does so before checking whether the packet crosses network namespaces, while the XFRM interface path does so only for cross-network-namespace packets. The XFRM_MAX_DEPTH error path can also reset the secpath before the final drop callback reports the current state's protocol. If secpath_reset() drops the last state reference while the state is concurrently deleted, xfrm_input() can still dereference the freed state when selecting transport_finish() or reporting the drop callback protocol. Save the state protocol on the stack while the state is still valid, and use the already saved address family for transport_finish(). A larval XFRM_STATE_ACQ state has no type, so retain nexthdr as its protocol. This preserves the existing drop-path fallback while avoiding the post-reset state dereferences without adding an extra state reference to every received packet. Fixes: df3893c176e9 ("vti: Update the ipv4 side to use it's own receive hook.") Cc: stable@vger.kernel.org Reported-by: Vega Signed-off-by: Zhiling Zou Signed-off-by: Steffen Klassert [ omitted the protocol fallback assignment for the state-direction rejection branch absent in 6.6. ] Signed-off-by: Sasha Levin --- net/xfrm/xfrm_input.c | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/net/xfrm/xfrm_input.c b/net/xfrm/xfrm_input.c index c3c909d9c8fab..43dfd4f663101 100644 --- a/net/xfrm/xfrm_input.c +++ b/net/xfrm/xfrm_input.c @@ -462,6 +462,7 @@ int xfrm_input(struct sk_buff *skb, int nexthdr, __be32 spi, int encap_type) struct xfrm_state *x = NULL; xfrm_address_t *daddr; u32 mark = skb->mark; + u8 xfrm_proto = nexthdr; unsigned int family = AF_UNSPEC; int decaps = 0; int async = 0; @@ -472,6 +473,7 @@ int xfrm_input(struct sk_buff *skb, int nexthdr, __be32 spi, int encap_type) if (encap_type < 0 || (xo && (xo->flags & XFRM_GRO || encap_type == 0))) { x = xfrm_input_state(skb); + xfrm_proto = x->type ? x->type->proto : nexthdr; if (unlikely(x->km.state != XFRM_STATE_VALID)) { if (x->km.state == XFRM_STATE_ACQ) @@ -572,11 +574,13 @@ int xfrm_input(struct sk_buff *skb, int nexthdr, __be32 spi, int encap_type) x = xfrm_state_lookup(net, mark, daddr, spi, nexthdr, family); if (x == NULL) { + xfrm_proto = nexthdr; secpath_reset(skb); XFRM_INC_STATS(net, LINUX_MIB_XFRMINNOSTATES); xfrm_audit_state_notfound(skb, family, spi, seq); goto drop; } + xfrm_proto = x->type ? x->type->proto : nexthdr; skb->mark = xfrm_smark_get(skb->mark, x); @@ -692,7 +696,7 @@ int xfrm_input(struct sk_buff *skb, int nexthdr, __be32 spi, int encap_type) crypto_done = false; } while (!err); - err = xfrm_rcv_cb(skb, family, x->type->proto, 0); + err = xfrm_rcv_cb(skb, family, xfrm_proto, 0); if (err) goto drop; @@ -713,7 +717,7 @@ int xfrm_input(struct sk_buff *skb, int nexthdr, __be32 spi, int encap_type) err = -EAFNOSUPPORT; rcu_read_lock(); - afinfo = xfrm_state_afinfo_get_rcu(x->props.family); + afinfo = xfrm_state_afinfo_get_rcu(family); if (likely(afinfo)) err = afinfo->transport_finish(skb, xfrm_gro || async); rcu_read_unlock(); @@ -733,7 +737,7 @@ int xfrm_input(struct sk_buff *skb, int nexthdr, __be32 spi, int encap_type) drop_unlock: spin_unlock(&x->lock); drop: - xfrm_rcv_cb(skb, family, x && x->type ? x->type->proto : nexthdr, -1); + xfrm_rcv_cb(skb, family, xfrm_proto, -1); kfree_skb(skb); return 0; } -- 2.53.0