Skip to contentSkip to conversation

mtd: lpddr2_nvm: i2c: mux: reg: Fix possible null-ptr-deref

PATCH Superseded Hui Tang 2 participants 3 messages Nov 14, 2022 Memory technology devices (MTD)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore

Hui Tang

author
#0 lore raw

PATCH 1/1 mtd: lpddr2_nvm: i2c: mux: reg: Fix possible null-ptr-deref

It will cause null-ptr-deref when resource_size(add_range) invoked, if platform_get_resource() returns NULL.

Fixes 96ba9dd65788 ("mtd: lpddr: add driver for LPDDR2-NVM PCM memories")
---
 drivers/mtd/lpddr/lpddr2_nvm.c | 2 ++
 1 file changed, 2 insertions(+)
drivers/mtd/lpddr/lpddr2_nvm.c +2 -0
index 367e2d906de0..cf8e86eb4b2c 100644
@@ -433,6 +433,8 @@ static int lpddr2_nvm_probe(struct platform_device *pdev)
 
 	/* lpddr2_nvm address range */
 	add_range = platform_get_resource(pdev, IORESOURCE_MEM, 0);
+	if (IS_ERR(add_range))
+		return -ENODEV;
 
 	/* Populate map_info data structure */
 	*map = (struct map_info) {
Signature · 1 line
2.17.1
maintainer
#1 lore raw

Hi Hui,

[email protected] wrote on Mon, 14 Nov 2022 10:01:41 +0800:

Quoted 14 lines

It will cause null-ptr-deref when resource_size(add_range) invoked, if platform_get_resource() returns NULL.

Fixes 96ba9dd65788 ("mtd: lpddr: add driver for LPDDR2-NVM PCM memories")
---
 drivers/mtd/lpddr/lpddr2_nvm.c | 2 ++
 1 file changed, 2 insertions(+)
drivers/mtd/lpddr/lpddr2_nvm.c +0 -0
index 367e2d906de0..cf8e86eb4b2c 100644

drivers/mtd/lpddr/lpddr2_nvm.c static int lpddr2_nvm_probe(struct platform_device *pdev) · line 436

Quoted 4 lines
drivers/mtd/lpddr/lpddr2_nvm.c +1 -0
@@ -433,6 +433,8 @@ static int lpddr2_nvm_probe(struct platform_device *pdev)
 
 	/* lpddr2_nvm address range */
 	add_range = platform_get_resource(pdev, IORESOURCE_MEM, 0);
+	if (IS_ERR(add_range))

platform_get_resource() just returns NULL upon error.

drivers/mtd/lpddr/lpddr2_nvm.c static int lpddr2_nvm_probe(struct platform_device *pdev) · line 440

Quoted 4 lines
drivers/mtd/lpddr/lpddr2_nvm.c +1 -0
+		return -ENODEV;
 
 	/* Populate map_info data structure */
 	*map = (struct map_info) {

Thanks,
Miquèl

author
#2 lore raw
Quoted 19 lines · Miquel Raynal

Hi Hui,

[email protected] wrote on Mon, 14 Nov 2022 10:01:41 +0800:

Quoted 15 lines

It will cause null-ptr-deref when resource_size(add_range) invoked, if platform_get_resource() returns NULL.

Fixes 96ba9dd65788 ("mtd: lpddr: add driver for LPDDR2-NVM PCM memories")
---
 drivers/mtd/lpddr/lpddr2_nvm.c | 2 ++
 1 file changed, 2 insertions(+)
drivers/mtd/lpddr/lpddr2_nvm.c +0 -0
index 367e2d906de0..cf8e86eb4b2c 100644
@@ -433,6 +433,8 @@ static int lpddr2_nvm_probe(struct platform_device *pdev)
 
Quoted 5 lines

drivers/mtd/lpddr/lpddr2_nvm.c static int lpddr2_nvm_probe(struct platform_device *pdev) · line 436

Quoted 3 lines
drivers/mtd/lpddr/lpddr2_nvm.c +1 -0
 	/* lpddr2_nvm address range */
 	add_range = platform_get_resource(pdev, IORESOURCE_MEM, 0);
+	if (IS_ERR(add_range))

platform_get_resource() just returns NULL upon error.

Thanks

Quoted 1 line