Received: by 2002:a25:c593:0:0:0:0:0 with SMTP id v141csp4116604ybe; Mon, 9 Sep 2019 04:35:54 -0700 (PDT) X-Google-Smtp-Source: APXvYqzxjwd7pp4Vyg7T8iFjFWU8sqvRBAaB2wOY6ACgYc0ZWcBOIhfFhxCpZYWyuAN+U9WxVuyz X-Received: by 2002:a17:906:1542:: with SMTP id c2mr18492478ejd.120.1568028954209; Mon, 09 Sep 2019 04:35:54 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1568028954; cv=none; d=google.com; s=arc-20160816; b=D8OALGxwWg0KcrrpUJ3F7soTPTxctPZsYPXD0UynnbeRTD8YnalTQ892K0B4FtQi+I Hn49of6z8iJcSTD7L55UPlND1TaiJlNpHgc7S/KsvBHRnUyHVak0/7ru4qxNWKUFwuI5 dzCsHyvSWzYwKvNhIo4ykJd32UhzU+IgbKiGWAbP6OahoSqLtd/yq4LQ3KDKaV+Lug5u cs1flbE60eRS+CRpp5iw0OQ3M2Ro0l9l1aUfsWaGL2+/ZF54riJq4RRSdnuZCbd1XtOs kUo+w+cDF+BVrIada+Li7kphV3RI9DMJwf7I2+CgD3VSx3CfSsNthpLearuRfZjkKLIV R1qg== 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=Inrbg0CnEQrsTBV7IgoruNd9+wGbGk03L14QHMJkFRg=; b=RzdFNm3Ed+79u62Q1cJYSuHqhgCI5VnEkSwxZeCb+av7B4A0n2GEgPTIP8Ayg5K0qF J4VcIJ2QWzKdv6huuCk9Pc1sJ7QbUkqx8LVmPrhanSHfaijb62ghQ+67UjFPVu6tS/uM sOjKQzlSnjE7COgolT79hfMEQNLYcCtoSYdJ/FJNd/xDZXxmFpBKSrt/yqlHg/KBHBv7 Jxbyox6qxp1nGpCoElGZbYxtJDsABDXmRMsdg6aNpin+o0GZvj1tDwvewwCxh8rTLtql icf23T0/9+SNzNqxHXJ0K6bgiXjrffQooEUh61fmBd7R1wtEI6qmlvdUkC5a4ayrDb5X +xig== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=nkv4jSiT; 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 s10si8049322edx.233.2019.09.09.04.35.30; Mon, 09 Sep 2019 04:35:54 -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=nkv4jSiT; 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 S1730693AbfIHMra (ORCPT + 99 others); Sun, 8 Sep 2019 08:47:30 -0400 Received: from mail.kernel.org ([198.145.29.99]:35844 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730670AbfIHMr1 (ORCPT ); Sun, 8 Sep 2019 08:47:27 -0400 Received: from localhost (unknown [62.28.240.114]) (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 BE9B2218AC; Sun, 8 Sep 2019 12:47:26 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1567946847; bh=SAHsHnMvyscJ7r82CopdaOIYpTmE+pyunMQT2p9mYVg=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=nkv4jSiTT/hZkVgxIPI9w5ArJKwejJwyAMEw9tu+UuU5w5aZkA8k1X816WqklHymP vEMCdXJ5Y7Xhfc9aNHTegrIIbOqm37KB8Y15FocBes0JapnFhb3JGkJ/ToHfttSlks a56Le9uqVgmtcRtNIymngf1pnPZ8H55NicNzkfys= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Pablo Neira Ayuso , Sasha Levin Subject: [PATCH 4.19 22/57] netfilter: nft_flow_offload: skip tcp rst and fin packets Date: Sun, 8 Sep 2019 13:41:46 +0100 Message-Id: <20190908121134.633656644@linuxfoundation.org> X-Mailer: git-send-email 2.23.0 In-Reply-To: <20190908121125.608195329@linuxfoundation.org> References: <20190908121125.608195329@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 dfe42be15fde16232340b8b2a57c359f51cc10d9 ] TCP rst and fin packets do not qualify to place a flow into the flowtable. Most likely there will be no more packets after connection closure. Without this patch, this flow entry expires and connection tracking picks up the entry in ESTABLISHED state using the fixup timeout, which makes this look inconsistent to the user for a connection that is actually already closed. Signed-off-by: Pablo Neira Ayuso Signed-off-by: Sasha Levin --- net/netfilter/nft_flow_offload.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/net/netfilter/nft_flow_offload.c b/net/netfilter/nft_flow_offload.c index 6e0c26025ab13..69decbe2c9884 100644 --- a/net/netfilter/nft_flow_offload.c +++ b/net/netfilter/nft_flow_offload.c @@ -71,11 +71,11 @@ static void nft_flow_offload_eval(const struct nft_expr *expr, { struct nft_flow_offload *priv = nft_expr_priv(expr); struct nf_flowtable *flowtable = &priv->flowtable->data; + struct tcphdr _tcph, *tcph = NULL; enum ip_conntrack_info ctinfo; struct nf_flow_route route; struct flow_offload *flow; enum ip_conntrack_dir dir; - bool is_tcp = false; struct nf_conn *ct; int ret; @@ -88,7 +88,10 @@ static void nft_flow_offload_eval(const struct nft_expr *expr, switch (ct->tuplehash[IP_CT_DIR_ORIGINAL].tuple.dst.protonum) { case IPPROTO_TCP: - is_tcp = true; + tcph = skb_header_pointer(pkt->skb, pkt->xt.thoff, + sizeof(_tcph), &_tcph); + if (unlikely(!tcph || tcph->fin || tcph->rst)) + goto out; break; case IPPROTO_UDP: break; @@ -115,7 +118,7 @@ static void nft_flow_offload_eval(const struct nft_expr *expr, if (!flow) goto err_flow_alloc; - if (is_tcp) { + if (tcph) { ct->proto.tcp.seen[0].flags |= IP_CT_TCP_FLAG_BE_LIBERAL; ct->proto.tcp.seen[1].flags |= IP_CT_TCP_FLAG_BE_LIBERAL; } -- 2.20.1