From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-alma10-1.taild15c8.ts.net [100.103.45.18]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 292784457AF; Thu, 30 Jul 2026 15:21:06 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=100.103.45.18 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1785424868; cv=none; b=AvWGs2W/q95cBdM9QbJcUoDXGt/0Mcn/J3LiapkdASQeMi2zgjzHd+pnhe5+k24anzv+WJa9xQkkTL4bZvknJ++RNSP9Yrf7u9eQhj8xUT3GP/wjylkqwDwQaOknKdh/Irisdyh9/zEY0SQbwTmJQLw/KQLDz7NPYO5AxYgdPUE= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1785424868; c=relaxed/simple; bh=90WynpdXS4eOgv8sW1d8g6O8NkI/lCbSKFzyGfplCg0=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=nJNi/M3QkW7G9bdVvYRgLAjfl9Bpjp88bAcsWZLzPqNla+swUvAiVn9CVaJ2DAqdOUzpfVYgsvoTV4wv1VBQXqWWXtwROyF5g9hbVm5XTlTf458/47ZBHxBTAI9z8KzTdEk16/ogWYf7Z7jWmAgGj+IqFiw4Qb8UzVGHYGCF8L4= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b=Tc0hpKYD; arc=none smtp.client-ip=100.103.45.18 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b="Tc0hpKYD" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 778711F00ACF; Thu, 30 Jul 2026 15:21:05 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxfoundation.org; s=korg; t=1785424866; bh=rXMcijH3rpffIIjGtPfNqOoAHCTmK8+Br/o7y27+GEg=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=Tc0hpKYDWS0AXdmZY+yz0Jnvz025HtZNpUGlgDmphsUyYKHJC3jFgxZs5Uw/rpFrK SVS8VKRS90U3d6LodspPfcYQ0CPGrXzp2/ro1nDI+attmQ6SFmvQnKBDRKt0Ueg7zs +6d3O79drUeTTlVqFnVVQANCv1FH8jyQ+gmXg/0U= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, Fan Wu , Jacob Keller , Jakub Kicinski Subject: [PATCH 6.18 542/675] net: hip04: fix RX buffer leak on build_skb failure Date: Thu, 30 Jul 2026 16:14:32 +0200 Message-ID: <20260730141456.663408375@linuxfoundation.org> X-Mailer: git-send-email 2.55.0 In-Reply-To: <20260730141445.110192266@linuxfoundation.org> References: <20260730141445.110192266@linuxfoundation.org> User-Agent: quilt/0.69 X-stable: review X-Patchwork-Hint: ignore Precedence: bulk X-Mailing-List: patches@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 6.18-stable review patch. If anyone has any objections, please let me know. ------------------ From: Fan Wu commit 14fa65d10f5696b063a7d8d26e8291ea84a2c6ed upstream. When build_skb() fails in hip04_rx_poll(), the driver jumps to the refill path without releasing the current RX buffer and its DMA mapping. Installing a replacement buffer then overwrites the slot references and leaks both resources. Keep the current slot intact and return budget so NAPI retries the same buffer. Also free a newly allocated RX fragment when dma_map_single() fails. This issue was found by an in-house static analysis tool. Fixes: 701a0fd52318 ("hip04_eth: fix missing error handle for build_skb failed") Cc: stable@vger.kernel.org Signed-off-by: Fan Wu Reviewed-by: Jacob Keller Link: https://patch.msgid.link/20260712142729.2057636-1-fanwu01@zju.edu.cn Signed-off-by: Jakub Kicinski Signed-off-by: Greg Kroah-Hartman --- drivers/net/ethernet/hisilicon/hip04_eth.c | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) --- a/drivers/net/ethernet/hisilicon/hip04_eth.c +++ b/drivers/net/ethernet/hisilicon/hip04_eth.c @@ -594,7 +594,11 @@ static int hip04_rx_poll(struct napi_str skb = build_skb(buf, priv->rx_buf_size); if (unlikely(!skb)) { net_dbg_ratelimited("build_skb failed\n"); - goto refill; + /* Retain the slot; return budget so NAPI retries this + * buffer. Refill would overwrite rx_buf[]/rx_phys[] + * and leak them. + */ + return budget; } dma_unmap_single(priv->dev, priv->rx_phys[priv->rx_head], @@ -622,14 +626,15 @@ static int hip04_rx_poll(struct napi_str rx++; } -refill: buf = netdev_alloc_frag(priv->rx_buf_size); if (!buf) goto done; phys = dma_map_single(priv->dev, buf, RX_BUF_SIZE, DMA_FROM_DEVICE); - if (dma_mapping_error(priv->dev, phys)) + if (dma_mapping_error(priv->dev, phys)) { + skb_free_frag(buf); goto done; + } priv->rx_buf[priv->rx_head] = buf; priv->rx_phys[priv->rx_head] = phys; hip04_set_recv_desc(priv, phys);