From patchwork Fri Feb 3 00:28:00 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bill Fischofer X-Patchwork-Id: 93142 Delivered-To: patch@linaro.org Received: by 10.140.20.99 with SMTP id 90csp370328qgi; Thu, 2 Feb 2017 16:28:16 -0800 (PST) X-Received: by 10.107.15.196 with SMTP id 65mr8913064iop.141.1486081696004; Thu, 02 Feb 2017 16:28:16 -0800 (PST) Return-Path: Received: from lists.linaro.org (lists.linaro.org. [54.225.227.206]) by mx.google.com with ESMTP id u7si134566itb.27.2017.02.02.16.28.14; Thu, 02 Feb 2017 16:28:15 -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 645BB62DD6; Fri, 3 Feb 2017 00:28: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, 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 688A860F44; Fri, 3 Feb 2017 00:28:11 +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 07C7860F47; Fri, 3 Feb 2017 00:28:08 +0000 (UTC) Received: from mail-ot0-f175.google.com (mail-ot0-f175.google.com [74.125.82.175]) by lists.linaro.org (Postfix) with ESMTPS id 1C2C6609A1 for ; Fri, 3 Feb 2017 00:28:07 +0000 (UTC) Received: by mail-ot0-f175.google.com with SMTP id f9so3428182otd.1 for ; Thu, 02 Feb 2017 16:28:07 -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; bh=Em5iMW6ZfClukj3qRQR7cEXH+MB11W0Uht7c7EnkaiQ=; b=ovuXqcN6qcrNbWTSlOlDh4tGinY0NSeMEzAguBX/yIjOcfy2yoo6s8hJzQJiNsx/EY SDlpd0T2Axj3XSr+awC1++d4ZfWzxUFzRH1tlfmTlDNRI+HllmhyNN5bohJb89LNAGpw JEYzENfFRxvfmMvqgIN2MEAnVbmyEm0zOLbOlljqOP3PNREWaR5exsQ1cy1D4uR5LMMt U+QdvC6SQUfHv5uJEQfpUyfoAAoIygQ80kpwlfE3GYi95mUUt0wh5lZJG4KS/7YXNlwi lzNdepwCYCCYz1Qys9kXV+pfs5IHdmiSw8PxHWtHlNIyGCzJ03rFYlix4AvjSVwFkfrV p8sg== X-Gm-Message-State: AIkVDXLxX3vndoa6myKONSj/Cb6/uQn4KTy+yfJAeHByVXKHnFe//2F1rb1dQNQSpC4CnAe+c2c= X-Received: by 10.157.63.162 with SMTP id r31mr5174709otc.39.1486081686628; Thu, 02 Feb 2017 16:28:06 -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.05 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 02 Feb 2017 16:28:05 -0800 (PST) From: Bill Fischofer To: lng-odp@lists.linaro.org Date: Thu, 2 Feb 2017 18:28:00 -0600 Message-Id: <20170203002802.28881-1-bill.fischofer@linaro.org> X-Mailer: git-send-email 2.11.0.295.gd7dffce Subject: [lng-odp] [PATCH 1/3] helper: cuckootable: avoid storage leaks on error paths 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" Ensure that malloced storage areas are freed on error paths. This resolves Bug https://bugs.linaro.org/show_bug.cgi?id=2830 Signed-off-by: Bill Fischofer --- helper/test/cuckootable.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) -- 2.11.0.295.gd7dffce diff --git a/helper/test/cuckootable.c b/helper/test/cuckootable.c index 002e52e0..be655911 100644 --- a/helper/test/cuckootable.c +++ b/helper/test/cuckootable.c @@ -453,10 +453,15 @@ static int test_performance(int number) unsigned key_num = key_len * elem_num; key_space = (uint8_t *)malloc(key_num); - key_ptr = (const void **)malloc(sizeof(void *) * elem_num); if (key_space == NULL) return -ENOENT; + key_ptr = (const void **)malloc(sizeof(void *) * elem_num); + if (key_ptr == NULL) { + free(key_space); + return -ENOENT; + } + for (j = 0; j < key_num; j++) { key_space[j] = rand() % 255; if (j % key_len == 0) @@ -473,6 +478,8 @@ static int test_performance(int number) "performance_test", PERFORMANCE_CAPACITY, key_len, 0); if (table == NULL) { printf("cuckoo table creation failed\n"); + free(key_ptr); + free(key_space); return -ENOENT; } From patchwork Fri Feb 3 00:28:01 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bill Fischofer X-Patchwork-Id: 93143 Delivered-To: patch@linaro.org Received: by 10.140.20.99 with SMTP id 90csp370425qgi; Thu, 2 Feb 2017 16:28:39 -0800 (PST) X-Received: by 10.107.6.30 with SMTP id 30mr8121004iog.78.1486081719740; Thu, 02 Feb 2017 16:28:39 -0800 (PST) Return-Path: Received: from lists.linaro.org (lists.linaro.org. [54.225.227.206]) by mx.google.com with ESMTP id c66si139947ite.5.2017.02.02.16.28.39; Thu, 02 Feb 2017 16:28:39 -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 0E2BB62DD9; Fri, 3 Feb 2017 00:28:39 +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 D44D062DD1; Fri, 3 Feb 2017 00:28:13 +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 141FD60F4A; Fri, 3 Feb 2017 00:28:09 +0000 (UTC) Received: from mail-oi0-f45.google.com (mail-oi0-f45.google.com [209.85.218.45]) by lists.linaro.org (Postfix) with ESMTPS id 0BEC8609A1 for ; Fri, 3 Feb 2017 00:28:08 +0000 (UTC) Received: by mail-oi0-f45.google.com with SMTP id s203so2638616oie.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=/pCN/DwqNUh43P5HGbN56VlPMHF7FlVl/oRpz6hjm/w=; b=Ol5ohUCw2OqmOpw73tzmlgRhBYx4A2Wc/UktOpqjnPsZKNXSCuYTs7BYsV2MR6+FHr eoWGiHR1ER0LVDMvF7pIEqBFST6bgGW/3C0SZs9G7HIpBO59dfViumYcHuPEF2+XDnFp 95oivQT0yFWbzmJAzkAN9SgF28Cf+o0i7OCnJZsu1p2Ufj7wimvizMV60gTeUr1pM+V6 0uqDa9EyfS+X2q/aAivb3CeBtsyYegHufiAIbgPtk4oAYJ+rJJMOqFjuMhDKEjrpTHBY V8GSdkK3oHmFOsJHGbQnZgwUNEfF0Ym2tIMU8zqxFHBntkzOvJDG0w7W4wGECNnUhr28 K2MA== X-Gm-Message-State: AIkVDXJPJLKULpsMoPA7OQ2o3tq4KEhmX5Ii4nvVl/Hkb4Oq/PjQ/iIrcdz8WhS57n9g2phqIHs= X-Received: by 10.202.245.214 with SMTP id t205mr5232761oih.52.1486081687261; 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.06 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 02 Feb 2017 16:28:06 -0800 (PST) From: Bill Fischofer To: lng-odp@lists.linaro.org Date: Thu, 2 Feb 2017 18:28:01 -0600 Message-Id: <20170203002802.28881-2-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 2/3] helper: iplookuptable: removed unused variable 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" Resolve Bug https://bugs.linaro.org/show_bug.cgi?id=2829 by avoiding unused variable. Signed-off-by: Bill Fischofer --- helper/iplookuptable.c | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) -- 2.11.0.295.gd7dffce diff --git a/helper/iplookuptable.c b/helper/iplookuptable.c index 845125b3..9abdab22 100644 --- a/helper/iplookuptable.c +++ b/helper/iplookuptable.c @@ -639,11 +639,9 @@ prefix_insert_iter( /* If this entry contains a nexthop and a small cidr, * push it to the next level. */ - if (entry->cidr > 0) { - state = prefix_insert_into_lx( - tbl, ne, entry->cidr, - push, entry->cidr + 8); - } + if (entry->cidr > 0) + (void)prefix_insert_into_lx(tbl, ne, entry->cidr, + push, entry->cidr + 8); } ne += (ip >> 24); 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 &&