Skip to contentSkip to conversation

UBI: potential leak in ubi_scan_erase_peb

PATCH In review Florin Malita 2 participants 2 messages Jul 19, 2007 – Jul 20, 2007

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

PATCH 1/1 UBI: potential leak in ubi_scan_erase_peb

Coverity (1769) found the following problem: if the erase counter overflow check triggers, ec_hdr is leaked.

Moving the allocation after the overflow check should take care of it.

---

drivers/mtd/ubi/scan.c | 8 ++++----

1 file changed, 4 insertions(+), 4 deletions(-)
drivers/mtd/ubi/scan.c +0 -0
index 94ee549..80c73d8 100644
@@ -673,10 +673,6 @@ int ubi_scan_erase_peb(const struct ubi_device *ubi,
	int err;
	struct ubi_ec_hdr *ec_hdr;

- ec_hdr = kzalloc(ubi->ec_hdr_alsize, GFP_KERNEL);
- if (!ec_hdr)
- return -ENOMEM;
-

	if ((long long)ec >= UBI_MAX_ERASECOUNTER) {
		/*
		 * Erase counter overflow. Upgrade UBI and use 64-bit
@@ -686,6 +682,10 @@ int ubi_scan_erase_peb(const struct ubi_device *ubi,
		return -EINVAL;
	}

+ ec_hdr = kzalloc(ubi->ec_hdr_alsize, GFP_KERNEL);
+ if (!ec_hdr)
+ return -ENOMEM;
+

	ec_hdr->ec = cpu_to_be64(ec);

	err = ubi_io_sync_erase(ubi, pnum, 0);
#1 lore raw
Quoted 6 lines · Florin Malita

Coverity (1769) found the following problem: if the erase counter overflow check triggers, ec_hdr is leaked.

Moving the allocation after the overflow check should take care of it.

Committed, thank you!

Signature · 2 lines
Best regards,
Artem Bityutskiy (Битюцкий Артём)