git: efd07ee95616 - stable/14 - tcp: improve validation of received TCP over UDP packets
- Go to: [ bottom of page ] [ top of archives ] [ this month ]
Date: Tue, 19 May 2026 14:57:17 UTC
The branch stable/14 has been updated by tuexen:
URL: https://cgit.FreeBSD.org/src/commit/?id=efd07ee956162648f6ddb4bfe76b702a51ef427b
commit efd07ee956162648f6ddb4bfe76b702a51ef427b
Author: Michael Tuexen <tuexen@FreeBSD.org>
AuthorDate: 2026-02-20 21:21:37 +0000
Commit: Michael Tuexen <tuexen@FreeBSD.org>
CommitDate: 2026-05-19 12:55:55 +0000
tcp: improve validation of received TCP over UDP packets
Reviewed by: glebius, pouria
Sponsored by: Netflix, Inc.
Differential Revision: https://reviews.freebsd.org/D55410
(cherry picked from commit e1886559ea477add82a0a86cddf728f6778f1603)
---
sys/netinet/tcp_subr.c | 22 +++++++++++++++++-----
1 file changed, 17 insertions(+), 5 deletions(-)
diff --git a/sys/netinet/tcp_subr.c b/sys/netinet/tcp_subr.c
index e1346b433899..ca201d721616 100644
--- a/sys/netinet/tcp_subr.c
+++ b/sys/netinet/tcp_subr.c
@@ -626,7 +626,7 @@ tcp_recv_udp_tunneled_packet(struct mbuf *m, int off, struct inpcb *inp,
#endif
struct udphdr *uh;
struct tcphdr *th;
- int thlen;
+ int len, thlen;
uint16_t port;
TCPSTAT_INC(tcps_tunneled_pkts);
@@ -670,15 +670,27 @@ tcp_recv_udp_tunneled_packet(struct mbuf *m, int off, struct inpcb *inp,
switch (iph->ip_v) {
#ifdef INET
case IPVERSION:
- iph->ip_len = htons(ntohs(iph->ip_len) - sizeof(struct udphdr));
- tcp_input_with_port(&m, &off, IPPROTO_TCP, port);
+ len = ntohs(iph->ip_len) - sizeof(struct udphdr);
+ if (len != m->m_pkthdr.len) {
+ TCPSTAT_INC(tcps_tunneled_errs);
+ goto out;
+ } else {
+ iph->ip_len = htons(len);
+ tcp_input_with_port(&m, &off, IPPROTO_TCP, port);
+ }
break;
#endif
#ifdef INET6
case IPV6_VERSION >> 4:
ip6 = mtod(m, struct ip6_hdr *);
- ip6->ip6_plen = htons(ntohs(ip6->ip6_plen) - sizeof(struct udphdr));
- tcp6_input_with_port(&m, &off, IPPROTO_TCP, port);
+ len = ntohs(ip6->ip6_plen) - sizeof(struct udphdr);
+ if (len + sizeof(struct ip6_hdr) != m->m_pkthdr.len) {
+ TCPSTAT_INC(tcps_tunneled_errs);
+ goto out;
+ } else {
+ ip6->ip6_plen = htons(len);
+ tcp6_input_with_port(&m, &off, IPPROTO_TCP, port);
+ }
break;
#endif
default: