]> www.infradead.org Git - users/dwmw2/linux.git/commitdiff
ubi: eba: properly rollback inside self_check_eba
authorFedor Pchelkin <pchelkin@ispras.ru>
Thu, 29 Feb 2024 20:42:36 +0000 (23:42 +0300)
committerRichard Weinberger <richard@nod.at>
Fri, 12 Jul 2024 17:42:46 +0000 (19:42 +0200)
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>
drivers/mtd/ubi/eba.c

index e5ac3cd0bbae62494846a3514548ff163439163f..c7ba7a15c9f78b6214b245b5e8969c1214fbd4fd 100644 (file)
@@ -1564,6 +1564,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;
                }
 
@@ -1599,7 +1600,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;