From patchwork Tue Feb 5 00:23:07 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Darrell Ball X-Patchwork-Id: 1036382 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=openvswitch.org (client-ip=140.211.169.12; helo=mail.linuxfoundation.org; envelope-from=ovs-dev-bounces@openvswitch.org; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=gmail.com Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="bCq3+Io3"; dkim-atps=neutral Received: from mail.linuxfoundation.org (mail.linuxfoundation.org [140.211.169.12]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 43tlmj2Ht3z9sMl for ; Tue, 5 Feb 2019 11:28:37 +1100 (AEDT) Received: from mail.linux-foundation.org (localhost [127.0.0.1]) by mail.linuxfoundation.org (Postfix) with ESMTP id B565D9BB2; Tue, 5 Feb 2019 00:27:52 +0000 (UTC) X-Original-To: dev@openvswitch.org Delivered-To: ovs-dev@mail.linuxfoundation.org Received: from smtp1.linuxfoundation.org (smtp1.linux-foundation.org [172.17.192.35]) by mail.linuxfoundation.org (Postfix) with ESMTPS id 9C2EE94E5 for ; Tue, 5 Feb 2019 00:23:19 +0000 (UTC) X-Greylist: whitelisted by SQLgrey-1.7.6 Received: from mail-pg1-f194.google.com (mail-pg1-f194.google.com [209.85.215.194]) by smtp1.linuxfoundation.org (Postfix) with ESMTPS id 35A4E86D for ; Tue, 5 Feb 2019 00:23:19 +0000 (UTC) Received: by mail-pg1-f194.google.com with SMTP id s198so675855pgs.2 for ; Mon, 04 Feb 2019 16:23:19 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=7E7qlOuSdGHlMQsdyolkMjI0CChpKfAguknhsy8fBAI=; b=bCq3+Io3GyjzjNUeZg2sbGH4XXm4pubA4zUsZ/sttv6PwATnqQjAeBFlOD4y0i3W/7 sCXTdwvn878LGX0ptEFs+U6mH2CoJj7T6SS7Qlfg+5E+gVRS5iYijaNvZ1ra3nw9ELXv VcRr0eWhrZmEdlLDcpty3ULFzYIPf0hqK/u1Gu46kKOsgw3/6QeBHyKA4MpfEI7SWvXI 86aJWmtFmoNCI2Om+MGdpUkc41yVL2KtTNjkEn9NWLdR5qD+d9ElbkjXyI+w8MgWJ1uz JGu27V3DbNBPRgDCOxL4B9LE9NClcGe3JMOOzwWuKox+iTvThO8cg4zhcM6QdDP9l7S5 7afw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=7E7qlOuSdGHlMQsdyolkMjI0CChpKfAguknhsy8fBAI=; b=W4QDmKykqDIIXxzHO1V2bA+3sNGvu1ZEKy2O8Sc4et9Qv+7ymd1xSgMRyRJl65/K0H NKu9mso+OwSOCGKfVVjzSXBvl4CtkP1Uc+dBmiLjw2v+uuaFIq2h3c9F4z1ykfDMprU7 QrlmCKWSxZLZTPy/p2WG1ANIkg0yfmzKWgARWO/Wm30BVvl0VsW7XUrV4O/KZ+uV3mlN HUClo0HFKkD5b1CKXHZcKKbckMRvjqGOZ7Y8xf3u+fnNCtVKQ3HxYLfm2APKGXMBf1Ka LjBQSnVVNz13tghRtwxhZQM4YdQ74kUNu+lL5awd7pFrT9iYOZi9+mnO7vw258xNNzO9 aZFg== X-Gm-Message-State: AHQUAua3yKnQrN1Ij7p3jDVUUa30iR0v27mKDkZbaQUhvwDL7uVdviTj Ax3vV/EAD+w3lr8tjElEMSQ= X-Google-Smtp-Source: AHgI3Ib23OVThgmxneLZKbkQIX8kruGcmR0HkcmoJ7uYs1XzOUpDvz9eLTriMbonm0M5UzaLs7ctYQ== X-Received: by 2002:a63:e5d:: with SMTP id 29mr1919045pgo.237.1549326198809; Mon, 04 Feb 2019 16:23:18 -0800 (PST) Received: from ubuntu.localdomain ([208.91.2.2]) by smtp.gmail.com with ESMTPSA id 84sm1560976pfk.134.2019.02.04.16.23.17 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Mon, 04 Feb 2019 16:23:18 -0800 (PST) From: Darrell Ball To: dlu998@gmail.com, dev@openvswitch.org Date: Mon, 4 Feb 2019 16:23:07 -0800 Message-Id: <1549326187-82147-2-git-send-email-dlu998@gmail.com> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1549326187-82147-1-git-send-email-dlu998@gmail.com> References: <1549326187-82147-1-git-send-email-dlu998@gmail.com> X-Spam-Status: No, score=-1.7 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_ENVFROM_END_DIGIT,FREEMAIL_FROM, RCVD_IN_DNSWL_NONE autolearn=no version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on smtp1.linux-foundation.org Cc: Nitin Katiyar Subject: [ovs-dev] [patch v4 2/2] conntrack: Exclude l2 padding in 'conn_key_extract()'. X-BeenThere: ovs-dev@openvswitch.org X-Mailman-Version: 2.1.12 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Sender: ovs-dev-bounces@openvswitch.org Errors-To: ovs-dev-bounces@openvswitch.org 'conn_key_extract()' in userspace conntrack is including L2 (Ethernet) pad bytes for both L3 and L4 sizes. One problem is any packet with non-zero L2 padding can incorrectly fail L4 checksum validation. This patch fixes conn_key_extract() by ignoring L2 pad bytes. Fixes: a489b16854b5 ("conntrack: New userspace connection tracker.") CC: Daniele Di Proietto Co-authored-by: Vishal Deep Ajmera Co-authored-by: Venkatesan Pradeep Co-authored-by: Nitin Katiyar Signed-off-by: Vishal Deep Ajmera Signed-off-by: Venkatesan Pradeep Signed-off-by: Nitin Katiyar Signed-off-by: Darrell Ball --- v3: Removed line inadvertently merged from another patch. lib/conntrack.c | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/lib/conntrack.c b/lib/conntrack.c index 0fedddd..e1f4041 100644 --- a/lib/conntrack.c +++ b/lib/conntrack.c @@ -1875,6 +1875,9 @@ extract_l4_icmp6(struct conn_key *key, const void *data, size_t size, * processed, the function will extract the key from the packet nested * in the ICMP payload and set '*related' to true. * + * 'size' here is the layer 4 size, which can be a nested size if parsing + * an ICMP or ICMP6 header. + * * If 'related' is NULL, it means that we're already parsing a header nested * in an ICMP error. In this case, we skip checksum and length validation. */ static inline bool @@ -1949,7 +1952,6 @@ conn_key_extract(struct conntrack *ct, struct dp_packet *pkt, ovs_be16 dl_type, * we use a sparse representation (miniflow). * */ - const char *tail = dp_packet_tail(pkt); bool ok; ctx->key.dl_type = dl_type; @@ -1960,11 +1962,11 @@ conn_key_extract(struct conntrack *ct, struct dp_packet *pkt, ovs_be16 dl_type, } else { bool hwol_good_l3_csum = dp_packet_ip_checksum_valid(pkt); /* Validate the checksum only when hwol is not supported. */ - ok = extract_l3_ipv4(&ctx->key, l3, tail - (char *) l3, NULL, + ok = extract_l3_ipv4(&ctx->key, l3, dp_packet_l3_size(pkt), NULL, !hwol_good_l3_csum); } } else if (ctx->key.dl_type == htons(ETH_TYPE_IPV6)) { - ok = extract_l3_ipv6(&ctx->key, l3, tail - (char *) l3, NULL); + ok = extract_l3_ipv6(&ctx->key, l3, dp_packet_l3_size(pkt), NULL); } else { ok = false; } @@ -1974,8 +1976,8 @@ conn_key_extract(struct conntrack *ct, struct dp_packet *pkt, ovs_be16 dl_type, if (!hwol_bad_l4_csum) { bool hwol_good_l4_csum = dp_packet_l4_checksum_valid(pkt); /* Validate the checksum only when hwol is not supported. */ - if (extract_l4(&ctx->key, l4, tail - l4, &ctx->icmp_related, l3, - !hwol_good_l4_csum)) { + if (extract_l4(&ctx->key, l4, dp_packet_l4_size(pkt), + &ctx->icmp_related, l3, !hwol_good_l4_csum)) { ctx->hash = conn_key_hash(&ctx->key, ct->hash_basis); return true; }