Skip to contentSkip to conversation

bonding: fix overflow check

PATCH Superseded Min Hu (Connor) 2 participants 7 messages Apr 22, 2021 – Apr 30, 2021

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 bonding: fix overflow check

Buffer 'test_params->slave_port_ids' of size 6 accessed may overflow, since its index 'i' can have value be is out of range.

This patch fixed it.

Fixes 92073ef961ee ("bond: unit tests")
---
 app/test/test_link_bonding.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
app/test/test_link_bonding.c +2 -1
index 8a5c831..b5a6042 100644
@@ -2216,7 +2216,8 @@ test_activebackup_rx_burst(void)
 			"failed to get primary slave for bonded port (%d)",
 			test_params->bonded_port_id);
 
-	for (i = 0; i < test_params->bonded_slave_count; i++) {
+	for (i = 0; i < test_params->bonded_slave_count &&
+		i < TEST_MAX_NUMBER_OF_PORTS; i++) {
 		/* Generate test bursts of packets to transmit */
 		TEST_ASSERT_EQUAL(generate_test_burst(
 				&gen_pkt_burst[0], burst_size, 0, 1, 0, 0, 0),
Signature · 1 line
2.7.4
#1 lore raw
Quoted 19 lines · Min Hu (Connor)

Buffer 'test_params->slave_port_ids' of size 6 accessed may overflow, since its index 'i' can have value be is out of range.

This patch fixed it.

Fixes 92073ef961ee ("bond: unit tests")
---
 app/test/test_link_bonding.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
app/test/test_link_bonding.c +0 -0
index 8a5c831..b5a6042 100644

app/test/test_link_bonding.c test_activebackup_rx_burst(void) · line 2223

Quoted 9 lines
app/test/test_link_bonding.c +2 -1
@@ -2216,7 +2216,8 @@ test_activebackup_rx_burst(void)
 			"failed to get primary slave for bonded port (%d)",
 			test_params->bonded_port_id);
 
-	for (i = 0; i < test_params->bonded_slave_count; i++) {
+	for (i = 0; i < test_params->bonded_slave_count &&
+		i < TEST_MAX_NUMBER_OF_PORTS; i++) {
 		/* Generate test bursts of packets to transmit */
 		TEST_ASSERT_EQUAL(generate_test_burst(
 				&gen_pkt_burst[0], burst_size, 0, 1, 0, 0, 0),

Hi Connor,

There is nothing wrong with the check you add, but at first place how 'test_params->bonded_slave_count' can become bigger than 'TEST_MAX_NUMBER_OF_PORTS'? Should we fix there, instead of this loop?

Also in same function, there are a few more loops iterate until " < test_params->bonded_slave_count", so fixing the root case works for them too.

#3 lore raw

PATCH v2 1/1 bonding: fix overflow check

In reply to Min Hu (Connor)

Buffer 'test_params->slave_port_ids' of size 6 accessed may overflow, since its index 'i' can have value be is out of range.

This patch fixed it.

Fixes 92073ef961ee ("bond: unit tests")

---
v2:
* fix bonded_slave_count value.

---
 app/test/test_link_bonding.c | 3 +++
 1 file changed, 3 insertions(+)
app/test/test_link_bonding.c +3 -0
index 8a5c831..f8abb22 100644
@@ -2216,6 +2216,9 @@ test_activebackup_rx_burst(void)
 			"failed to get primary slave for bonded port (%d)",
 			test_params->bonded_port_id);
 
+	if (test_params->bonded_slave_count > TEST_MAX_NUMBER_OF_PORTS)
+		test_params->bonded_slave_count = TEST_MAX_NUMBER_OF_PORTS;
+
 	for (i = 0; i < test_params->bonded_slave_count; i++) {
 		/* Generate test bursts of packets to transmit */
 		TEST_ASSERT_EQUAL(generate_test_burst(
Signature · 1 line
2.7.4
#2 lore raw
In reply to Ferruh Yigit
Quoted 32 lines · Ferruh Yigit
Quoted 19 lines · Min Hu (Connor)

Buffer 'test_params->slave_port_ids' of size 6 accessed may overflow, since its index 'i' can have value be is out of range.

This patch fixed it.

Fixes 92073ef961ee ("bond: unit tests")
---
  app/test/test_link_bonding.c | 3 ++-
  1 file changed, 2 insertions(+), 1 deletion(-)
app/test/test_link_bonding.c +0 -0
index 8a5c831..b5a6042 100644

app/test/test_link_bonding.c test_activebackup_rx_burst(void) · line 2223

Quoted 9 lines
app/test/test_link_bonding.c +2 -1
@@ -2216,7 +2216,8 @@ test_activebackup_rx_burst(void)
  			"failed to get primary slave for bonded port (%d)",
  			test_params->bonded_port_id);
 
-	for (i = 0; i < test_params->bonded_slave_count; i++) {
+	for (i = 0; i < test_params->bonded_slave_count &&
+		i < TEST_MAX_NUMBER_OF_PORTS; i++) {
  		/* Generate test bursts of packets to transmit */
  		TEST_ASSERT_EQUAL(generate_test_burst(
  				&gen_pkt_burst[0], burst_size, 0, 1, 0, 0, 0),

Hi Connor,

Quoted 7 lines

There is nothing wrong with the check you add, but at first place how 'test_params->bonded_slave_count' can become bigger than 'TEST_MAX_NUMBER_OF_PORTS'? Should we fix there, instead of this loop?

Also in same function, there are a few more loops iterate until " < test_params->bonded_slave_count", so fixing the root case works for them too.

Hi, fixed in v2, thanks.

Quoted 1 line
#4 lore raw
In reply to Min Hu (Connor)
Quoted 21 lines · Min Hu (Connor)

Buffer 'test_params->slave_port_ids' of size 6 accessed may overflow, since its index 'i' can have value be is out of range.

This patch fixed it.

Fixes 92073ef961ee ("bond: unit tests")

---
v2:
* fix bonded_slave_count value.

---
 app/test/test_link_bonding.c | 3 +++
 1 file changed, 3 insertions(+)
app/test/test_link_bonding.c +0 -0
index 8a5c831..f8abb22 100644

app/test/test_link_bonding.c test_activebackup_rx_burst(void) · line 2221

Quoted 6 lines
app/test/test_link_bonding.c +3 -0
@@ -2216,6 +2216,9 @@ test_activebackup_rx_burst(void)
 			"failed to get primary slave for bonded port (%d)",
 			test_params->bonded_port_id);
 
+	if (test_params->bonded_slave_count > TEST_MAX_NUMBER_OF_PORTS)
+		test_params->bonded_slave_count = TEST_MAX_NUMBER_OF_PORTS;
+

Hi Connor,

Similar comment as previous version, what is the root cause, how 'bonded_slave_count' end up being bigger than 'TEST_MAX_NUMBER_OF_PORTS'?

Quoted 4 lines
app/test/test_link_bonding.c +0 -0
 	for (i = 0; i < test_params->bonded_slave_count; i++) {
 		/* Generate test bursts of packets to transmit */
 		TEST_ASSERT_EQUAL(generate_test_burst(
#5 lore raw
Quoted 25 lines · Ferruh Yigit
Quoted 24 lines · Min Hu (Connor)

Buffer 'test_params->slave_port_ids' of size 6 accessed may overflow, since its index 'i' can have value be is out of range.

This patch fixed it.

Fixes 92073ef961ee ("bond: unit tests")

---
v2:
* fix bonded_slave_count value.

---
  app/test/test_link_bonding.c | 3 +++
  1 file changed, 3 insertions(+)
app/test/test_link_bonding.c +0 -0
index 8a5c831..f8abb22 100644
@@ -2216,6 +2216,9 @@ test_activebackup_rx_burst(void)
  			"failed to get primary slave for bonded port (%d)",
  			test_params->bonded_port_id);
 
Quoted 9 lines

app/test/test_link_bonding.c test_activebackup_rx_burst(void) · line 2221

Quoted 3 lines
app/test/test_link_bonding.c +3 -0
+	if (test_params->bonded_slave_count > TEST_MAX_NUMBER_OF_PORTS)
+		test_params->bonded_slave_count = TEST_MAX_NUMBER_OF_PORTS;
+

Hi Connor,

Similar comment as previous version, what is the root cause, how 'bonded_slave_count' end up being bigger than 'TEST_MAX_NUMBER_OF_PORTS'?

Hi Ferruh,
Currently, it will not happen.
But if the testcase extended, for instance,
"test_add_slave_to_bonded_device" is called over
TEST_MAX_NUMBER_OF_PORTS(6) times in
"test_add_already_bonded_slave_to_bonded_device",
then 'bonded_slave_count' will be bigger than
'TEST_MAX_NUMBER_OF_PORTS'.

Quoted 7 lines

app/test/test_link_bonding.c test_activebackup_rx_burst(void) · line 2224

Quoted 4 lines
app/test/test_link_bonding.c +0 -0
  	for (i = 0; i < test_params->bonded_slave_count; i++) {
  		/* Generate test bursts of packets to transmit */
  		TEST_ASSERT_EQUAL(generate_test_burst(

.

#6 lore raw
Quoted 36 lines · Min Hu (Connor)
Quoted 30 lines · Ferruh Yigit
Quoted 21 lines · Min Hu (Connor)

Buffer 'test_params->slave_port_ids' of size 6 accessed may overflow, since its index 'i' can have value be is out of range.

This patch fixed it.

Fixes 92073ef961ee ("bond: unit tests")

---
v2:
* fix bonded_slave_count value.
---
  app/test/test_link_bonding.c | 3 +++

  1 file changed, 3 insertions(+)
app/test/test_link_bonding.c +0 -0
index 8a5c831..f8abb22 100644

app/test/test_link_bonding.c test_activebackup_rx_burst(void) · line 2220

Quoted 5 lines
app/test/test_link_bonding.c +2 -0
@@ -2216,6 +2216,9 @@ test_activebackup_rx_burst(void)
               "failed to get primary slave for bonded port (%d)",
               test_params->bonded_port_id);
   +    if (test_params->bonded_slave_count > TEST_MAX_NUMBER_OF_PORTS)
+        test_params->bonded_slave_count = TEST_MAX_NUMBER_OF_PORTS;
+

Hi Connor,

Quoted 3 lines

Similar comment as previous version, what is the root cause, how 'bonded_slave_count' end up being bigger than 'TEST_MAX_NUMBER_OF_PORTS'?

Quoted 9 lines

Hi Ferruh,
Currently, it will not happen.
But if the testcase extended, for instance,
"test_add_slave_to_bonded_device" is called over
TEST_MAX_NUMBER_OF_PORTS(6) times in
"test_add_already_bonded_slave_to_bonded_device",
then 'bonded_slave_count' will be bigger than
'TEST_MAX_NUMBER_OF_PORTS'.

What do you think adding 'test_params->bonded_slave_count' check at the beginning of the 'test_add_slave_to_bonded_device()' and fail test case if it is bigger than 'TEST_MAX_NUMBER_OF_PORTS'?

Quoted 7 lines
Quoted 7 lines
Quoted 4 lines
app/test/test_link_bonding.c +0 -0
       for (i = 0; i < test_params->bonded_slave_count; i++) {
           /* Generate test bursts of packets to transmit */

          TEST_ASSERT_EQUAL(generate_test_burst(

.