Linux kernel -stable discussions
 help / color / mirror / Atom feed
From: Yuansheng Yang <0xbeac@gmail.com>
To: Tony Nguyen <anthony.l.nguyen@intel.com>,
	Przemek Kitszel <przemyslaw.kitszel@intel.com>,
	Andrew Lunn <andrew+netdev@lunn.ch>,
	"David S. Miller" <davem@davemloft.net>,
	Eric Dumazet <edumazet@kernel.org>,
	Jakub Kicinski <kuba@kernel.org>, Paolo Abeni <pabeni@redhat.com>
Cc: intel-wired-lan@lists.osuosl.org, netdev@vger.kernel.org,
	stable@vger.kernel.org
Subject: [PATCH net] igc: clear tx_buffer_info on setup failure and check ring setup errors
Date: Sun,  6 Dec 2026 11:12:15 +0800	[thread overview]
Message-ID: <20261206031215.2280320-1-0xbeac@gmail.com> (raw)

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

             reply	other threads:[~2026-12-06  3:12 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-12-06  3:12 Yuansheng Yang [this message]
2026-12-06  3:18 ` [PATCH net] igc: clear tx_buffer_info on setup failure and check ring setup errors netdev-bot+sinfo

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20261206031215.2280320-1-0xbeac@gmail.com \
    --to=0xbeac@gmail.com \
    --cc=andrew+netdev@lunn.ch \
    --cc=anthony.l.nguyen@intel.com \
    --cc=davem@davemloft.net \
    --cc=edumazet@kernel.org \
    --cc=intel-wired-lan@lists.osuosl.org \
    --cc=kuba@kernel.org \
    --cc=netdev@vger.kernel.org \
    --cc=pabeni@redhat.com \
    --cc=przemyslaw.kitszel@intel.com \
    --cc=stable@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox