Skip to contentSkip to conversation

cxgbit: check skb dequeue result in cxgbit_send_tx_flowc_wr()

PATCH In review Denis Plotnikov 2 participants 2 messages Apr 7, 2023 – Apr 10, 2023

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

PATCH 1/1 cxgbit: check skb dequeue result in cxgbit_send_tx_flowc_wr()

Skb dequeuing may end up with returning NULL if a queue is empty, which, in turn, may end up with further null pointer dereference.

Fix it by checking the return value of skb dequeuing end returning before the pointer dereference.

Found by Linux Verification Center(linuxtesting.org) with SVACE.

Fixes 9730ffcb8957 ("cxgbit: add files for cxgbit.ko")
---
 drivers/target/iscsi/cxgbit/cxgbit_cm.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)
drivers/target/iscsi/cxgbit/cxgbit_cm.c +4 -1
index d9204c590d9ab..426a5c795fd93 100644
@@ -1424,10 +1424,13 @@ u32 cxgbit_send_tx_flowc_wr(struct cxgbit_sock *csk)
 #ifdef CONFIG_CHELSIO_T4_DCB
 	u16 vlan = ((struct l2t_entry *)csk->l2t)->vlan;
 #endif
+	skb = __skb_dequeue(&csk->skbq);
+
+	if (!skb)
+		return 0;
 
 	flowclen16 = cxgbit_tx_flowc_wr_credits(csk, &nparams, &flowclen);
 
-	skb = __skb_dequeue(&csk->skbq);
 	flowc = __skb_put_zero(skb, flowclen);
 
 	flowc->op_to_nparams = cpu_to_be32(FW_WR_OP_V(FW_FLOWC_WR) |
Signature · 1 line
2.25.1
#1 lore raw
Quoted 6 lines

Skb dequeuing may end up with returning NULL if a queue is empty, which, in turn, may end up with further null pointer dereference.

Fix it by checking the return value of skb dequeuing end returning before the pointer dereference.

skbs in csk->skbq are preallocated for critical events in cxgbit_alloc_csk_skb(), so there is no need to check for NULL.