Skip to content

Commit 1f4777d

Browse files
author
CKI Backport Bot
committed
net: usb: lan78xx: Fix double free issue with interrupt buffer allocation
JIRA: https://issues.redhat.com/browse/RHEL-72355 CVE: CVE-2024-53213 commit 03819ab Author: Oleksij Rempel <linux@rempel-privat.de> Date: Sat Nov 16 14:05:57 2024 +0100 net: usb: lan78xx: Fix double free issue with interrupt buffer allocation 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: a6df95c ("lan78xx: Fix memory allocation bug") Cc: John Efstathiades <john.efstathiades@pebblebay.com> Signed-off-by: Oleksij Rempel <o.rempel@pengutronix.de> Link: https://patch.msgid.link/20241116130558.1352230-1-o.rempel@pengutronix.de Signed-off-by: Jakub Kicinski <kuba@kernel.org> Signed-off-by: CKI Backport Bot <cki-ci-bot+cki-gitlab-backport-bot@redhat.com>
1 parent 8987e6b commit 1f4777d

File tree

1 file changed

+14
-15
lines changed

1 file changed

+14
-15
lines changed

drivers/net/usb/lan78xx.c

Lines changed: 14 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -4412,37 +4412,38 @@ static int lan78xx_probe(struct usb_interface *intf,
44124412

44134413
period = ep_intr->desc.bInterval;
44144414
maxp = usb_maxpacket(dev->udev, dev->pipe_intr);
4415-
buf = kmalloc(maxp, GFP_KERNEL);
4416-
if (!buf) {
4415+
4416+
dev->urb_intr = usb_alloc_urb(0, GFP_KERNEL);
4417+
if (!dev->urb_intr) {
44174418
ret = -ENOMEM;
44184419
goto out5;
44194420
}
44204421

4421-
dev->urb_intr = usb_alloc_urb(0, GFP_KERNEL);
4422-
if (!dev->urb_intr) {
4422+
buf = kmalloc(maxp, GFP_KERNEL);
4423+
if (!buf) {
44234424
ret = -ENOMEM;
4424-
goto out6;
4425-
} else {
4426-
usb_fill_int_urb(dev->urb_intr, dev->udev,
4427-
dev->pipe_intr, buf, maxp,
4428-
intr_complete, dev, period);
4429-
dev->urb_intr->transfer_flags |= URB_FREE_BUFFER;
4425+
goto free_urbs;
44304426
}
44314427

4428+
usb_fill_int_urb(dev->urb_intr, dev->udev,
4429+
dev->pipe_intr, buf, maxp,
4430+
intr_complete, dev, period);
4431+
dev->urb_intr->transfer_flags |= URB_FREE_BUFFER;
4432+
44324433
dev->maxpacket = usb_maxpacket(dev->udev, dev->pipe_out);
44334434

44344435
/* Reject broken descriptors. */
44354436
if (dev->maxpacket == 0) {
44364437
ret = -ENODEV;
4437-
goto out6;
4438+
goto free_urbs;
44384439
}
44394440

44404441
/* driver requires remote-wakeup capability during autosuspend. */
44414442
intf->needs_remote_wakeup = 1;
44424443

44434444
ret = lan78xx_phy_init(dev);
44444445
if (ret < 0)
4445-
goto out7;
4446+
goto free_urbs;
44464447

44474448
ret = register_netdev(netdev);
44484449
if (ret != 0) {
@@ -4464,10 +4465,8 @@ static int lan78xx_probe(struct usb_interface *intf,
44644465

44654466
out8:
44664467
phy_disconnect(netdev->phydev);
4467-
out7:
4468+
free_urbs:
44684469
usb_free_urb(dev->urb_intr);
4469-
out6:
4470-
kfree(buf);
44714470
out5:
44724471
lan78xx_unbind(dev, intf);
44734472
out4:

0 commit comments

Comments
 (0)