Skip to contentSkip to conversation

dvb: usb: fix use after free in dvb_usb_device_exit

PATCH Superseded Oliver Neukum 2 participants 2 messages Apr 30, 2019 Media (V4L/DVB)

v2 of 3 Superseded Latest is v3 →

lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 dvb: usb: fix use after free in dvb_usb_device_exit

dvb_usb_device_exit() frees and uses the device name in that order Fix by storing the name in a buffer before freeing it

v2: fixed style issues

---
 drivers/media/usb/dvb-usb/dvb-usb-init.c | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)
drivers/media/usb/dvb-usb/dvb-usb-init.c +6 -1
index 99951e02a880..959bbdad8f00 100644
@@ -288,13 +288,18 @@ void dvb_usb_device_exit(struct usb_interface *intf)
 {
 	struct dvb_usb_device *d = usb_get_intfdata(intf);
 	const char *name = "generic DVB-USB module";
+	char identifier[40];
 
 	usb_set_intfdata(intf, NULL);
 	if (d != NULL && d->desc != NULL) {
 		name = d->desc->name;
+		memcpy(identifier, name, 39);
+		identifier[39] = 0;
 		dvb_usb_exit(d);
+	} else {
+		memcpy(identifier, name, 39);
 	}
-	info("%s successfully deinitialized and disconnected.", name);
+	info("%s successfully deinitialized and disconnected.", identifier);
 
 }
 EXPORT_SYMBOL(dvb_usb_device_exit);
Signature · 1 line
2.16.4
#1 lore raw

Em Tue, 30 Apr 2019 12:43:58 +0200
Oliver Neukum <[email protected]> escreveu:

Quoted 16 lines

dvb_usb_device_exit() frees and uses the device name in that order Fix by storing the name in a buffer before freeing it

v2: fixed style issues

---
 drivers/media/usb/dvb-usb/dvb-usb-init.c | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)
drivers/media/usb/dvb-usb/dvb-usb-init.c +0 -0
index 99951e02a880..959bbdad8f00 100644

drivers/media/usb/dvb-usb/dvb-usb-init.c void dvb_usb_device_exit(struct usb_interface *intf) · line 290

Quoted 3 lines
drivers/media/usb/dvb-usb/dvb-usb-init.c +0 -0
@@ -288,13 +288,18 @@ void dvb_usb_device_exit(struct usb_interface *intf)
 {
 	struct dvb_usb_device *d = usb_get_intfdata(intf);
 	const char *name = "generic DVB-USB module";

I would change this to default_name;

drivers/media/usb/dvb-usb/dvb-usb-init.c void dvb_usb_device_exit(struct usb_interface *intf) · line 291

Quoted 1 line
drivers/media/usb/dvb-usb/dvb-usb-init.c +1 -0
+	char identifier[40];

And use name here, instead of identifier.

IMO, this makes easier to understand the code, as it is a common practice to call "name" for such kind of var.

drivers/media/usb/dvb-usb/dvb-usb-init.c void dvb_usb_device_exit(struct usb_interface *intf) · line 297

Quoted 7 lines
drivers/media/usb/dvb-usb/dvb-usb-init.c +2 -0
 	usb_set_intfdata(intf, NULL);
 
 	if (d != NULL && d->desc != NULL) {
 		name = d->desc->name;
+		memcpy(identifier, name, 39);
+		identifier[39] = 0;

Please use instead (considering the rename I proposed before):

	strscpy(name, d->desc->name, sizeof(name));

drivers/media/usb/dvb-usb/dvb-usb-init.c void dvb_usb_device_exit(struct usb_interface *intf) · line 300

Quoted 3 lines
drivers/media/usb/dvb-usb/dvb-usb-init.c +2 -0
 		dvb_usb_exit(d);
+	} else {
+		memcpy(identifier, name, 39);

And here:

	strscpy(name, default_name, sizeof(name));

drivers/media/usb/dvb-usb/dvb-usb-init.c void dvb_usb_device_exit(struct usb_interface *intf) · line 302

Quoted 4 lines
drivers/media/usb/dvb-usb/dvb-usb-init.c +1 -1
 	}
 
-	info("%s successfully deinitialized and disconnected.", name);
+	info("%s successfully deinitialized and disconnected.", identifier);

Dropping this change.

drivers/media/usb/dvb-usb/dvb-usb-init.c void dvb_usb_device_exit(struct usb_interface *intf) · line 305

Quoted 3 lines
drivers/media/usb/dvb-usb/dvb-usb-init.c +0 -0
 }
 EXPORT_SYMBOL(dvb_usb_device_exit);

Thanks,
Mauro