Skip to content

Commit

Permalink
media: dvbsky: Avoid leaking dvb frontend
Browse files Browse the repository at this point in the history
Commit 14f4eae ("media: dvbsky: fix driver unregister logic") fixed
a use-after-free by removing the reference to the frontend after deleting
the backing i2c device.

This has the unfortunate side effect the frontend device is never freed
in the dvb core leaving a dangling device, leading to errors when the
dvb core tries to register the frontend after e.g. a replug as reported
here: https://www.spinics.net/lists/linux-media/msg138181.html

media: dvbsky: issues with DVBSky T680CI

===
[  561.119145] sp2 8-0040: CIMaX SP2 successfully attached
[  561.119161] usb 2-3: DVB: registering adapter 0 frontend 0 (Silicon Labs
Si2168)...
[  561.119174] sysfs: cannot create duplicate filename '/class/dvb/
dvb0.frontend0'
===

The use after free happened as dvb_usbv2_disconnect calls in this order:
- dvb_usb_device::props->exit(...)
- dvb_usbv2_adapter_frontend_exit(...)
  + if (fe) dvb_unregister_frontend(fe)
  + dvb_usb_device::props->frontend_detach(...)

Moving the release of the i2c device from exit() to frontend_detach()
avoids the dangling pointer access and allows the core to unregister
the frontend.

This was originally reported for a DVBSky T680CI, but it also affects
the MyGica T230C. As all supported devices structure the registration/
unregistration identically, apply the change for all device types.

Signed-off-by: Stefan Brüns <[email protected]>
Signed-off-by: Sean Young <[email protected]>
Signed-off-by: Mauro Carvalho Chehab <[email protected]>
  • Loading branch information
StefanBruens authored and mchehab committed Mar 19, 2019
1 parent ef4bb63 commit fdfa59c
Showing 1 changed file with 10 additions and 8 deletions.
18 changes: 10 additions & 8 deletions drivers/media/usb/dvb-usb-v2/dvbsky.c
Original file line number Diff line number Diff line change
Expand Up @@ -615,16 +615,18 @@ static int dvbsky_init(struct dvb_usb_device *d)
return 0;
}

static void dvbsky_exit(struct dvb_usb_device *d)
static int dvbsky_frontend_detach(struct dvb_usb_adapter *adap)
{
struct dvb_usb_device *d = adap_to_d(adap);
struct dvbsky_state *state = d_to_priv(d);
struct dvb_usb_adapter *adap = &d->adapter[0];

dev_dbg(&d->udev->dev, "%s: adap=%d\n", __func__, adap->id);

dvb_module_release(state->i2c_client_tuner);
dvb_module_release(state->i2c_client_demod);
dvb_module_release(state->i2c_client_ci);

adap->fe[0] = NULL;
return 0;
}

/* DVB USB Driver stuff */
Expand All @@ -640,11 +642,11 @@ static struct dvb_usb_device_properties dvbsky_s960_props = {

.i2c_algo = &dvbsky_i2c_algo,
.frontend_attach = dvbsky_s960_attach,
.frontend_detach = dvbsky_frontend_detach,
.init = dvbsky_init,
.get_rc_config = dvbsky_get_rc_config,
.streaming_ctrl = dvbsky_streaming_ctrl,
.identify_state = dvbsky_identify_state,
.exit = dvbsky_exit,
.read_mac_address = dvbsky_read_mac_addr,

.num_adapters = 1,
Expand All @@ -667,11 +669,11 @@ static struct dvb_usb_device_properties dvbsky_s960c_props = {

.i2c_algo = &dvbsky_i2c_algo,
.frontend_attach = dvbsky_s960c_attach,
.frontend_detach = dvbsky_frontend_detach,
.init = dvbsky_init,
.get_rc_config = dvbsky_get_rc_config,
.streaming_ctrl = dvbsky_streaming_ctrl,
.identify_state = dvbsky_identify_state,
.exit = dvbsky_exit,
.read_mac_address = dvbsky_read_mac_addr,

.num_adapters = 1,
Expand All @@ -694,11 +696,11 @@ static struct dvb_usb_device_properties dvbsky_t680c_props = {

.i2c_algo = &dvbsky_i2c_algo,
.frontend_attach = dvbsky_t680c_attach,
.frontend_detach = dvbsky_frontend_detach,
.init = dvbsky_init,
.get_rc_config = dvbsky_get_rc_config,
.streaming_ctrl = dvbsky_streaming_ctrl,
.identify_state = dvbsky_identify_state,
.exit = dvbsky_exit,
.read_mac_address = dvbsky_read_mac_addr,

.num_adapters = 1,
Expand All @@ -721,11 +723,11 @@ static struct dvb_usb_device_properties dvbsky_t330_props = {

.i2c_algo = &dvbsky_i2c_algo,
.frontend_attach = dvbsky_t330_attach,
.frontend_detach = dvbsky_frontend_detach,
.init = dvbsky_init,
.get_rc_config = dvbsky_get_rc_config,
.streaming_ctrl = dvbsky_streaming_ctrl,
.identify_state = dvbsky_identify_state,
.exit = dvbsky_exit,
.read_mac_address = dvbsky_read_mac_addr,

.num_adapters = 1,
Expand All @@ -748,11 +750,11 @@ static struct dvb_usb_device_properties mygica_t230c_props = {

.i2c_algo = &dvbsky_i2c_algo,
.frontend_attach = dvbsky_mygica_t230c_attach,
.frontend_detach = dvbsky_frontend_detach,
.init = dvbsky_init,
.get_rc_config = dvbsky_get_rc_config,
.streaming_ctrl = dvbsky_streaming_ctrl,
.identify_state = dvbsky_identify_state,
.exit = dvbsky_exit,

.num_adapters = 1,
.adapter = {
Expand Down

0 comments on commit fdfa59c

Please sign in to comment.