From patchwork Thu Nov 22 02:51:56 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Honnappa Nagarahalli X-Patchwork-Id: 151708 Delivered-To: patch@linaro.org Received: by 2002:a2e:299d:0:0:0:0:0 with SMTP id p29-v6csp188908ljp; Wed, 21 Nov 2018 18:52:12 -0800 (PST) X-Google-Smtp-Source: AJdET5de9kOpd4I4u3xs+W25lunqS9EN+mBrVwdeerOwrQceXvGxpUEFwd6DMpKdPlKh5pjz0qAb X-Received: by 2002:a17:906:5a0a:: with SMTP id p10-v6mr6894048ejq.43.1542855132784; Wed, 21 Nov 2018 18:52:12 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1542855132; cv=none; d=google.com; s=arc-20160816; b=GvI5hUylyxiBNIY3kjN6YC4Xqsa6+ZS+4UUhsCXl/56vI2P+m+Fk5miVj2X1Wdbs8b 9CJSymZWnn1dQLPS67foPKhrXMyR1vJgRusBkNwviHvmuc9GZl1yOX9pQUiyapCGEUpD 1fAxfbk8EV77QX1BvbwaUW7nIyOrJfVNF3Hqfqx4HBK+zh3Ctfo01OatPaChr07wkCHe /CWD5nIr53d+kpGFIi9TddRp7XjXlOWOLQS+/wFVV8RP8HdqvZltlGBk2cgjevtZkaVH Or7pKQZ39ypmsMgsVhbl1Hsxg2+NofEqfC4AAMuUkzwA2zZUA7qTgbUQJ2JeE6Dfy5HP ovFg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:subject:message-id:date:cc:to :from; bh=AJxR7KrjYOTDEDt34QzR12DWeZ7fCLoJ+DLLQ7SKDwo=; b=bx/8nc+M4HooSHK8ukBKw08PhuwOipf/n02+qO+fpGNq8ZsrL0iUZxYt9UaGVNNkqW hA4IMVfE7GbN/+nzPSsmq3VjL7qNFPqxdMAcXS/3JiLReYLPgHNuUnnWQ/MQt8/w+TPT lAckiT7mXqj+n+knok5GJdNKRkm2D8hiZLmxlk0uXjZJvss0VBsr390MDY5R8O+XnqVj Gcp2Ph1pv3/8Xavf8e4KMuYgbZW96w5IxnH+wHEfPNZQAh3s3DqZ61auwfxAUZeHL/98 elhmUfUx8dSdqF60q8BKxv+ZFg54qvAee36UKTIx+skvAGmm0Tx2T6JNfpuuy+lXC8on qOow== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of dev-bounces@dpdk.org designates 92.243.14.124 as permitted sender) smtp.mailfrom=dev-bounces@dpdk.org Return-Path: Received: from dpdk.org (dpdk.org. [92.243.14.124]) by mx.google.com with ESMTP id u11-v6si3338329ejz.118.2018.11.21.18.52.12; Wed, 21 Nov 2018 18:52:12 -0800 (PST) Received-SPF: pass (google.com: domain of dev-bounces@dpdk.org designates 92.243.14.124 as permitted sender) client-ip=92.243.14.124; Authentication-Results: mx.google.com; spf=pass (google.com: domain of dev-bounces@dpdk.org designates 92.243.14.124 as permitted sender) smtp.mailfrom=dev-bounces@dpdk.org Received: from [92.243.14.124] (localhost [127.0.0.1]) by dpdk.org (Postfix) with ESMTP id 0B6D21B19A; Thu, 22 Nov 2018 03:52:11 +0100 (CET) Received: from foss.arm.com (usa-sjc-mx-foss1.foss.arm.com [217.140.101.70]) by dpdk.org (Postfix) with ESMTP id 51C3E1B163 for ; Thu, 22 Nov 2018 03:52:10 +0100 (CET) Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.72.51.249]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 97A6136C2; Wed, 21 Nov 2018 18:52:09 -0800 (PST) Received: from qc2400f-1.austin.arm.com (qc2400f-1.austin.arm.com [10.118.14.34]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 38DB83F5CF; Wed, 21 Nov 2018 18:52:09 -0800 (PST) From: Honnappa Nagarahalli To: bruce.richardson@intel.com, pablo.de.lara.guarch@intel.com Cc: dev@dpdk.org, yipeng1.wang@intel.com, gavin.hu@arm.com, honnappa.nagarahalli@arm.com, nd@arm.com Date: Wed, 21 Nov 2018 20:51:56 -0600 Message-Id: <20181122025156.42217-1-honnappa.nagarahalli@arm.com> X-Mailer: git-send-email 2.17.1 Subject: [dpdk-dev] [PATCH] hash: fix out-of-bound write while freeing key slot X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org Sender: "dev" Add a debug check for out-of-bound write while freeing the key slot. Coverity issue: 325733 Fixes: e605a1d36ca7 ("hash: add lock-free r/w concurrency") Cc: honnappa.nagarahalli@arm.com Signed-off-by: Honnappa Nagarahalli Reviewed-by: Steve Capper Reviewed-by: Gavin Hu --- lib/librte_hash/rte_cuckoo_hash.c | 4 ++++ lib/librte_hash/rte_cuckoo_hash.h | 11 +++++++++++ 2 files changed, 15 insertions(+) -- 2.17.1 Acked-by: Bruce Richardson diff --git a/lib/librte_hash/rte_cuckoo_hash.c b/lib/librte_hash/rte_cuckoo_hash.c index 5ddcccd87..c35a60266 100644 --- a/lib/librte_hash/rte_cuckoo_hash.c +++ b/lib/librte_hash/rte_cuckoo_hash.c @@ -1272,6 +1272,9 @@ remove_entry(const struct rte_hash *h, struct rte_hash_bucket *bkt, unsigned i) n_slots = rte_ring_mp_enqueue_burst(h->free_slots, cached_free_slots->objs, LCORE_CACHE_SIZE, NULL); + ERR_IF_TRUE((n_slots == 0), + "%s: could not enqueue free slots in global ring\n", + __func__); cached_free_slots->len -= n_slots; } /* Put index of new free slot in cache. */ @@ -1477,6 +1480,7 @@ rte_hash_free_key_with_position(const struct rte_hash *h, n_slots = rte_ring_mp_enqueue_burst(h->free_slots, cached_free_slots->objs, LCORE_CACHE_SIZE, NULL); + RETURN_IF_TRUE((n_slots == 0), -EFAULT); cached_free_slots->len -= n_slots; } /* Put index of new free slot in cache. */ diff --git a/lib/librte_hash/rte_cuckoo_hash.h b/lib/librte_hash/rte_cuckoo_hash.h index 5dfbbc48b..eacdaa8d4 100644 --- a/lib/librte_hash/rte_cuckoo_hash.h +++ b/lib/librte_hash/rte_cuckoo_hash.h @@ -29,6 +29,17 @@ #define RETURN_IF_TRUE(cond, retval) #endif +#if defined(RTE_LIBRTE_HASH_DEBUG) +#define ERR_IF_TRUE(cond, fmt, args...) do { \ + if (cond) { \ + RTE_LOG(ERR, HASH, fmt, ##args); \ + return; \ + } \ +} while (0) +#else +#define ERR_IF_TRUE(cond, fmt, args...) +#endif + #include #include