Skip to contentSkip to conversation

mtd: inftl: Fix potential table leaks on mount failure

PATCH Applied Guangshuo Li 2 participants 2 messages Nov 11 – Nov 17 Memory technology devices (MTD)

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 mtd: inftl: Fix potential table leaks on mount failure

If the temporary ANAC table allocation fails, the unit tables allocated by find_boot_record() are left behind when the caller frees the INFTL record. Free both tables before returning the error.

This issue was found by our static analysis tool under development.

Fixes 8766af935f3f ("[PATCH] check for failed kmalloc in inftlmount.c")
---
 drivers/mtd/inftlmount.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)
drivers/mtd/inftlmount.c +4 -1
index 87e246a6f488..841ae05bca7b 100644
@@ -551,8 +551,11 @@ int INFTL_mount(struct INFTLrecord *s)
 
 	/* Temporary buffer to store ANAC numbers. */
 	ANACtable = kcalloc(s->nb_blocks, sizeof(u8), GFP_KERNEL);
-	if (!ANACtable)
+	if (!ANACtable) {
+		kfree(s->PUtable);
+		kfree(s->VUtable);
 		return -ENOMEM;
+	}
 
 	/*
 	 * First pass is to explore each physical unit, and construct the

base-commit: 6628e7d4c6b25c8d18f1345e3a20d21829aae7e4

maintainer Applied
#1 lore raw
Quoted 8 lines · Guangshuo Li

If the temporary ANAC table allocation fails, the unit tables allocated by find_boot_record() are left behind when the caller frees the INFTL record. Free both tables before returning the error.

This issue was found by our static analysis tool under development.

[...]

Applied to mtd/next, thanks!

[1/1] mtd: inftl: Fix potential table leaks on mount failure

      commit: dd4e68b5061efb56eea093b6a9b7a6da49efda07

Patche(s) should be available on mtd/linux.git and will be part of the next PR (provided that no robot complains by then).

Kind regards,
Miquèl