Skip to contentSkip to conversation

igb: Check if num of q_vectors is smaller than max before array access.

Intel-wired-lan Aleksandr Loktionov 2 participants 2 messages Apr 21, 2021

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

Ensure that the adapter->q_vector[MAX_Q_VECTORS] array isn't accessed beyond its size. It was fixed by using a local variable num_q_vectors as a limit for loop index, and ensure that num_q_vectors is not bigger than MAX_Q_VECTORS.

Fixes 047e0030f1e6 ("igb: add new data structure for handling

interrupts and NAPI")

---
 drivers/net/ethernet/intel/igb/igb_main.c | 9 ++++++++-
 1 file changed, 8 insertions(+), 1 deletion(-)
drivers/net/ethernet/intel/igb/igb_main.c +8 -1
index 55051a492..2c601261f 100644
@@ -929,6 +929,7 @@ static void igb_configure_msix(struct igb_adapter *adapter)
  **/
 static int igb_request_msix(struct igb_adapter *adapter)
 {
+	unsigned int num_q_vectors = adapter->num_q_vectors;
 	struct net_device *netdev = adapter->netdev;
 	int i, err = 0, vector = 0, free_vector = 0;
 
@@ -937,7 +938,13 @@ static int igb_request_msix(struct igb_adapter *adapter)
 	if (err)
 		goto err_out;
 
-	for (i = 0; i < adapter->num_q_vectors; i++) {
+	if (num_q_vectors > MAX_Q_VECTORS) {
+		num_q_vectors = MAX_Q_VECTORS;
+		dev_warn(&adapter->pdev->dev,
+			 "The number of queue vectors (%d) is higher than max allowed (%d)\n",
+			 adapter->num_q_vectors, MAX_Q_VECTORS);
+	}
+	for (i = 0; i < num_q_vectors; i++) {
 		struct igb_q_vector *q_vector = adapter->q_vector[i];
 
 		vector++;
Signature · 1 line
2.17.1
#1 lore raw
Quoted 8 lines · Aleksandr Loktionov

Ensure that the adapter->q_vector[MAX_Q_VECTORS] array isn't accessed beyond its size. It was fixed by using a local variable num_q_vectors as a limit for loop index, and ensure that num_q_vectors is not bigger
than MAX_Q_VECTORS.

Fixes 047e0030f1e6 ("igb: add new data structure for handling

interrupts and NAPI")

As I mentioned in the last version, don't wrap the Fixes tag. It can go over 75 char.

Fixes tag: Fixes: 047e0030f1e6 ("igb: add new data structure
for handling
Has these problem(s):
- Subject has leading but no trailing parentheses
- Subject has leading but no trailing quotes

Also, please remember to indicate revisions with change log when resending. i.e. this should've been 'v2'. Can you fix the above and resend as v3?

Quoted 7 lines

---