Skip to content

Commit 0cb03b6

Browse files
arndbgregkh
authored andcommitted
dvb-usb-v2: avoid use-after-free
commit 005145378c9ad7575a01b6ce1ba118fb427f583a upstream. I ran into a stack frame size warning because of the on-stack copy of the USB device structure: drivers/media/usb/dvb-usb-v2/dvb_usb_core.c: In function 'dvb_usbv2_disconnect': drivers/media/usb/dvb-usb-v2/dvb_usb_core.c:1029:1: error: the frame size of 1104 bytes is larger than 1024 bytes [-Werror=frame-larger-than=] Copying a device structure like this is wrong for a number of other reasons too aside from the possible stack overflow. One of them is that the dev_info() call will print the name of the device later, but AFAICT we have only copied a pointer to the name earlier and the actual name has been freed by the time it gets printed. This removes the on-stack copy of the device and instead copies the device name using kstrdup(). I'm ignoring the possible failure here as both printk() and kfree() are able to deal with NULL pointers. Signed-off-by: Arnd Bergmann <arnd@arndb.de> Signed-off-by: Mauro Carvalho Chehab <mchehab@s-opensource.com> Cc: Ben Hutchings <ben@decadent.org.uk> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
1 parent ea6d8d6 commit 0cb03b6

1 file changed

Lines changed: 5 additions & 4 deletions

File tree

drivers/media/usb/dvb-usb-v2/dvb_usb_core.c

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1010,8 +1010,8 @@ EXPORT_SYMBOL(dvb_usbv2_probe);
10101010
void dvb_usbv2_disconnect(struct usb_interface *intf)
10111011
{
10121012
struct dvb_usb_device *d = usb_get_intfdata(intf);
1013-
const char *name = d->name;
1014-
struct device dev = d->udev->dev;
1013+
const char *devname = kstrdup(dev_name(&d->udev->dev), GFP_KERNEL);
1014+
const char *drvname = d->name;
10151015

10161016
dev_dbg(&d->udev->dev, "%s: bInterfaceNumber=%d\n", __func__,
10171017
intf->cur_altsetting->desc.bInterfaceNumber);
@@ -1021,8 +1021,9 @@ void dvb_usbv2_disconnect(struct usb_interface *intf)
10211021

10221022
dvb_usbv2_exit(d);
10231023

1024-
dev_info(&dev, "%s: '%s' successfully deinitialized and disconnected\n",
1025-
KBUILD_MODNAME, name);
1024+
pr_info("%s: '%s:%s' successfully deinitialized and disconnected\n",
1025+
KBUILD_MODNAME, drvname, devname);
1026+
kfree(devname);
10261027
}
10271028
EXPORT_SYMBOL(dvb_usbv2_disconnect);
10281029

0 commit comments

Comments
 (0)