Received: by 2002:a05:6a10:6d10:0:0:0:0 with SMTP id gq16csp2955363pxb; Mon, 18 Apr 2022 11:54:19 -0700 (PDT) X-Google-Smtp-Source: ABdhPJy8jidzSCaPr24YIiaT2LvCD6gYFKRbjrQ5O0+9gA1GqID6UmcJowJluvCQ/g95c9ab04lb X-Received: by 2002:a17:90b:4d01:b0:1d0:f39f:6073 with SMTP id mw1-20020a17090b4d0100b001d0f39f6073mr14460289pjb.175.1650308059488; Mon, 18 Apr 2022 11:54:19 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1650308059; cv=none; d=google.com; s=arc-20160816; b=kS3PYGS+ITpzAe/ak2LZhZznAlK84WoplxD4yr8HOwBIJ9OQ//ai4YgHnoMbsW4sjV APbaZ7DFfnvXGEGySiMlz7ktEWprFYR9HSKM/RrqEvA9ypOP4551rta57KfnuJ5Ldweh 4A1jg2HVe3IUc/OsyzP9PgPQojXhK6eZaibfi4lWtnHHg6VxX+gZoYFwY2ToNBQHurMQ N5s5SdGcU7mFf6/PYgfyZ2MIoS3I5Nb/4yXVb1GOBJNTSIxg5Lhoe91ZzwQu7X29bw1q Cac10fuXsHLWNg/PCrNgFqg7H9sxNZiSdAwp57razkgb+D/OwpE37ZS9Rf00o4ePCYDl Bszw== 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=Tfq2BITGdCcBdUtRwMoR4adUKgg4ShywwidNrP2NCXg=; b=SyBoFTERp/T9vtK4RuqEF1mtCmHuk08+4gv2EXDCYjtmfhvL5UgGPpQJ5e6q2wxvfT cjwP+CQ9xTH2c6bLJu1jIhJQUVFHX4zy5lOiUhH/6IJUz7wZPPuolvXjoOcduekCwPDG nQO4DkVbw13v1KLU+DsUmDU/k04QjbDd8sJwzrwCTAnPOvtpmwpmztT7qaItDznFGKig dIZI3BD5mzp89OssJtygx2PDqZ1YxdwlRiqQ84nSwqCDQHe7DUOvja9MokKSoNFwSY+G PUZjcNyaOSVvXGHauSeGjra2mBu7y/Gje6C49SgpgQ6Rj3NMXlQSP8fycISFVSsjj0sm Al1Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b="k6OHHc/z"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id l2-20020a6542c2000000b003987299c842si9892571pgp.672.2022.04.18.11.54.03; Mon, 18 Apr 2022 11:54:19 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b="k6OHHc/z"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S243795AbiDRNuM (ORCPT + 99 others); Mon, 18 Apr 2022 09:50:12 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41320 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S244543AbiDRNag (ORCPT ); Mon, 18 Apr 2022 09:30:36 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 211213FBE6; Mon, 18 Apr 2022 05:54:43 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id B2FE660FF7; Mon, 18 Apr 2022 12:54:41 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id C66FEC385A7; Mon, 18 Apr 2022 12:54:40 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1650286481; bh=JZZmyJXJTfR9m3f1cBsQ6R4p/0iYOIJFlYrSFLblW2s=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=k6OHHc/zHZEcGaaLF68cUFDjRRH6Y//RO9uCesTMQjJtOs9YnoEiXsy9FVte8QUZC tL8is8djPAqEFLx6ZX6hAYY6rCZEq0BIJveCfITYGfzkEsT0k6o04RNec9rifaBK2Y Vli1K+sbdqX8WFUydzUMv7nrxwgoJBkGobCjJ0kg= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Sven Auhagen , Pablo Neira Ayuso , Sasha Levin Subject: [PATCH 4.14 148/284] netfilter: nf_conntrack_tcp: preserve liberal flag in tcp options Date: Mon, 18 Apr 2022 14:12:09 +0200 Message-Id: <20220418121215.811257073@linuxfoundation.org> X-Mailer: git-send-email 2.35.3 In-Reply-To: <20220418121210.689577360@linuxfoundation.org> References: <20220418121210.689577360@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-7.7 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Pablo Neira Ayuso [ Upstream commit f2dd495a8d589371289981d5ed33e6873df94ecc ] Do not reset IP_CT_TCP_FLAG_BE_LIBERAL flag in out-of-sync scenarios coming before the TCP window tracking, otherwise such connections will fail in the window check. Update tcp_options() to leave this flag in place and add a new helper function to reset the tcp window state. Based on patch from Sven Auhagen. Fixes: c4832c7bbc3f ("netfilter: nf_ct_tcp: improve out-of-sync situation in TCP tracking") Tested-by: Sven Auhagen Signed-off-by: Pablo Neira Ayuso Signed-off-by: Sasha Levin --- net/netfilter/nf_conntrack_proto_tcp.c | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/net/netfilter/nf_conntrack_proto_tcp.c b/net/netfilter/nf_conntrack_proto_tcp.c index cba1c6ffe51a..5239c502c016 100644 --- a/net/netfilter/nf_conntrack_proto_tcp.c +++ b/net/netfilter/nf_conntrack_proto_tcp.c @@ -383,8 +383,8 @@ static void tcp_options(const struct sk_buff *skb, length, buff); BUG_ON(ptr == NULL); - state->td_scale = - state->flags = 0; + state->td_scale = 0; + state->flags &= IP_CT_TCP_FLAG_BE_LIBERAL; while (length > 0) { int opcode=*ptr++; @@ -797,6 +797,16 @@ static unsigned int *tcp_get_timeouts(struct net *net) return tcp_pernet(net)->timeouts; } +static void nf_ct_tcp_state_reset(struct ip_ct_tcp_state *state) +{ + state->td_end = 0; + state->td_maxend = 0; + state->td_maxwin = 0; + state->td_maxack = 0; + state->td_scale = 0; + state->flags &= IP_CT_TCP_FLAG_BE_LIBERAL; +} + /* Returns verdict for packet, or -1 for invalid. */ static int tcp_packet(struct nf_conn *ct, const struct sk_buff *skb, @@ -897,8 +907,7 @@ static int tcp_packet(struct nf_conn *ct, ct->proto.tcp.last_flags &= ~IP_CT_EXP_CHALLENGE_ACK; ct->proto.tcp.seen[ct->proto.tcp.last_dir].flags = ct->proto.tcp.last_flags; - memset(&ct->proto.tcp.seen[dir], 0, - sizeof(struct ip_ct_tcp_state)); + nf_ct_tcp_state_reset(&ct->proto.tcp.seen[dir]); break; } ct->proto.tcp.last_index = index; -- 2.34.1