Skip to content

Commit a38c401

Browse files
edumazetgregkh
authored andcommitted
tcp: tcp_fragment() should apply sane memory limits
commit f070ef2 upstream. Jonathan Looney reported that a malicious peer can force a sender to fragment its retransmit queue into tiny skbs, inflating memory usage and/or overflow 32bit counters. TCP allows an application to queue up to sk_sndbuf bytes, so we need to give some allowance for non malicious splitting of retransmit queue. A new SNMP counter is added to monitor how many times TCP did not allow to split an skb if the allowance was exceeded. Note that this counter might increase in the case applications use SO_SNDBUF socket option to lower sk_sndbuf. CVE-2019-11478 : tcp_fragment, prevent fragmenting a packet when the socket is already using more than half the allowed space Signed-off-by: Eric Dumazet <edumazet@google.com> Reported-by: Jonathan Looney <jtl@netflix.com> Acked-by: Neal Cardwell <ncardwell@google.com> Acked-by: Yuchung Cheng <ycheng@google.com> Reviewed-by: Tyler Hicks <tyhicks@canonical.com> Cc: Bruce Curtis <brucec@netflix.com> Cc: Jonathan Lemon <jonathan.lemon@gmail.com> Signed-off-by: David S. Miller <davem@davemloft.net> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
1 parent d907a07 commit a38c401

3 files changed

Lines changed: 7 additions & 0 deletions

File tree

‎include/uapi/linux/snmp.h‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -283,6 +283,7 @@ enum
283283
LINUX_MIB_TCPACKCOMPRESSED, /* TCPAckCompressed */
284284
LINUX_MIB_TCPZEROWINDOWDROP, /* TCPZeroWindowDrop */
285285
LINUX_MIB_TCPRCVQDROP, /* TCPRcvQDrop */
286+
LINUX_MIB_TCPWQUEUETOOBIG, /* TCPWqueueTooBig */
286287
__LINUX_MIB_MAX
287288
};
288289

‎net/ipv4/proc.c‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -291,6 +291,7 @@ static const struct snmp_mib snmp4_net_list[] = {
291291
SNMP_MIB_ITEM("TCPAckCompressed", LINUX_MIB_TCPACKCOMPRESSED),
292292
SNMP_MIB_ITEM("TCPZeroWindowDrop", LINUX_MIB_TCPZEROWINDOWDROP),
293293
SNMP_MIB_ITEM("TCPRcvQDrop", LINUX_MIB_TCPRCVQDROP),
294+
SNMP_MIB_ITEM("TCPWqueueTooBig", LINUX_MIB_TCPWQUEUETOOBIG),
294295
SNMP_MIB_SENTINEL
295296
};
296297

‎net/ipv4/tcp_output.c‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1299,6 +1299,11 @@ int tcp_fragment(struct sock *sk, enum tcp_queue tcp_queue,
12991299
if (nsize < 0)
13001300
nsize = 0;
13011301

1302+
if (unlikely((sk->sk_wmem_queued >> 1) > sk->sk_sndbuf)) {
1303+
NET_INC_STATS(sock_net(sk), LINUX_MIB_TCPWQUEUETOOBIG);
1304+
return -ENOMEM;
1305+
}
1306+
13021307
if (skb_unclone(skb, gfp))
13031308
return -ENOMEM;
13041309

0 commit comments

Comments
 (0)