From patchwork Tue Jun 7 14:53:44 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bill Fischofer X-Patchwork-Id: 69516 Delivered-To: patch@linaro.org Received: by 10.140.106.246 with SMTP id e109csp2020635qgf; Tue, 7 Jun 2016 07:54:24 -0700 (PDT) X-Received: by 10.55.7.5 with SMTP id 5mr5177473qkh.135.1465311264129; Tue, 07 Jun 2016 07:54:24 -0700 (PDT) Return-Path: Received: from lists.linaro.org (lists.linaro.org. [54.225.227.206]) by mx.google.com with ESMTP id l123si14235873qke.121.2016.06.07.07.54.23; Tue, 07 Jun 2016 07:54:24 -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=pass (p=NONE dis=NONE) header.from=linaro.org Received: by lists.linaro.org (Postfix, from userid 109) id 9156968032; Tue, 7 Jun 2016 14:54:23 +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=-2.6 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_LOW, RCVD_IN_MSPIKE_H3, RCVD_IN_MSPIKE_WL, 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 EC80F61744; Tue, 7 Jun 2016 14:54:16 +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 C890261775; Tue, 7 Jun 2016 14:53:50 +0000 (UTC) Received: from mail-oi0-f50.google.com (mail-oi0-f50.google.com [209.85.218.50]) by lists.linaro.org (Postfix) with ESMTPS id 5164B616F9 for ; Tue, 7 Jun 2016 14:53:49 +0000 (UTC) Received: by mail-oi0-f50.google.com with SMTP id k23so280537559oih.0 for ; Tue, 07 Jun 2016 07:53:49 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=ZnO5KJuJTa5WSIcn/yoBIv+Cy8z5NQQlDbVNo9jCZxA=; b=Wn4f8diGjJUTJN0IimSd2kA/CZvTRczF1q0jQszqi1zypLI/JOFKcYThZqA0iUeVmM 3LAtFFKlW2hBGKqqigGkoA5TVIVfT4qNHeGjKZ/k0GrWFVnMFiKeRmboWs0o5ynrATS+ k0ZsSCaKqAPJv++TgIDsesm7HjVM2SGU4EZz6nF28/HdkWEJiJAeZ8dxxMJce4xnqvvL WEQaOMaVLl1daxmEgN+A2pT1rguGzQpMOLxya4YgO5x8io1P3y/szKNyfIUoEnq2EmAN qeB8vdVIBdwpaMu/QEG1z1JePkraM2dIMz6VWwNLjUSuXM6JiWvybEk6tu4Bfn0PZOTI MaBQ== X-Gm-Message-State: ALyK8tK0v/ZyM+2nOfHXigw35LgsqJzlhQ5hLQJi0AHP4reSDJdlbUxgCiTgpQQodaaJtUROKNo= X-Received: by 10.157.35.111 with SMTP id k44mr397212otd.18.1465311228649; Tue, 07 Jun 2016 07:53:48 -0700 (PDT) Received: from localhost.localdomain (cpe-66-68-129-43.austin.res.rr.com. [66.68.129.43]) by smtp.gmail.com with ESMTPSA id t92sm5206323otb.10.2016.06.07.07.53.47 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Tue, 07 Jun 2016 07:53:48 -0700 (PDT) From: Bill Fischofer To: lng-odp@lists.linaro.org Date: Tue, 7 Jun 2016 09:53:44 -0500 Message-Id: <1465311225-26490-1-git-send-email-bill.fischofer@linaro.org> X-Mailer: git-send-email 2.7.4 X-Topics: patch Subject: [lng-odp] [PATCH 1/2] linux-generic: packet: copy user area as part of odp_packet_copy() 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: , MIME-Version: 1.0 Errors-To: lng-odp-bounces@lists.linaro.org Sender: "lng-odp" Resolve Bug https://bugs.linaro.org/show_bug.cgi?id=2310 by copying the user area as part of odp_packet_copy(). The copy fails if the user area size of the destination pool is not large enough to hold the source packet user area. Signed-off-by: Bill Fischofer --- platform/linux-generic/include/odp_packet_internal.h | 2 +- platform/linux-generic/odp_packet.c | 18 ++++-------------- 2 files changed, 5 insertions(+), 15 deletions(-) diff --git a/platform/linux-generic/include/odp_packet_internal.h b/platform/linux-generic/include/odp_packet_internal.h index d5ace12..5c74d97 100644 --- a/platform/linux-generic/include/odp_packet_internal.h +++ b/platform/linux-generic/include/odp_packet_internal.h @@ -294,7 +294,7 @@ static inline int packet_parse_not_complete(odp_packet_hdr_t *pkt_hdr) } /* Forward declarations */ -void _odp_packet_copy_md_to_packet(odp_packet_t srcpkt, odp_packet_t dstpkt); +int _odp_packet_copy_md_to_packet(odp_packet_t srcpkt, odp_packet_t dstpkt); odp_packet_t packet_alloc(odp_pool_t pool_hdl, uint32_t len, int parse); diff --git a/platform/linux-generic/odp_packet.c b/platform/linux-generic/odp_packet.c index 2868736..f92c257 100644 --- a/platform/linux-generic/odp_packet.c +++ b/platform/linux-generic/odp_packet.c @@ -756,22 +756,11 @@ odp_packet_t odp_packet_copy(odp_packet_t pkt, odp_pool_t pool) { odp_packet_hdr_t *srchdr = odp_packet_hdr(pkt); uint32_t pktlen = srchdr->frame_len; - uint32_t meta_offset = ODP_FIELD_SIZEOF(odp_packet_hdr_t, buf_hdr); odp_packet_t newpkt = odp_packet_alloc(pool, pktlen); if (newpkt != ODP_PACKET_INVALID) { - odp_packet_hdr_t *newhdr = odp_packet_hdr(newpkt); - uint8_t *newstart, *srcstart; - - /* Must copy metadata first, followed by packet data */ - newstart = (uint8_t *)newhdr + meta_offset; - srcstart = (uint8_t *)srchdr + meta_offset; - - memcpy(newstart, srcstart, - sizeof(odp_packet_hdr_t) - meta_offset); - - if (odp_packet_copy_from_pkt(newpkt, 0, pkt, 0, - pktlen) != 0) { + if (_odp_packet_copy_md_to_packet(pkt, newpkt) || + odp_packet_copy_from_pkt(newpkt, 0, pkt, 0, pktlen)) { odp_packet_free(newpkt); newpkt = ODP_PACKET_INVALID; } @@ -966,7 +955,7 @@ int odp_packet_is_valid(odp_packet_t pkt) * */ -void _odp_packet_copy_md_to_packet(odp_packet_t srcpkt, odp_packet_t dstpkt) +int _odp_packet_copy_md_to_packet(odp_packet_t srcpkt, odp_packet_t dstpkt) { odp_packet_hdr_t *srchdr = odp_packet_hdr(srcpkt); odp_packet_hdr_t *dsthdr = odp_packet_hdr(dstpkt); @@ -986,6 +975,7 @@ void _odp_packet_copy_md_to_packet(odp_packet_t srcpkt, odp_packet_t dstpkt) odp_atomic_load_u32( &srchdr->buf_hdr.ref_count)); copy_packet_parser_metadata(srchdr, dsthdr); + return dsthdr->buf_hdr.uarea_size < srchdr->buf_hdr.uarea_size; } /**