Commit f03484f
xc2028: Fix use-after-free bug properly
commit 22a1e7783e173ab3d86018eb590107d68df46c11 upstream.
The commit 8dfbcc4351a0 ("[media] xc2028: avoid use after free") tried
to address the reported use-after-free by clearing the reference.
However, it's clearing the wrong pointer; it sets NULL to
priv->ctrl.fname, but it's anyway overwritten by the next line
memcpy(&priv->ctrl, p, sizeof(priv->ctrl)).
OTOH, the actual code accessing the freed string is the strcmp() call
with priv->fname:
if (!firmware_name[0] && p->fname &&
priv->fname && strcmp(p->fname, priv->fname))
free_firmware(priv);
where priv->fname points to the previous file name, and this was
already freed by kfree().
For fixing the bug properly, this patch does the following:
- Keep the copy of firmware file name in only priv->fname,
priv->ctrl.fname isn't changed;
- The allocation is done only when the firmware gets loaded;
- The kfree() is called in free_firmware() commonly
Fixes: commit 8dfbcc4351a0 ('[media] xc2028: avoid use after free')
Signed-off-by: Takashi Iwai <tiwai@suse.de>
Signed-off-by: Mauro Carvalho Chehab <mchehab@s-opensource.com>
Signed-off-by: Amit Pundir <amit.pundir@linaro.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>1 parent e0188a5 commit f03484f
1 file changed
Lines changed: 16 additions & 21 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
281 | 281 | | |
282 | 282 | | |
283 | 283 | | |
| 284 | + | |
| 285 | + | |
| 286 | + | |
| 287 | + | |
| 288 | + | |
| 289 | + | |
| 290 | + | |
| 291 | + | |
284 | 292 | | |
285 | 293 | | |
286 | 294 | | |
| |||
291 | 299 | | |
292 | 300 | | |
293 | 301 | | |
294 | | - | |
295 | | - | |
296 | | - | |
297 | 302 | | |
298 | 303 | | |
299 | 304 | | |
| |||
884 | 889 | | |
885 | 890 | | |
886 | 891 | | |
887 | | - | |
| 892 | + | |
888 | 893 | | |
889 | | - | |
890 | 894 | | |
891 | 895 | | |
892 | 896 | | |
| |||
1332 | 1336 | | |
1333 | 1337 | | |
1334 | 1338 | | |
1335 | | - | |
| 1339 | + | |
1336 | 1340 | | |
1337 | | - | |
1338 | | - | |
1339 | | - | |
1340 | 1341 | | |
1341 | 1342 | | |
1342 | 1343 | | |
| |||
1399 | 1400 | | |
1400 | 1401 | | |
1401 | 1402 | | |
1402 | | - | |
1403 | | - | |
1404 | 1403 | | |
1405 | | - | |
1406 | | - | |
1407 | 1404 | | |
1408 | | - | |
1409 | | - | |
1410 | | - | |
1411 | | - | |
1412 | | - | |
1413 | | - | |
1414 | | - | |
1415 | 1405 | | |
1416 | 1406 | | |
1417 | 1407 | | |
| |||
1426 | 1416 | | |
1427 | 1417 | | |
1428 | 1418 | | |
1429 | | - | |
| 1419 | + | |
1430 | 1420 | | |
1431 | 1421 | | |
1432 | 1422 | | |
| 1423 | + | |
| 1424 | + | |
| 1425 | + | |
| 1426 | + | |
| 1427 | + | |
1433 | 1428 | | |
1434 | 1429 | | |
1435 | 1430 | | |
| |||
0 commit comments