From patchwork Fri Feb 27 12:21:55 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Maxim Uvarov X-Patchwork-Id: 45224 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-lb0-f197.google.com (mail-lb0-f197.google.com [209.85.217.197]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id E7FE320674 for ; Fri, 27 Feb 2015 12:22:21 +0000 (UTC) Received: by lbdu10 with SMTP id u10sf14188406lbd.3 for ; Fri, 27 Feb 2015 04:22:20 -0800 (PST) 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=jEyDeMYrQ0IClkKXcsT4hVH55Eq7hn+eSoEPKX5Xp2U=; b=WpO4MiYUO26c63mHmD7tmQlsNKOgu94kND9oM33eg8Lf/xjabIogP72ZWKG57/EV7M hl90HEYvQQSqtNwPW++CZJX7Vo+DSAKkqd6ITOlpt0p9FMWk47HatQisnEF9cqWbkPka UKzpMRwwdyE30AK7ez9dAe8Uw8my/Rok2bwUmbCRJ9JYizQ3u7GoHoZqEi2KV/WD7CGG XOdB1C5fivcRd5k0JN7CmxBSEDH+QJZlFyxGux0HGUFP5Cg4mumHA2OfhHUvXUEcwaOS VbD5A9VZq6QKDIguqq007vYTnffPDZbdHuPBjv1eVew18Im+zL9cvgrsJrXIbh61P4p2 mCUg== X-Gm-Message-State: ALoCoQnUvDJ1AFUEJ9Pd3CcqXbSIRxoBbz/BJdX2YFolJ/G/ptfwz4eYTFQUNBt/hKMlithp0E2E X-Received: by 10.112.214.234 with SMTP id od10mr1995710lbc.3.1425039740892; Fri, 27 Feb 2015 04:22:20 -0800 (PST) X-BeenThere: patchwork-forward@linaro.org Received: by 10.152.5.137 with SMTP id s9ls144182las.15.gmail; Fri, 27 Feb 2015 04:22:20 -0800 (PST) X-Received: by 10.112.126.98 with SMTP id mx2mr12069199lbb.52.1425039740578; Fri, 27 Feb 2015 04:22:20 -0800 (PST) Received: from mail-lb0-f178.google.com (mail-lb0-f178.google.com. [209.85.217.178]) by mx.google.com with ESMTPS id ls12si2755603lac.132.2015.02.27.04.22.20 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 27 Feb 2015 04:22:20 -0800 (PST) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.217.178 as permitted sender) client-ip=209.85.217.178; Received: by lbdu10 with SMTP id u10so16891053lbd.7 for ; Fri, 27 Feb 2015 04:22:20 -0800 (PST) X-Received: by 10.152.206.70 with SMTP id lm6mr12415058lac.35.1425039740397; Fri, 27 Feb 2015 04:22:20 -0800 (PST) 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.35.133 with SMTP id h5csp3900915lbj; Fri, 27 Feb 2015 04:22:19 -0800 (PST) X-Received: by 10.140.135.200 with SMTP id 191mr28830408qhh.25.1425039738911; Fri, 27 Feb 2015 04:22:18 -0800 (PST) Received: from ip-10-35-177-41.ec2.internal (lists.linaro.org. [54.225.227.206]) by mx.google.com with ESMTPS id d3si3822731qaq.125.2015.02.27.04.22.17 (version=TLSv1 cipher=RC4-SHA bits=128/128); Fri, 27 Feb 2015 04:22:18 -0800 (PST) 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 1YRJvq-0007bk-2S; Fri, 27 Feb 2015 12:22:14 +0000 Received: from mail-la0-f42.google.com ([209.85.215.42]) by ip-10-35-177-41.ec2.internal with esmtp (Exim 4.76) (envelope-from ) id 1YRJvk-0007bc-Mc for lng-odp@lists.linaro.org; Fri, 27 Feb 2015 12:22:08 +0000 Received: by labhs14 with SMTP id hs14so17159722lab.4 for ; Fri, 27 Feb 2015 04:22:02 -0800 (PST) X-Received: by 10.152.242.41 with SMTP id wn9mr4384600lac.22.1425039722553; Fri, 27 Feb 2015 04:22:02 -0800 (PST) Received: from localhost.localdomain (broadband-46-188-125-102.2com.net. [46.188.125.102]) by mx.google.com with ESMTPSA id xg10sm795701lac.42.2015.02.27.04.22.00 (version=TLSv1.1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Fri, 27 Feb 2015 04:22:01 -0800 (PST) From: Maxim Uvarov To: lng-odp@lists.linaro.org Date: Fri, 27 Feb 2015 15:21:55 +0300 Message-Id: <1425039715-16614-1-git-send-email-maxim.uvarov@linaro.org> X-Mailer: git-send-email 1.8.5.1.163.gd7aced9 X-Topics: patch Subject: [lng-odp] [PATCHv3] linux-generic: pktio check for NULL entry 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: maxim.uvarov@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.217.178 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 CID: 85427 https://bugs.linaro.org/show_bug.cgi?id=1175 get_pktio_entry() can return NULL entry then it can be derefenced inside is_free(entry). Signed-off-by: Maxim Uvarov Reviewed-by: Bill Fischofer --- v3: print enties as 64 bit value. v2: do not call odp_abort on excced pktio entries. platform/linux-generic/include/odp_packet_io_internal.h | 10 ++++++++-- platform/linux-generic/odp_packet_io.c | 2 +- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/platform/linux-generic/include/odp_packet_io_internal.h b/platform/linux-generic/include/odp_packet_io_internal.h index 47b8992..25d49fb 100644 --- a/platform/linux-generic/include/odp_packet_io_internal.h +++ b/platform/linux-generic/include/odp_packet_io_internal.h @@ -22,6 +22,7 @@ extern "C" { #include #include #include +#include #include #include @@ -67,10 +68,15 @@ extern void *pktio_entry_ptr[]; static inline pktio_entry_t *get_pktio_entry(odp_pktio_t id) { - if (odp_unlikely(id == ODP_PKTIO_INVALID || - _odp_typeval(id) > ODP_CONFIG_PKTIO_ENTRIES)) + if (odp_unlikely(id == ODP_PKTIO_INVALID)) return NULL; + if (odp_unlikely(_odp_typeval(id) > ODP_CONFIG_PKTIO_ENTRIES)) { + ODP_DBG("pktio limit %d/%d exceed\n", + _odp_typeval(id), ODP_CONFIG_PKTIO_ENTRIES); + return NULL; + } + return pktio_entry_ptr[_odp_typeval(id) - 1]; } #ifdef __cplusplus diff --git a/platform/linux-generic/odp_packet_io.c b/platform/linux-generic/odp_packet_io.c index 21f0c17..b04ce8b 100644 --- a/platform/linux-generic/odp_packet_io.c +++ b/platform/linux-generic/odp_packet_io.c @@ -339,7 +339,7 @@ odp_pktio_t odp_pktio_lookup(const char *dev) for (i = 1; i <= ODP_CONFIG_PKTIO_ENTRIES; ++i) { entry = get_pktio_entry(_odp_cast_scalar(odp_pktio_t, i)); - if (is_free(entry)) + if (!entry || is_free(entry)) continue; lock_entry(entry);