Skip to contentSkip to conversation

net/ionic: avoid OOB TX partner lookup for hwstamp RXQ

PATCH Applied Anand Khoje 5 participants 5 messages Aug 13 – Aug 18

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

PATCH v3 1/1 net/ionic: avoid OOB TX partner lookup for hwstamp RXQ

The dedicated hardware timestamp RX queue is allocated with q->index equal to lif->ionic->nrxqs_per_lif. The normal txqcqs array only contains the regular queue pairs, so using that index to set rxq->partner can read one entry past txqcqs[] and then write through the derived pointer.
Only link RX/TX partners for normal queue-pair indexes. Leave the hwstamp RX queue unpaired, and make the XDP_TX path abort cleanly if an RX queue has no TX partner.

Fixes 8eeed8373e1c ("ionic: Add XDP_TX support")

---
v3:
Use dev_err() and return -ENXIO for a missing normal TX partner.

v2:
Correct the Fixes tag.

 drivers/net/ethernet/pensando/ionic/ionic_lif.c | 17 +++++++++++++++--
 .../net/ethernet/pensando/ionic/ionic_txrx.c    |  7 ++++++-
 2 files changed, 21 insertions(+), 3 deletions(-)
drivers/net/ethernet/pensando/ionic/ionic_lif.c +15 -2
index fd3ee98..abc8e35 100644
@@ -920,8 +920,21 @@ static int ionic_lif_rxq_init(struct ionic_lif *lif, struct ionic_qcq *qcq)
 	};
 	int err;
 
-	q->partner = &lif->txqcqs[q->index]->q;
-	q->partner->partner = q;
+	q->partner = NULL;
+
+	/* Only normal RX queues have matching TX queue partners. */
+	if (q->index < lif->nxqs) {
+		if (!lif->txqcqs ||
+		    q->index >= lif->ionic->ntxqs_per_lif ||
+		    !lif->txqcqs[q->index]) {
+			dev_err(dev, "missing TX queue partner for RX queue %u\n",
+				q->index);
+			return -ENXIO;
+		}
+
+		q->partner = &lif->txqcqs[q->index]->q;
+		q->partner->partner = q;
+	}
 
 	if (!lif->xdp_prog ||
 	    (lif->xdp_prog->aux && lif->xdp_prog->aux->xdp_has_frags))
drivers/net/ethernet/pensando/ionic/ionic_txrx.c +6 -1
index 301ebee..73998d6 100644
@@ -545,13 +545,18 @@ static bool ionic_run_xdp(struct ionic_rx_stats *stats,
 		break;
 
 	case XDP_TX:
+		txq = rxq->partner;
+		if (unlikely(!txq)) {
+			err = -EIO;
+			break;
+		}
+
 		xdpf = xdp_convert_buff_to_frame(&xdp_buf);
 		if (!xdpf) {
 			err = -ENOSPC;
 			break;
 		}
 
-		txq = rxq->partner;
 		nq = netdev_get_tx_queue(netdev, txq->index);
 		__netif_tx_lock(nq, smp_processor_id());
 		txq_trans_cond_update(nq);
Signature · 1 line
2.52.0
reviewer Reviewed-by on v3 1/1
#1 lore raw
Quoted 14 lines · Anand Khoje

The dedicated hardware timestamp RX queue is allocated with q->index equal to lif->ionic->nrxqs_per_lif. The normal txqcqs array only contains the regular queue pairs, so using that index to set rxq->partner can read one entry past txqcqs[] and then write through the derived pointer.
Only link RX/TX partners for normal queue-pair indexes. Leave the hwstamp RX queue unpaired, and make the XDP_TX path abort cleanly if an RX queue has no TX partner.

Fixes 8eeed8373e1c ("ionic: Add XDP_TX support")
Quoted 6 lines

---
v3:
Use dev_err() and return -ENXIO for a missing normal TX partner.

v2:
Correct the Fixes tag.

Reviewed-by Brett Creeley on v3 1/1
#2 lore raw
In reply to Anand Khoje
Quoted 70 lines · Anand Khoje

Caution: This message originated from an External Source. Use proper caution when opening attachments, clicking links, or responding.

The dedicated hardware timestamp RX queue is allocated with q->index equal to lif->ionic->nrxqs_per_lif. The normal txqcqs array only contains the regular queue pairs, so using that index to set rxq->partner can read one entry past txqcqs[] and then write through the derived pointer.
Only link RX/TX partners for normal queue-pair indexes. Leave the hwstamp RX queue unpaired, and make the XDP_TX path abort cleanly if an RX queue has no TX partner.

Fixes 8eeed8373e1c ("ionic: Add XDP_TX support")

---
v3:
Use dev_err() and return -ENXIO for a missing normal TX partner.

v2:
Correct the Fixes tag.

  drivers/net/ethernet/pensando/ionic/ionic_lif.c | 17 +++++++++++++++--
  .../net/ethernet/pensando/ionic/ionic_txrx.c    |  7 ++++++-
  2 files changed, 21 insertions(+), 3 deletions(-)
drivers/net/ethernet/pensando/ionic/ionic_lif.c +15 -2
index fd3ee98..abc8e35 100644
@@ -920,8 +920,21 @@ static int ionic_lif_rxq_init(struct ionic_lif *lif, struct ionic_qcq *qcq)
         };
         int err;
 
-       q->partner = &lif->txqcqs[q->index]->q;
-       q->partner->partner = q;
+       q->partner = NULL;
+
+       /* Only normal RX queues have matching TX queue partners. */
+       if (q->index < lif->nxqs) {
+               if (!lif->txqcqs ||
+                   q->index >= lif->ionic->ntxqs_per_lif ||
+                   !lif->txqcqs[q->index]) {
+                       dev_err(dev, "missing TX queue partner for RX queue %u\n",
+                               q->index);
+                       return -ENXIO;
+               }
+
+               q->partner = &lif->txqcqs[q->index]->q;
+               q->partner->partner = q;
+       }
 
         if (!lif->xdp_prog ||
             (lif->xdp_prog->aux && lif->xdp_prog->aux->xdp_has_frags))
drivers/net/ethernet/pensando/ionic/ionic_txrx.c +6 -0
index 301ebee..73998d6 100644
@@ -545,13 +545,18 @@ static bool ionic_run_xdp(struct ionic_rx_stats *stats,
                 break;
 
         case XDP_TX:
+               txq = rxq->partner;
+               if (unlikely(!txq)) {
+                       err = -EIO;
+                       break;
+               }
+

drivers/net/ethernet/pensando/ionic/ionic_txrx.c static bool ionic_run_xdp(struct ionic_rx_stats *stats, · line 562

Quoted 10 lines
drivers/net/ethernet/pensando/ionic/ionic_txrx.c +0 -1
                 xdpf = xdp_convert_buff_to_frame(&xdp_buf);
                 if (!xdpf) {
                         err = -ENOSPC;
                         break;
                 }
 
-               txq = rxq->partner;
                 nq = netdev_get_tx_queue(netdev, txq->index);
                 __netif_tx_lock(nq, smp_processor_id());
                 txq_trans_cond_update(nq);

LGTM. Thanks for the fix.

Quoted 2 lines

--
2.52.0

maintainer
#3 lore raw
In reply to Anand Khoje
Quoted 9 lines · Anand Khoje

The dedicated hardware timestamp RX queue is allocated with q->index equal to lif->ionic->nrxqs_per_lif. The normal txqcqs array only contains the regular queue pairs, so using that index to set rxq->partner can read one entry past txqcqs[] and then write through the derived pointer.
Only link RX/TX partners for normal queue-pair indexes. Leave the hwstamp RX queue unpaired, and make the XDP_TX path abort cleanly if an RX queue has no TX partner.

Quoted 5 lines
Fixes 8eeed8373e1c ("ionic: Add XDP_TX support")

This is net material, you should have set accordingly the target tree into the subj prefix. Also your SoB should come last.

No need to resend just for this, but keep in mind for future submissions.

/P

#4 lore raw
In reply to Anand Khoje
This patch was applied to netdev/net-next.git (main) by Paolo Abeni <[email protected]>:

Hello:

This patch was applied to netdev/net-next.git (main) by Paolo Abeni <[email protected]>:

Quoted 10 lines · On Thu, 13 Aug 2026 08:37:05 +0000 you wrote:

The dedicated hardware timestamp RX queue is allocated with q->index equal to lif->ionic->nrxqs_per_lif. The normal txqcqs array only contains the regular queue pairs, so using that index to set rxq->partner can read one entry past txqcqs[] and then write through the derived pointer.
Only link RX/TX partners for normal queue-pair indexes. Leave the hwstamp RX queue unpaired, and make the XDP_TX path abort cleanly if an RX queue has no TX partner.

[...]

Here is the summary with links:
- [net-next,v3] net/ionic: avoid OOB TX partner lookup for hwstamp RXQ

    https://git.kernel.org/netdev/net-next/c/d92255b405fb

You are awesome, thank you!

Signature · 2 lines
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html