Skip to content

Commit 745d9f4

Browse files
pchelkin91richardweinberger
authored andcommitted
ubi: eba: properly rollback inside self_check_eba
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: 00abf30 ("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>
1 parent 22a40d1 commit 745d9f4

File tree

1 file changed

+2
-1
lines changed

1 file changed

+2
-1
lines changed

drivers/mtd/ubi/eba.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1564,6 +1564,7 @@ int self_check_eba(struct ubi_device *ubi, struct ubi_attach_info *ai_fastmap,
15641564
GFP_KERNEL);
15651565
if (!fm_eba[i]) {
15661566
ret = -ENOMEM;
1567+
kfree(scan_eba[i]);
15671568
goto out_free;
15681569
}
15691570

@@ -1599,7 +1600,7 @@ int self_check_eba(struct ubi_device *ubi, struct ubi_attach_info *ai_fastmap,
15991600
}
16001601

16011602
out_free:
1602-
for (i = 0; i < num_volumes; i++) {
1603+
while (--i >= 0) {
16031604
if (!ubi->volumes[i])
16041605
continue;
16051606

0 commit comments

Comments
 (0)