Commit 17bfe0a8 authored by Dipayaan Roy's avatar Dipayaan Roy Committed by Jakub Kicinski
Browse files

net: mana: Add NULL guards in teardown path to prevent panic on attach failure



When queue allocation fails partway through, the error cleanup frees
and NULLs apc->tx_qp and apc->rxqs. Multiple teardown paths such as
mana_remove(), mana_change_mtu() recovery, and internal error handling
in mana_alloc_queues() can subsequently call into functions that
dereference these pointers without NULL checks:

- mana_chn_setxdp() dereferences apc->rxqs[0], causing a NULL pointer
  dereference panic (CR2: 0000000000000000 at mana_chn_setxdp+0x26).
- mana_destroy_vport() iterates apc->rxqs without a NULL check.
- mana_fence_rqs() iterates apc->rxqs without a NULL check.
- mana_dealloc_queues() iterates apc->tx_qp without a NULL check.

Add NULL guards for apc->rxqs in mana_fence_rqs(),
mana_destroy_vport(), and before the mana_chn_setxdp() call. Add a
NULL guard for apc->tx_qp in mana_dealloc_queues() to skip TX queue
draining when TX queues were never allocated or already freed.

Fixes: ca9c54d2 ("net: mana: Add a driver for Microsoft Azure Network Adapter (MANA)")
Reviewed-by: default avatarHaiyang Zhang <haiyangz@microsoft.com>
Signed-off-by: default avatarDipayaan Roy <dipayanroy@linux.microsoft.com>
Link: https://patch.msgid.link/20260525081129.1230035-2-dipayanroy@linux.microsoft.com


Signed-off-by: default avatarJakub Kicinski <kuba@kernel.org>
parent 3e200099
Loading
Loading
Loading
Loading
+41 −29
Original line number Diff line number Diff line
@@ -1727,6 +1727,9 @@ static void mana_fence_rqs(struct mana_port_context *apc)
	struct mana_rxq *rxq;
	int err;

	if (!apc->rxqs)
		return;

	for (rxq_idx = 0; rxq_idx < apc->num_queues; rxq_idx++) {
		rxq = apc->rxqs[rxq_idx];
		err = mana_fence_rq(apc, rxq);
@@ -2858,6 +2861,8 @@ static void mana_destroy_vport(struct mana_port_context *apc)
	struct mana_rxq *rxq;
	u32 rxq_idx;

	if (apc->rxqs) {

		for (rxq_idx = 0; rxq_idx < apc->num_queues; rxq_idx++) {
			rxq = apc->rxqs[rxq_idx];
			if (!rxq)
@@ -2866,6 +2871,7 @@ static void mana_destroy_vport(struct mana_port_context *apc)
			mana_destroy_rxq(apc, rxq, true);
			apc->rxqs[rxq_idx] = NULL;
		}
	}

	mana_destroy_txq(apc);
	mana_uncfg_vport(apc);
@@ -3269,6 +3275,7 @@ static int mana_dealloc_queues(struct net_device *ndev)
	if (apc->port_is_up)
		return -EINVAL;

	if (apc->rxqs)
		mana_chn_setxdp(apc, NULL);

	if (gd->gdma_context->is_pf && !apc->ac->bm_hostmode)
@@ -3287,6 +3294,7 @@ static int mana_dealloc_queues(struct net_device *ndev)
	 * number of queues.
	 */

	if (apc->tx_qp) {
		for (i = 0; i < apc->num_queues; i++) {
			txq = &apc->tx_qp[i].txq;
			tsleep = 1000;
@@ -3296,10 +3304,12 @@ static int mana_dealloc_queues(struct net_device *ndev)
				tsleep <<= 1;
			}
			if (atomic_read(&txq->pending_sends)) {
			err = pcie_flr(to_pci_dev(gd->gdma_context->dev));
				err =
				    pcie_flr(to_pci_dev(gd->gdma_context->dev));
				if (err) {
					netdev_err(ndev, "flr failed %d with %d pkts pending in txq %u\n",
					   err, atomic_read(&txq->pending_sends),
						   err,
					    atomic_read(&txq->pending_sends),
					    txq->gdma_txq_id);
				}
				break;
@@ -3314,6 +3324,8 @@ static int mana_dealloc_queues(struct net_device *ndev)
			}
			atomic_set(&txq->pending_sends, 0);
		}
	}

	/* We're 100% sure the queues can no longer be woken up, because
	 * we're sure now mana_poll_tx_cq() can't be running.
	 */