From patchwork Fri Feb 3 00:28:02 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bill Fischofer X-Patchwork-Id: 93144 Delivered-To: patch@linaro.org Received: by 10.140.20.99 with SMTP id 90csp370584qgi; Thu, 2 Feb 2017 16:29:09 -0800 (PST) X-Received: by 10.36.55.201 with SMTP id r192mr235410itr.41.1486081749575; Thu, 02 Feb 2017 16:29:09 -0800 (PST) Return-Path: Received: from lists.linaro.org (lists.linaro.org. [54.225.227.206]) by mx.google.com with ESMTP id s80si2314629ios.102.2017.02.02.16.29.04; Thu, 02 Feb 2017 16:29:09 -0800 (PST) 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 sp=NONE dis=NONE) header.from=linaro.org Received: by lists.linaro.org (Postfix, from userid 109) id 4A70762DCF; Fri, 3 Feb 2017 00:29:04 +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, RCVD_IN_DNSWL_NONE, 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 60C1C62DD5; Fri, 3 Feb 2017 00:28:17 +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 5B45660F47; Fri, 3 Feb 2017 00:28:11 +0000 (UTC) Received: from mail-ot0-f172.google.com (mail-ot0-f172.google.com [74.125.82.172]) by lists.linaro.org (Postfix) with ESMTPS id 8D2E860F44 for ; Fri, 3 Feb 2017 00:28:08 +0000 (UTC) Received: by mail-ot0-f172.google.com with SMTP id f9so3428491otd.1 for ; Thu, 02 Feb 2017 16:28:08 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=0EjT34p7XAvUmQxsT0ln3GiX1Z0daXF9CzwxHmPpuuI=; b=H/4GOkzf/dStLnG2aRKaF171CCyYamcWTG56s8sr1MHEDSiDTJWhqZmNZ4Qw1WC1Sh guL818tdsYOTXrWf3f0cUD6G2oDJFJMqPnu43YTw8/yjGlU5uKjpSOm1FP3u5w+objXa tqRjgi4g74C5c67O35dQFmKs6Ov0cofh0aNetmDvP/3NTS0D2g4qcgKuDNsqyHUtO8c0 VYSZwfgS2RCrfnOCKGmnIf5vQKDnOi65UxkgmuvU/3S3OfUX1vs3FNb2N985W/Vqp25K G2iYaCSQQvC5Sfudg/KyiRVWue8ZQKiRs72TG6sXTpIR7pVu+AgXsVHOyr8pF4AxMb0Q 0RHg== X-Gm-Message-State: AMke39nqDZ5PopFXRYdwJjDGCDl3/FiDB12o7je+cpESice8pLelOFjRCUYFuW3odQbc9ijxIek= X-Received: by 10.157.31.114 with SMTP id x47mr5120280otx.233.1486081687950; Thu, 02 Feb 2017 16:28:07 -0800 (PST) Received: from localhost.localdomain (cpe-70-121-83-241.austin.res.rr.com. [70.121.83.241]) by smtp.gmail.com with ESMTPSA id u19sm13094328ota.12.2017.02.02.16.28.07 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 02 Feb 2017 16:28:07 -0800 (PST) From: Bill Fischofer To: lng-odp@lists.linaro.org Date: Thu, 2 Feb 2017 18:28:02 -0600 Message-Id: <20170203002802.28881-3-bill.fischofer@linaro.org> X-Mailer: git-send-email 2.11.0.295.gd7dffce In-Reply-To: <20170203002802.28881-1-bill.fischofer@linaro.org> References: <20170203002802.28881-1-bill.fischofer@linaro.org> Subject: [lng-odp] [PATCH 3/3] helper: tables: avoid invalid odp_shm_addr() calls 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" In the various table lookup routines, check that odp_shm_lookup() returns a valid handle before attempting to dereference it via odp_shm_addr(). Signed-off-by: Bill Fischofer --- helper/cuckootable.c | 7 +++++-- helper/hashtable.c | 7 +++++-- helper/iplookuptable.c | 5 ++++- helper/lineartable.c | 7 +++++-- 4 files changed, 19 insertions(+), 7 deletions(-) -- 2.11.0.295.gd7dffce diff --git a/helper/cuckootable.c b/helper/cuckootable.c index 6a7fb215..80ff4989 100644 --- a/helper/cuckootable.c +++ b/helper/cuckootable.c @@ -151,12 +151,15 @@ align32pow2(uint32_t x) odph_table_t odph_cuckoo_table_lookup(const char *name) { - odph_cuckoo_table_impl *tbl; + odph_cuckoo_table_impl *tbl = NULL; + odp_shm_t shm; if (name == NULL || strlen(name) >= ODPH_TABLE_NAME_LEN) return NULL; - tbl = (odph_cuckoo_table_impl *)odp_shm_addr(odp_shm_lookup(name)); + shm = odp_shm_lookup(name); + if (shm != ODP_SHM_INVALID) + tbl = (odph_cuckoo_table_impl *)odp_shm_addr(shm); if (!tbl || tbl->magicword != ODPH_CUCKOO_TABLE_MAGIC_WORD) return NULL; diff --git a/helper/hashtable.c b/helper/hashtable.c index 1c2b8523..9d411444 100644 --- a/helper/hashtable.c +++ b/helper/hashtable.c @@ -150,12 +150,15 @@ int odph_hash_table_destroy(odph_table_t table) odph_table_t odph_hash_table_lookup(const char *name) { - odph_hash_table_imp *hash_tbl; + odph_hash_table_imp *hash_tbl = NULL; + odp_shm_t shm; if (name == NULL || strlen(name) >= ODPH_TABLE_NAME_LEN) return NULL; - hash_tbl = (odph_hash_table_imp *)odp_shm_addr(odp_shm_lookup(name)); + shm = odp_shm_lookup(name); + if (shm != ODP_SHM_INVALID) + hash_tbl = (odph_hash_table_imp *)odp_shm_addr(shm); if (hash_tbl != NULL && strcmp(hash_tbl->name, name) == 0) return (odph_table_t)hash_tbl; return NULL; diff --git a/helper/iplookuptable.c b/helper/iplookuptable.c index 9abdab22..aae21994 100644 --- a/helper/iplookuptable.c +++ b/helper/iplookuptable.c @@ -419,11 +419,14 @@ odph_table_t odph_iplookup_table_lookup(const char *name) { odph_iplookup_table_impl *tbl = NULL; + odp_shm_t shm; if (name == NULL || strlen(name) >= ODPH_TABLE_NAME_LEN) return NULL; - tbl = (odph_iplookup_table_impl *)odp_shm_addr(odp_shm_lookup(name)); + shm = odp_shm_lookup(name); + if (shm != ODP_SHM_INVALID) + tbl = (odph_iplookup_table_impl *)odp_shm_addr(shm); if ( tbl != NULL && diff --git a/helper/lineartable.c b/helper/lineartable.c index e1a396c1..32c4956e 100644 --- a/helper/lineartable.c +++ b/helper/lineartable.c @@ -128,12 +128,15 @@ int odph_linear_table_destroy(odph_table_t table) odph_table_t odph_linear_table_lookup(const char *name) { - odph_linear_table_imp *tbl; + odph_linear_table_imp *tbl = NULL; + odp_shm_t shm; if (name == NULL || strlen(name) >= ODPH_TABLE_NAME_LEN) return NULL; - tbl = (odph_linear_table_imp *)odp_shm_addr(odp_shm_lookup(name)); + shm = odp_shm_lookup(name); + if (shm != ODP_SHM_INVALID) + tbl = (odph_linear_table_imp *)odp_shm_addr(shm); /* check magicword to make sure the memory block is used by a table */ if (tbl != NULL &&