Received: by 2002:a05:6a10:9e8c:0:0:0:0 with SMTP id y12csp472660pxx; Wed, 28 Oct 2020 09:06:54 -0700 (PDT) X-Google-Smtp-Source: ABdhPJy/4unMlx1tk2HTYdai9LghsszXysN4+9KLX/mkqpT5DfTJ85R+/JnvCRPeja0hO4S12aZ5 X-Received: by 2002:a17:906:d0cc:: with SMTP id bq12mr2697143ejb.127.1603901214684; Wed, 28 Oct 2020 09:06:54 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1603901214; cv=none; d=google.com; s=arc-20160816; b=lp0ljrzl0/VuwIr+jovj4nuEl2vLP3TYsXKXL0zjtb3MtqzHUW1sSqY5X0mmkpgWq3 R8mKY3xA2TBhVPtJ3BteqoArhW5ExSc6tv/pjXLrVqbxDJMgxFJTY47oLbXIi0yUMfSZ LpnYH0X7uLWtI2KCmG/gC45c4EvPUSqPqnw1WgkL0EzJewetK07GjHZ1vE4LABW1PQNS wju3iFlKnj0/RCbuR7iIQ3sZibSDNKiYF61kJe38WUeRWqI3V3YoAFowaKoWwoOGkR56 4N3Rgh1uSY0vyAwRK3sGPUVOltcl7wiZGkm3NGHu2MlrfkNUcdgkHjtYHKjj73N2Inn3 0N9w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=/u5mJpba9AjSIBszxpc6EkIOTPXyeqtXSLhZvbPzHxQ=; b=Xts4uRW4baKEwu4dZazMPF/xYPDZCfpW46JXZkJwkhSH/AGn4MgL2ZaIeJmuugf3o+ YoSs+Uj3NSWiPIOJKFDlhevPdHEw5zH4iKROhzHpb+7g8YOI0CDFmnclyXpBDPo6FwcG P+ndwjgZqKPl0+DAEEGM2e8Q+2d91RV3ezxRLSk3JFP4sl4y68m4b4qsOVWqddZfHare HOmhWYLk/uNYkb00bHiwgO5+n+dXAmgXGxeONxK5ZoxNTxgUD9vFSloZrrfIG/Xc7ti2 k+8GIxQqF+fq+t/GvPKjQdJU8GPuP1ddnwXo3wEcD4f3g8vKtyRp8EWv0gIrSkqgsE2k 5bDg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=RmanrJiC; 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=linuxfoundation.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id bt10si1135660edb.503.2020.10.28.09.06.31; Wed, 28 Oct 2020 09:06:54 -0700 (PDT) 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; dkim=pass header.i=@kernel.org header.s=default header.b=RmanrJiC; 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=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1806761AbgJ0Q6w (ORCPT + 99 others); Tue, 27 Oct 2020 12:58:52 -0400 Received: from mail.kernel.org ([198.145.29.99]:45392 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1794055AbgJ0PJz (ORCPT ); Tue, 27 Oct 2020 11:09:55 -0400 Received: from localhost (83-86-74-64.cable.dynamic.v4.ziggo.nl [83.86.74.64]) (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 D359F206F4; Tue, 27 Oct 2020 15:09:53 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1603811394; bh=AHPu6VlPpb0XC/2887H1Sa35fVDy3w65m8Olms9NGyU=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=RmanrJiCImoUHUD702mCrdsRXaXcsSkWuLM+d8COc9ES0PqnmImRIXWNJq3wWOC5v /dozVAqQd4UvuzvmqwEZyrHNsPXkdP82x9NJtx7aTuWzwXbwNEvBna7Vr92YmCHrWE YdPwxXXOurIe9dRva5FE0AgP4Hdnr0ywZjkaFaXU= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Francesco Ruggeri , Pablo Neira Ayuso , Sasha Levin Subject: [PATCH 5.8 476/633] netfilter: conntrack: connection timeout after re-register Date: Tue, 27 Oct 2020 14:53:39 +0100 Message-Id: <20201027135545.068416120@linuxfoundation.org> X-Mailer: git-send-email 2.29.1 In-Reply-To: <20201027135522.655719020@linuxfoundation.org> References: <20201027135522.655719020@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Francesco Ruggeri [ Upstream commit 4f25434bccc28cf8a07876ef5142a2869a674353 ] If the first packet conntrack sees after a re-register is an outgoing keepalive packet with no data (SEG.SEQ = SND.NXT-1), td_end is set to SND.NXT-1. When the peer correctly acknowledges SND.NXT, tcp_in_window fails check III (Upper bound for valid (s)ack: sack <= receiver.td_end) and returns false, which cascades into nf_conntrack_in setting skb->_nfct = 0 and in later conntrack iptables rules not matching. In cases where iptables are dropping packets that do not match conntrack rules this can result in idle tcp connections to time out. v2: adjust td_end when getting the reply rather than when sending out the keepalive packet. Fixes: f94e63801ab2 ("netfilter: conntrack: reset tcp maxwin on re-register") Signed-off-by: Francesco Ruggeri Signed-off-by: Pablo Neira Ayuso Signed-off-by: Sasha Levin --- net/netfilter/nf_conntrack_proto_tcp.c | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/net/netfilter/nf_conntrack_proto_tcp.c b/net/netfilter/nf_conntrack_proto_tcp.c index 1926fd56df56a..848b137151c26 100644 --- a/net/netfilter/nf_conntrack_proto_tcp.c +++ b/net/netfilter/nf_conntrack_proto_tcp.c @@ -541,13 +541,20 @@ static bool tcp_in_window(const struct nf_conn *ct, swin = win << sender->td_scale; sender->td_maxwin = (swin == 0 ? 1 : swin); sender->td_maxend = end + sender->td_maxwin; - /* - * We haven't seen traffic in the other direction yet - * but we have to tweak window tracking to pass III - * and IV until that happens. - */ - if (receiver->td_maxwin == 0) + if (receiver->td_maxwin == 0) { + /* We haven't seen traffic in the other + * direction yet but we have to tweak window + * tracking to pass III and IV until that + * happens. + */ receiver->td_end = receiver->td_maxend = sack; + } else if (sack == receiver->td_end + 1) { + /* Likely a reply to a keepalive. + * Needed for III. + */ + receiver->td_end++; + } + } } else if (((state->state == TCP_CONNTRACK_SYN_SENT && dir == IP_CT_DIR_ORIGINAL) -- 2.25.1