From patchwork Wed Aug 30 09:00:07 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Github ODP bot X-Patchwork-Id: 111293 Delivered-To: patch@linaro.org Received: by 10.140.95.112 with SMTP id h103csp607483qge; Wed, 30 Aug 2017 02:01:15 -0700 (PDT) X-Google-Smtp-Source: ADKCNb62IcGf5PhRW0BPWtgpOJBBlKXpljju8qebZBc7RtbUykX+mq/oCf4xNnIONkd4ASa3vGg7 X-Received: by 10.200.34.43 with SMTP id o40mr1059350qto.202.1504083675414; Wed, 30 Aug 2017 02:01:15 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1504083675; cv=none; d=google.com; s=arc-20160816; b=gmM6vV9grWJ+AMQ+xIxmk50YUVKZYNM9xiSg8h+Matmnn3kEE78NoxfewE3u1dj7js pI6p0bf7RUmtspd+X1qDR2/MnY+e7idyZZHH3SBsIgcOqxMZAbHS+anxHO03IpZGn1Ht trDwDom+Tw6+paptF8a8KfH1IWinIpWLRGFuo5FNylCcRt/q+uS4AESkdXZUpAbmyCWJ OTOOHzOPDwOe9kqDLVfPJqOfRBiOVGYIy7DWsDLxG86MTIfDBC1SwA11tF+X1j+FtbRO qTxX9QvdMIIcfU4oEegtUS0velVqzKF1RVw2xmSjulxF7sK0yPqwopu5bzV/DTdDfw65 t3fw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:subject:github-pr-num :references:in-reply-to:message-id:date:to:from:delivered-to :arc-authentication-results; bh=bAVXToAXuqZdKMNKE30pUYYPuxAtaXo+AkSNpPxkHB0=; b=LtIKZdLwG7L20PVCW+HQZeVMK4W4nuwZa4ZtuLL4GFoqZBwH990cCDfKCe9/HKD9e7 jx53SDdi39AmqVV8b5EoMKMUH5XsC6ln094aKf2TapvSKQL+LidlZdHLcX+nxqpxB9IB 92ceFZJYEdIxUnYCUiFM/ecE+zLC/h6q24Ozaf3h0yzngxBTbZqvUtEpt/bNy7meSh2t kARy0+mnIzm/DT+xYj0yvC5euxBq9ciuSgK51eCNQ18n1fUz7fTBR7PNxegLtrJuPelq 1xsKWqBNDOf+U3ChgKLKzdAH6Wf1R2LS5LZBuUjaxPFTQQRPM9fKw+G7iwvrw3uSHXT7 oedQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of lng-odp-bounces@lists.linaro.org designates 54.225.227.206 as permitted sender) smtp.mailfrom=lng-odp-bounces@lists.linaro.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=yandex.ru Return-Path: Received: from lists.linaro.org (lists.linaro.org. [54.225.227.206]) by mx.google.com with ESMTP id t82si5069061qke.272.2017.08.30.02.01.14; Wed, 30 Aug 2017 02:01:15 -0700 (PDT) Received-SPF: pass (google.com: domain of lng-odp-bounces@lists.linaro.org designates 54.225.227.206 as permitted sender) client-ip=54.225.227.206; Authentication-Results: mx.google.com; spf=pass (google.com: domain of lng-odp-bounces@lists.linaro.org designates 54.225.227.206 as permitted sender) smtp.mailfrom=lng-odp-bounces@lists.linaro.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=yandex.ru Received: by lists.linaro.org (Postfix, from userid 109) id D1EAD60861; Wed, 30 Aug 2017 09:01:14 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on ip-10-142-244-252 X-Spam-Level: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,FREEMAIL_FROM, RCVD_IN_DNSWL_NONE,URIBL_BLOCKED autolearn=disabled version=3.4.0 Received: from [127.0.0.1] (localhost [127.0.0.1]) by lists.linaro.org (Postfix) with ESMTP id 08ECF60D8D; Wed, 30 Aug 2017 09:00:29 +0000 (UTC) X-Original-To: lng-odp@lists.linaro.org Delivered-To: lng-odp@lists.linaro.org Received: by lists.linaro.org (Postfix, from userid 109) id 01A4D60D88; Wed, 30 Aug 2017 09:00:21 +0000 (UTC) Received: from forward104j.mail.yandex.net (forward104j.mail.yandex.net [5.45.198.247]) by lists.linaro.org (Postfix) with ESMTPS id 07B53608C0 for ; Wed, 30 Aug 2017 09:00:16 +0000 (UTC) Received: from mxback9o.mail.yandex.net (mxback9o.mail.yandex.net [IPv6:2a02:6b8:0:1a2d::23]) by forward104j.mail.yandex.net (Yandex) with ESMTP id 994784513D for ; Wed, 30 Aug 2017 12:00:14 +0300 (MSK) Received: from smtp2o.mail.yandex.net (smtp2o.mail.yandex.net [2a02:6b8:0:1a2d::26]) by mxback9o.mail.yandex.net (nwsmtp/Yandex) with ESMTP id NqaD44GKxW-0EACv9db; Wed, 30 Aug 2017 12:00:14 +0300 Received: by smtp2o.mail.yandex.net (nwsmtp/Yandex) with ESMTPSA id m3koOsRvjF-0ECSTx64; Wed, 30 Aug 2017 12:00:14 +0300 (using TLSv1.2 with cipher ECDHE-RSA-AES128-SHA256 (128/128 bits)) (Client certificate not present) From: Github ODP bot To: lng-odp@lists.linaro.org Date: Wed, 30 Aug 2017 12:00:07 +0300 Message-Id: <1504083607-26833-2-git-send-email-odpbot@yandex.ru> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1504083607-26833-1-git-send-email-odpbot@yandex.ru> References: <1504083607-26833-1-git-send-email-odpbot@yandex.ru> Github-pr-num: 154 Subject: [lng-odp] [PATCH v1 1/1] helper: chksum: add few guarding conditions X-BeenThere: lng-odp@lists.linaro.org X-Mailman-Version: 2.1.16 Precedence: list List-Id: "The OpenDataPlane \(ODP\) List" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: lng-odp-bounces@lists.linaro.org Sender: "lng-odp" From: Dmitry Eremin-Solenikov Add few guarding conditions, otherwise bad packet can hang up ODP code. Noted by one of the corner case tests for IPsec. Signed-off-by: Dmitry Eremin-Solenikov --- /** Email created from pull request 154 (lumag:fix-checksum-2) ** https://github.com/Linaro/odp/pull/154 ** Patch: https://github.com/Linaro/odp/pull/154.patch ** Base sha: 7508c5ac906bb7cb1d339b4c5e924f3a18e504ca ** Merge commit sha: 1e5007e87de61c85e055ffd04fd343b472a3dfa7 **/ helper/include/odp/helper/ip.h | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/helper/include/odp/helper/ip.h b/helper/include/odp/helper/ip.h index e0d5c3bf..fb7e5ddc 100644 --- a/helper/include/odp/helper/ip.h +++ b/helper/include/odp/helper/ip.h @@ -100,10 +100,12 @@ static inline int odph_ipv4_csum(odp_packet_t pkt, odph_ipv4hdr_t *ip, odp_u16sum_t *chksum) { - int nleft = ODPH_IPV4HDR_IHL(ip->ver_ihl) * 4; + unsigned nleft = ODPH_IPV4HDR_IHL(ip->ver_ihl) * 4; uint16_t buf[nleft / 2]; int res; + if (odp_unlikely(nleft < sizeof(*ip))) + return -1; ip->chksum = 0; memcpy(buf, ip, sizeof(*ip)); res = odp_packet_copy_to_mem(pkt, offset + sizeof(*ip), @@ -135,7 +137,9 @@ static inline int odph_ipv4_csum_valid(odp_packet_t pkt) if (offset == ODP_PACKET_OFFSET_INVALID) return 0; - odp_packet_copy_to_mem(pkt, offset, sizeof(odph_ipv4hdr_t), &ip); + res = odp_packet_copy_to_mem(pkt, offset, sizeof(odph_ipv4hdr_t), &ip); + if (odp_unlikely(res < 0)) + return 0; chksum = ip.chksum;