Linux kernel -stable discussions
 help / color / mirror / Atom feed
* [PATCH net] igc: clear tx_buffer_info on setup failure and check ring setup errors
@ 2026-12-06  3:12 Yuansheng Yang
  2026-12-06  3:18 ` netdev-bot+sinfo
  0 siblings, 1 reply; 2+ messages in thread
From: Yuansheng Yang @ 2026-12-06  3:12 UTC (permalink / raw)
  To: Tony Nguyen, Przemek Kitszel, Andrew Lunn, David S. Miller,
	Eric Dumazet, Jakub Kicinski, Paolo Abeni
  Cc: intel-wired-lan, netdev, stable

In igc_setup_tx_resources(), if dma_alloc_coherent() fails after
vzalloc() has allocated tx_ring->tx_buffer_info, the err path calls
vfree(tx_ring->tx_buffer_info) without setting tx_ring->tx_buffer_info
to NULL, unlike the symmetric error unwind in igc_setup_rx_resources().

Additionally, igc_request_irq() ignores the return values of
igc_setup_all_tx_resources() and igc_setup_all_rx_resources() when falling
back from MSI-X to MSI interrupts. If ring allocation fails partway
through, igc_request_irq() proceeds without aborting and returns success
or unwinds into __igc_open()'s err_req_irq label (or a later
igc_close()), which invokes igc_free_all_tx_resources() and
igc_free_all_rx_resources():

1. Calling igc_free_tx_resources() on the failed Tx ring enters
   igc_disable_tx_ring() -> igc_clean_tx_ring(), triggering a vmalloc
   use-after-free in memset(tx_ring->tx_buffer_info, ...), a
   NULL-pointer dereference in memset(tx_ring->desc, ...), and a double
   vfree():

     BUG: KASAN: vmalloc-out-of-bounds in igc_clean_tx_ring
     Write of size 32768 at addr ...
     Call Trace:
      __asan_memset
      igc_clean_tx_ring
      igc_free_tx_resources

2. Calling igc_free_rx_resources() on an Rx ring whose setup already
   failed (or was rolled back by igc_setup_all_rx_resources()) invokes
   xdp_rxq_info_unreg() again on a ring already in
   REG_STATE_UNREGISTERED, triggering WARN() in
   xdp_rxq_info_unreg_mem_model().

Clear tx_ring->tx_buffer_info to NULL after vfree() on the error path of
igc_setup_tx_resources(), make igc_free_tx_resources() and
igc_free_rx_resources() safe for re-entry when buffer_info and desc are
both NULL (checking xdp_rxq_info_is_reg() before unregistering XDP
state), and check the return values of igc_setup_all_tx_resources() and
igc_setup_all_rx_resources() in igc_request_irq().

Fixes: 13b5b7fd6a4a ("igc: Add support for Tx/Rx rings")
Cc: stable@vger.kernel.org
Signed-off-by: Yuansheng Yang <0xbeac@gmail.com>
---
Compiled drivers/net/ethernet/intel/igc/igc_main.o with W=1 on x86_64
(0 warnings, 0 errors) and verified on v7.4-rc5 in an x86_64 KASAN
QEMU guest via failing dma_alloc_coherent() in both
igc_setup_tx_resources() and igc_setup_rx_resources() followed by
igc_free_tx_resources() and igc_free_rx_resources(): before this fix,
KASAN reports a vmalloc out-of-bounds write and null-ptr-deref in
igc_clean_tx_ring() followed by a vfree() warning; after this fix,
10/10 iterations unwind cleanly on both Tx and Rx paths with
tx_buffer_info == NULL, rx_buffer_info == NULL, and 0 KASAN, BUG, or
WARNING diagnostics.

 drivers/net/ethernet/intel/igc/igc_main.c | 23 ++++++++++++++++++-----
 1 file changed, 18 insertions(+), 5 deletions(-)

diff --git a/drivers/net/ethernet/intel/igc/igc_main.c b/drivers/net/ethernet/intel/igc/igc_main.c
index 1fb5f3cbe..8dd5a7196 100644
--- a/drivers/net/ethernet/intel/igc/igc_main.c
+++ b/drivers/net/ethernet/intel/igc/igc_main.c
@@ -281,6 +281,9 @@ static void igc_clean_tx_ring(struct igc_ring *tx_ring)
  */
 void igc_free_tx_resources(struct igc_ring *tx_ring)
 {
+	if (!tx_ring->tx_buffer_info && !tx_ring->desc)
+		return;
+
 	igc_disable_tx_ring(tx_ring);
 
 	vfree(tx_ring->tx_buffer_info);
@@ -384,6 +387,7 @@ int igc_setup_tx_resources(struct igc_ring *tx_ring)
 
 err:
 	vfree(tx_ring->tx_buffer_info);
+	tx_ring->tx_buffer_info = NULL;
 	netdev_err(ndev, "Unable to allocate memory for Tx descriptor ring\n");
 	return -ENOMEM;
 }
@@ -501,9 +505,14 @@ static void igc_clean_all_rx_rings(struct igc_adapter *adapter)
  */
 void igc_free_rx_resources(struct igc_ring *rx_ring)
 {
-	igc_clean_rx_ring(rx_ring);
+	if (rx_ring->rx_buffer_info || rx_ring->desc)
+		igc_clean_rx_ring(rx_ring);
 
-	xdp_rxq_info_unreg(&rx_ring->xdp_rxq);
+	if (xdp_rxq_info_is_reg(&rx_ring->xdp_rxq))
+		xdp_rxq_info_unreg(&rx_ring->xdp_rxq);
+
+	if (!rx_ring->rx_buffer_info && !rx_ring->desc)
+		return;
 
 	vfree(rx_ring->rx_buffer_info);
 	rx_ring->rx_buffer_info = NULL;
@@ -6150,8 +6159,12 @@ static int igc_request_irq(struct igc_adapter *adapter)
 		err = igc_init_interrupt_scheme(adapter, false);
 		if (err)
 			goto request_done;
-		igc_setup_all_tx_resources(adapter);
-		igc_setup_all_rx_resources(adapter);
+		err = igc_setup_all_tx_resources(adapter);
+		if (err)
+			goto request_done;
+		err = igc_setup_all_rx_resources(adapter);
+		if (err)
+			goto request_done;
 		igc_configure(adapter);
 	}
 
-- 
2.53.0

^ permalink raw reply related	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2026-12-06  3:18 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-12-06  3:12 [PATCH net] igc: clear tx_buffer_info on setup failure and check ring setup errors Yuansheng Yang
2026-12-06  3:18 ` netdev-bot+sinfo

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox