Skip to content

Commit 589a9f0

Browse files
Druidosmchehab
authored andcommitted
media: dw2102: Fix use after free
dvb_usb_device_init stores parts of properties at d->props and d->desc and uses it on dvb_usb_device_exit. Free of properties on module probe leads to use after free. Bugzilla: https://bugzilla.kernel.org/show_bug.cgi?id=204597 The patch makes properties static instead of allocated on heap to prevent memleak and use after free. Also fixes s421_properties.devices initialization to have 2 element instead of 6 copied from p7500_properties. [mchehab: fix function call alignments] Link: https://lore.kernel.org/linux-media/20190822104147.4420-1-vasilyev@ispras.ru Signed-off-by: Anton Vasilyev <vasilyev@ispras.ru> Fixes: 299c700 ("media: dw2102: Fix memleak on sequence of probes") Signed-off-by: Mauro Carvalho Chehab <mchehab+huawei@kernel.org>
1 parent c00d65e commit 589a9f0

1 file changed

Lines changed: 215 additions & 123 deletions

File tree

‎drivers/media/usb/dvb-usb/dw2102.c‎

Lines changed: 215 additions & 123 deletions
Original file line numberDiff line numberDiff line change
@@ -2150,46 +2150,153 @@ static struct dvb_usb_device_properties s6x0_properties = {
21502150
}
21512151
};
21522152

2153-
static const struct dvb_usb_device_description d1100 = {
2154-
"Prof 1100 USB ",
2155-
{&dw2102_table[PROF_1100], NULL},
2156-
{NULL},
2157-
};
2153+
static struct dvb_usb_device_properties p1100_properties = {
2154+
.caps = DVB_USB_IS_AN_I2C_ADAPTER,
2155+
.usb_ctrl = DEVICE_SPECIFIC,
2156+
.size_of_priv = sizeof(struct dw2102_state),
2157+
.firmware = P1100_FIRMWARE,
2158+
.no_reconnect = 1,
21582159

2159-
static const struct dvb_usb_device_description d660 = {
2160-
"TeVii S660 USB",
2161-
{&dw2102_table[TEVII_S660], NULL},
2162-
{NULL},
2163-
};
2160+
.i2c_algo = &s6x0_i2c_algo,
2161+
.rc.core = {
2162+
.rc_interval = 150,
2163+
.rc_codes = RC_MAP_TBS_NEC,
2164+
.module_name = "dw2102",
2165+
.allowed_protos = RC_PROTO_BIT_NEC,
2166+
.rc_query = prof_rc_query,
2167+
},
21642168

2165-
static const struct dvb_usb_device_description d480_1 = {
2166-
"TeVii S480.1 USB",
2167-
{&dw2102_table[TEVII_S480_1], NULL},
2168-
{NULL},
2169+
.generic_bulk_ctrl_endpoint = 0x81,
2170+
.num_adapters = 1,
2171+
.download_firmware = dw2102_load_firmware,
2172+
.read_mac_address = s6x0_read_mac_address,
2173+
.adapter = {
2174+
{
2175+
.num_frontends = 1,
2176+
.fe = {{
2177+
.frontend_attach = stv0288_frontend_attach,
2178+
.stream = {
2179+
.type = USB_BULK,
2180+
.count = 8,
2181+
.endpoint = 0x82,
2182+
.u = {
2183+
.bulk = {
2184+
.buffersize = 4096,
2185+
}
2186+
}
2187+
},
2188+
} },
2189+
}
2190+
},
2191+
.num_device_descs = 1,
2192+
.devices = {
2193+
{"Prof 1100 USB ",
2194+
{&dw2102_table[PROF_1100], NULL},
2195+
{NULL},
2196+
},
2197+
}
21692198
};
21702199

2171-
static const struct dvb_usb_device_description d480_2 = {
2172-
"TeVii S480.2 USB",
2173-
{&dw2102_table[TEVII_S480_2], NULL},
2174-
{NULL},
2175-
};
2200+
static struct dvb_usb_device_properties s660_properties = {
2201+
.caps = DVB_USB_IS_AN_I2C_ADAPTER,
2202+
.usb_ctrl = DEVICE_SPECIFIC,
2203+
.size_of_priv = sizeof(struct dw2102_state),
2204+
.firmware = S660_FIRMWARE,
2205+
.no_reconnect = 1,
21762206

2177-
static const struct dvb_usb_device_description d7500 = {
2178-
"Prof 7500 USB DVB-S2",
2179-
{&dw2102_table[PROF_7500], NULL},
2180-
{NULL},
2181-
};
2207+
.i2c_algo = &s6x0_i2c_algo,
2208+
.rc.core = {
2209+
.rc_interval = 150,
2210+
.rc_codes = RC_MAP_TEVII_NEC,
2211+
.module_name = "dw2102",
2212+
.allowed_protos = RC_PROTO_BIT_NEC,
2213+
.rc_query = dw2102_rc_query,
2214+
},
21822215

2183-
static const struct dvb_usb_device_description d421 = {
2184-
"TeVii S421 PCI",
2185-
{&dw2102_table[TEVII_S421], NULL},
2186-
{NULL},
2216+
.generic_bulk_ctrl_endpoint = 0x81,
2217+
.num_adapters = 1,
2218+
.download_firmware = dw2102_load_firmware,
2219+
.read_mac_address = s6x0_read_mac_address,
2220+
.adapter = {
2221+
{
2222+
.num_frontends = 1,
2223+
.fe = {{
2224+
.frontend_attach = ds3000_frontend_attach,
2225+
.stream = {
2226+
.type = USB_BULK,
2227+
.count = 8,
2228+
.endpoint = 0x82,
2229+
.u = {
2230+
.bulk = {
2231+
.buffersize = 4096,
2232+
}
2233+
}
2234+
},
2235+
} },
2236+
}
2237+
},
2238+
.num_device_descs = 3,
2239+
.devices = {
2240+
{"TeVii S660 USB",
2241+
{&dw2102_table[TEVII_S660], NULL},
2242+
{NULL},
2243+
},
2244+
{"TeVii S480.1 USB",
2245+
{&dw2102_table[TEVII_S480_1], NULL},
2246+
{NULL},
2247+
},
2248+
{"TeVii S480.2 USB",
2249+
{&dw2102_table[TEVII_S480_2], NULL},
2250+
{NULL},
2251+
},
2252+
}
21872253
};
21882254

2189-
static const struct dvb_usb_device_description d632 = {
2190-
"TeVii S632 USB",
2191-
{&dw2102_table[TEVII_S632], NULL},
2192-
{NULL},
2255+
static struct dvb_usb_device_properties p7500_properties = {
2256+
.caps = DVB_USB_IS_AN_I2C_ADAPTER,
2257+
.usb_ctrl = DEVICE_SPECIFIC,
2258+
.size_of_priv = sizeof(struct dw2102_state),
2259+
.firmware = P7500_FIRMWARE,
2260+
.no_reconnect = 1,
2261+
2262+
.i2c_algo = &s6x0_i2c_algo,
2263+
.rc.core = {
2264+
.rc_interval = 150,
2265+
.rc_codes = RC_MAP_TBS_NEC,
2266+
.module_name = "dw2102",
2267+
.allowed_protos = RC_PROTO_BIT_NEC,
2268+
.rc_query = prof_rc_query,
2269+
},
2270+
2271+
.generic_bulk_ctrl_endpoint = 0x81,
2272+
.num_adapters = 1,
2273+
.download_firmware = dw2102_load_firmware,
2274+
.read_mac_address = s6x0_read_mac_address,
2275+
.adapter = {
2276+
{
2277+
.num_frontends = 1,
2278+
.fe = {{
2279+
.frontend_attach = prof_7500_frontend_attach,
2280+
.stream = {
2281+
.type = USB_BULK,
2282+
.count = 8,
2283+
.endpoint = 0x82,
2284+
.u = {
2285+
.bulk = {
2286+
.buffersize = 4096,
2287+
}
2288+
}
2289+
},
2290+
} },
2291+
}
2292+
},
2293+
.num_device_descs = 1,
2294+
.devices = {
2295+
{"Prof 7500 USB DVB-S2",
2296+
{&dw2102_table[PROF_7500], NULL},
2297+
{NULL},
2298+
},
2299+
}
21932300
};
21942301

21952302
static struct dvb_usb_device_properties su3000_properties = {
@@ -2273,6 +2380,59 @@ static struct dvb_usb_device_properties su3000_properties = {
22732380
}
22742381
};
22752382

2383+
static struct dvb_usb_device_properties s421_properties = {
2384+
.caps = DVB_USB_IS_AN_I2C_ADAPTER,
2385+
.usb_ctrl = DEVICE_SPECIFIC,
2386+
.size_of_priv = sizeof(struct dw2102_state),
2387+
.power_ctrl = su3000_power_ctrl,
2388+
.num_adapters = 1,
2389+
.identify_state = su3000_identify_state,
2390+
.i2c_algo = &su3000_i2c_algo,
2391+
2392+
.rc.core = {
2393+
.rc_interval = 150,
2394+
.rc_codes = RC_MAP_SU3000,
2395+
.module_name = "dw2102",
2396+
.allowed_protos = RC_PROTO_BIT_RC5,
2397+
.rc_query = su3000_rc_query,
2398+
},
2399+
2400+
.read_mac_address = su3000_read_mac_address,
2401+
2402+
.generic_bulk_ctrl_endpoint = 0x01,
2403+
2404+
.adapter = {
2405+
{
2406+
.num_frontends = 1,
2407+
.fe = {{
2408+
.streaming_ctrl = su3000_streaming_ctrl,
2409+
.frontend_attach = m88rs2000_frontend_attach,
2410+
.stream = {
2411+
.type = USB_BULK,
2412+
.count = 8,
2413+
.endpoint = 0x82,
2414+
.u = {
2415+
.bulk = {
2416+
.buffersize = 4096,
2417+
}
2418+
}
2419+
}
2420+
} },
2421+
}
2422+
},
2423+
.num_device_descs = 2,
2424+
.devices = {
2425+
{ "TeVii S421 PCI",
2426+
{ &dw2102_table[TEVII_S421], NULL },
2427+
{ NULL },
2428+
},
2429+
{ "TeVii S632 USB",
2430+
{ &dw2102_table[TEVII_S632], NULL },
2431+
{ NULL },
2432+
},
2433+
}
2434+
};
2435+
22762436
static struct dvb_usb_device_properties t220_properties = {
22772437
.caps = DVB_USB_IS_AN_I2C_ADAPTER,
22782438
.usb_ctrl = DEVICE_SPECIFIC,
@@ -2390,101 +2550,33 @@ static struct dvb_usb_device_properties tt_s2_4600_properties = {
23902550
static int dw2102_probe(struct usb_interface *intf,
23912551
const struct usb_device_id *id)
23922552
{
2393-
int retval = -ENOMEM;
2394-
struct dvb_usb_device_properties *p1100;
2395-
struct dvb_usb_device_properties *s660;
2396-
struct dvb_usb_device_properties *p7500;
2397-
struct dvb_usb_device_properties *s421;
2398-
2399-
p1100 = kmemdup(&s6x0_properties,
2400-
sizeof(struct dvb_usb_device_properties), GFP_KERNEL);
2401-
if (!p1100)
2402-
goto err0;
2403-
2404-
/* copy default structure */
2405-
/* fill only different fields */
2406-
p1100->firmware = P1100_FIRMWARE;
2407-
p1100->devices[0] = d1100;
2408-
p1100->rc.core.rc_query = prof_rc_query;
2409-
p1100->rc.core.rc_codes = RC_MAP_TBS_NEC;
2410-
p1100->adapter->fe[0].frontend_attach = stv0288_frontend_attach;
2411-
2412-
s660 = kmemdup(&s6x0_properties,
2413-
sizeof(struct dvb_usb_device_properties), GFP_KERNEL);
2414-
if (!s660)
2415-
goto err1;
2416-
2417-
s660->firmware = S660_FIRMWARE;
2418-
s660->num_device_descs = 3;
2419-
s660->devices[0] = d660;
2420-
s660->devices[1] = d480_1;
2421-
s660->devices[2] = d480_2;
2422-
s660->adapter->fe[0].frontend_attach = ds3000_frontend_attach;
2423-
2424-
p7500 = kmemdup(&s6x0_properties,
2425-
sizeof(struct dvb_usb_device_properties), GFP_KERNEL);
2426-
if (!p7500)
2427-
goto err2;
2428-
2429-
p7500->firmware = P7500_FIRMWARE;
2430-
p7500->devices[0] = d7500;
2431-
p7500->rc.core.rc_query = prof_rc_query;
2432-
p7500->rc.core.rc_codes = RC_MAP_TBS_NEC;
2433-
p7500->adapter->fe[0].frontend_attach = prof_7500_frontend_attach;
2434-
2435-
2436-
s421 = kmemdup(&su3000_properties,
2437-
sizeof(struct dvb_usb_device_properties), GFP_KERNEL);
2438-
if (!s421)
2439-
goto err3;
2440-
2441-
s421->num_device_descs = 2;
2442-
s421->devices[0] = d421;
2443-
s421->devices[1] = d632;
2444-
s421->adapter->fe[0].frontend_attach = m88rs2000_frontend_attach;
2445-
2446-
if (0 == dvb_usb_device_init(intf, &dw2102_properties,
2447-
THIS_MODULE, NULL, adapter_nr) ||
2448-
0 == dvb_usb_device_init(intf, &dw2104_properties,
2449-
THIS_MODULE, NULL, adapter_nr) ||
2450-
0 == dvb_usb_device_init(intf, &dw3101_properties,
2451-
THIS_MODULE, NULL, adapter_nr) ||
2452-
0 == dvb_usb_device_init(intf, &s6x0_properties,
2453-
THIS_MODULE, NULL, adapter_nr) ||
2454-
0 == dvb_usb_device_init(intf, p1100,
2455-
THIS_MODULE, NULL, adapter_nr) ||
2456-
0 == dvb_usb_device_init(intf, s660,
2457-
THIS_MODULE, NULL, adapter_nr) ||
2458-
0 == dvb_usb_device_init(intf, p7500,
2459-
THIS_MODULE, NULL, adapter_nr) ||
2460-
0 == dvb_usb_device_init(intf, s421,
2461-
THIS_MODULE, NULL, adapter_nr) ||
2462-
0 == dvb_usb_device_init(intf, &su3000_properties,
2463-
THIS_MODULE, NULL, adapter_nr) ||
2464-
0 == dvb_usb_device_init(intf, &t220_properties,
2465-
THIS_MODULE, NULL, adapter_nr) ||
2466-
0 == dvb_usb_device_init(intf, &tt_s2_4600_properties,
2467-
THIS_MODULE, NULL, adapter_nr)) {
2468-
2469-
/* clean up copied properties */
2470-
kfree(s421);
2471-
kfree(p7500);
2472-
kfree(s660);
2473-
kfree(p1100);
2553+
if (!(dvb_usb_device_init(intf, &dw2102_properties,
2554+
THIS_MODULE, NULL, adapter_nr) &&
2555+
dvb_usb_device_init(intf, &dw2104_properties,
2556+
THIS_MODULE, NULL, adapter_nr) &&
2557+
dvb_usb_device_init(intf, &dw3101_properties,
2558+
THIS_MODULE, NULL, adapter_nr) &&
2559+
dvb_usb_device_init(intf, &s6x0_properties,
2560+
THIS_MODULE, NULL, adapter_nr) &&
2561+
dvb_usb_device_init(intf, &p1100_properties,
2562+
THIS_MODULE, NULL, adapter_nr) &&
2563+
dvb_usb_device_init(intf, &s660_properties,
2564+
THIS_MODULE, NULL, adapter_nr) &&
2565+
dvb_usb_device_init(intf, &p7500_properties,
2566+
THIS_MODULE, NULL, adapter_nr) &&
2567+
dvb_usb_device_init(intf, &s421_properties,
2568+
THIS_MODULE, NULL, adapter_nr) &&
2569+
dvb_usb_device_init(intf, &su3000_properties,
2570+
THIS_MODULE, NULL, adapter_nr) &&
2571+
dvb_usb_device_init(intf, &t220_properties,
2572+
THIS_MODULE, NULL, adapter_nr) &&
2573+
dvb_usb_device_init(intf, &tt_s2_4600_properties,
2574+
THIS_MODULE, NULL, adapter_nr))) {
24742575

24752576
return 0;
24762577
}
24772578

2478-
retval = -ENODEV;
2479-
kfree(s421);
2480-
err3:
2481-
kfree(p7500);
2482-
err2:
2483-
kfree(s660);
2484-
err1:
2485-
kfree(p1100);
2486-
err0:
2487-
return retval;
2579+
return -ENODEV;
24882580
}
24892581

24902582
static void dw2102_disconnect(struct usb_interface *intf)

0 commit comments

Comments
 (0)