From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by dpdk.org (Postfix) with ESMTP id B30A81B49D for ; Thu, 22 Nov 2018 17:52:26 +0100 (CET) Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 1979C307D84E; Thu, 22 Nov 2018 16:52:26 +0000 (UTC) Received: from ktraynor.remote.csb (unknown [10.36.118.7]) by smtp.corp.redhat.com (Postfix) with ESMTP id 833BF60E3F; Thu, 22 Nov 2018 16:52:24 +0000 (UTC) From: Kevin Traynor To: Yipeng Wang Cc: Honnappa Nagarahalli , Dharmik Thakkar , Bruce Richardson , dpdk stable Date: Thu, 22 Nov 2018 16:49:26 +0000 Message-Id: <20181122164957.13003-34-ktraynor@redhat.com> In-Reply-To: <20181122164957.13003-1-ktraynor@redhat.com> References: <20181122164957.13003-1-ktraynor@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.48]); Thu, 22 Nov 2018 16:52:26 +0000 (UTC) Subject: [dpdk-stable] patch 'hash: fix race condition in iterate' has been queued to stable release 18.08.1 X-BeenThere: stable@dpdk.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: patches for DPDK stable branches List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 22 Nov 2018 16:52:27 -0000 Hi, FYI, your patch has been queued to stable release 18.08.1 Note it hasn't been pushed to http://dpdk.org/browse/dpdk-stable yet. It will be pushed if I get no objections before 11/28/18. So please shout if anyone has objections. Also note that after the patch there's a diff of the upstream commit vs the patch applied to the branch. If the code is different (ie: not only metadata diffs), due for example to a change in context or macro names, please double check it. Thanks. Kevin Traynor --- >>From e916f02d3fb7ddf504589359aa941ec0971da471 Mon Sep 17 00:00:00 2001 From: Yipeng Wang Date: Mon, 22 Oct 2018 11:39:45 -0700 Subject: [PATCH] hash: fix race condition in iterate [ upstream commit 99040943442426ebfef0ad69eca73559a9e3b730 ] In rte_hash_iterate, the reader lock did not protect the while loop which checks empty entry. This created a race condition that the entry may become empty when enters the lock, then a wrong key data value would be read out. This commit reads out the position in the while condition, which makes sure that the position will not be changed to empty before entering the lock. Fixes: f2e3001b53ec ("hash: support read/write concurrency") Reported-by: Honnappa Nagarahalli Signed-off-by: Yipeng Wang Reviewed-by: Honnappa Nagarahalli Acked-by: Dharmik Thakkar Acked-by: Bruce Richardson --- lib/librte_hash/rte_cuckoo_hash.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/lib/librte_hash/rte_cuckoo_hash.c b/lib/librte_hash/rte_cuckoo_hash.c index f7b86c8c9..da8ddf40a 100644 --- a/lib/librte_hash/rte_cuckoo_hash.c +++ b/lib/librte_hash/rte_cuckoo_hash.c @@ -1319,5 +1319,5 @@ rte_hash_iterate(const struct rte_hash *h, const void **key, void **data, uint32 /* If current position is empty, go to the next one */ - while (h->buckets[bucket_idx].key_idx[idx] == EMPTY_SLOT) { + while ((position = h->buckets[bucket_idx].key_idx[idx]) == EMPTY_SLOT) { (*next)++; /* End of table */ @@ -1327,7 +1327,6 @@ rte_hash_iterate(const struct rte_hash *h, const void **key, void **data, uint32 idx = *next % RTE_HASH_BUCKET_ENTRIES; } + __hash_rw_reader_lock(h); - /* Get position of entry in key table */ - position = h->buckets[bucket_idx].key_idx[idx]; next_key = (struct rte_hash_key *) ((char *)h->key_store + position * h->key_entry_size); -- 2.19.0 --- Diff of the applied patch vs upstream commit (please double-check if non-empty: --- --- - 2018-11-22 16:47:33.134904760 +0000 +++ 0034-hash-fix-race-condition-in-iterate.patch 2018-11-22 16:47:32.000000000 +0000 @@ -1,8 +1,10 @@ -From 99040943442426ebfef0ad69eca73559a9e3b730 Mon Sep 17 00:00:00 2001 +From e916f02d3fb7ddf504589359aa941ec0971da471 Mon Sep 17 00:00:00 2001 From: Yipeng Wang Date: Mon, 22 Oct 2018 11:39:45 -0700 Subject: [PATCH] hash: fix race condition in iterate +[ upstream commit 99040943442426ebfef0ad69eca73559a9e3b730 ] + In rte_hash_iterate, the reader lock did not protect the while loop which checks empty entry. This created a race condition that the entry may become empty when enters @@ -13,7 +15,6 @@ to empty before entering the lock. Fixes: f2e3001b53ec ("hash: support read/write concurrency") -Cc: stable@dpdk.org Reported-by: Honnappa Nagarahalli Signed-off-by: Yipeng Wang