Skip to contentSkip to conversation

igb-linux: fix array size overrun

PATCH In review Andrii Staikov 2 participants 2 messages Apr 21, 2023 – Apr 25, 2023

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

PATCH v2 1/1 igb-linux: fix array size overrun

igb_configure_msix() and igb_setup_dca() functions use the value of q_vectors number without checking if it exceeds the MAX_Q_VECTORS limit. As these functions read values from an array, there is a chance it will case an undesired and undefined behavior. Other parts of the code do this check, issue a warning and alter their logic by using the MAX_Q_VECTORS value in such case.
Fix it by introducing num_q_vectors variable inside these functions which value depends on a check.

Fixes 9d5c824399de ("igb: PCI-Express 82575 Gigabit Ethernet driver")

---
v2: Fixed the commit message

---
 drivers/net/ethernet/intel/igb/igb.h      | 2 +-
 drivers/net/ethernet/intel/igb/igb_main.c | 6 ++++--
 2 files changed, 5 insertions(+), 3 deletions(-)
drivers/net/ethernet/intel/igb/igb.h +1 -1
index 015b78144114..1eef5022f749 100644
@@ -45,7 +45,7 @@ struct igb_adapter;
 #define IGB_MAX_ITR_USECS	10000
 #define IGB_MIN_ITR_USECS	10
 #define NON_Q_VECTORS		1
-#define MAX_Q_VECTORS		8
+#define MAX_Q_VECTORS		8U
 #define MAX_MSIX_ENTRIES	10
 
 /* Transmit and receive queues */
drivers/net/ethernet/intel/igb/igb_main.c +4 -2
index 274c781b5547..0b46268cb264 100644
@@ -865,6 +865,7 @@ static void igb_configure_msix(struct igb_adapter *adapter)
 	u32 tmp;
 	int i, vector = 0;
 	struct e1000_hw *hw = &adapter->hw;
+	int num_q_vectors = min(MAX_Q_VECTORS, adapter->num_q_vectors);
 
 	adapter->eims_enable_mask = 0;
 
@@ -913,7 +914,7 @@ static void igb_configure_msix(struct igb_adapter *adapter)
 
 	adapter->eims_enable_mask |= adapter->eims_other;
 
-	for (i = 0; i < adapter->num_q_vectors; i++)
+	for (i = 0; i < num_q_vectors; i++)
 		igb_assign_vector(adapter->q_vector[i], vector++);
 
 	wrfl();
@@ -7149,6 +7150,7 @@ static void igb_setup_dca(struct igb_adapter *adapter)
 {
 	struct e1000_hw *hw = &adapter->hw;
 	int i;
+	int num_q_vectors = min(MAX_Q_VECTORS, adapter->num_q_vectors);
 
 	if (!(adapter->flags & IGB_FLAG_DCA_ENABLED))
 		return;
@@ -7156,7 +7158,7 @@ static void igb_setup_dca(struct igb_adapter *adapter)
 	/* Always use CB2 mode, difference is masked in the CB driver. */
 	wr32(E1000_DCA_CTRL, E1000_DCA_CTRL_DCA_MODE_CB2);
 
-	for (i = 0; i < adapter->num_q_vectors; i++) {
+	for (i = 0; i < num_q_vectors; i++) {
 		adapter->q_vector[i]->cpu = -1;
 		igb_update_dca(adapter->q_vector[i]);
 	}
Signature · 6 lines
2.25.1

_______________________________________________
Intel-wired-lan mailing list
[email protected]
https://lists.osuosl.org/mailman/listinfo/intel-wired-lan
maintainer
#1 lore raw

s/igb-linux/igb

Quoted 36 lines · Andrii Staikov

igb_configure_msix() and igb_setup_dca() functions use the value of q_vectors number without checking if it exceeds the MAX_Q_VECTORS limit. As these functions read values from an array, there is a chance it will case an undesired and undefined behavior. Other parts of the code do this check, issue a warning and alter their logic by using the MAX_Q_VECTORS value in such case.
Fix it by introducing num_q_vectors variable inside these functions which value depends on a check.

Fixes 9d5c824399de ("igb: PCI-Express 82575 Gigabit Ethernet driver")

---
v2: Fixed the commit message

---
  drivers/net/ethernet/intel/igb/igb.h      | 2 +-
  drivers/net/ethernet/intel/igb/igb_main.c | 6 ++++--
  2 files changed, 5 insertions(+), 3 deletions(-)
drivers/net/ethernet/intel/igb/igb.h +1 -1
index 015b78144114..1eef5022f749 100644
@@ -45,7 +45,7 @@ struct igb_adapter;
  #define IGB_MAX_ITR_USECS	10000
  #define IGB_MIN_ITR_USECS	10
  #define NON_Q_VECTORS		1
-#define MAX_Q_VECTORS		8
+#define MAX_Q_VECTORS		8U
  #define MAX_MSIX_ENTRIES	10
 
  /* Transmit and receive queues */
drivers/net/ethernet/intel/igb/igb_main.c +0 -0
index 274c781b5547..0b46268cb264 100644

drivers/net/ethernet/intel/igb/igb_main.c static void igb_configure_msix(struct igb_adapter *adapter) · line 868

Quoted 4 lines
drivers/net/ethernet/intel/igb/igb_main.c +1 -0
@@ -865,6 +865,7 @@ static void igb_configure_msix(struct igb_adapter *adapter)
  	u32 tmp;
  	int i, vector = 0;
  	struct e1000_hw *hw = &adapter->hw;
+	int num_q_vectors = min(MAX_Q_VECTORS, adapter->num_q_vectors);

RCT please

Quoted 12 lines
drivers/net/ethernet/intel/igb/igb_main.c +1 -1
  	adapter->eims_enable_mask = 0;
 
@@ -913,7 +914,7 @@ static void igb_configure_msix(struct igb_adapter *adapter)
 
  	adapter->eims_enable_mask |= adapter->eims_other;
 
-	for (i = 0; i < adapter->num_q_vectors; i++)
+	for (i = 0; i < num_q_vectors; i++)
  		igb_assign_vector(adapter->q_vector[i], vector++);
 
  	wrfl();

drivers/net/ethernet/intel/igb/igb_main.c static void igb_setup_dca(struct igb_adapter *adapter) · line 7153

Quoted 4 lines
drivers/net/ethernet/intel/igb/igb_main.c +1 -0
@@ -7149,6 +7150,7 @@ static void igb_setup_dca(struct igb_adapter *adapter)
  {
  	struct e1000_hw *hw = &adapter->hw;
  	int i;
+	int num_q_vectors = min(MAX_Q_VECTORS, adapter->num_q_vectors);

Here as well

drivers/net/ethernet/intel/igb/igb_main.c static void igb_setup_dca(struct igb_adapter *adapter) · line 7164

Quoted 11 lines
drivers/net/ethernet/intel/igb/igb_main.c +1 -1
  	if (!(adapter->flags & IGB_FLAG_DCA_ENABLED))
  		return;
@@ -7156,7 +7158,7 @@ static void igb_setup_dca(struct igb_adapter *adapter)
  	/* Always use CB2 mode, difference is masked in the CB driver. */
  	wr32(E1000_DCA_CTRL, E1000_DCA_CTRL_DCA_MODE_CB2);
 
-	for (i = 0; i < adapter->num_q_vectors; i++) {
+	for (i = 0; i < num_q_vectors; i++) {
  		adapter->q_vector[i]->cpu = -1;
  		igb_update_dca(adapter->q_vector[i]);
  	}

_______________________________________________
Intel-wired-lan mailing list
[email protected]
https://lists.osuosl.org/mailman/listinfo/intel-wired-lan