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 AF27023392B; Sat, 30 May 2026 17:44:55 +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=1780163096; cv=none; b=phz/FdYYzrzcI1h9Ydf130stY0U3Kv30x2pmhnDEgvs3ogWuvoClvYbtYawlX/ItXDPSXhAVESCZ9kf8a10SMTmrP8XC2qrsrbfATCnN0hlkfqlyKRQ3rDRxoHnSX1HckVid4HZUUvF+qBrSJ+3qHx2hljddcpyv31g9A81NOXY= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1780163096; c=relaxed/simple; bh=JdC8zvT57Wq7TmNLOU4aZU2eS9+vlfOdp+mqDX4DJqY=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=n2lJqh1HfpIf8x41nTu/l8TkTlsEwi4gEuSAncYSyeAzfimeicsgVj0wJkcDxJZfr4t+UuEQ0GfntIrpBWPpDWjjRdAcVzpICgdAlnt1EcH/7rpos12S9TMWHQSogbjK6chnmKq2RkHyg0wlQ3u19JAsCSN7xQTorKYJ6erx97Q= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b=2TbXdMfq; 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="2TbXdMfq" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 005001F00893; Sat, 30 May 2026 17:44:54 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxfoundation.org; s=korg; t=1780163095; bh=/YPQD0oKRUXqM0X2U0OxqQ53EVu45NAtlRCWHg05D08=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=2TbXdMfqKKpuITzGEsdUio+HB8OQfgxYZpnpVh+8HLDiuOB31oJ8TBHmTXaWi8Leq UTbBvz2rFRSnEuk9R9LSV6iOZkasE/oy1aquClmKPGC0got73ilmGn9zAMx3P3lS6s 4d4b1KXv46yppsDILfpNATiYE0BRmj94THejtlec= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, John Efstathiades , Oleksij Rempel , Jakub Kicinski , Wenshan Lan Subject: [PATCH 5.15 153/776] net: usb: lan78xx: Fix double free issue with interrupt buffer allocation Date: Sat, 30 May 2026 17:57:47 +0200 Message-ID: <20260530160244.414328748@linuxfoundation.org> X-Mailer: git-send-email 2.53.0 In-Reply-To: <20260530160240.228940103@linuxfoundation.org> References: <20260530160240.228940103@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 5.15-stable review patch. If anyone has any objections, please let me know. ------------------ From: Oleksij Rempel [ Upstream commit 03819abbeb11117dcbba40bfe322b88c0c88a6b6 ] In lan78xx_probe(), the buffer `buf` was being freed twice: once implicitly through `usb_free_urb(dev->urb_intr)` with the `URB_FREE_BUFFER` flag and again explicitly by `kfree(buf)`. This caused a double free issue. To resolve this, reordered `kmalloc()` and `usb_alloc_urb()` calls to simplify the initialization sequence and removed the redundant `kfree(buf)`. Now, `buf` is allocated after `usb_alloc_urb()`, ensuring it is correctly managed by `usb_fill_int_urb()` and freed by `usb_free_urb()` as intended. Fixes: a6df95cae40b ("lan78xx: Fix memory allocation bug") Cc: John Efstathiades Signed-off-by: Oleksij Rempel Link: https://patch.msgid.link/20241116130558.1352230-1-o.rempel@pengutronix.de Signed-off-by: Jakub Kicinski [ Adjust context. Make the function usb_alloc_urb() call before kmalloc(). ] Signed-off-by: Wenshan Lan Signed-off-by: Greg Kroah-Hartman --- drivers/net/usb/lan78xx.c | 29 ++++++++++++++--------------- 1 file changed, 14 insertions(+), 15 deletions(-) --- a/drivers/net/usb/lan78xx.c +++ b/drivers/net/usb/lan78xx.c @@ -4111,29 +4111,30 @@ static int lan78xx_probe(struct usb_inte period = ep_intr->desc.bInterval; maxp = usb_maxpacket(dev->udev, dev->pipe_intr, 0); - buf = kmalloc(maxp, GFP_KERNEL); - if (!buf) { + + dev->urb_intr = usb_alloc_urb(0, GFP_KERNEL); + if (!dev->urb_intr) { ret = -ENOMEM; goto out3; } - dev->urb_intr = usb_alloc_urb(0, GFP_KERNEL); - if (!dev->urb_intr) { + buf = kmalloc(maxp, GFP_KERNEL); + if (!buf) { ret = -ENOMEM; - goto out4; - } else { - usb_fill_int_urb(dev->urb_intr, dev->udev, - dev->pipe_intr, buf, maxp, - intr_complete, dev, period); - dev->urb_intr->transfer_flags |= URB_FREE_BUFFER; + goto free_urbs; } + usb_fill_int_urb(dev->urb_intr, dev->udev, + dev->pipe_intr, buf, maxp, + intr_complete, dev, period); + dev->urb_intr->transfer_flags |= URB_FREE_BUFFER; + dev->maxpacket = usb_maxpacket(dev->udev, dev->pipe_out, 1); /* Reject broken descriptors. */ if (dev->maxpacket == 0) { ret = -ENODEV; - goto out5; + goto free_urbs; } /* driver requires remote-wakeup capability during autosuspend. */ @@ -4141,7 +4142,7 @@ static int lan78xx_probe(struct usb_inte ret = lan78xx_phy_init(dev); if (ret < 0) - goto out5; + goto free_urbs; ret = register_netdev(netdev); if (ret != 0) { @@ -4163,10 +4164,8 @@ static int lan78xx_probe(struct usb_inte out6: phy_disconnect(netdev->phydev); -out5: +free_urbs: usb_free_urb(dev->urb_intr); -out4: - kfree(buf); out3: lan78xx_unbind(dev, intf); out2: