Skip to contentSkip to conversation

qed: potential overflow in qed_cxt_src_t2_alloc()

PATCH Applied Dan Carpenter 3 participants 3 messages Jun 7, 2016 – Jun 8, 2016

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

PATCH 1/1 qed: potential overflow in qed_cxt_src_t2_alloc()

In the current code "ent_per_page" could be more than "conn_num" making "conn_num" negative after the subtraction. In the next iteration through the loop then the negative is treated as a very high positive meaning we don't put a limit on "ent_num". It could lead to memory corruption.

Fixes dbb799c39717 ('qed: Initialize hardware for new protocols')
drivers/net/ethernet/qlogic/qed/qed_cxt.c +1 -1
index d85b7ba..1c35f37 100644
@@ -850,7 +850,7 @@ static int qed_cxt_src_t2_alloc(struct qed_hwfn *p_hwfn)
 			val = 0;
 		entries[j].next = cpu_to_be64(val);
 
-		conn_num -= ent_per_page;
+		conn_num -= ent_num;
 	}
 
 	return 0;
Acked-by on v1 1/1
#1 lore raw
Quoted 7 lines

In the current code "ent_per_page" could be more than "conn_num" making "conn_num" negative after the subtraction. In the next iteration through the loop then the negative is treated as a very high positive meaning we don't put a limit on "ent_num". It could lead to memory corruption.

Fixes dbb799c39717 ('qed: Initialize hardware for new protocols')

I don't think we can actually hit an issue here, since the number of iterations was also calculated based on conn_num, so this can only happen on the last iteration.

Regardless, yours is the correct way to go. Thanks, Yuval.

maintainer Applied
#2 lore raw
In reply to Dan Carpenter

From: Dan Carpenter <[email protected]>
Date: Tue, 7 Jun 2016 15:04:16 +0300

Quoted 8 lines

In the current code "ent_per_page" could be more than "conn_num" making "conn_num" negative after the subtraction. In the next iteration through the loop then the negative is treated as a very high positive meaning we don't put a limit on "ent_num". It could lead to memory corruption.

Fixes dbb799c39717 ('qed: Initialize hardware for new protocols')

Applied, thanks.