Skip to contentSkip to conversation

scsi: target: cxgbit: check skb dequeue result

PATCH In review Denis Plotnikov 3 participants 5 messages Apr 6, 2023 – Apr 10, 2023

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

PATCH 1/1 scsi: target: cxgbit: check skb dequeue result

On a couple of abort packet paths skb dequeuing may end up with returning NULL, which, in turn, may end up with further null pointer dereference.

Fix it by checking the return value of skb dequeuing.

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

Fixes 9730ffcb8957 (cxgbit: add files for cxgbit.ko)
---
 drivers/target/iscsi/cxgbit/cxgbit_cm.c | 10 +++++++---
 1 file changed, 7 insertions(+), 3 deletions(-)
drivers/target/iscsi/cxgbit/cxgbit_cm.c +7 -3
index 518ded214e74..d43fd761c20a 100644
@@ -669,6 +669,9 @@ static int cxgbit_send_abort_req(struct cxgbit_sock *csk)
 		cxgbit_send_tx_flowc_wr(csk);
 
 	skb = __skb_dequeue(&csk->skbq);
+	if (!skb)
+		return 0;
+
 	cxgb_mk_abort_req(skb, len, csk->tid, csk->txq_idx,
 			  csk->com.cdev, cxgbit_abort_arp_failure);
 
@@ -1769,9 +1772,10 @@ static void cxgbit_abort_req_rss(struct cxgbit_sock *csk, struct sk_buff *skb)
 		cxgbit_send_tx_flowc_wr(csk);
 
 	rpl_skb = __skb_dequeue(&csk->skbq);
-
-	cxgb_mk_abort_rpl(rpl_skb, len, csk->tid, csk->txq_idx);
-	cxgbit_ofld_send(csk->com.cdev, rpl_skb);
+	if (!rpl_skb) {
+		cxgb_mk_abort_rpl(rpl_skb, len, csk->tid, csk->txq_idx);
+		cxgbit_ofld_send(csk->com.cdev, rpl_skb);
+	}
 
 	if (wakeup_thread) {
 		cxgbit_queue_rx_skb(csk, skb);
Signature · 1 line
2.25.1
#1 lore raw
Quoted 29 lines · Denis Plotnikov

On a couple of abort packet paths skb dequeuing may end up with returning NULL, which, in turn, may end up with further null pointer dereference.

Fix it by checking the return value of skb dequeuing.

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

Fixes 9730ffcb8957 (cxgbit: add files for cxgbit.ko)
---
  drivers/target/iscsi/cxgbit/cxgbit_cm.c | 10 +++++++---
  1 file changed, 7 insertions(+), 3 deletions(-)
drivers/target/iscsi/cxgbit/cxgbit_cm.c +3 -0
index 518ded214e74..d43fd761c20a 100644
@@ -669,6 +669,9 @@ static int cxgbit_send_abort_req(struct cxgbit_sock *csk)
  		cxgbit_send_tx_flowc_wr(csk);
 
  	skb = __skb_dequeue(&csk->skbq);
+	if (!skb)
+		return 0;
+
  	cxgb_mk_abort_req(skb, len, csk->tid, csk->txq_idx,
  			  csk->com.cdev, cxgbit_abort_arp_failure);
 

drivers/target/iscsi/cxgbit/cxgbit_cm.c static void cxgbit_abort_req_rss(struct cxgbit_sock *csk, struct sk_buff *skb) · line 1775

Quoted 7 lines
drivers/target/iscsi/cxgbit/cxgbit_cm.c +1 -3
@@ -1769,9 +1772,10 @@ static void cxgbit_abort_req_rss(struct cxgbit_sock *csk, struct sk_buff *skb)
  		cxgbit_send_tx_flowc_wr(csk);
 
  	rpl_skb = __skb_dequeue(&csk->skbq);
-
-	cxgb_mk_abort_rpl(rpl_skb, len, csk->tid, csk->txq_idx);
-	cxgbit_ofld_send(csk->com.cdev, rpl_skb);
+	if (!rpl_skb) {

Honestly I have no clue about cxgbit, but to avoid null pointer dereference, shouldn't it be "if (rpl_skb) {"?

Bodo

Quoted 6 lines
drivers/target/iscsi/cxgbit/cxgbit_cm.c +3 -0
+		cxgb_mk_abort_rpl(rpl_skb, len, csk->tid, csk->txq_idx);
+		cxgbit_ofld_send(csk->com.cdev, rpl_skb);
+	}
 
  	if (wakeup_thread) {
  		cxgbit_queue_rx_skb(csk, skb);
#2 lore raw
Quoted 30 lines · Bodo Stroesser
Quoted 29 lines · Denis Plotnikov

On a couple of abort packet paths skb dequeuing may end up with returning NULL, which, in turn, may end up with further null pointer dereference.

Fix it by checking the return value of skb dequeuing.

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

Fixes 9730ffcb8957 (cxgbit: add files for cxgbit.ko)

---
  drivers/target/iscsi/cxgbit/cxgbit_cm.c | 10 +++++++---

  1 file changed, 7 insertions(+), 3 deletions(-)
drivers/target/iscsi/cxgbit/cxgbit_cm.c +3 -0
index 518ded214e74..d43fd761c20a 100644
@@ -669,6 +669,9 @@ static int cxgbit_send_abort_req(struct 
 cxgbit_sock *csk)
           cxgbit_send_tx_flowc_wr(csk);
         skb = __skb_dequeue(&csk->skbq);
+    if (!skb)
+        return 0;
+
       cxgb_mk_abort_req(skb, len, csk->tid, csk->txq_idx,
                 csk->com.cdev, cxgbit_abort_arp_failure);
   @@ -1769,9 +1772,10 @@ static void cxgbit_abort_req_rss(struct cxgbit_sock *csk, struct sk_buff *skb)

          cxgbit_send_tx_flowc_wr(csk);

Quoted 8 lines
Quoted 5 lines

        rpl_skb = __skb_dequeue(&csk->skbq);
-
-    cxgb_mk_abort_rpl(rpl_skb, len, csk->tid, csk->txq_idx); -    cxgbit_ofld_send(csk->com.cdev, rpl_skb);
+    if (!rpl_skb) {

Honestly I have no clue about cxgbit, but to avoid null pointer dereference, shouldn't it be "if (rpl_skb) {"?

Yes it should. Thanks for finding that. I'll resend the patch.

Frankly, I have no clue about cxgbit as well, so may be there is a better way to cope with the null pointer issue here.

Denis

Quoted 9 lines

Bodo

Quoted 5 lines

+        cxgb_mk_abort_rpl(rpl_skb, len, csk->tid, csk->txq_idx); +        cxgbit_ofld_send(csk->com.cdev, rpl_skb);
+    }
        if (wakeup_thread) {
          cxgbit_queue_rx_skb(csk, skb);

#3 lore raw
In reply to Denis Plotnikov
Quoted 6 lines

On a couple of abort packet paths skb dequeuing may end up with returning NULL, which, in turn, may end up with further null pointer dereference.

Fix it by checking the return value of skb dequeuing.

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

#4 lore raw
Quoted 7 lines · Varun Prakash
Quoted 5 lines

On a couple of abort packet paths skb dequeuing may end up with returning NULL, which, in turn, may end up with further null pointer dereference.

Fix it by checking the return value of skb dequeuing.

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

Ok, thanks for the reply