Skip to content

Commit 6af5cdb

Browse files
rr00xxyygregkh
authored andcommitted
xfrm: drop ESP-in-TCP packets with no ingress device
commit e1d7c5a upstream. 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: e27cca9 ("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> Signed-off-by: Steffen Klassert <steffen.klassert@secunet.com> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
1 parent 4bc0dfa commit 6af5cdb

1 file changed

Lines changed: 6 additions & 0 deletions

File tree

net/xfrm/espintcp.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,11 @@ static void handle_esp(struct sk_buff *skb, struct sock *sk)
3838

3939
rcu_read_lock();
4040
skb->dev = dev_get_by_index_rcu(sock_net(sk), skb->skb_iif);
41+
if (!skb->dev) {
42+
XFRM_INC_STATS(sock_net(sk), LINUX_MIB_XFRMINERROR);
43+
kfree_skb(skb);
44+
goto out;
45+
}
4146
local_bh_disable();
4247
#if IS_ENABLED(CONFIG_IPV6)
4348
if (sk->sk_family == AF_INET6)
@@ -46,6 +51,7 @@ static void handle_esp(struct sk_buff *skb, struct sock *sk)
4651
#endif
4752
xfrm4_rcv_encap(skb, IPPROTO_ESP, 0, TCP_ENCAP_ESPINTCP);
4853
local_bh_enable();
54+
out:
4955
rcu_read_unlock();
5056
}
5157

0 commit comments

Comments
 (0)