Received: by 10.213.65.68 with SMTP id h4csp2117678imn; Sun, 8 Apr 2018 20:08:45 -0700 (PDT) X-Google-Smtp-Source: AIpwx48kSATE/phxaiyZdvvKxE75o88nyCKRvySD/fqZbFOfZ/8kCxZO6DQYr3AayXeustjoD7wu X-Received: by 10.99.147.25 with SMTP id b25mr24025223pge.309.1523243325488; Sun, 08 Apr 2018 20:08:45 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1523243325; cv=none; d=google.com; s=arc-20160816; b=e/021Ln07ox5HmKmF95TvZKpVio8K3eeoRkSFwOfENrviUgLnPA6A3KkfwOgI7kXFM sADlFM3SO14y2heCaD2IP0/ttxDTpMSs6w0PSn30Yab3iJQ/T2FNCZaue9VhvXrCDvIq UqqAWvsm4nx4AfaSdELQfc9fFcVomsf+5eI1DF8mReM4Otqd/BLRidwHeU1gdXEgWWjV Br1M7Aiiya3IzElJ3CFC5N0PF4EyMwcQui7S5COozKba0aAn3Z3trVM7IB9R0d2AJOXU nEuE7czU1YtaLhq6+Mn9DPi0dQxdGG14FAziYwKCh6jGGOjK7g/4kJpjsDLIVCgpYsWh BmUA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:content-transfer-encoding :spamdiagnosticmetadata:spamdiagnosticoutput:content-language :accept-language:in-reply-to:references:message-id:date:thread-index :thread-topic:subject:cc:to:from:dkim-signature :arc-authentication-results; bh=kioKG/iQpaudekidcbwEglXIuYWxhY+uxyo9dRECNSE=; b=iQNzSrWtEOXc36+sZ7bsnIshm57xZfy8Jg6F/T3Yqc2xYADzlnjlka3CT0HL1g89Ji RqSJjUBmTtoXPIWTDjdvW0REQrJnsHl50ZOhPVJoIg20gvaBBhiUHYde8HMTygIKacox myzJcyyGZWJTEN9YhbEq0SuYRcl/NHRwOpwFmCql2XvKQpKJeLaHDz7RklHfwX6e2CCS F5rJU3SIUaRu8w/mpIjWA0t+jUFAg1lV/p7qzHI5BPcURJyzO5rwVSHXVAD25etaiRbP mKn0QSaGzNCjqLzYL/PeFgpy0dcEbUKR0slMNeXVc1DHeEuOHlvQOiyFaU5BtgGkRRpJ u4nQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@microsoft.com header.s=selector1 header.b=HJxxF4Ip; 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; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=microsoft.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id d8si10494996pgc.60.2018.04.08.20.08.08; Sun, 08 Apr 2018 20:08:45 -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=@microsoft.com header.s=selector1 header.b=HJxxF4Ip; 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; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=microsoft.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1756736AbeDIBrq (ORCPT + 99 others); Sun, 8 Apr 2018 21:47:46 -0400 Received: from mail-bl2nam02on0114.outbound.protection.outlook.com ([104.47.38.114]:2685 "EHLO NAM02-BL2-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S932333AbeDIAeD (ORCPT ); Sun, 8 Apr 2018 20:34:03 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version; bh=kioKG/iQpaudekidcbwEglXIuYWxhY+uxyo9dRECNSE=; b=HJxxF4IpBYDMTOIdDmTbZcXS23nrPHi+XfYq/VJyh24PTK/FRSUg9p/eCyhbPEKVt4g6ac8fmMQ3yKv+0sWbMJftYwYaN/B0kjxlQTQGpY5B5TCMkKCqNO0SDafmdReQVlphbFOWmjLihE7Ub8T2EXp+bnNBvb1275ZPa+SdypQ= Received: from DM5PR2101MB1032.namprd21.prod.outlook.com (52.132.128.13) by DM5PR2101MB0984.namprd21.prod.outlook.com (52.132.133.30) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.696.0; Mon, 9 Apr 2018 00:33:59 +0000 Received: from DM5PR2101MB1032.namprd21.prod.outlook.com ([fe80::8109:aef0:a777:7059]) by DM5PR2101MB1032.namprd21.prod.outlook.com ([fe80::8109:aef0:a777:7059%2]) with mapi id 15.20.0696.003; Mon, 9 Apr 2018 00:33:59 +0000 From: Sasha Levin To: "stable@vger.kernel.org" , "linux-kernel@vger.kernel.org" CC: Ed Swierk , "David S . Miller" , Sasha Levin Subject: [PATCH AUTOSEL for 4.9 264/293] openvswitch: Remove padding from packet before L3+ conntrack processing Thread-Topic: [PATCH AUTOSEL for 4.9 264/293] openvswitch: Remove padding from packet before L3+ conntrack processing Thread-Index: AQHTz5liDQens2NkrkS61Dp/1u8udg== Date: Mon, 9 Apr 2018 00:26:20 +0000 Message-ID: <20180409002239.163177-264-alexander.levin@microsoft.com> References: <20180409002239.163177-1-alexander.levin@microsoft.com> In-Reply-To: <20180409002239.163177-1-alexander.levin@microsoft.com> Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-originating-ip: [52.168.54.252] x-ms-publictraffictype: Email x-microsoft-exchange-diagnostics: 1;DM5PR2101MB0984;7:Tf6CwtDVE7QG/poeSrg9xmk6LTcKHCpj4D8Thte0RQE1M8FC7UqEeu6UZDbFB/jNkQRypo7Fd1tU5kLLnk9ANRuiCjdGL6fzNM/QCDm9/bNSbcjV6Y1L0zTU3unsnb/tlFym1IY3kNjKUvt9J73LJCZeSHv1Z5ljPMKROG/5EwXV1d1PAP49q2eTEs8mSC86WwnuJ6d5lURUI61DizBjZbVfH7KYf+QQyd9oyXkHfik0/sTbrP6EsmxP8DtqgOlR;20:bzlqW597+ftRMs5ClmJcvkN47ohIkXJIfyLLnNonb8/hY9A/ZJySRGwXkf+SYwJ/cZ2p9kcEWPDasLzBhQlnugIFoJ5NYoZuNIIvLfmGectqUfx9sVyvngNrXRP/iyDx2R74iD5cx0EhWUZn8Q2DTlvmYTnFVSRm7izFbIEuHM8= x-ms-office365-filtering-ht: Tenant X-MS-Office365-Filtering-Correlation-Id: b882984a-fe04-4f8c-f78a-08d59db1961f x-microsoft-antispam: UriScan:;BCL:0;PCL:0;RULEID:(7020095)(4652020)(48565401081)(5600026)(4604075)(3008032)(4534165)(4627221)(201703031133081)(201702281549075)(2017052603328)(7193020);SRVR:DM5PR2101MB0984; x-ms-traffictypediagnostic: DM5PR2101MB0984: authentication-results: spf=none (sender IP is ) smtp.mailfrom=Alexander.Levin@microsoft.com; x-microsoft-antispam-prvs: x-exchange-antispam-report-test: UriScan:(28532068793085)(89211679590171); x-exchange-antispam-report-cfa-test: BCL:0;PCL:0;RULEID:(8211001083)(61425038)(6040522)(2401047)(8121501046)(5005006)(93006095)(93001095)(3231221)(944501327)(52105095)(3002001)(10201501046)(6055026)(61426038)(61427038)(6041310)(20161123562045)(201703131423095)(201702281528075)(20161123555045)(201703061421075)(201703061406153)(20161123558120)(20161123564045)(20161123560045)(6072148)(201708071742011);SRVR:DM5PR2101MB0984;BCL:0;PCL:0;RULEID:;SRVR:DM5PR2101MB0984; x-forefront-prvs: 0637FCE711 x-forefront-antispam-report: SFV:NSPM;SFS:(10019020)(396003)(39860400002)(366004)(39380400002)(346002)(376002)(199004)(189003)(26005)(99286004)(2906002)(14454004)(97736004)(59450400001)(8676002)(81156014)(81166006)(8936002)(6512007)(106356001)(76176011)(186003)(3280700002)(10090500001)(36756003)(6506007)(66066001)(3660700001)(72206003)(478600001)(6666003)(53936002)(2900100001)(105586002)(102836004)(2501003)(110136005)(54906003)(5250100002)(486006)(1076002)(25786009)(6116002)(6436002)(11346002)(6486002)(22452003)(4326008)(446003)(7736002)(86362001)(305945005)(2616005)(476003)(68736007)(3846002)(86612001)(5660300001)(10290500003)(107886003)(316002)(22906009)(217873001);DIR:OUT;SFP:1102;SCL:1;SRVR:DM5PR2101MB0984;H:DM5PR2101MB1032.namprd21.prod.outlook.com;FPR:;SPF:None;LANG:en;PTR:InfoNoRecords;A:1;MX:1; received-spf: None (protection.outlook.com: microsoft.com does not designate permitted sender hosts) x-microsoft-antispam-message-info: BaxrIgQcBZWf292CT9Gbc/ntKeUqJQkCNvlutjDKKaWQJVXXnKtQFWlJDBYsWJZhQAYvVctwZCTFZjjyXG7l+WLRo9NtDioQr6lGwWC8yWIP9UGqs01grsllldAtWrl59k2hIMAantTMIAuklylwfeDcbpZ4q+zwrddc5W/CTMf2ZbCqgSnMX+B6DZnu+qjZKWEHTrmezted00ss0D+xtuKg06bpDScv4rdl9fzHQ2vks4912n7Fq1i8+0Q+FpFHJ4GyRqGpdK1fxeSUdN+Q8yJdUtzOV59OrLhg69CTlA6SckXH/UDAUuuQzUN9MKVU1a8fhsEE5YRLuoIlQKNYHp2ilE6GcNpo19eWxYQ0fn9+H3j83nZIIV+ZfYKQNyW5q46NcF+Y938Q/JIdJvoi5x4WCfhEjJFRqQ7Y4dmdYVs= spamdiagnosticoutput: 1:99 spamdiagnosticmetadata: NSPM Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 X-OriginatorOrg: microsoft.com X-MS-Exchange-CrossTenant-Network-Message-Id: b882984a-fe04-4f8c-f78a-08d59db1961f X-MS-Exchange-CrossTenant-originalarrivaltime: 09 Apr 2018 00:26:20.8632 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: 72f988bf-86f1-41af-91ab-2d7cd011db47 X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM5PR2101MB0984 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Ed Swierk [ Upstream commit 9382fe71c0058465e942a633869629929102843d ] IPv4 and IPv6 packets may arrive with lower-layer padding that is not included in the L3 length. For example, a short IPv4 packet may have up to 6 bytes of padding following the IP payload when received on an Ethernet device with a minimum packet length of 64 bytes. Higher-layer processing functions in netfilter (e.g. nf_ip_checksum(), and help() in nf_conntrack_ftp) assume skb->len reflects the length of the L3 header and payload, rather than referring back to ip_hdr->tot_len or ipv6_hdr->payload_len, and get confused by lower-layer padding. In the normal IPv4 receive path, ip_rcv() trims the packet to ip_hdr->tot_len before invoking netfilter hooks. In the IPv6 receive path, ip6_rcv() does the same using ipv6_hdr->payload_len. Similarly in the br_netfilter receive path, br_validate_ipv4() and br_validate_ipv6() trim the packet to the L3 length before invoking netfilter hooks. Currently in the OVS conntrack receive path, ovs_ct_execute() pulls the skb to the L3 header but does not trim it to the L3 length before calling nf_conntrack_in(NF_INET_PRE_ROUTING). When nf_conntrack_proto_tcp encounters a packet with lower-layer padding, nf_ip_checksum() fails causing a "nf_ct_tcp: bad TCP checksum" log message. While extra zero bytes don't affect the checksum, the length in the IP pseudoheader does. That length is based on skb->len, and without trimming, it doesn't match the length the sender used when computing the checksum. In ovs_ct_execute(), trim the skb to the L3 length before higher-layer processing. Signed-off-by: Ed Swierk Acked-by: Pravin B Shelar Signed-off-by: David S. Miller Signed-off-by: Sasha Levin --- net/openvswitch/conntrack.c | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) diff --git a/net/openvswitch/conntrack.c b/net/openvswitch/conntrack.c index 466393936db9..f135814c34ad 100644 --- a/net/openvswitch/conntrack.c +++ b/net/openvswitch/conntrack.c @@ -906,6 +906,36 @@ static int ovs_ct_commit(struct net *net, struct sw_fl= ow_key *key, return 0; } =20 +/* Trim the skb to the length specified by the IP/IPv6 header, + * removing any trailing lower-layer padding. This prepares the skb + * for higher-layer processing that assumes skb->len excludes padding + * (such as nf_ip_checksum). The caller needs to pull the skb to the + * network header, and ensure ip_hdr/ipv6_hdr points to valid data. + */ +static int ovs_skb_network_trim(struct sk_buff *skb) +{ + unsigned int len; + int err; + + switch (skb->protocol) { + case htons(ETH_P_IP): + len =3D ntohs(ip_hdr(skb)->tot_len); + break; + case htons(ETH_P_IPV6): + len =3D sizeof(struct ipv6hdr) + + ntohs(ipv6_hdr(skb)->payload_len); + break; + default: + len =3D skb->len; + } + + err =3D pskb_trim_rcsum(skb, len); + if (err) + kfree_skb(skb); + + return err; +} + /* Returns 0 on success, -EINPROGRESS if 'skb' is stolen, or other nonzero * value if 'skb' is freed. */ @@ -920,6 +950,10 @@ int ovs_ct_execute(struct net *net, struct sk_buff *sk= b, nh_ofs =3D skb_network_offset(skb); skb_pull_rcsum(skb, nh_ofs); =20 + err =3D ovs_skb_network_trim(skb); + if (err) + return err; + if (key->ip.frag !=3D OVS_FRAG_TYPE_NONE) { err =3D handle_fragments(net, key, info->zone.id, skb); if (err) --=20 2.15.1