Skip to content
This repository was archived by the owner on Jan 12, 2024. It is now read-only.

Commit d780ee8

Browse files
Pratham PratapGerrit - the friendly Code Review server
Pratham Pratap
authored and
Gerrit - the friendly Code Review server
committed
usb: dwc3: dbm: Fix double free in msm_dbm_probe
Memory allocated with devm_kzalloc is automatically released by the kernel if the probe function fails with an error code. Therefore, using kfree is unsafe since it can lead to the Double-Free security issue. This change removes kfree from msm_dbm_probe function to avoid double free for dbm_data. Change-Id: I512284d021ba89d5d04a6d498aa17489e37bff2e Signed-off-by: Pratham Pratap <[email protected]>
1 parent abd940c commit d780ee8

File tree

2 files changed

+8
-46
lines changed

2 files changed

+8
-46
lines changed

drivers/usb/dwc3/dbm-1_4.c

+4-23
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2012-2014, The Linux Foundation. All rights reserved.
2+
* Copyright (c) 2012-2014, 2018 The Linux Foundation. All rights reserved.
33
*
44
* This program is free software; you can redistribute it and/or modify
55
* it under the terms of the GNU General Public License version 2 and
@@ -372,7 +372,6 @@ static int msm_dbm_probe(struct platform_device *pdev)
372372
struct device *dev = &pdev->dev;
373373
struct dbm *dbm;
374374
struct resource *res;
375-
int ret = 0;
376375

377376
dbm_data = devm_kzalloc(dev, sizeof(*dbm_data), GFP_KERNEL);
378377
if (!dbm_data)
@@ -382,24 +381,21 @@ static int msm_dbm_probe(struct platform_device *pdev)
382381
res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
383382
if (!res) {
384383
dev_err(&pdev->dev, "missing memory base resource\n");
385-
ret = -ENODEV;
386-
goto free_dbm_data;
384+
return -ENODEV;
387385
}
388386

389387
dbm_data->base = devm_ioremap_nocache(&pdev->dev, res->start,
390388
resource_size(res));
391389
if (!dbm_data->base) {
392390
dev_err(&pdev->dev, "ioremap failed\n");
393-
ret = -ENOMEM;
394-
goto free_dbm_data;
391+
return -ENOMEM;
395392
}
396393

397394

398395
dbm = devm_kzalloc(dev, sizeof(*dbm), GFP_KERNEL);
399396
if (!dbm) {
400397
dev_err(&pdev->dev, "not enough memory\n");
401-
ret = -ENOMEM;
402-
goto free_dbm_data;
398+
return -ENOMEM;
403399
}
404400

405401
dbm->dev = dev;
@@ -418,20 +414,6 @@ static int msm_dbm_probe(struct platform_device *pdev)
418414
platform_set_drvdata(pdev, dbm);
419415

420416
return usb_add_dbm(dbm);
421-
422-
free_dbm_data:
423-
kfree(dbm_data);
424-
return ret;
425-
}
426-
427-
static int msm_dbm_remove(struct platform_device *pdev)
428-
{
429-
struct dbm *dbm = platform_get_drvdata(pdev);
430-
431-
kfree(dbm);
432-
kfree(dbm_data);
433-
434-
return 0;
435417
}
436418

437419
static const struct of_device_id msm_dbm_1_4_id_table[] = {
@@ -444,7 +426,6 @@ MODULE_DEVICE_TABLE(of, msm_dbm_1_4_id_table);
444426

445427
static struct platform_driver msm_dbm_driver = {
446428
.probe = msm_dbm_probe,
447-
.remove = msm_dbm_remove,
448429
.driver = {
449430
.name = "msm-usb-dbm-1-4",
450431
.of_match_table = of_match_ptr(msm_dbm_1_4_id_table),

drivers/usb/dwc3/dbm-1_5.c

+4-23
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2012-2014, The Linux Foundation. All rights reserved.
2+
* Copyright (c) 2012-2015, 2018 The Linux Foundation. All rights reserved.
33
*
44
* This program is free software; you can redistribute it and/or modify
55
* it under the terms of the GNU General Public License version 2 and
@@ -387,7 +387,6 @@ static int msm_dbm_probe(struct platform_device *pdev)
387387
struct device_node *node = pdev->dev.of_node;
388388
struct dbm *dbm;
389389
struct resource *res;
390-
int ret = 0;
391390

392391
dbm_data = devm_kzalloc(dev, sizeof(*dbm_data), GFP_KERNEL);
393392
if (!dbm_data)
@@ -397,24 +396,21 @@ static int msm_dbm_probe(struct platform_device *pdev)
397396
res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
398397
if (!res) {
399398
dev_err(&pdev->dev, "missing memory base resource\n");
400-
ret = -ENODEV;
401-
goto free_dbm_data;
399+
return -ENODEV;
402400
}
403401

404402
dbm_data->base = devm_ioremap_nocache(&pdev->dev, res->start,
405403
resource_size(res));
406404
if (!dbm_data->base) {
407405
dev_err(&pdev->dev, "ioremap failed\n");
408-
ret = -ENOMEM;
409-
goto free_dbm_data;
406+
return -ENOMEM;
410407
}
411408

412409

413410
dbm = devm_kzalloc(dev, sizeof(*dbm), GFP_KERNEL);
414411
if (!dbm) {
415412
dev_err(&pdev->dev, "not enough memory\n");
416-
ret = -ENOMEM;
417-
goto free_dbm_data;
413+
return -ENOMEM;
418414
}
419415

420416
dbm_data->dbm_reset_ep_after_lpm = of_property_read_bool(node,
@@ -437,20 +433,6 @@ static int msm_dbm_probe(struct platform_device *pdev)
437433
platform_set_drvdata(pdev, dbm);
438434

439435
return usb_add_dbm(dbm);
440-
441-
free_dbm_data:
442-
kfree(dbm_data);
443-
return ret;
444-
}
445-
446-
static int msm_dbm_remove(struct platform_device *pdev)
447-
{
448-
struct dbm *dbm = platform_get_drvdata(pdev);
449-
450-
kfree(dbm);
451-
kfree(dbm_data);
452-
453-
return 0;
454436
}
455437

456438
static const struct of_device_id msm_dbm_1_5_id_table[] = {
@@ -463,7 +445,6 @@ MODULE_DEVICE_TABLE(of, msm_dbm_1_5_id_table);
463445

464446
static struct platform_driver msm_dbm_driver = {
465447
.probe = msm_dbm_probe,
466-
.remove = msm_dbm_remove,
467448
.driver = {
468449
.name = "msm-usb-dbm-1-5",
469450
.of_match_table = of_match_ptr(msm_dbm_1_5_id_table),

0 commit comments

Comments
 (0)