From patchwork Thu Mar 26 17:52:27 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stuart Haslam X-Patchwork-Id: 46374 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-wi0-f198.google.com (mail-wi0-f198.google.com [209.85.212.198]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id 3816A21584 for ; Thu, 26 Mar 2015 17:53:08 +0000 (UTC) Received: by wibgr10 with SMTP id gr10sf7600817wib.2 for ; Thu, 26 Mar 2015 10:53:07 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:delivered-to:from:to:date:message-id:subject :precedence:list-id:list-unsubscribe:list-archive:list-post :list-help:list-subscribe:mime-version:content-type :content-transfer-encoding:errors-to:sender:x-original-sender :x-original-authentication-results:mailing-list; bh=TwLboEDIuIIkJCMwhseCSUKA9KwWQWfOyZmCBz0Dx84=; b=ZV4NobkGSpoNJLl8eAI0igzqJ349hH1QtoTVt+gLRJLc90FKV2SVi2ZYCh9FSIRfBo vlCRLanK/3s+rwDAgHSFweANFR/Cks1HnpmN7P5ZdiqPlnWro2OjnZg0xAGvrN0M/OYh gp6bXfB/VMv7pvudCyiChk42eZxXza124kprZZFwGt5D7LzKAZMnckcC6JVaG1YyyVZR nisS9GeIQTcV8zlVCJ+2H6TeKPkDgf1U0jdTxZnbFWx893s06kTKuf2FNSAJYHl6kyPl a8jL6teI+Cz9wdu5V65GrslTH99snXwyclQ3UR6WwbBryYR2518wAa5t6en4jFQ+1+fu 82ew== X-Gm-Message-State: ALoCoQn56w7IBp1imc4TMLsW8crlRcY42d93cJQoEDSdW9ETn0ULjUXhJQppIEsm+3t9Kq/Fs5hs X-Received: by 10.152.19.67 with SMTP id c3mr3653455lae.7.1427392387537; Thu, 26 Mar 2015 10:53:07 -0700 (PDT) X-BeenThere: patchwork-forward@linaro.org Received: by 10.152.28.100 with SMTP id a4ls273954lah.23.gmail; Thu, 26 Mar 2015 10:53:07 -0700 (PDT) X-Received: by 10.152.19.34 with SMTP id b2mr3426681lae.122.1427392387316; Thu, 26 Mar 2015 10:53:07 -0700 (PDT) Received: from mail-la0-f46.google.com (mail-la0-f46.google.com. [209.85.215.46]) by mx.google.com with ESMTPS id b6si5112303lbd.173.2015.03.26.10.53.07 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 26 Mar 2015 10:53:07 -0700 (PDT) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.215.46 as permitted sender) client-ip=209.85.215.46; Received: by labto5 with SMTP id to5so52049647lab.0 for ; Thu, 26 Mar 2015 10:53:07 -0700 (PDT) X-Received: by 10.112.141.202 with SMTP id rq10mr14427524lbb.88.1427392387232; Thu, 26 Mar 2015 10:53:07 -0700 (PDT) X-Forwarded-To: patchwork-forward@linaro.org X-Forwarded-For: patch@linaro.org patchwork-forward@linaro.org Delivered-To: patch@linaro.org Received: by 10.112.57.201 with SMTP id k9csp765931lbq; Thu, 26 Mar 2015 10:53:06 -0700 (PDT) X-Received: by 10.52.154.83 with SMTP id vm19mr18527280vdb.69.1427392385677; Thu, 26 Mar 2015 10:53:05 -0700 (PDT) Received: from ip-10-35-177-41.ec2.internal (lists.linaro.org. [54.225.227.206]) by mx.google.com with ESMTPS id gj9si7911393vdc.102.2015.03.26.10.53.03 (version=TLSv1 cipher=RC4-SHA bits=128/128); Thu, 26 Mar 2015 10:53:05 -0700 (PDT) Received-SPF: none (google.com: lng-odp-bounces@lists.linaro.org does not designate permitted sender hosts) client-ip=54.225.227.206; Received: from localhost ([127.0.0.1] helo=ip-10-35-177-41.ec2.internal) by ip-10-35-177-41.ec2.internal with esmtp (Exim 4.76) (envelope-from ) id 1YbBxk-0004IV-Of; Thu, 26 Mar 2015 17:53:00 +0000 Received: from mail-wi0-f181.google.com ([209.85.212.181]) by ip-10-35-177-41.ec2.internal with esmtp (Exim 4.76) (envelope-from ) id 1YbBxf-0004IK-83 for lng-odp@lists.linaro.org; Thu, 26 Mar 2015 17:52:55 +0000 Received: by wibg7 with SMTP id g7so22068760wib.1 for ; Thu, 26 Mar 2015 10:52:49 -0700 (PDT) X-Received: by 10.180.8.69 with SMTP id p5mr21913498wia.69.1427392369828; Thu, 26 Mar 2015 10:52:49 -0700 (PDT) Received: from e106441.cambridge.arm.com ([2001:41d0:a:3cb4::1]) by mx.google.com with ESMTPSA id vq9sm9381346wjc.6.2015.03.26.10.52.48 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Thu, 26 Mar 2015 10:52:48 -0700 (PDT) From: Stuart Haslam To: lng-odp@lists.linaro.org Date: Thu, 26 Mar 2015 17:52:27 +0000 Message-Id: <1427392347-22709-1-git-send-email-stuart.haslam@linaro.org> X-Mailer: git-send-email 2.1.1 X-Topics: patch Subject: [lng-odp] [PATCH] validation: pktio: fix memory corruption X-BeenThere: lng-odp@lists.linaro.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: 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-bounces@lists.linaro.org X-Removed-Original-Auth: Dkim didn't pass. X-Original-Sender: stuart.haslam@linaro.org X-Original-Authentication-Results: mx.google.com; spf=pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.215.46 as permitted sender) smtp.mail=patch+caf_=patchwork-forward=linaro.org@linaro.org Mailing-list: list patchwork-forward@linaro.org; contact patchwork-forward+owners@linaro.org X-Google-Group-Id: 836684582541 A magic number, used to ensure jumbo frames are transmitted and received in full, is written to the end of a packet buffer at a fixed offset of 9170 bytes. However for non-jumbo tests this is way beyond the end of the allocated buffer. Signed-off-by: Stuart Haslam --- test/validation/odp_pktio.c | 84 ++++++++++++++++++++++++++++----------------- 1 file changed, 52 insertions(+), 32 deletions(-) diff --git a/test/validation/odp_pktio.c b/test/validation/odp_pktio.c index e022c33..d653da4 100644 --- a/test/validation/odp_pktio.c +++ b/test/validation/odp_pktio.c @@ -44,7 +44,6 @@ typedef struct ODP_PACKED { /** structure of test packet UDP payload */ typedef struct ODP_PACKED { - pkt_head_t head; char data[PKT_BUF_JUMBO_MAX_PAYLOAD - sizeof(pkt_head_t) - sizeof(uint32be_t)]; uint32be_t magic2; @@ -74,33 +73,47 @@ static void pktio_pkt_set_macs(odp_packet_t pkt, static uint32_t pkt_payload_len(void) { - return test_jumbo ? sizeof(pkt_test_data_t) : sizeof(pkt_head_t); + uint32_t len; + + len = sizeof(pkt_head_t); + + if (test_jumbo) + len += sizeof(pkt_test_data_t); + + return len; } static int pktio_pkt_set_seq(odp_packet_t pkt) { static uint32_t tstseq; - size_t l4_off; - pkt_test_data_t *data; - uint32_t len = pkt_payload_len(); - + size_t off; + pkt_head_t head; - l4_off = odp_packet_l4_offset(pkt); - if (!l4_off) { + off = odp_packet_l4_offset(pkt); + if (!off) { CU_FAIL("packet L4 offset not set"); return -1; } - data = calloc(1, len); - CU_ASSERT_FATAL(data != NULL); + head.magic = TEST_SEQ_MAGIC; + head.seq = tstseq; + + off += ODPH_UDPHDR_LEN; + odp_packet_copydata_in(pkt, off, sizeof(head), &head); + + if (test_jumbo) { + pkt_test_data_t *data; + + data = calloc(1, sizeof(*data)); + CU_ASSERT_FATAL(data != NULL); - data->head.magic = TEST_SEQ_MAGIC; - data->magic2 = TEST_SEQ_MAGIC; - data->head.seq = tstseq; + data->magic2 = TEST_SEQ_MAGIC; + + off += sizeof(head); + odp_packet_copydata_in(pkt, off, sizeof(*data), data); + free(data); + } - odp_packet_copydata_in(pkt, l4_off+ODPH_UDPHDR_LEN, - len, data); - free(data); tstseq++; return 0; @@ -108,30 +121,37 @@ static int pktio_pkt_set_seq(odp_packet_t pkt) static uint32_t pktio_pkt_seq(odp_packet_t pkt) { - size_t l4_off; + size_t off; uint32_t seq = TEST_SEQ_INVALID; - pkt_test_data_t *data; - uint32_t len = pkt_payload_len(); + pkt_head_t head; - l4_off = odp_packet_l4_offset(pkt); - if (l4_off == ODP_PACKET_OFFSET_INVALID) + off = odp_packet_l4_offset(pkt); + if (off == ODP_PACKET_OFFSET_INVALID) return TEST_SEQ_INVALID; - data = calloc(1, len); - CU_ASSERT_FATAL(data != NULL); + off += ODPH_UDPHDR_LEN; + odp_packet_copydata_out(pkt, off, sizeof(head), &head); - odp_packet_copydata_out(pkt, l4_off+ODPH_UDPHDR_LEN, - len, data); + if (head.magic != TEST_SEQ_MAGIC) + return TEST_SEQ_INVALID; - if (data->head.magic == TEST_SEQ_MAGIC) { - if (test_jumbo && data->magic2 != TEST_SEQ_MAGIC) { - free(data); - return TEST_SEQ_INVALID; - } - seq = data->head.seq; + seq = head.seq; + + if (test_jumbo) { + pkt_test_data_t *data; + + data = calloc(1, sizeof(*data)); + CU_ASSERT_FATAL(data != NULL); + + off += sizeof(head); + odp_packet_copydata_out(pkt, off, sizeof(*data), data); + + if (data->magic2 != TEST_SEQ_MAGIC) + seq = TEST_SEQ_INVALID; + + free(data); } - free(data); return seq; }