Received: by 10.192.165.148 with SMTP id m20csp529039imm; Wed, 25 Apr 2018 03:44:35 -0700 (PDT) X-Google-Smtp-Source: AIpwx49d0+Z92/Da88MGKZRR26/TaJVBx+uUQmMy9Z5yVhSiovlSEOIovkGx2+UuVQr3GSAXi7vO X-Received: by 10.99.54.136 with SMTP id d130mr18927836pga.228.1524653075428; Wed, 25 Apr 2018 03:44:35 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1524653075; cv=none; d=google.com; s=arc-20160816; b=0neOG27x4C0JBQNupYYN7NS13odwFbBXaklqk+rOhah2RDy/rvWj6qo/3DmHddtrXF 44ky+UHadYoeB5jxYPyv/Gqcp7TjP/9N/XyyitiZDSIZ/WKeBswtbZENt33It4h7I+0x 0ScyoH8m5Be6GOA10X4/tfGoCvB/zA3mzT7F0mcJbmzVRH9z3SSjFNVJedlHVibvyE5G ++/f7EgnbG2uMi5E4kmpUHg6pAaITIgDBi8KkDBRmfe80yZrSxXLgQuhbPEk3FAThfGa v85p2630rB3L48kA1WqYUJtbVLzKpicndx8brgs+47C56jErfspz9c8ystKLRXMJv28o r4Xw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:user-agent:references :in-reply-to:message-id:date:subject:cc:to:from :arc-authentication-results; bh=dIbihSTzvXHDbMUhz+N9QeJ7WMSzPdOuXNtHw5FF8fM=; b=OaJYYrP0tZ7LqByumKsvmVHFWOqZriACZe9RJcq7VZhj0kOJ4uKRnJnuU4TyMVbTIA rmT6zt4ZGJqgdb1+Vk3HSaDPaW389P0cviKYKGxmj5bdsPiY46ImfgYoNJCIwUvTHCE1 LknvkOYImEyiuAKf9WFOp/X6poPTsscV91RKSooO6FwI3Afz1+dmRDOBypys7fBg5QWq AMruKtQXduPg6HqIUUViMDQc1GzEu9xLcw4ettZsyCzAKGu3EERTDgBjsjhd6XgO+bAb lStejWIb4akARtUErEuQWRK2BRWNskcYx8bfwcrcEnMKyX97DcGVdpkfVZQB/3pHEP6v oSfw== ARC-Authentication-Results: i=1; mx.google.com; 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 m14si13501604pgt.287.2018.04.25.03.44.20; Wed, 25 Apr 2018 03:44:35 -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; 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 S1754068AbeDYKmF (ORCPT + 99 others); Wed, 25 Apr 2018 06:42:05 -0400 Received: from mail.linuxfoundation.org ([140.211.169.12]:52528 "EHLO mail.linuxfoundation.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754047AbeDYKl6 (ORCPT ); Wed, 25 Apr 2018 06:41:58 -0400 Received: from localhost (LFbn-1-12247-202.w90-92.abo.wanadoo.fr [90.92.61.202]) by mail.linuxfoundation.org (Postfix) with ESMTPSA id D7FF1272; Wed, 25 Apr 2018 10:41:57 +0000 (UTC) From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Ed Swierk , Pravin B Shelar , "David S. Miller" , Sasha Levin Subject: [PATCH 4.14 118/183] openvswitch: Remove padding from packet before L3+ conntrack processing Date: Wed, 25 Apr 2018 12:35:38 +0200 Message-Id: <20180425103247.175945979@linuxfoundation.org> X-Mailer: git-send-email 2.17.0 In-Reply-To: <20180425103242.532713678@linuxfoundation.org> References: <20180425103242.532713678@linuxfoundation.org> User-Agent: quilt/0.65 X-stable: review MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 4.14-stable review patch. If anyone has any objections, please let me know. ------------------ 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 Signed-off-by: Greg Kroah-Hartman --- net/openvswitch/conntrack.c | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) --- a/net/openvswitch/conntrack.c +++ b/net/openvswitch/conntrack.c @@ -1097,6 +1097,36 @@ static int ovs_ct_commit(struct net *net return 0; } +/* 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 = ntohs(ip_hdr(skb)->tot_len); + break; + case htons(ETH_P_IPV6): + len = sizeof(struct ipv6hdr) + + ntohs(ipv6_hdr(skb)->payload_len); + break; + default: + len = skb->len; + } + + err = 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. */ @@ -1111,6 +1141,10 @@ int ovs_ct_execute(struct net *net, stru nh_ofs = skb_network_offset(skb); skb_pull_rcsum(skb, nh_ofs); + err = ovs_skb_network_trim(skb); + if (err) + return err; + if (key->ip.frag != OVS_FRAG_TYPE_NONE) { err = handle_fragments(net, key, info->zone.id, skb); if (err)