Skip to contentSkip to conversation

bnx2x: off by one in bnx2x_ets_e3b0_sp_pri_to_cos_set()

PATCH Applied Dan Carpenter 3 participants 3 messages Apr 18, 2012 – Apr 19, 2012

Subsystems (4)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 bnx2x: off by one in bnx2x_ets_e3b0_sp_pri_to_cos_set()

The sp_pri_to_cos[] array size depends on the config but lets say it is BX_E3B0_MAX_NUM_COS_PORT0 and max_num_of_cos is also DCBX_E3B0_MAX_NUM_COS_PORT0. In the original code
"pri = max_num_of_cos" was accepted but it is one past the end of the array.

Also we used "pri" before capping it. It's a harmless read past the end of the array, but it would affect which error message gets printed.

drivers/net/ethernet/broadcom/bnx2x/bnx2x_link.c +6 -6
index ff882a4..6b21b21 100644
@@ -922,6 +922,12 @@ static int bnx2x_ets_e3b0_sp_pri_to_cos_set(const struct link_params *params,
 	const u8 max_num_of_cos = (port) ? DCBX_E3B0_MAX_NUM_COS_PORT1 :
 		DCBX_E3B0_MAX_NUM_COS_PORT0;
 
+	if (pri >= max_num_of_cos) {
+		DP(NETIF_MSG_LINK, "bnx2x_ets_e3b0_sp_pri_to_cos_set invalid "
+		   "parameter Illegal strict priority\n");
+	    return -EINVAL;
+	}
+
 	if (sp_pri_to_cos[pri] != DCBX_INVALID_COS) {
 		DP(NETIF_MSG_LINK, "bnx2x_ets_e3b0_sp_pri_to_cos_set invalid "
 				   "parameter There can't be two COS's with "
@@ -929,12 +935,6 @@ static int bnx2x_ets_e3b0_sp_pri_to_cos_set(const struct link_params *params,
 		return -EINVAL;
 	}
 
-	if (pri > max_num_of_cos) {
-		DP(NETIF_MSG_LINK, "bnx2x_ets_e3b0_sp_pri_to_cos_set invalid "
-		   "parameter Illegal strict priority\n");
-	    return -EINVAL;
-	}
-
 	sp_pri_to_cos[pri] = cos_entry;
 	return 0;
 
Acked-by on v1 1/1
#1 lore raw
Quoted 11 lines · Dan Carpenter

The sp_pri_to_cos[] array size depends on the config but lets say it is BX_E3B0_MAX_NUM_COS_PORT0 and max_num_of_cos is also DCBX_E3B0_MAX_NUM_COS_PORT0. In the original code
"pri = max_num_of_cos" was accepted but it is one past the end of the array.

Also we used "pri" before capping it. It's a harmless read past the end of the array, but it would affect which error message gets printed.

Thanks Dan - this is obviously better.

maintainer Applied
#2 lore raw

From: "Eilon Greenstein" <[email protected]>
Date: Wed, 18 Apr 2012 12:27:07 +0300

Quoted 7 lines · Dan Carpenter
Quoted 6 lines

The sp_pri_to_cos[] array size depends on the config but lets say it is BX_E3B0_MAX_NUM_COS_PORT0 and max_num_of_cos is also DCBX_E3B0_MAX_NUM_COS_PORT0. In the original code
"pri = max_num_of_cos" was accepted but it is one past the end of the array.

Quoted 7 lines
Quoted 5 lines

Also we used "pri" before capping it. It's a harmless read past the end of the array, but it would affect which error message gets printed.

Applied, thanks everyone.