Received: by 2002:a25:8b12:0:0:0:0:0 with SMTP id i18csp1083853ybl; Wed, 14 Aug 2019 10:25:58 -0700 (PDT) X-Google-Smtp-Source: APXvYqxw2mXBNfmmmAu4YdeDgBmeldUeTjf7g9CUd1UUFg71MOA2YfGqjNN6ycdQx3FSN5SrK1R0 X-Received: by 2002:a17:902:223:: with SMTP id 32mr499708plc.220.1565803558646; Wed, 14 Aug 2019 10:25:58 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1565803558; cv=none; d=google.com; s=arc-20160816; b=z+OU43os81FM/t6T1Fd985NLK9jakpcnr7oU1s/RqMARO7wcj+1whCIBp2VqIGxaQ4 BVz9ZE88WAO5PT3PwupSi3tLK/MvfnL18psoalQfUWnPzoZBE/vxgyUVgCSzFBCQIyVj aNvodeIA4UeW4RWFGcyGBM0l34ryTWdcPsqacNYoJSbFLh1U2J+caFVTWh3IYJqA6/4k PRjS+JeO1PdKgusk0FURBqPKZJb7PrTALbBHHEbwjdPIK8xcQZ8y2frO/sdaGnMV2AVC Gy+VDIGgAntcmz1E4Wgs2Kq1xWeJqaDsGERKJPNhQ4k55aCUYiol/sL3U1CnyWoJ2MSG ACQA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=S3MM1w7vjGgJapybS0/RmyVsOzBKPLl77Pj08quR7Ds=; b=NnWurq6sEQRcqWTF17ssQ1rKiIgwcQZLLGX9QgzMq2NV85lrrx8p+Z8h3ZmmkiHE6U b4OxA72dxy1mgz8sN8yLJEUWmuCUtvYpaTSzooerdSSOuJ87yWcsEw/6TAeaPTE4LGUR FhEXzPQrUYNq00X4+EvFMFWtL99O4+/eIw9nv8SGDlXg/QWc0pbvXh7YZS8ogl4OpakX idji/Dpd+RX1xOrBed+JJtb6/2j9nq+oD61wWEQpaNd5St901WdV2PjNiKQ+CZQUReDk Qd7ply8zc5CvNPUTKOqr/50VX9YwCa6dHkb0l/lY/plY3fvUaQOlu5I4KdIVikN8nrw1 JfVg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=SkTnDRFT; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id l9si209673pgm.43.2019.08.14.10.25.43; Wed, 14 Aug 2019 10:25:58 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=SkTnDRFT; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729620AbfHNRZO (ORCPT + 99 others); Wed, 14 Aug 2019 13:25:14 -0400 Received: from mail.kernel.org ([198.145.29.99]:54888 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729530AbfHNRFy (ORCPT ); Wed, 14 Aug 2019 13:05:54 -0400 Received: from localhost (83-86-89-107.cable.dynamic.v4.ziggo.nl [83.86.89.107]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id CBB672084D; Wed, 14 Aug 2019 17:05:52 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1565802353; bh=fyYJhajAG5edpUDBNypC3q65eVAZN2n/N9KBNEYaUC4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=SkTnDRFTeMuKu6I8kMBKNqakmelLK8d98FlAH/bALLZIT6l89yIOcuLx16APPFHRJ EUtUwXPJz+2BlZXOLDrk4P5beDw+zbyhjqgGcqNisyKUSb8dkw+wT6y5QzYipagY+d eNx3c2+t7V1N3ih7TKtM0tWRi4X4jlPj5qvEJ1ww= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Jakub Jankowski , Florian Westphal , Jozsef Kadlecsik , Pablo Neira Ayuso , Sasha Levin Subject: [PATCH 5.2 055/144] netfilter: conntrack: always store window size un-scaled Date: Wed, 14 Aug 2019 19:00:11 +0200 Message-Id: <20190814165802.133017542@linuxfoundation.org> X-Mailer: git-send-email 2.22.0 In-Reply-To: <20190814165759.466811854@linuxfoundation.org> References: <20190814165759.466811854@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org [ Upstream commit 959b69ef57db00cb33e9c4777400ae7183ebddd3 ] Jakub Jankowski reported following oddity: After 3 way handshake completes, timeout of new connection is set to max_retrans (300s) instead of established (5 days). shortened excerpt from pcap provided: 25.070622 IP (flags [DF], proto TCP (6), length 52) 10.8.5.4.1025 > 10.8.1.2.80: Flags [S], seq 11, win 64240, [wscale 8] 26.070462 IP (flags [DF], proto TCP (6), length 48) 10.8.1.2.80 > 10.8.5.4.1025: Flags [S.], seq 82, ack 12, win 65535, [wscale 3] 27.070449 IP (flags [DF], proto TCP (6), length 40) 10.8.5.4.1025 > 10.8.1.2.80: Flags [.], ack 83, win 512, length 0 Turns out the last_win is of u16 type, but we store the scaled value: 512 << 8 (== 0x20000) becomes 0 window. The Fixes tag is not correct, as the bug has existed forever, but without that change all that this causes might cause is to mistake a window update (to-nonzero-from-zero) for a retransmit. Fixes: fbcd253d2448b8 ("netfilter: conntrack: lower timeout to RETRANS seconds if window is 0") Reported-by: Jakub Jankowski Tested-by: Jakub Jankowski Signed-off-by: Florian Westphal Acked-by: Jozsef Kadlecsik Signed-off-by: Pablo Neira Ayuso Signed-off-by: Sasha Levin --- net/netfilter/nf_conntrack_proto_tcp.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/net/netfilter/nf_conntrack_proto_tcp.c b/net/netfilter/nf_conntrack_proto_tcp.c index 1e2cc83ff5da8..ae1f8c6b3a974 100644 --- a/net/netfilter/nf_conntrack_proto_tcp.c +++ b/net/netfilter/nf_conntrack_proto_tcp.c @@ -472,6 +472,7 @@ static bool tcp_in_window(const struct nf_conn *ct, struct ip_ct_tcp_state *receiver = &state->seen[!dir]; const struct nf_conntrack_tuple *tuple = &ct->tuplehash[dir].tuple; __u32 seq, ack, sack, end, win, swin; + u16 win_raw; s32 receiver_offset; bool res, in_recv_win; @@ -480,7 +481,8 @@ static bool tcp_in_window(const struct nf_conn *ct, */ seq = ntohl(tcph->seq); ack = sack = ntohl(tcph->ack_seq); - win = ntohs(tcph->window); + win_raw = ntohs(tcph->window); + win = win_raw; end = segment_seq_plus_len(seq, skb->len, dataoff, tcph); if (receiver->flags & IP_CT_TCP_FLAG_SACK_PERM) @@ -655,14 +657,14 @@ static bool tcp_in_window(const struct nf_conn *ct, && state->last_seq == seq && state->last_ack == ack && state->last_end == end - && state->last_win == win) + && state->last_win == win_raw) state->retrans++; else { state->last_dir = dir; state->last_seq = seq; state->last_ack = ack; state->last_end = end; - state->last_win = win; + state->last_win = win_raw; state->retrans = 0; } } -- 2.20.1