Skip to content

Commit a79327b

Browse files
Druidosgregkh
authored andcommitted
media: dw2102: Fix use after free
[ Upstream commit 589a9f0 ] 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> Signed-off-by: Sasha Levin <sashal@kernel.org>
1 parent 958a881 commit a79327b

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
@@ -2148,46 +2148,153 @@ static struct dvb_usb_device_properties s6x0_properties = {
21482148
}
21492149
};
21502150

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

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

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

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

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

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

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

21932300
static struct dvb_usb_device_properties su3000_properties = {
@@ -2267,6 +2374,59 @@ static struct dvb_usb_device_properties su3000_properties = {
22672374
}
22682375
};
22692376

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

24692570
return 0;
24702571
}
24712572

2472-
retval = -ENODEV;
2473-
kfree(s421);
2474-
err3:
2475-
kfree(p7500);
2476-
err2:
2477-
kfree(s660);
2478-
err1:
2479-
kfree(p1100);
2480-
err0:
2481-
return retval;
2573+
return -ENODEV;
24822574
}
24832575

24842576
static void dw2102_disconnect(struct usb_interface *intf)

0 commit comments

Comments
 (0)