Received: by 2002:a05:6a10:2726:0:0:0:0 with SMTP id ib38csp710482pxb; Tue, 5 Apr 2022 19:47:49 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxmYhqqwW9tV839U7VFR6UMD/zYqP1fNq5aliq9b9ZWVQ5CBfCXCeAaB1qlym0RxV3hu5Tz X-Received: by 2002:a05:6402:40cf:b0:41b:593b:90b7 with SMTP id z15-20020a05640240cf00b0041b593b90b7mr6556854edb.52.1649213268902; Tue, 05 Apr 2022 19:47:48 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1649213268; cv=none; d=google.com; s=arc-20160816; b=Xy8RqqKi1GD8djpONHU0HOf+QG84zps9m7Pzxc6kHMmXfHPNZLPiLxFAwdd5NCoGJB 3DbKEB9UGhZZO4KKyDobsuMgrgkFycCy99WJTAM87kXMlw8uFQIdlm7z4yn8Nfq7B9VC vT5Myotv/0TGT+9zxNjVbE+rgeUrHBhyr3JwRf6so/Dm4WLHkFDCqAH+9w5OEFxLAd4S pR0/w1CgkWjjMmfLDASbNTw/yAH7qWwJTuQ6gtk8UKglmKGWQ/h14GvHDR+S9VYwnJQ2 XXbRJveLUEPKuYDem1w7FSXzb3XyCJE9TwThJpFlUeOh/xg+CZ2gGxsooMlnb+CcvJLX vKqg== 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=5A6luiIUT89y2sfV7qL/61axRntER2CpfNXCweTCqNw=; b=O6EDbHIWa2NIdnwdT7sldyNVAsGymldaW0sfhC15cJtgmUFakfx0R3KnsQLYQFTtlA jIa4COiOzZ+Kywp6u8E7E8t0mnOwbG7A5VmV+m5gBtI3+Feac7nb9CD8pRcvvTtDfmbV +uBpaAFNB3lRAi1XBtigL4nWm0q7+cS1vpNvicxtE8y2jPaOb8BtxXB8cYgBzQfMfhxX g+6JpVnDOtX1szRO9SwuEAopPGLS6X2uBSueuYV46ls3MRH1Z4wq+V+uoKLgdu35muP7 b45Z8zoU0mcw+Ae6DfJwGlhEIFpdXwiIQ0Jo4C5NMw1P9pgko0dMuxIo6x8fdq4qjFsx kBVQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=rSI3e27B; 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 ss4-20020a170907c00400b006e804fac620si3753367ejc.404.2022.04.05.19.47.20; Tue, 05 Apr 2022 19:47:48 -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=rSI3e27B; 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 S1380322AbiDENOC (ORCPT + 99 others); Tue, 5 Apr 2022 09:14:02 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45320 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1344225AbiDEJSu (ORCPT ); Tue, 5 Apr 2022 05:18:50 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B89AD46B30; Tue, 5 Apr 2022 02:05:47 -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 565A6614E4; Tue, 5 Apr 2022 09:05:47 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 6A1F0C385A0; Tue, 5 Apr 2022 09:05:46 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1649149546; bh=rdP+btfujumuIu3/jnl32qr0EKP44WX3lE/wBICng7E=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=rSI3e27B/sQFq7bEMvXp/UQskpTasovtlTZgZ5mUF2TrC7CAMNhVEK+khiTC5xpCb AOBACJY8kF7ONB78UqH+76RrrEfjZ7nXVtRZASdDschNn40HO5alJZt/AnKZiv1yaZ i/M3Pb7qZsfp4aU6tWGps/Rmq6GbEFE6K+mhNKik= 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 5.16 0717/1017] netfilter: nf_conntrack_tcp: preserve liberal flag in tcp options Date: Tue, 5 Apr 2022 09:27:10 +0200 Message-Id: <20220405070415.552134740@linuxfoundation.org> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220405070354.155796697@linuxfoundation.org> References: <20220405070354.155796697@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.1 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 af5115e127cf..3cee5d8ee702 100644 --- a/net/netfilter/nf_conntrack_proto_tcp.c +++ b/net/netfilter/nf_conntrack_proto_tcp.c @@ -341,8 +341,8 @@ static void tcp_options(const struct sk_buff *skb, if (!ptr) return; - state->td_scale = - state->flags = 0; + state->td_scale = 0; + state->flags &= IP_CT_TCP_FLAG_BE_LIBERAL; while (length > 0) { int opcode=*ptr++; @@ -839,6 +839,16 @@ static bool tcp_can_early_drop(const struct nf_conn *ct) return false; } +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. */ int nf_conntrack_tcp_packet(struct nf_conn *ct, struct sk_buff *skb, @@ -945,8 +955,7 @@ int nf_conntrack_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