Received: by 2002:a05:6a10:16a7:0:0:0:0 with SMTP id gp39csp3074446pxb; Mon, 9 Nov 2020 01:37:04 -0800 (PST) X-Google-Smtp-Source: ABdhPJyqb6jEwSpZO3ZKRlHFe7/F88HgJdhxZucTJcqSya6lKEIn6S5X6yCuaSvqu4qAHbzDI0X9 X-Received: by 2002:a50:ab5e:: with SMTP id t30mr14568318edc.314.1604914624126; Mon, 09 Nov 2020 01:37:04 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1604914624; cv=none; d=google.com; s=arc-20160816; b=uRSx9oDWUhFxoUuIVKrk2ABmxs/rjHsLJM69vNrEfzRPDL9IcN0+OUTH4J3fGZl6RS lK8ak99r0/HW8tUkHir/Z7vnFeK63ctqNqxUlUQUTPXmknLfIuNgyJiVXkkS1pVx3A0x yh4wJMu3TUrgXoMOCJl1YoTlP+e2TYMyyGCMcTYciDhXsYGNsWa7QXiJ/2e1Y5W3828E jvd57eJ+JIje74cGAbRN9D2+SrKANkc1njDOlZ0URO1H/Itw3vSbI8Lun6ToqgEZRfsi xLTncvdD0RKvb4wxdO5kIwKByyNqpAheVsxj3XN9gutmwjh2HS56pJX30Z0r1hzSRjdQ 25Tw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:references:in-reply-to:message-id:date:subject :cc:to:from; bh=8oG7/qLVr7h9j0WZL8PNM3tGQ33mr6pZ9W8w1IaTCNI=; b=bIFv2/+jBibzoiNFgUApdf7paChGRHEEf1+8jo21hICbiEAlYR8/P1lUyAaalxoBff fGsTrRfjfbMSHaOJBvdpaeAf6sJ6AOn30G5bPNofix2m6dMTjEB2bW4XVFAxdosFF0LM oLgB0RWTUvxBkS+dvBC5T/SY+2NTmyPRt9fdhi/kCpzjO3JRjD2RMFUpQo5rxb3lJOe5 4lJiBVgmj1e1uSgKlDpxXlEWZ2lNaP2yBcevcf4eDxkW0C/dRn1qVqnTzIthsF8otOnX pQwD2w4d+VIa0v+yrQ7m54FsbdK53ZYpMUNNJxWB1ISkPy9PgYFIRmtNarWAFMeTws1F SpSg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=alibaba.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id d1si6485036ejj.113.2020.11.09.01.36.41; Mon, 09 Nov 2020 01:37:04 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=alibaba.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729050AbgKIJdw (ORCPT + 99 others); Mon, 9 Nov 2020 04:33:52 -0500 Received: from out30-130.freemail.mail.aliyun.com ([115.124.30.130]:58823 "EHLO out30-130.freemail.mail.aliyun.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726176AbgKIJdw (ORCPT ); Mon, 9 Nov 2020 04:33:52 -0500 X-Alimail-AntiSpam: AC=PASS;BC=-1|-1;BR=01201311R471e4;CH=green;DM=||false|;DS=||;FP=0|-1|-1|-1|0|-1|-1|-1;HT=e01e04426;MF=wenan.mao@linux.alibaba.com;NM=1;PH=DS;RN=9;SR=0;TI=SMTPD_---0UEjN9Yi_1604914421; Received: from VM20200710-3.tbsite.net(mailfrom:wenan.mao@linux.alibaba.com fp:SMTPD_---0UEjN9Yi_1604914421) by smtp.aliyun-inc.com(127.0.0.1); Mon, 09 Nov 2020 17:33:49 +0800 From: Mao Wenan To: edumazet@google.com, davem@davemloft.net, kuznet@ms2.inr.ac.ru, yoshfuji@linux-ipv6.org, kuba@kernel.org Cc: netdev@vger.kernel.org, linux-kernel@vger.kernel.org, kernel-janitors@vger.kernel.org, Mao Wenan Subject: [PATCH net v2] net: Update window_clamp if SOCK_RCVBUF is set Date: Mon, 9 Nov 2020 17:33:37 +0800 Message-Id: <1604914417-24578-1-git-send-email-wenan.mao@linux.alibaba.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1604913614-19432-1-git-send-email-wenan.mao@linux.alibaba.com> References: <1604913614-19432-1-git-send-email-wenan.mao@linux.alibaba.com> Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org When net.ipv4.tcp_syncookies=1 and syn flood is happened, cookie_v4_check or cookie_v6_check tries to redo what tcp_v4_send_synack or tcp_v6_send_synack did, rsk_window_clamp will be changed if SOCK_RCVBUF is set, which will make rcv_wscale is different, the client still operates with initial window scale and can overshot granted window, the client use the initial scale but local server use new scale to advertise window value, and session work abnormally. Signed-off-by: Mao Wenan --- v2: fix for ipv6. net/ipv4/syncookies.c | 4 ++++ net/ipv6/syncookies.c | 5 +++++ 2 files changed, 9 insertions(+) diff --git a/net/ipv4/syncookies.c b/net/ipv4/syncookies.c index 6ac473b..57ce317 100644 --- a/net/ipv4/syncookies.c +++ b/net/ipv4/syncookies.c @@ -427,6 +427,10 @@ struct sock *cookie_v4_check(struct sock *sk, struct sk_buff *skb) /* Try to redo what tcp_v4_send_synack did. */ req->rsk_window_clamp = tp->window_clamp ? :dst_metric(&rt->dst, RTAX_WINDOW); + /* limit the window selection if the user enforce a smaller rx buffer */ + if (sk->sk_userlocks & SOCK_RCVBUF_LOCK && + (req->rsk_window_clamp > tcp_full_space(sk) || req->rsk_window_clamp == 0)) + req->rsk_window_clamp = tcp_full_space(sk); tcp_select_initial_window(sk, tcp_full_space(sk), req->mss, &req->rsk_rcv_wnd, &req->rsk_window_clamp, diff --git a/net/ipv6/syncookies.c b/net/ipv6/syncookies.c index e796a64..c041360 100644 --- a/net/ipv6/syncookies.c +++ b/net/ipv6/syncookies.c @@ -241,6 +241,11 @@ struct sock *cookie_v6_check(struct sock *sk, struct sk_buff *skb) } req->rsk_window_clamp = tp->window_clamp ? :dst_metric(dst, RTAX_WINDOW); + /* limit the window selection if the user enforce a smaller rx buffer */ + if (sk->sk_userlocks & SOCK_RCVBUF_LOCK && + (req->rsk_window_clamp > tcp_full_space(sk) || req->rsk_window_clamp == 0)) + req->rsk_window_clamp = tcp_full_space(sk); + tcp_select_initial_window(sk, tcp_full_space(sk), req->mss, &req->rsk_rcv_wnd, &req->rsk_window_clamp, ireq->wscale_ok, &rcv_wscale, -- 1.8.3.1