Module Name: src Committed By: christos Date: Mon Jul 6 18:49:12 UTC 2020
Modified Files: src/sys/netinet: tcp_input.c Log Message: - always set both ip and ip6, otherwise a kernel assertion can be triggered - move alignment early so that we do less work To generate a diff of this commit: cvs rdiff -u -r1.417 -r1.418 src/sys/netinet/tcp_input.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
Modified files: Index: src/sys/netinet/tcp_input.c diff -u src/sys/netinet/tcp_input.c:1.417 src/sys/netinet/tcp_input.c:1.418 --- src/sys/netinet/tcp_input.c:1.417 Sat Nov 16 05:15:10 2019 +++ src/sys/netinet/tcp_input.c Mon Jul 6 14:49:12 2020 @@ -1,4 +1,4 @@ -/* $NetBSD: tcp_input.c,v 1.417 2019/11/16 10:15:10 maxv Exp $ */ +/* $NetBSD: tcp_input.c,v 1.418 2020/07/06 18:49:12 christos Exp $ */ /* * Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project. @@ -148,7 +148,7 @@ */ #include <sys/cdefs.h> -__KERNEL_RCSID(0, "$NetBSD: tcp_input.c,v 1.417 2019/11/16 10:15:10 maxv Exp $"); +__KERNEL_RCSID(0, "$NetBSD: tcp_input.c,v 1.418 2020/07/06 18:49:12 christos Exp $"); #ifdef _KERNEL_OPT #include "opt_inet.h" @@ -1240,15 +1240,29 @@ tcp_input(struct mbuf *m, int off, int p } /* + * Enforce alignment requirements that are violated in + * some cases, see kern/50766 for details. + */ + if (TCP_HDR_ALIGNED_P(th) == 0) { + m = m_copyup(m, off + sizeof(struct tcphdr), 0); + if (m == NULL) { + TCP_STATINC(TCP_STAT_RCVSHORT); + return; + } + th = (struct tcphdr *)(mtod(m, char *) + off); + } + KASSERT(TCP_HDR_ALIGNED_P(th)); + + /* * Get IP and TCP header. * Note: IP leaves IP header in first mbuf. */ ip = mtod(m, struct ip *); - switch (ip->ip_v) { - case 4: #ifdef INET6 - ip6 = NULL; + ip6 = mtod(m, struct ip6_hdr *); #endif + switch (ip->ip_v) { + case 4: af = AF_INET; iphlen = sizeof(struct ip); @@ -1263,10 +1277,8 @@ tcp_input(struct mbuf *m, int off, int p break; #ifdef INET6 case 6: - ip = NULL; iphlen = sizeof(struct ip6_hdr); af = AF_INET6; - ip6 = mtod(m, struct ip6_hdr *); /* * Be proactive about unspecified IPv6 address in source. @@ -1301,23 +1313,6 @@ tcp_input(struct mbuf *m, int off, int p return; } - /* - * Enforce alignment requirements that are violated in - * some cases, see kern/50766 for details. - */ - if (TCP_HDR_ALIGNED_P(th) == 0) { - m = m_copyup(m, off + sizeof(struct tcphdr), 0); - if (m == NULL) { - TCP_STATINC(TCP_STAT_RCVSHORT); - return; - } - ip = mtod(m, struct ip *); -#ifdef INET6 - ip6 = mtod(m, struct ip6_hdr *); -#endif - th = (struct tcphdr *)(mtod(m, char *) + off); - } - KASSERT(TCP_HDR_ALIGNED_P(th)); /* * Check that TCP offset makes sense, pull out TCP options and @@ -1515,7 +1510,6 @@ findpcb: m_freem(in6p->in6p_options); in6p->in6p_options = NULL; } - KASSERT(ip6 != NULL); ip6_savecontrol(in6p, &in6p->in6p_options, ip6, m); } #endif