summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFedor Pchelkin <pchelkin@ispras.ru>2024-02-29 23:42:36 +0300
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>2024-08-03 09:49:38 +0300
commitadb7146d1758daa0592a846922368a68cb5dc9cf (patch)
tree066626fe6fc404943a3bfbb92873f089975303e9
parentfcc70ce1c7e71a53de0630bd5c596cd4b7180432 (diff)
downloadlinux-adb7146d1758daa0592a846922368a68cb5dc9cf.tar.xz
ubi: eba: properly rollback inside self_check_eba
commit 745d9f4a31defec731119ee8aad8ba9f2536dd9a upstream. In case of a memory allocation failure in the volumes loop we can only process the already allocated scan_eba and fm_eba array elements on the error path - others are still uninitialized. Found by Linux Verification Center (linuxtesting.org). Fixes: 00abf3041590 ("UBI: Add self_check_eba()") Cc: stable@vger.kernel.org Signed-off-by: Fedor Pchelkin <pchelkin@ispras.ru> Reviewed-by: Zhihao Cheng <chengzhihao1@huawei.com> Signed-off-by: Richard Weinberger <richard@nod.at> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
-rw-r--r--drivers/mtd/ubi/eba.c3
1 files changed, 2 insertions, 1 deletions
diff --git a/drivers/mtd/ubi/eba.c b/drivers/mtd/ubi/eba.c
index 4e1d80746b04..38f41ce72b6a 100644
--- a/drivers/mtd/ubi/eba.c
+++ b/drivers/mtd/ubi/eba.c
@@ -1560,6 +1560,7 @@ int self_check_eba(struct ubi_device *ubi, struct ubi_attach_info *ai_fastmap,
GFP_KERNEL);
if (!fm_eba[i]) {
ret = -ENOMEM;
+ kfree(scan_eba[i]);
goto out_free;
}
@@ -1595,7 +1596,7 @@ int self_check_eba(struct ubi_device *ubi, struct ubi_attach_info *ai_fastmap,
}
out_free:
- for (i = 0; i < num_volumes; i++) {
+ while (--i >= 0) {
if (!ubi->volumes[i])
continue;