Skip to contentSkip to conversation

mtd: parsers: tplink_safeloader: fix uninitialized variable bug

PATCH Applied Dan Carpenter 3 participants 7 messages Oct 25, 2022 – Nov 7, 2022 1 message not in the archive

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 mtd: parsers: tplink_safeloader: fix uninitialized variable bug

On 64 bit systems, the highest 32 bits of the "offset" variable are not initialized. Also the existing code is not endian safe (it will fail on big endian systems). Change the type of "offset" to a u32.

Fixes aec4d5f5ffd0 ("mtd: parsers: add TP-Link SafeLoader partitions table parser")
---
 drivers/mtd/parsers/tplink_safeloader.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
drivers/mtd/parsers/tplink_safeloader.c +3 -3
index 23584a477391..f601e7bd8627 100644
@@ -23,8 +23,8 @@ static void *mtd_parser_tplink_safeloader_read_table(struct mtd_info *mtd)
 	struct safeloader_cmn_header hdr;
 	struct device_node *np;
 	size_t bytes_read;
-	size_t offset;
 	size_t size;
+	u32 offset;
 	char *buf;
 	int err;
 
@@ -34,14 +34,14 @@ static void *mtd_parser_tplink_safeloader_read_table(struct mtd_info *mtd)
 	else
 		np = of_get_child_by_name(np, "partitions");
 
-	if (of_property_read_u32(np, "partitions-table-offset", (u32 *)&offset)) {
+	if (of_property_read_u32(np, "partitions-table-offset", &offset)) {
 		pr_err("Failed to get partitions table offset\n");
 		goto err_put;
 	}
 
 	err = mtd_read(mtd, offset, sizeof(hdr), &bytes_read, (uint8_t *)&hdr);
 	if (err && !mtd_is_bitflip(err)) {
-		pr_err("Failed to read from %s at 0x%zx\n", mtd->name, offset);
+		pr_err("Failed to read from %s at 0x%x\n", mtd->name, offset);
 		goto err_put;
 	}
 
Signature · 6 lines
2.35.1


______________________________________________________
Linux MTD discussion mailing list
http://lists.infradead.org/mailman/listinfo/linux-mtd/
Acked-by on v1 1/1
#1 lore raw
Quoted 6 lines · Dan Carpenter

On 64 bit systems, the highest 32 bits of the "offset" variable are not initialized. Also the existing code is not endian safe (it will fail on big endian systems). Change the type of "offset" to a u32.

Fixes aec4d5f5ffd0 ("mtd: parsers: add TP-Link SafeLoader partitions table parser")

Thanks

Quoted 25 lines
---
  drivers/mtd/parsers/tplink_safeloader.c | 6 +++---
  1 file changed, 3 insertions(+), 3 deletions(-)
drivers/mtd/parsers/tplink_safeloader.c +2 -2
index 23584a477391..f601e7bd8627 100644
@@ -23,8 +23,8 @@ static void *mtd_parser_tplink_safeloader_read_table(struct mtd_info *mtd)
  	struct safeloader_cmn_header hdr;
  	struct device_node *np;
  	size_t bytes_read;
-	size_t offset;
  	size_t size;
+	u32 offset;
  	char *buf;
  	int err;
 
@@ -34,14 +34,14 @@ static void *mtd_parser_tplink_safeloader_read_table(struct mtd_info *mtd)
  	else
  		np = of_get_child_by_name(np, "partitions");
 
-	if (of_property_read_u32(np, "partitions-table-offset", (u32 *)&offset)) {
+	if (of_property_read_u32(np, "partitions-table-offset", &offset)) {
  		pr_err("Failed to get partitions table offset\n");

drivers/mtd/parsers/tplink_safeloader.c static void *mtd_parser_tplink_safeloader_read_table(struct mtd_info *mtd) · line 47

Quoted 10 lines
drivers/mtd/parsers/tplink_safeloader.c +1 -1
  		goto err_put;
  	}
 
  	err = mtd_read(mtd, offset, sizeof(hdr), &bytes_read, (uint8_t *)&hdr);
  	if (err && !mtd_is_bitflip(err)) {
-		pr_err("Failed to read from %s at 0x%zx\n", mtd->name, offset);
+		pr_err("Failed to read from %s at 0x%x\n", mtd->name, offset);
  		goto err_put;
  	}
 

______________________________________________________
Linux MTD discussion mailing list
http://lists.infradead.org/mailman/listinfo/linux-mtd/

A message that is not in the archive (sent off-list or not yet received): MN2PR17MB33758BC764511BB48B64192AB8319@MN2PR17MB3375.namprd17.prod.outlook.com

#3 lore raw
Quoted 1 line · Vanessa Page

On its 64 dysfunctional delusional system

Hey Venessa,

I had been told you were removed from the [email protected] list but I guess not. I've sent you an unsubscribe email, if you just click on the URL then you won't get these emails any more.

regards,
dan carpenter

maintainer
#4 lore raw
In reply to Dan Carpenter

Hi Dan,

[email protected] wrote on Tue, 25 Oct 2022 18:34:24 +0300:

drivers/mtd/parsers/tplink_safeloader.c

Quoted 14 lines

On 64 bit systems, the highest 32 bits of the "offset" variable are not initialized. Also the existing code is not endian safe (it will fail on big endian systems). Change the type of "offset" to a u32.

Fixes aec4d5f5ffd0 ("mtd: parsers: add TP-Link SafeLoader partitions table parser")
---
 drivers/mtd/parsers/tplink_safeloader.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
drivers/mtd/parsers/tplink_safeloader.c +0 -0
index 23584a477391..f601e7bd8627 100644

I am sorry but I don't have this file in my tree, what kernel are you using?

Quoted 17 lines
drivers/mtd/parsers/tplink_safeloader.c +2 -2
@@ -23,8 +23,8 @@ static void *mtd_parser_tplink_safeloader_read_table(struct mtd_info *mtd)
 	struct safeloader_cmn_header hdr;
 	struct device_node *np;
 	size_t bytes_read;
-	size_t offset;
 	size_t size;
+	u32 offset;
 	char *buf;
 	int err;
 
@@ -34,14 +34,14 @@ static void *mtd_parser_tplink_safeloader_read_table(struct mtd_info *mtd)
 	else
 		np = of_get_child_by_name(np, "partitions");
 
-	if (of_property_read_u32(np, "partitions-table-offset", (u32 *)&offset)) {
+	if (of_property_read_u32(np, "partitions-table-offset", &offset)) {
 		pr_err("Failed to get partitions table offset\n");

drivers/mtd/parsers/tplink_safeloader.c static void *mtd_parser_tplink_safeloader_read_table(struct mtd_info *mtd) · line 47

Quoted 10 lines
drivers/mtd/parsers/tplink_safeloader.c +1 -1
 		goto err_put;
 	}
 
 	err = mtd_read(mtd, offset, sizeof(hdr), &bytes_read, (uint8_t *)&hdr);
 	if (err && !mtd_is_bitflip(err)) {
-		pr_err("Failed to read from %s at 0x%zx\n", mtd->name, offset);
+		pr_err("Failed to read from %s at 0x%x\n", mtd->name, offset);
 		goto err_put;
 	}
 

Thanks,
Miquèl

#5 lore raw
Quoted 14 lines · Miquel Raynal

Hi Dan,

[email protected] wrote on Tue, 25 Oct 2022 18:34:24 +0300:

Quoted 10 lines

On 64 bit systems, the highest 32 bits of the "offset" variable are not initialized. Also the existing code is not endian safe (it will fail on big endian systems). Change the type of "offset" to a u32.

Fixes aec4d5f5ffd0 ("mtd: parsers: add TP-Link SafeLoader partitions table parser")
---
  drivers/mtd/parsers/tplink_safeloader.c | 6 +++---
  1 file changed, 3 insertions(+), 3 deletions(-)
Quoted 7 lines

drivers/mtd/parsers/tplink_safeloader.c

Quoted 4 lines
drivers/mtd/parsers/tplink_safeloader.c +0 -0
index 23584a477391..f601e7bd8627 100644

I am sorry but I don't have this file in my tree, what kernel are you using?

https://git.kernel.org/pub/scm/linux/kernel/git/mtd/linux.git/log/?h=mtd/next
https://git.kernel.org/pub/scm/linux/kernel/git/mtd/linux.git/commit/?h=mtd/next&id=aec4d5f5ffd0f0092bd9dc21ea90e0bc237d4b74

(committer Miquel Raynal ;) )

Quoted 20 lines
Quoted 20 lines
drivers/mtd/parsers/tplink_safeloader.c +2 -2
@@ -23,8 +23,8 @@ static void *mtd_parser_tplink_safeloader_read_table(struct mtd_info *mtd)
  	struct safeloader_cmn_header hdr;
  	struct device_node *np;
  	size_t bytes_read;
-	size_t offset;
  	size_t size;
+	u32 offset;
  	char *buf;
  	int err;
 
@@ -34,14 +34,14 @@ static void *mtd_parser_tplink_safeloader_read_table(struct mtd_info *mtd)
  	else
  		np = of_get_child_by_name(np, "partitions");
 
-	if (of_property_read_u32(np, "partitions-table-offset", (u32 *)&offset)) {
+	if (of_property_read_u32(np, "partitions-table-offset", &offset)) {
  		pr_err("Failed to get partitions table offset\n");
  		goto err_put;
  	}
 
Quoted 7 lines

drivers/mtd/parsers/tplink_safeloader.c static void *mtd_parser_tplink_safeloader_read_table(struct mtd_info *mtd) · line 47

Quoted 7 lines
drivers/mtd/parsers/tplink_safeloader.c +1 -1
  	err = mtd_read(mtd, offset, sizeof(hdr), &bytes_read, (uint8_t *)&hdr);
  	if (err && !mtd_is_bitflip(err)) {
-		pr_err("Failed to read from %s at 0x%zx\n", mtd->name, offset);
+		pr_err("Failed to read from %s at 0x%x\n", mtd->name, offset);
  		goto err_put;
  	}
 

______________________________________________________
Linux MTD discussion mailing list
http://lists.infradead.org/mailman/listinfo/linux-mtd/

maintainer
#6 lore raw

[email protected] wrote on Mon, 7 Nov 2022 17:01:04 +0100:

Quoted 23 lines · Miquel Raynal
Quoted 14 lines

Hi Dan,

[email protected] wrote on Tue, 25 Oct 2022 18:34:24 +0300:

Quoted 10 lines

On 64 bit systems, the highest 32 bits of the "offset" variable are not initialized. Also the existing code is not endian safe (it will fail on big endian systems). Change the type of "offset" to a u32.

Fixes aec4d5f5ffd0 ("mtd: parsers: add TP-Link SafeLoader partitions table parser")
---
  drivers/mtd/parsers/tplink_safeloader.c | 6 +++---
  1 file changed, 3 insertions(+), 3 deletions(-)
Quoted 7 lines

drivers/mtd/parsers/tplink_safeloader.c

Quoted 4 lines
drivers/mtd/parsers/tplink_safeloader.c +0 -0
index 23584a477391..f601e7bd8627 100644

I am sorry but I don't have this file in my tree, what kernel are you using?

Quoted 4 lines

https://git.kernel.org/pub/scm/linux/kernel/git/mtd/linux.git/log/?h=mtd/next
https://git.kernel.org/pub/scm/linux/kernel/git/mtd/linux.git/commit/?h=mtd/next&id=aec4d5f5ffd0f0092bd9dc21ea90e0bc237d4b74

(committer Miquel Raynal ;) )

Ah, I knew I was missing something: the right branch. :-)

Thanks,
Miquèl

maintainer Applied
#7 lore raw
In reply to Dan Carpenter
Quoted 7 lines · Dan Carpenter

On 64 bit systems, the highest 32 bits of the "offset" variable are not initialized. Also the existing code is not endian safe (it will fail on big endian systems). Change the type of "offset" to a u32.

Fixes aec4d5f5ffd0 ("mtd: parsers: add TP-Link SafeLoader partitions table parser")

Applied to https://git.kernel.org/pub/scm/linux/kernel/git/mtd/linux.git mtd/next, thanks.

Miquel