Skip to content

Commit

Permalink
MFS r352673:
Browse files Browse the repository at this point in the history
When the RACK stack computes the space for user data in a TCP segment,
it wasn't taking the IP level options into account. This patch fixes this.
In addition, it also corrects a KASSERT and adds protection code to assure
that the IP header chain and the TCP head fit in the first fragment as
required by RFC 7112.

MFS: r353035:

RFC 7112 requires a host to put the complete IP header chain
including the TCP header in the first IP packet.
Enforce this in tcp_output(). In addition make sure that at least
one byte payload fits in the TCP segement to allow making progress.
Without this check, a kernel with INVARIANTS will panic.
This issue was found by running an instance of syzkaller.

Approved by:		re (kib@)
Reviewed by:		rrs@ (r352673), jtl@ (r353035)
Sponsored by:		Netflix, Inc.
Differential Revision:	https://reviews.freebsd.org/D21665
Differential Revision:	https://reviews.freebsd.org/D21666
  • Loading branch information
tuexen committed Oct 3, 2019
1 parent 6400e37 commit 77ee64c
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 10 deletions.
14 changes: 14 additions & 0 deletions sys/netinet/tcp_output.c
Original file line number Diff line number Diff line change
Expand Up @@ -931,6 +931,20 @@ tcp_output(struct tcpcb *tp)
if (tp->t_flags & TF_NEEDFIN)
sendalot = 1;
} else {
if (optlen + ipoptlen >= tp->t_maxseg) {
/*
* Since we don't have enough space to put
* the IP header chain and the TCP header in
* one packet as required by RFC 7112, don't
* send it. Also ensure that at least one
* byte of the payload can be put into the
* TCP segment.
*/
SOCKBUF_UNLOCK(&so->so_snd);
error = EMSGSIZE;
sack_rxmit = 0;
goto out;
}
len = tp->t_maxseg - optlen - ipoptlen;
sendalot = 1;
if (dont_sendalot)
Expand Down
37 changes: 27 additions & 10 deletions sys/netinet/tcp_stacks/rack.c
Original file line number Diff line number Diff line change
Expand Up @@ -7872,7 +7872,16 @@ rack_output(struct tcpcb *tp)
hdrlen += sizeof(struct udphdr);
}
#endif
ipoptlen = 0;
#ifdef INET6
if (isipv6)
ipoptlen = ip6_optlen(tp->t_inpcb);
else
#endif
if (tp->t_inpcb->inp_options)
ipoptlen = tp->t_inpcb->inp_options->m_len -
offsetof(struct ipoption, ipopt_list);
else
ipoptlen = 0;
#if defined(IPSEC) || defined(IPSEC_SUPPORT)
ipoptlen += ipsec_optlen;
#endif
Expand Down Expand Up @@ -7945,6 +7954,20 @@ rack_output(struct tcpcb *tp)
sendalot = 1;

} else {
if (optlen + ipoptlen >= tp->t_maxseg) {
/*
* Since we don't have enough space to put
* the IP header chain and the TCP header in
* one packet as required by RFC 7112, don't
* send it. Also ensure that at least one
* byte of the payload can be put into the
* TCP segment.
*/
SOCKBUF_UNLOCK(&so->so_snd);
error = EMSGSIZE;
sack_rxmit = 0;
goto out;
}
len = tp->t_maxseg - optlen - ipoptlen;
sendalot = 1;
}
Expand Down Expand Up @@ -8438,15 +8461,9 @@ rack_output(struct tcpcb *tp)
m->m_pkthdr.csum_flags |= CSUM_TSO;
m->m_pkthdr.tso_segsz = tp->t_maxseg - optlen;
}
#if defined(IPSEC) || defined(IPSEC_SUPPORT)
KASSERT(len + hdrlen + ipoptlen - ipsec_optlen == m_length(m, NULL),
("%s: mbuf chain shorter than expected: %d + %u + %u - %u != %u",
__func__, len, hdrlen, ipoptlen, ipsec_optlen, m_length(m, NULL)));
#else
KASSERT(len + hdrlen + ipoptlen == m_length(m, NULL),
("%s: mbuf chain shorter than expected: %d + %u + %u != %u",
__func__, len, hdrlen, ipoptlen, m_length(m, NULL)));
#endif
KASSERT(len + hdrlen == m_length(m, NULL),
("%s: mbuf chain different than expected: %d + %u != %u",
__func__, len, hdrlen, m_length(m, NULL)));

#ifdef TCP_HHOOK
/* Run HHOOK_TCP_ESTABLISHED_OUT helper hooks. */
Expand Down

0 comments on commit 77ee64c

Please sign in to comment.