Skip to content

Commit 970a5a3

Browse files
edumazetkuba-moo
authored andcommitted
ipv4: tcp: send zero IPID in SYNACK messages
In commit 431280e ("ipv4: tcp: send zero IPID for RST and ACK sent in SYN-RECV and TIME-WAIT state") we took care of some ctl packets sent by TCP. It turns out we need to use a similar strategy for SYNACK packets. By default, they carry IP_DF and IPID==0, but there are ways to ask them to use the hashed IP ident generator and thus be used to build off-path attacks. (Ref: Off-Path TCP Exploits of the Mixed IPID Assignment) One of this way is to force (before listener is started) echo 1 >/proc/sys/net/ipv4/ip_no_pmtu_disc Another way is using forged ICMP ICMP_FRAG_NEEDED with a very small MTU (like 68) to force a false return from ip_dont_fragment() In this patch, ip_build_and_send_pkt() uses the following heuristics. 1) Most SYNACK packets are smaller than IPV4_MIN_MTU and therefore can use IP_DF regardless of the listener or route pmtu setting. 2) In case the SYNACK packet is bigger than IPV4_MIN_MTU, we use prandom_u32() generator instead of the IPv4 hashed ident one. Fixes: 1da177e ("Linux-2.6.12-rc2") Signed-off-by: Eric Dumazet <[email protected]> Reported-by: Ray Che <[email protected]> Reviewed-by: David Ahern <[email protected]> Cc: Geoff Alexander <[email protected]> Cc: Willy Tarreau <[email protected]> Signed-off-by: Jakub Kicinski <[email protected]>
1 parent 153a0d1 commit 970a5a3

File tree

1 file changed

+9
-2
lines changed

1 file changed

+9
-2
lines changed

net/ipv4/ip_output.c

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -162,12 +162,19 @@ int ip_build_and_send_pkt(struct sk_buff *skb, const struct sock *sk,
162162
iph->daddr = (opt && opt->opt.srr ? opt->opt.faddr : daddr);
163163
iph->saddr = saddr;
164164
iph->protocol = sk->sk_protocol;
165-
if (ip_dont_fragment(sk, &rt->dst)) {
165+
/* Do not bother generating IPID for small packets (eg SYNACK) */
166+
if (skb->len <= IPV4_MIN_MTU || ip_dont_fragment(sk, &rt->dst)) {
166167
iph->frag_off = htons(IP_DF);
167168
iph->id = 0;
168169
} else {
169170
iph->frag_off = 0;
170-
__ip_select_ident(net, iph, 1);
171+
/* TCP packets here are SYNACK with fat IPv4/TCP options.
172+
* Avoid using the hashed IP ident generator.
173+
*/
174+
if (sk->sk_protocol == IPPROTO_TCP)
175+
iph->id = (__force __be16)prandom_u32();
176+
else
177+
__ip_select_ident(net, iph, 1);
171178
}
172179

173180
if (opt && opt->opt.optlen) {

0 commit comments

Comments
 (0)