Skip to contentSkip to conversation

test/timer: fix memzone reserve failure check

PATCH Superseded Min Hu (Connor) 3 participants 10 messages Apr 22, 2021 – May 13, 2021

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 test/timer: fix memzone reserve failure check

Segmentation fault may occur without checking if memzone reserves succeed or not.

This patch fixed it.

Fixes 50247fe03fe0 ("test/timer: exercise new APIs in secondary process")
---
 app/test/test_timer_secondary.c | 10 ++++++++++
 1 file changed, 10 insertions(+)
app/test/test_timer_secondary.c +10 -0
index 1e8f1d4..281f5bd 100644
@@ -125,6 +125,11 @@ test_timer_secondary(void)
 
 		mz = rte_memzone_reserve(TEST_INFO_MZ_NAME, sizeof(*test_info),
 					 SOCKET_ID_ANY, 0);
+		if (mz == NULL) {
+			printf("Failed to reserve memzone\n");
+			return TEST_SKIPPED;
+		}
+
 		test_info = mz->addr;
 		TEST_ASSERT_NOT_NULL(test_info, "Couldn't allocate memory for "
 				     "test data");
@@ -171,6 +176,11 @@ test_timer_secondary(void)
 		int i;
 
 		mz = rte_memzone_lookup(TEST_INFO_MZ_NAME);
+		if (mz == NULL) {
+			printf("Failed to lookup memzone\n");
+			return TEST_SKIPPED;
+		}
+
 		test_info = mz->addr;
 		TEST_ASSERT_NOT_NULL(test_info, "Couldn't lookup memzone for "
 				     "test info");
Signature · 1 line
2.7.4
#1 lore raw
Quoted 37 lines

-----Original Message-----
From: Min Hu (Connor) <[email protected]>
Sent: Thursday, April 22, 2021 4:19 AM
To: [email protected]
Cc: Yigit, Ferruh <[email protected]>; [email protected]; Carrillo, Erik G <[email protected]>
Subject: [PATCH] test/timer: fix memzone reserve failure check

Segmentation fault may occur without checking if memzone reserves succeed or not.

This patch fixed it.

Fixes 50247fe03fe0 ("test/timer: exercise new APIs in secondary process")
---
 app/test/test_timer_secondary.c | 10 ++++++++++
 1 file changed, 10 insertions(+)
(quoted diff) +0 -0

b/app/test/test_timer_secondary.c index 1e8f1d4..281f5bd 100644

app/test/test_timer_secondary.c +5 -0
@@ -125,6 +125,11 @@ test_timer_secondary(void)
 
 		mz = rte_memzone_reserve(TEST_INFO_MZ_NAME,
 sizeof(*test_info),
 					 SOCKET_ID_ANY, 0);
+		if (mz == NULL) {
+			printf("Failed to reserve memzone\n");
+			return TEST_SKIPPED;
+		}
+
 		test_info = mz->addr;
 		TEST_ASSERT_NOT_NULL(test_info, "Couldn't allocate
Quoted 2 lines

memory for "
"test data");

I think the TEST_ASSERT_NOT_NULL check here should be the area we update -- instead of checking the test_info pointer, we should check "mz", and that will address the issue you have noted. We can then move the "test_info = mz->addr" assignment below the assert.

Quoted 11 lines
app/test/test_timer_secondary.c +5 -0
@@ -171,6 +176,11 @@ test_timer_secondary(void)
 		int i;
 
 		mz = rte_memzone_lookup(TEST_INFO_MZ_NAME);
+		if (mz == NULL) {
+			printf("Failed to lookup memzone\n");
+			return TEST_SKIPPED;
+		}
+
 		test_info = mz->addr;
 		TEST_ASSERT_NOT_NULL(test_info, "Couldn't lookup
Quoted 2 lines

memzone for "
"test info");

Same thing here -- we can update the TEST_ASSERT_NOT_NULL call here instead, and move it above the "test_info = mz->addr" assignment.

Thanks,
Erik

Quoted 2 lines

--
2.7.4

#2 lore raw
Quoted 27 lines · Erik G
Quoted 27 lines

-----Original Message-----
From: Min Hu (Connor) <[email protected]>
Sent: Thursday, April 22, 2021 4:19 AM
To: [email protected]
Cc: Yigit, Ferruh <[email protected]>; [email protected]; Carrillo, Erik G <[email protected]>
Subject: [PATCH] test/timer: fix memzone reserve failure check

Segmentation fault may occur without checking if memzone reserves succeed or not.

This patch fixed it.

Fixes 50247fe03fe0 ("test/timer: exercise new APIs in secondary process")
---
  app/test/test_timer_secondary.c | 10 ++++++++++
  1 file changed, 10 insertions(+)
(quoted diff) +0 -0

b/app/test/test_timer_secondary.c index 1e8f1d4..281f5bd 100644

app/test/test_timer_secondary.c +0 -0
@@ -125,6 +125,11 @@ test_timer_secondary(void)
 
Quoted 15 lines
Quoted 10 lines
app/test/test_timer_secondary.c +5 -0
  		mz = rte_memzone_reserve(TEST_INFO_MZ_NAME,
 sizeof(*test_info),
  					 SOCKET_ID_ANY, 0);
+		if (mz == NULL) {
+			printf("Failed to reserve memzone\n");
+			return TEST_SKIPPED;
+		}
+
  		test_info = mz->addr;
  		TEST_ASSERT_NOT_NULL(test_info, "Couldn't allocate
Quoted 2 lines

memory for "
"test data");

I think the TEST_ASSERT_NOT_NULL check here should be the area we update -- instead of checking the test_info pointer, we should check "mz", and that will address the issue you have noted. We can then move the "test_info = mz->addr" assignment below the assert.

Agreed, fixed in v2, thanks.

Quoted 16 lines
Quoted 11 lines
app/test/test_timer_secondary.c +5 -0
@@ -171,6 +176,11 @@ test_timer_secondary(void)
  		int i;
 
  		mz = rte_memzone_lookup(TEST_INFO_MZ_NAME);
+		if (mz == NULL) {
+			printf("Failed to lookup memzone\n");
+			return TEST_SKIPPED;
+		}
+
  		test_info = mz->addr;
  		TEST_ASSERT_NOT_NULL(test_info, "Couldn't lookup
Quoted 2 lines

memzone for "
"test info");

Same thing here -- we can update the TEST_ASSERT_NOT_NULL call here instead, and move it above the "test_info = mz->addr" assignment.

Fixed in v2, thanks.

Quoted 8 lines

Thanks,
Erik

Quoted 2 lines

--
2.7.4

.

#3 lore raw

PATCH v2 1/1 test/timer: fix memzone reserve failure check

In reply to Min Hu (Connor)

Segmentation fault may occur without checking if memzone reserves succeed or not.

This patch fixed it.

Fixes 50247fe03fe0 ("test/timer: exercise new APIs in secondary process")

---
v2:
* use TEST_ASSERT_NOT_NULL check "mz" instead of checking the test_info pointer.

---
 app/test/test_timer_secondary.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)
app/test/test_timer_secondary.c +4 -4
index 1e8f1d4..16a9f18 100644
@@ -125,9 +125,9 @@ test_timer_secondary(void)
 
 		mz = rte_memzone_reserve(TEST_INFO_MZ_NAME, sizeof(*test_info),
 					 SOCKET_ID_ANY, 0);
-		test_info = mz->addr;
-		TEST_ASSERT_NOT_NULL(test_info, "Couldn't allocate memory for "
+		TEST_ASSERT_NOT_NULL(mz, "Couldn't allocate memory for "
 				     "test data");
+		test_info = mz->addr;
 
 		test_info->tim_mempool = rte_mempool_create("test_timer_mp",
 				NUM_TIMERS, sizeof(struct rte_timer), 0, 0,
@@ -171,9 +171,9 @@ test_timer_secondary(void)
 		int i;
 
 		mz = rte_memzone_lookup(TEST_INFO_MZ_NAME);
-		test_info = mz->addr;
-		TEST_ASSERT_NOT_NULL(test_info, "Couldn't lookup memzone for "
+		TEST_ASSERT_NOT_NULL(mz, "Couldn't lookup memzone for "
 				     "test info");
+		test_info = mz->addr;
 
 		for (i = 0; i < NUM_TIMERS; i++) {
 			rte_mempool_get(test_info->tim_mempool, (void **)&tim);
Signature · 1 line
2.7.4
Acked-by on v2 1/1
#4 lore raw
Quoted 16 lines

-----Original Message-----
From: Min Hu (Connor) <[email protected]>
Sent: Monday, May 3, 2021 8:08 PM
To: [email protected]
Cc: Yigit, Ferruh <[email protected]>; Carrillo, Erik G <[email protected]>; [email protected]
Subject: [PATCH v2] test/timer: fix memzone reserve failure check

Segmentation fault may occur without checking if memzone reserves succeed or not.

This patch fixed it.

Fixes 50247fe03fe0 ("test/timer: exercise new APIs in secondary process")
Quoted 6 lines

---
v2:
* use TEST_ASSERT_NOT_NULL check "mz" instead of checking the test_info pointer.
---

Thanks,

#5 lore raw
In reply to Min Hu (Connor)

04/05/2021 03:07, Min Hu (Connor):

Quoted 2 lines

Segmentation fault may occur without checking if memzone reserves succeed or not.

The sentence is confusing. Please try to make it more logical. Something like "It was potentially dereferencing a null pointer. It is fixed by checking the pointer before dereferencing."

Quoted 7 lines

This patch fixed it.

Fixes 50247fe03fe0 ("test/timer: exercise new APIs in secondary process")

[...]

app/test/test_timer_secondary.c test_timer_secondary(void) · line 129

Quoted 4 lines
app/test/test_timer_secondary.c +1 -2
-		test_info = mz->addr;
-		TEST_ASSERT_NOT_NULL(test_info, "Couldn't allocate memory for "
+		TEST_ASSERT_NOT_NULL(mz, "Couldn't allocate memory for "
 				     "test data");

Error messages should not be split. I makes search difficult. Please fix it in this patch while touching this line.

#6 lore raw
Quoted 15 lines · Thomas Monjalon

04/05/2021 03:07, Min Hu (Connor):

Quoted 2 lines

Segmentation fault may occur without checking if memzone reserves succeed or not.

The sentence is confusing. Please try to make it more logical. Something like "It was potentially dereferencing a null pointer. It is fixed by checking the pointer before dereferencing."

Quoted 7 lines

This patch fixed it.

Fixes 50247fe03fe0 ("test/timer: exercise new APIs in secondary process")
Quoted 9 lines

[...]

app/test/test_timer_secondary.c test_timer_secondary(void) · line 129

Quoted 4 lines
app/test/test_timer_secondary.c +1 -2
-		test_info = mz->addr;
-		TEST_ASSERT_NOT_NULL(test_info, "Couldn't allocate memory for "
+		TEST_ASSERT_NOT_NULL(mz, "Couldn't allocate memory for "
  				     "test data");

Error messages should not be split. I makes search difficult. Please fix it in this patch while touching this line.

Fixed in v3, thanks.

Quoted 4 lines

.

#7 lore raw

PATCH v3 1/1 test/timer: fix memzone reserve failure check

In reply to Min Hu (Connor)

Segmentation fault may occur without checking if memzone reserves succeed or not.

This patch fixed it.

Fixes 50247fe03fe0 ("test/timer: exercise new APIs in secondary process")

---
v3:
* do not split error messages.

v2:
* use TEST_ASSERT_NOT_NULL check "mz" instead of checking the test_info pointer.

---
 app/test/test_timer_secondary.c | 6 ++----
 1 file changed, 2 insertions(+), 4 deletions(-)
app/test/test_timer_secondary.c +2 -4
index 1e8f1d4..decfaef 100644
@@ -125,9 +125,8 @@ test_timer_secondary(void)
 
 		mz = rte_memzone_reserve(TEST_INFO_MZ_NAME, sizeof(*test_info),
 					 SOCKET_ID_ANY, 0);
+		TEST_ASSERT_NOT_NULL(mz, "Couldn't allocate memory for test data");
 		test_info = mz->addr;
-		TEST_ASSERT_NOT_NULL(test_info, "Couldn't allocate memory for "
-				     "test data");
 
 		test_info->tim_mempool = rte_mempool_create("test_timer_mp",
 				NUM_TIMERS, sizeof(struct rte_timer), 0, 0,
@@ -171,9 +170,8 @@ test_timer_secondary(void)
 		int i;
 
 		mz = rte_memzone_lookup(TEST_INFO_MZ_NAME);
+		TEST_ASSERT_NOT_NULL(mz, "Couldn't lookup memzone for test info");
 		test_info = mz->addr;
-		TEST_ASSERT_NOT_NULL(test_info, "Couldn't lookup memzone for "
-				     "test info");
 
 		for (i = 0; i < NUM_TIMERS; i++) {
 			rte_mempool_get(test_info->tim_mempool, (void **)&tim);
Signature · 1 line
2.7.4
Acked-by Erik Gabriel Carrillo on v3 1/1 Applied
#8 lore raw

11/05/2021 02:53, Min Hu (Connor):

Quoted 9 lines

Segmentation fault may occur without checking if memzone reserves succeed or not.

This patch fixed it.

Fixes 50247fe03fe0 ("test/timer: exercise new APIs in secondary process")

You missed reporting previous ack:

Applied, thanks

PS: please do not forget marking old patches as superseded when sending a new version.

#9 lore raw
Quoted 11 lines · Thomas Monjalon

11/05/2021 02:53, Min Hu (Connor):

Quoted 9 lines

Segmentation fault may occur without checking if memzone reserves succeed or not.

This patch fixed it.

Fixes 50247fe03fe0 ("test/timer: exercise new APIs in secondary process")
Quoted 7 lines

You missed reporting previous ack:

Applied, thanks

PS: please do not forget marking old patches as superseded when sending a new version.

Got it, thanks.

Quoted 4 lines

.