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=1795034637; b=F3fu9IiLSN3RzHIoI9xtvY+jj9pTRUA/joxLBod/tfbsBt7ryeOCdW6p05xrQo2JVTdp EAgeuGeAlum/YSXIfrEJ4RN0BNEAoIaTnhyKJTccLqPkhptII+h68JSlOPxlwXeBbzvYN ZCfCJFqSpSmVizy4TZj6hTo/nQ8AVgeuTM0ebAkRj6UvUMW0ttR44roXaicFyOFLD18QQ eZQrbDFSS/V6JrFbQOVlGmus7O3KXiUjHoW1xwA+yEwWqmXj8mx9RI6sF61wJLBoqQOVz Q4LMHkrpuXRAzHEheh6gy1pL+ZpqS+dEfAk8/Bb79pMDQY+4vAbQ/k+SX1oroeyYjUg== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1795034637; h=Received:DKIM-Signature:From:To:Cc:Subject:Date:Message-ID:X-Mailer: In-Reply-To:References:User-Agent:X-stable:X-Patchwork-Hint: MIME-Version:Content-Transfer-Encoding; bh=lHf9n8XIiE5Rau9U38vwvOT2EK9cJZ6vVLvrfLlXA94=; b=iwruSylKdyQMM38DHTu0faJNSG9ghZkTBCnCwKbZS6gPU5qRClLDu5qZf9PGov9N4jyL htt1YF5N7X5Xc9pi9KtL5z616cM0sEbJoTjssTyzQwoQU3Engp4NnEEts45COd7HCw07z wvcbQBasJwcJcOxtIgIG64la0RkW48VIWk/tweBrCm9i8LBgyj5M99yI8mAXn0yjKMbj5 oTBAg4EOQSJqPxIMB+kbHqwbre2/D762Ta9or/LK1Z4h7zM7N1NHsqYUR1Gd1Ml/LVRVU yW6qyXZr3p6cf78t0GZXWL4xPh33iWYxIcPbnYPhdhL6kIe7YrhwIqTuPI4mmyxiC6Q== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass header.d=linuxfoundation.org header.i=@linuxfoundation.org header.a=rsa-sha256 header.s=korg header.b=JzU8EQRx; 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 81403606A325; Wed, 18 Nov 2026 20:43:57 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.a=rsa-sha256 header.s=korg header.b=JzU8EQRx Received: by smtp.kernel.org (Postfix) with ESMTPSA id D91571F000C4; Wed, 18 Nov 2026 20:43:56 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxfoundation.org; s=korg; t=1795034637; bh=lHf9n8XIiE5Rau9U38vwvOT2EK9cJZ6vVLvrfLlXA94=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=JzU8EQRx8CxD4BR6FKOs461g1/5tRUcD1+UDcpF3LeLzEvrT9yQuN6D5aNeos4ISu Sojd7s+DTLuSdEpJuKgHlKkiiUoBXBjhWUzqaCEykSoAbsJuIt/FpzfCCQTVd3viza 9oGtDE/cZQosfpP0hLm3ubpXg7SVrvUbh9KX1XuU= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, Vega , Zhiling Zou , Steffen Klassert , Sasha Levin Subject: [PATCH 6.6 0441/3318] xfrm: save input state data before secpath resets Date: Wed, 18 Nov 2026 15:17:43 +0100 Message-ID: <20261118150329.933642088@linuxfoundation.org> X-Mailer: git-send-email 2.56.0 In-Reply-To: <20261118150313.527275416@linuxfoundation.org> References: <20261118150313.527275416@linuxfoundation.org> User-Agent: quilt/0.69 X-stable: review X-Patchwork-Hint: ignore X-Mailing-List: stable@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 6.6-stable review patch. If anyone has any objections, please let me know. ------------------ 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 [ sashal: Dropped the x->dir hunk and kept the tree's existing RCU and dev_put(skb->dev) structure, applying only the xfrm_proto and family substitutions in the callback, afinfo lookup, and drop paths. ] 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 da015efb45414..3c55fc2a37c0f 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); @@ -696,7 +700,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; @@ -719,7 +723,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(); @@ -743,7 +747,7 @@ int xfrm_input(struct sk_buff *skb, int nexthdr, __be32 spi, int encap_type) drop: if (async) dev_put(skb->dev); - 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