All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH net 1/1] xfrm: drop ESP-in-TCP packets with no ingress device
       [not found] <cover.1784312563.git.roxy520tt@gmail.com>
@ 2026-07-18  7:12 ` Ren Wei
  2026-07-23  7:38   ` Steffen Klassert
  0 siblings, 1 reply; 2+ messages in thread
From: Ren Wei @ 2026-07-18  7:12 UTC (permalink / raw)
  To: netdev
  Cc: steffen.klassert, herbert, davem, edumazet, pabeni, horms, sd,
	vega, roxy520tt, enjou1224z

From: Zhiling Zou <roxy520tt@gmail.com>

ESP-in-TCP receives records through the TCP strparser. handle_esp()
restores skb->dev from the saved skb_iif before passing the packet into
the XFRM input path.

Queued TCP data can be processed after the original ingress device has
been removed, for example during veth or net namespace teardown. In that
case dev_get_by_index_rcu() returns NULL. The XFRM IPv4 and IPv6 input
paths both expect skb->dev to be valid while building the route lookup,
so queued ESP-in-TCP data can dereference a NULL device.

Drop the packet if the saved ingress device can no longer be resolved.
Such a packet can no longer be routed through the normal XFRM receive
path, and this preserves the existing behaviour for packets whose ingress
device still exists.

Fixes: e27cca96cd68 ("xfrm: add espintcp (RFC 8229)")
Cc: stable@vger.kernel.org
Reported-by: Vega <vega@nebusec.ai>
Signed-off-by: Zhiling Zou <roxy520tt@gmail.com>
Assisted-by: Codex:gpt-5.4
Reviewed-by: Ren Wei <enjou1224z@gmail.com>
---
 net/xfrm/espintcp.c | 6 ++++++
 1 file changed, 6 insertions(+)

diff --git a/net/xfrm/espintcp.c b/net/xfrm/espintcp.c
index 374e1b964438..fc01ce89492a 100644
--- a/net/xfrm/espintcp.c
+++ b/net/xfrm/espintcp.c
@@ -37,6 +37,11 @@ static void handle_esp(struct sk_buff *skb, struct sock *sk)
 
 	rcu_read_lock();
 	skb->dev = dev_get_by_index_rcu(sock_net(sk), skb->skb_iif);
+	if (!skb->dev) {
+		XFRM_INC_STATS(sock_net(sk), LINUX_MIB_XFRMINERROR);
+		kfree_skb(skb);
+		goto out;
+	}
 	local_bh_disable();
 #if IS_ENABLED(CONFIG_IPV6)
 	if (sk->sk_family == AF_INET6)
@@ -45,6 +50,7 @@ static void handle_esp(struct sk_buff *skb, struct sock *sk)
 #endif
 		xfrm4_rcv_encap(skb, IPPROTO_ESP, 0, TCP_ENCAP_ESPINTCP);
 	local_bh_enable();
+out:
 	rcu_read_unlock();
 }
 
-- 
2.43.0

^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH net 1/1] xfrm: drop ESP-in-TCP packets with no ingress device
  2026-07-18  7:12 ` [PATCH net 1/1] xfrm: drop ESP-in-TCP packets with no ingress device Ren Wei
@ 2026-07-23  7:38   ` Steffen Klassert
  0 siblings, 0 replies; 2+ messages in thread
From: Steffen Klassert @ 2026-07-23  7:38 UTC (permalink / raw)
  To: Ren Wei
  Cc: netdev, herbert, davem, edumazet, pabeni, horms, sd, vega,
	roxy520tt

On Sat, Jul 18, 2026 at 03:12:50PM +0800, Ren Wei wrote:
> From: Zhiling Zou <roxy520tt@gmail.com>
> 
> ESP-in-TCP receives records through the TCP strparser. handle_esp()
> restores skb->dev from the saved skb_iif before passing the packet into
> the XFRM input path.
> 
> Queued TCP data can be processed after the original ingress device has
> been removed, for example during veth or net namespace teardown. In that
> case dev_get_by_index_rcu() returns NULL. The XFRM IPv4 and IPv6 input
> paths both expect skb->dev to be valid while building the route lookup,
> so queued ESP-in-TCP data can dereference a NULL device.
> 
> Drop the packet if the saved ingress device can no longer be resolved.
> Such a packet can no longer be routed through the normal XFRM receive
> path, and this preserves the existing behaviour for packets whose ingress
> device still exists.
> 
> Fixes: e27cca96cd68 ("xfrm: add espintcp (RFC 8229)")
> Cc: stable@vger.kernel.org
> Reported-by: Vega <vega@nebusec.ai>
> Signed-off-by: Zhiling Zou <roxy520tt@gmail.com>
> Assisted-by: Codex:gpt-5.4
> Reviewed-by: Ren Wei <enjou1224z@gmail.com>

Applied, thanks a lot!

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2026-07-23  7:38 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
     [not found] <cover.1784312563.git.roxy520tt@gmail.com>
2026-07-18  7:12 ` [PATCH net 1/1] xfrm: drop ESP-in-TCP packets with no ingress device Ren Wei
2026-07-23  7:38   ` Steffen Klassert

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.