Skip to contentSkip to conversation

mtd: parsers: Fix potential memory leak in mtd_parser_tplink_safeloader_parse()

PATCH RESEND Applied Yuan Can 3 participants 4 messages Dec 8, 2022 – Jan 2, 2023 Memory technology devices (MTD)

lore
Share & tools
lore

Yuan Can

author
#0 lore raw

PATCH RESEND v2 1/1 mtd: parsers: Fix potential memory leak in mtd_parser_tplink_safeloader_parse()

The parts needs to be freed with all its elements, otherwise it will be leaked.

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

---
Changes in v2:
- Add a new label err_free_parts and jumps to it when mtd_parser_tplink_safeloader_read_table() failed to avoid leaking parts.

 drivers/mtd/parsers/tplink_safeloader.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
drivers/mtd/parsers/tplink_safeloader.c +3 -1
index f601e7bd8627..1c689dafca2a 100644
@@ -91,7 +91,7 @@ static int mtd_parser_tplink_safeloader_parse(struct mtd_info *mtd,
 	buf = mtd_parser_tplink_safeloader_read_table(mtd);
 	if (!buf) {
 		err = -ENOENT;
-		goto err_out;
+		goto err_free_parts;
 	}
 
 	for (idx = 0, offset = TPLINK_SAFELOADER_DATA_OFFSET;
@@ -118,6 +118,8 @@ static int mtd_parser_tplink_safeloader_parse(struct mtd_info *mtd,
 err_free:
 	for (idx -= 1; idx >= 0; idx--)
 		kfree(parts[idx].name);
+err_free_parts:
+	kfree(parts);
 err_out:
 	return err;
 };
Signature · 6 lines
2.17.1


______________________________________________________
Linux MTD discussion mailing list
http://lists.infradead.org/mailman/listinfo/linux-mtd/
Reviewed-by on v2 1/1
#1 lore raw
Quoted 10 lines · Yuan Can

The parts needs to be freed with all its elements, otherwise it will be leaked.

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

---
Changes in v2:
- Add a new label err_free_parts and jumps to it when mtd_parser_tplink_safeloader_read_table() failed to avoid leaking parts.

This is the same code as v2 but with an explanation added.

I spotted that the explanation was missing but knew what the explanation was so I didn't mention it. For me, a lot of patches have minor flaws and if I complained about everything the whole kernel development process would grind to a halt. Greg is more picky about explanations for new versions because he has to deal with a lot of patches and because he is trying to teach newbies how to follow the process.

Although minutes ago I just criticized someone else for not putting the note under the cut off but that's because I had no idea why they were resending.

Next time please avoid putting RESEND in the subject because that means there was no changes because your patch was perfect as-is. Instead put v3:

v2: blah blah
v3: add this explanatory message.

But don't do that in this case, for now the patch is fine. :P I'm just telling you the process for next time.

regards,
dan carpenter

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

author
#2 lore raw
Quoted 30 lines · Dan Carpenter
Quoted 10 lines · Yuan Can

The parts needs to be freed with all its elements, otherwise it will be leaked.

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

---
Changes in v2:
- Add a new label err_free_parts and jumps to it when mtd_parser_tplink_safeloader_read_table() failed to avoid leaking parts.

This is the same code as v2 but with an explanation added.

I spotted that the explanation was missing but knew what the explanation was so I didn't mention it. For me, a lot of patches have minor flaws and if I complained about everything the whole kernel development process would grind to a halt. Greg is more picky about explanations for new versions because he has to deal with a lot of patches and because he is trying to teach newbies how to follow the process.

Although minutes ago I just criticized someone else for not putting the note under the cut off but that's because I had no idea why they were resending.

Next time please avoid putting RESEND in the subject because that means there was no changes because your patch was perfect as-is. Instead put v3:

Quoted 5 lines

v2: blah blah
v3: add this explanatory message.

But don't do that in this case, for now the patch is fine. :P I'm just telling you the process for next time.

Ok, thanks for your explanation!

Signature · 7 lines
Best regards,
Yuan Can


______________________________________________________
Linux MTD discussion mailing list
http://lists.infradead.org/mailman/listinfo/linux-mtd/
maintainer Applied
#3 lore raw
In reply to Yuan Can
Quoted 6 lines · Yuan Can

The parts needs to be freed with all its elements, otherwise it will be leaked.

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

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

Miquel

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