Skip to contentSkip to conversation

cxgb4i: a couple invalid dereference bugs

PATCH New Dan Carpenter 1 participant 1 message Feb 27, 2013

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

PATCH 1/1 cxgb4i: a couple invalid dereference bugs

"tid" and "opc" come from skb->data so Smatch complains that the bounds checking is inadequate. If "tid" is out of bounds it would lead to a NULL dereference when debugging is enabled. If "opc" is invalid we would dereference a bogus function pointer.

drivers/scsi/cxgbi/cxgb4i/cxgb4i.c +5 -2
index 3fecf35..4facd10 100644
@@ -1047,8 +1047,11 @@ static void do_set_tcb_rpl(struct cxgbi_device *cdev, struct sk_buff *skb)
 	struct cxgbi_sock *csk;
 
 	csk = lookup_tid(t, tid);
-	if (!csk)
+	if (!csk) {
 		pr_err("can't find conn. for tid %u.\n", tid);
+		__kfree_skb(skb);
+		return;
+	}
 
 	log_debug(1 << CXGBI_DBG_TOE | 1 << CXGBI_DBG_SOCK,
 		"csk 0x%p,%u,%lx,%u, status 0x%x.\n",
@@ -1534,7 +1537,7 @@ static int t4_uld_rx_handler(void *handle, const __be64 *rsp,
 	log_debug(1 << CXGBI_DBG_TOE,
 		"cdev %p, opcode 0x%x(0x%x,0x%x), skb %p.\n",
 		 cdev, opc, rpl->ot.opcode_tid, ntohl(rpl->ot.opcode_tid), skb);
-	if (cxgb4i_cplhandlers[opc])
+	if (opc < ARRAY_SIZE(cxgb4i_cplhandlers) && cxgb4i_cplhandlers[opc])
 		cxgb4i_cplhandlers[opc](cdev, skb);
 	else {
 		pr_err("No handler for opcode 0x%x.\n", opc);