From patchwork Thu Aug 22 10:09:34 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yanqin Wei X-Patchwork-Id: 1151441 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=none (p=none dis=none) header.from=arm.com 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 46DgJg080Rz9s3Z for ; Thu, 22 Aug 2019 20:10:27 +1000 (AEST) Received: from mail.linux-foundation.org (localhost [127.0.0.1]) by mail.linuxfoundation.org (Postfix) with ESMTP id 9C955E92; Thu, 22 Aug 2019 10:09:44 +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 BAF49AE7 for ; Thu, 22 Aug 2019 10:09:42 +0000 (UTC) X-Greylist: domain auto-whitelisted by SQLgrey-1.7.6 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by smtp1.linuxfoundation.org (Postfix) with ESMTP id 5348667F for ; Thu, 22 Aug 2019 10:09:42 +0000 (UTC) Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 0DCFF15A2; Thu, 22 Aug 2019 03:09:42 -0700 (PDT) Received: from net-arm-thunderx2-01.test.ast.arm.com (net-arm-thunderx2-01.shanghai.arm.com [10.169.40.40]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id AAA4B3F246; Thu, 22 Aug 2019 03:09:40 -0700 (PDT) From: Yanqin Wei To: dev@openvswitch.org Date: Thu, 22 Aug 2019 18:09:34 +0800 Message-Id: <1566468574-21240-1-git-send-email-Yanqin.Wei@arm.com> X-Mailer: git-send-email 2.7.4 X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00 autolearn=ham version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on smtp1.linux-foundation.org Cc: nd@arm.com, Gavin.Hu@arm.com Subject: [ovs-dev] [PATCH v2] flow: fix incorrect padding length checking and combine branch in ipv6_sanity_check 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 The padding length is (packet size - ipv6 header length - ipv6 plen). This patch fixes incorrect ipv6 size checking and improves it by combining branch. Reviewed-by: Gavin Hu Signed-off-by: Yanqin Wei --- lib/flow.c | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/lib/flow.c b/lib/flow.c index e5b554b..1b21f51 100644 --- a/lib/flow.c +++ b/lib/flow.c @@ -688,18 +688,16 @@ ipv4_get_nw_frag(const struct ip_header *nh) static inline bool ipv6_sanity_check(const struct ovs_16aligned_ip6_hdr *nh, size_t size) { - uint16_t plen; + int pad_len; if (OVS_UNLIKELY(size < sizeof *nh)) { return false; } - plen = ntohs(nh->ip6_plen); - if (OVS_UNLIKELY(plen + IPV6_HEADER_LEN > size)) { - return false; - } + pad_len = size - IPV6_HEADER_LEN - ntohs(nh->ip6_plen); + /* Jumbo Payload option not supported yet. */ - if (OVS_UNLIKELY(size - plen > UINT8_MAX)) { + if (OVS_UNLIKELY(pad_len < 0 || pad_len > UINT8_MAX)) { return false; }