[dpdk-stable] patch 'test/hash: fix buffer overflow with jhash' has been queued to stable release 20.11.4

Xueming Li xuemingl at nvidia.com
Wed Nov 10 07:30:52 CET 2021


Hi,

FYI, your patch has been queued to stable release 20.11.4

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/12/21. 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. This will indicate if there was any rebasing
needed to apply to the stable branch. If there were code changes for rebasing
(ie: not only metadata diffs), please double check that the rebase was
correctly done.

Queued patches are on a temporary branch at:
https://github.com/steevenlee/dpdk

This queued commit can be viewed at:
https://github.com/steevenlee/dpdk/commit/936f56164e3e98ca53b1b4b26558e4919c6a37ce

Thanks.

Xueming Li <xuemingl at nvidia.com>

---
>From 936f56164e3e98ca53b1b4b26558e4919c6a37ce Mon Sep 17 00:00:00 2001
From: Vladimir Medvedkin <vladimir.medvedkin at intel.com>
Date: Thu, 14 Oct 2021 18:48:19 +0100
Subject: [PATCH] test/hash: fix buffer overflow with jhash
Cc: Xueming Li <xuemingl at nvidia.com>

[ upstream commit e30ef3a3a032875cc4bc395dc13201a11b110f9f ]

This patch fixes buffer overflow reported by ASAN,
please reference https://bugs.dpdk.org/show_bug.cgi?id=818

Some tests for the rte_hash table use the rte_jhash_32b() as
the hash function. This hash function interprets the length
argument in units of 4 bytes.

This patch adds a wrapper function around rte_jhash_32b()
to reflect API differences regarding the length argument,
effectively dividing it by 4.

For some tests rte_jhash() is used with keys of length not
a multiple of 4 bytes. From the rte_jhash() documentation:
If input key is not aligned to four byte boundaries or a
multiple of four bytes in length, the memory region just
after may be read (but not used in the computation).

This patch increases the size of the proto field of the
flow_key struct up to uint32_t.

Bugzilla ID: 818
Fixes: af75078fece3 ("first public release")

Signed-off-by: Vladimir Medvedkin <vladimir.medvedkin at intel.com>
Acked-by: Yipeng Wang <yipeng1.wang at intel.com>
---
 app/test/test_hash.c | 35 ++++++++++++++++++++++++++---------
 1 file changed, 26 insertions(+), 9 deletions(-)

diff --git a/app/test/test_hash.c b/app/test/test_hash.c
index bd4d0cb722..b99e8de1db 100644
--- a/app/test/test_hash.c
+++ b/app/test/test_hash.c
@@ -74,13 +74,17 @@ static uint32_t hashtest_key_lens[] = {0, 2, 4, 5, 6, 7, 8, 10, 11, 15, 16, 21,
 	}								\
 } while (0)
 
-/* 5-tuple key type */
+/*
+ * 5-tuple key type.
+ * Should be packed to avoid holes with potentially
+ * undefined content in the middle.
+ */
 struct flow_key {
 	uint32_t ip_src;
 	uint32_t ip_dst;
 	uint16_t port_src;
 	uint16_t port_dst;
-	uint8_t proto;
+	uint32_t proto;
 } __rte_packed;
 
 /*
@@ -147,7 +151,7 @@ static struct flow_key keys[5] = { {
 /* Parameters used for hash table in unit test functions. Name set later. */
 static struct rte_hash_parameters ut_params = {
 	.entries = 64,
-	.key_len = sizeof(struct flow_key), /* 13 */
+	.key_len = sizeof(struct flow_key),
 	.hash_func = rte_jhash,
 	.hash_func_init_val = 0,
 	.socket_id = 0,
@@ -792,7 +796,7 @@ static int test_full_bucket(void)
 	struct rte_hash_parameters params_pseudo_hash = {
 		.name = "test4",
 		.entries = 64,
-		.key_len = sizeof(struct flow_key), /* 13 */
+		.key_len = sizeof(struct flow_key),
 		.hash_func = pseudo_hash,
 		.hash_func_init_val = 0,
 		.socket_id = 0,
@@ -895,7 +899,7 @@ static int test_extendable_bucket(void)
 	struct rte_hash_parameters params_pseudo_hash = {
 		.name = "test5",
 		.entries = 64,
-		.key_len = sizeof(struct flow_key), /* 13 */
+		.key_len = sizeof(struct flow_key),
 		.hash_func = pseudo_hash,
 		.hash_func_init_val = 0,
 		.socket_id = 0,
@@ -1606,6 +1610,17 @@ static struct rte_hash_parameters hash_params_ex = {
 	.socket_id = 0,
 };
 
+/*
+ * Wrapper function around rte_jhash_32b.
+ * It is required because rte_jhash_32b() accepts the length
+ * as size of 4-byte units.
+ */
+static inline uint32_t
+test_jhash_32b(const void *k, uint32_t length, uint32_t initval)
+{
+	return rte_jhash_32b(k, length >> 2, initval);
+}
+
 /*
  * add/delete key with jhash2
  */
@@ -1618,7 +1633,7 @@ test_hash_add_delete_jhash2(void)
 
 	hash_params_ex.name = "hash_test_jhash2";
 	hash_params_ex.key_len = 4;
-	hash_params_ex.hash_func = (rte_hash_function)rte_jhash_32b;
+	hash_params_ex.hash_func = (rte_hash_function)test_jhash_32b;
 
 	handle = rte_hash_create(&hash_params_ex);
 	if (handle == NULL) {
@@ -1657,7 +1672,7 @@ test_hash_add_delete_2_jhash2(void)
 
 	hash_params_ex.name = "hash_test_2_jhash2";
 	hash_params_ex.key_len = 8;
-	hash_params_ex.hash_func = (rte_hash_function)rte_jhash_32b;
+	hash_params_ex.hash_func = (rte_hash_function)test_jhash_32b;
 
 	handle = rte_hash_create(&hash_params_ex);
 	if (handle == NULL)
@@ -1915,7 +1930,7 @@ test_hash_rcu_qsbr_dq_mode(uint8_t ext_bkt)
 	struct rte_hash_parameters params_pseudo_hash = {
 		.name = "test_hash_rcu_qsbr_dq_mode",
 		.entries = total_entries,
-		.key_len = sizeof(struct flow_key), /* 13 */
+		.key_len = sizeof(struct flow_key),
 		.hash_func = pseudo_hash,
 		.hash_func_init_val = 0,
 		.socket_id = 0,
@@ -2085,7 +2100,7 @@ test_hash_rcu_qsbr_sync_mode(uint8_t ext_bkt)
 	struct rte_hash_parameters params_pseudo_hash = {
 		.name = "test_hash_rcu_qsbr_sync_mode",
 		.entries = total_entries,
-		.key_len = sizeof(struct flow_key), /* 13 */
+		.key_len = sizeof(struct flow_key),
 		.hash_func = pseudo_hash,
 		.hash_func_init_val = 0,
 		.socket_id = 0,
@@ -2180,6 +2195,8 @@ test_hash_rcu_qsbr_sync_mode(uint8_t ext_bkt)
 static int
 test_hash(void)
 {
+	RTE_BUILD_BUG_ON(sizeof(struct flow_key) % sizeof(uint32_t) != 0);
+
 	if (test_add_delete() < 0)
 		return -1;
 	if (test_hash_add_delete_jhash2() < 0)
-- 
2.33.0

---
  Diff of the applied patch vs upstream commit (please double-check if non-empty:
---
--- -	2021-11-10 14:17:09.402785798 +0800
+++ 0168-test-hash-fix-buffer-overflow-with-jhash.patch	2021-11-10 14:17:01.980745191 +0800
@@ -1 +1 @@
-From e30ef3a3a032875cc4bc395dc13201a11b110f9f Mon Sep 17 00:00:00 2001
+From 936f56164e3e98ca53b1b4b26558e4919c6a37ce Mon Sep 17 00:00:00 2001
@@ -4,0 +5,3 @@
+Cc: Xueming Li <xuemingl at nvidia.com>
+
+[ upstream commit e30ef3a3a032875cc4bc395dc13201a11b110f9f ]
@@ -28 +30,0 @@
-Cc: stable at dpdk.org


More information about the stable mailing list