Commit e57e0d8e authored by Artem Bityutskiy's avatar Artem Bityutskiy

UBI: fix use-after-free on error path

When we fail to erase a PEB, we free the corresponding erase entry object,
but then re-schedule this object if the error code was something like -EAGAIN.
Obviously, it is a bug to use the object after we have freed it.
Reported-by: default avatarEmese Revfy <re.emese@gmail.com>
Cc: stable@kernel.org [v2.6.23+]
Signed-off-by: default avatarArtem Bityutskiy <artem.bityutskiy@linux.intel.com>
parent e801e128
...@@ -1052,7 +1052,6 @@ static int erase_worker(struct ubi_device *ubi, struct ubi_work *wl_wrk, ...@@ -1052,7 +1052,6 @@ static int erase_worker(struct ubi_device *ubi, struct ubi_work *wl_wrk,
ubi_err("failed to erase PEB %d, error %d", pnum, err); ubi_err("failed to erase PEB %d, error %d", pnum, err);
kfree(wl_wrk); kfree(wl_wrk);
kmem_cache_free(ubi_wl_entry_slab, e);
if (err == -EINTR || err == -ENOMEM || err == -EAGAIN || if (err == -EINTR || err == -ENOMEM || err == -EAGAIN ||
err == -EBUSY) { err == -EBUSY) {
...@@ -1065,14 +1064,16 @@ static int erase_worker(struct ubi_device *ubi, struct ubi_work *wl_wrk, ...@@ -1065,14 +1064,16 @@ static int erase_worker(struct ubi_device *ubi, struct ubi_work *wl_wrk,
goto out_ro; goto out_ro;
} }
return err; return err;
} else if (err != -EIO) { }
kmem_cache_free(ubi_wl_entry_slab, e);
if (err != -EIO)
/* /*
* If this is not %-EIO, we have no idea what to do. Scheduling * If this is not %-EIO, we have no idea what to do. Scheduling
* this physical eraseblock for erasure again would cause * this physical eraseblock for erasure again would cause
* errors again and again. Well, lets switch to R/O mode. * errors again and again. Well, lets switch to R/O mode.
*/ */
goto out_ro; goto out_ro;
}
/* It is %-EIO, the PEB went bad */ /* It is %-EIO, the PEB went bad */
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment