Skip to content

Commit aa5ad3b

Browse files
richardweinbergerdedekind
authored andcommitted
UBI: Fix double free after do_sync_erase()
If the erase worker is unable to erase a PEB it will free the ubi_wl_entry itself. The failing ubi_wl_entry must not free()'d again after do_sync_erase() returns. Cc: <[email protected]> Signed-off-by: Richard Weinberger <[email protected]> Signed-off-by: Artem Bityutskiy <[email protected]>
1 parent a76284e commit aa5ad3b

File tree

1 file changed

+3
-7
lines changed

1 file changed

+3
-7
lines changed

drivers/mtd/ubi/wl.c

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1216,7 +1216,6 @@ static int wear_leveling_worker(struct ubi_device *ubi, struct ubi_work *wrk,
12161216

12171217
err = do_sync_erase(ubi, e1, vol_id, lnum, 0);
12181218
if (err) {
1219-
kmem_cache_free(ubi_wl_entry_slab, e1);
12201219
if (e2)
12211220
kmem_cache_free(ubi_wl_entry_slab, e2);
12221221
goto out_ro;
@@ -1230,10 +1229,8 @@ static int wear_leveling_worker(struct ubi_device *ubi, struct ubi_work *wrk,
12301229
dbg_wl("PEB %d (LEB %d:%d) was put meanwhile, erase",
12311230
e2->pnum, vol_id, lnum);
12321231
err = do_sync_erase(ubi, e2, vol_id, lnum, 0);
1233-
if (err) {
1234-
kmem_cache_free(ubi_wl_entry_slab, e2);
1232+
if (err)
12351233
goto out_ro;
1236-
}
12371234
}
12381235

12391236
dbg_wl("done");
@@ -1269,10 +1266,9 @@ static int wear_leveling_worker(struct ubi_device *ubi, struct ubi_work *wrk,
12691266

12701267
ubi_free_vid_hdr(ubi, vid_hdr);
12711268
err = do_sync_erase(ubi, e2, vol_id, lnum, torture);
1272-
if (err) {
1273-
kmem_cache_free(ubi_wl_entry_slab, e2);
1269+
if (err)
12741270
goto out_ro;
1275-
}
1271+
12761272
mutex_unlock(&ubi->move_mutex);
12771273
return 0;
12781274

0 commit comments

Comments
 (0)