[Devel] tcp: fix 0 divide in __tcp_select_window()

Submitted by Stanislav Kinsburskiy on Sept. 4, 2017, 11:38 a.m.

Details

Message ID 20170904113754.16563.58205.stgit@localhost.localdomain
State New
Series "tcp: fix 0 divide in __tcp_select_window()"
Headers show

Commit Message

Stanislav Kinsburskiy Sept. 4, 2017, 11:38 a.m.
From: Eric Dumazet <edumazet@google.com>

syszkaller fuzzer was able to trigger a divide by zero, when
TCP window scaling is not enabled.

SO_RCVBUF can be used not only to increase sk_rcvbuf, also
to decrease it below current receive buffers utilization.

If mss is negative or 0, just return a zero TCP window.

https://jira.sw.ru/browse/PSBM-71285

Back-port of ML commit: 06425c308b92eaf60767bc71d359f4cbc7a561f8

Signed-off-by: Eric Dumazet <edumazet@google.com>
Reported-by: Dmitry Vyukov  <dvyukov@google.com>
Acked-by: Neal Cardwell <ncardwell@google.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
Signed-off-by: Stanislav Kinsburskiy <skinsbursky@virtuozzo.com>
---
 net/ipv4/tcp_output.c |    6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)

Patch hide | download patch | download mbox

diff --git a/net/ipv4/tcp_output.c b/net/ipv4/tcp_output.c
index f395a09..3d24481 100644
--- a/net/ipv4/tcp_output.c
+++ b/net/ipv4/tcp_output.c
@@ -2295,9 +2295,11 @@  u32 __tcp_select_window(struct sock *sk)
 	int full_space = min_t(int, tp->window_clamp, allowed_space);
 	int window;
 
-	if (mss > full_space)
+	if (unlikely(mss > full_space)) {
 		mss = full_space;
-
+		if (mss <= 0)
+			return 0;
+	}
 	if (free_space < (full_space >> 1)) {
 		icsk->icsk_ack.quick = 0;