[dpdk-stable] patch 'distributor: fix buffer use after free' has been queued to LTS release 18.11.11

Kevin Traynor ktraynor at redhat.com
Wed Nov 18 17:35:06 CET 2020


Hi,

FYI, your patch has been queued to LTS release 18.11.11

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/24/20. 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/kevintraynor/dpdk-stable-queue

This queued commit can be viewed at:
https://github.com/kevintraynor/dpdk-stable-queue/commit/de6e48d0b37ccb04376af977abc27c2833f7364e

Thanks.

Kevin.

---
>From de6e48d0b37ccb04376af977abc27c2833f7364e Mon Sep 17 00:00:00 2001
From: Lukasz Wojciechowski <l.wojciechow at partner.samsung.com>
Date: Sat, 17 Oct 2020 05:06:47 +0200
Subject: [PATCH] distributor: fix buffer use after free

[ upstream commit 6bd951b48222caaa10a796057f617cab04f928b0 ]

rte_distributor_request_pkt and rte_distributor_get_pkt dereferenced
oldpkt parameter when in RTE_DIST_ALG_SINGLE even if number
of returned buffers from worker to distributor was 0.

This patch passes NULL to the legacy API when number of returned
buffers is 0. This allows passing NULL as oldpkt parameter.

Distributor tests are also updated passing NULL as oldpkt and
0 as number of returned packets, where packets are not returned.

Fixes: 775003ad2f96 ("distributor: add new burst-capable library")

Signed-off-by: Lukasz Wojciechowski <l.wojciechow at partner.samsung.com>
Acked-by: David Hunt <david.hunt at intel.com>
---
 lib/librte_distributor/rte_distributor.c |  4 ++--
 test/test/test_distributor.c             | 28 +++++++++---------------
 2 files changed, 12 insertions(+), 20 deletions(-)

diff --git a/lib/librte_distributor/rte_distributor.c b/lib/librte_distributor/rte_distributor.c
index d1f8b14d2e..5f9dde8494 100644
--- a/lib/librte_distributor/rte_distributor.c
+++ b/lib/librte_distributor/rte_distributor.c
@@ -44,5 +44,5 @@ rte_distributor_request_pkt_v1705(struct rte_distributor *d,
 	if (unlikely(d->alg_type == RTE_DIST_ALG_SINGLE)) {
 		rte_distributor_request_pkt_v20(d->d_v20,
-			worker_id, oldpkt[0]);
+			worker_id, count ? oldpkt[0] : NULL);
 		return;
 	}
@@ -144,5 +144,5 @@ rte_distributor_get_pkt_v1705(struct rte_distributor *d,
 		if (return_count <= 1) {
 			pkts[0] = rte_distributor_get_pkt_v20(d->d_v20,
-				worker_id, oldpkt[0]);
+				worker_id, return_count ? oldpkt[0] : NULL);
 			return (pkts[0]) ? 1 : 0;
 		} else
diff --git a/test/test/test_distributor.c b/test/test/test_distributor.c
index 6aa4e49e69..ae7eff5a91 100644
--- a/test/test/test_distributor.c
+++ b/test/test/test_distributor.c
@@ -63,11 +63,8 @@ handle_work(void *arg)
 	struct worker_params *wp = arg;
 	struct rte_distributor *db = wp->dist;
-	unsigned int count = 0, num = 0;
+	unsigned int count = 0, num;
 	unsigned int id = __sync_fetch_and_add(&worker_idx, 1);
-	int i;
 
-	for (i = 0; i < 8; i++)
-		buf[i] = NULL;
-	num = rte_distributor_get_pkt(db, id, buf, buf, num);
+	num = rte_distributor_get_pkt(db, id, buf, NULL, 0);
 	while (!quit) {
 		__atomic_fetch_add(&worker_stats[id].handled_packets, num,
@@ -273,10 +270,8 @@ handle_work_with_free_mbufs(void *arg)
 	unsigned int count = 0;
 	unsigned int i;
-	unsigned int num = 0;
+	unsigned int num;
 	unsigned int id = __sync_fetch_and_add(&worker_idx, 1);
 
-	for (i = 0; i < 8; i++)
-		buf[i] = NULL;
-	num = rte_distributor_get_pkt(d, id, buf, buf, num);
+	num = rte_distributor_get_pkt(d, id, buf, NULL, 0);
 	while (!quit) {
 		worker_stats[id].handled_packets += num;
@@ -284,6 +279,5 @@ handle_work_with_free_mbufs(void *arg)
 		for (i = 0; i < num; i++)
 			rte_pktmbuf_free(buf[i]);
-		num = rte_distributor_get_pkt(d,
-				id, buf, buf, num);
+		num = rte_distributor_get_pkt(d, id, buf, NULL, 0);
 	}
 	worker_stats[id].handled_packets += num;
@@ -343,5 +337,5 @@ handle_work_for_shutdown_test(void *arg)
 	struct rte_distributor *d = wp->dist;
 	unsigned int count = 0;
-	unsigned int num = 0;
+	unsigned int num;
 	unsigned int total = 0;
 	unsigned int i;
@@ -349,5 +343,5 @@ handle_work_for_shutdown_test(void *arg)
 	const unsigned int id = __sync_fetch_and_add(&worker_idx, 1);
 
-	num = rte_distributor_get_pkt(d, id, buf, buf, num);
+	num = rte_distributor_get_pkt(d, id, buf, NULL, 0);
 
 	/* wait for quit single globally, or for worker zero, wait
@@ -358,6 +352,5 @@ handle_work_for_shutdown_test(void *arg)
 		for (i = 0; i < num; i++)
 			rte_pktmbuf_free(buf[i]);
-		num = rte_distributor_get_pkt(d,
-				id, buf, buf, num);
+		num = rte_distributor_get_pkt(d, id, buf, NULL, 0);
 		total += num;
 	}
@@ -373,6 +366,5 @@ handle_work_for_shutdown_test(void *arg)
 			usleep(100);
 
-		num = rte_distributor_get_pkt(d,
-				id, buf, buf, num);
+		num = rte_distributor_get_pkt(d, id, buf, NULL, 0);
 
 		while (!quit) {
@@ -380,5 +372,5 @@ handle_work_for_shutdown_test(void *arg)
 			count += num;
 			rte_pktmbuf_free(pkt);
-			num = rte_distributor_get_pkt(d, id, buf, buf, num);
+			num = rte_distributor_get_pkt(d, id, buf, NULL, 0);
 		}
 		returned = rte_distributor_return_pkt(d,
-- 
2.26.2

---
  Diff of the applied patch vs upstream commit (please double-check if non-empty:
---
--- -	2020-11-18 16:33:38.352188647 +0000
+++ 0020-distributor-fix-buffer-use-after-free.patch	2020-11-18 16:33:37.926215060 +0000
@@ -1 +1 @@
-From 6bd951b48222caaa10a796057f617cab04f928b0 Mon Sep 17 00:00:00 2001
+From de6e48d0b37ccb04376af977abc27c2833f7364e Mon Sep 17 00:00:00 2001
@@ -5,0 +6,2 @@
+[ upstream commit 6bd951b48222caaa10a796057f617cab04f928b0 ]
+
@@ -17 +18,0 @@
-Cc: stable at dpdk.org
@@ -22 +22,0 @@
- app/test/test_distributor.c              | 28 +++++++++---------------
@@ -23,0 +24 @@
+ test/test/test_distributor.c             | 28 +++++++++---------------
@@ -26,4 +27,22 @@
-diff --git a/app/test/test_distributor.c b/app/test/test_distributor.c
-index ba1f81cf8d..52230d2504 100644
---- a/app/test/test_distributor.c
-+++ b/app/test/test_distributor.c
+diff --git a/lib/librte_distributor/rte_distributor.c b/lib/librte_distributor/rte_distributor.c
+index d1f8b14d2e..5f9dde8494 100644
+--- a/lib/librte_distributor/rte_distributor.c
++++ b/lib/librte_distributor/rte_distributor.c
+@@ -44,5 +44,5 @@ rte_distributor_request_pkt_v1705(struct rte_distributor *d,
+ 	if (unlikely(d->alg_type == RTE_DIST_ALG_SINGLE)) {
+ 		rte_distributor_request_pkt_v20(d->d_v20,
+-			worker_id, oldpkt[0]);
++			worker_id, count ? oldpkt[0] : NULL);
+ 		return;
+ 	}
+@@ -144,5 +144,5 @@ rte_distributor_get_pkt_v1705(struct rte_distributor *d,
+ 		if (return_count <= 1) {
+ 			pkts[0] = rte_distributor_get_pkt_v20(d->d_v20,
+-				worker_id, oldpkt[0]);
++				worker_id, return_count ? oldpkt[0] : NULL);
+ 			return (pkts[0]) ? 1 : 0;
+ 		} else
+diff --git a/test/test/test_distributor.c b/test/test/test_distributor.c
+index 6aa4e49e69..ae7eff5a91 100644
+--- a/test/test/test_distributor.c
++++ b/test/test/test_distributor.c
@@ -35 +54 @@
- 	unsigned int id = __atomic_fetch_add(&worker_idx, 1, __ATOMIC_RELAXED);
+ 	unsigned int id = __sync_fetch_and_add(&worker_idx, 1);
@@ -49 +68 @@
- 	unsigned int id = __atomic_fetch_add(&worker_idx, 1, __ATOMIC_RELAXED);
+ 	unsigned int id = __sync_fetch_and_add(&worker_idx, 1);
@@ -72,2 +91,2 @@
-@@ -350,5 +344,5 @@ handle_work_for_shutdown_test(void *arg)
- 			__ATOMIC_RELAXED);
+@@ -349,5 +343,5 @@ handle_work_for_shutdown_test(void *arg)
+ 	const unsigned int id = __sync_fetch_and_add(&worker_idx, 1);
@@ -79 +98 @@
-@@ -359,6 +353,5 @@ handle_work_for_shutdown_test(void *arg)
+@@ -358,6 +352,5 @@ handle_work_for_shutdown_test(void *arg)
@@ -87 +106 @@
-@@ -374,6 +367,5 @@ handle_work_for_shutdown_test(void *arg)
+@@ -373,6 +366,5 @@ handle_work_for_shutdown_test(void *arg)
@@ -95 +114 @@
-@@ -381,5 +373,5 @@ handle_work_for_shutdown_test(void *arg)
+@@ -380,5 +372,5 @@ handle_work_for_shutdown_test(void *arg)
@@ -102,18 +120,0 @@
-diff --git a/lib/librte_distributor/rte_distributor.c b/lib/librte_distributor/rte_distributor.c
-index d6d4350a28..93c90cf543 100644
---- a/lib/librte_distributor/rte_distributor.c
-+++ b/lib/librte_distributor/rte_distributor.c
-@@ -43,5 +43,5 @@ rte_distributor_request_pkt(struct rte_distributor *d,
- 	if (unlikely(d->alg_type == RTE_DIST_ALG_SINGLE)) {
- 		rte_distributor_request_pkt_single(d->d_single,
--			worker_id, oldpkt[0]);
-+			worker_id, count ? oldpkt[0] : NULL);
- 		return;
- 	}
-@@ -135,5 +135,5 @@ rte_distributor_get_pkt(struct rte_distributor *d,
- 		if (return_count <= 1) {
- 			pkts[0] = rte_distributor_get_pkt_single(d->d_single,
--				worker_id, oldpkt[0]);
-+				worker_id, return_count ? oldpkt[0] : NULL);
- 			return (pkts[0]) ? 1 : 0;
- 		} else



More information about the stable mailing list