Re: [PATCH 4.4 23/97] ubi: fastmap: Dont flush fastmap work on detach

From: Ben Hutchings
Date: Wed May 16 2018 - 12:21:35 EST


On Sun, 2018-04-22 at 15:53 +0200, Greg Kroah-Hartman wrote:
> 4.4-stable review patch.ÂÂIf anyone has any objections, please let me know.
>
> ------------------
>
> From: Richard Weinberger <richard@xxxxxx>
>
> commit 29b7a6fa1ec07e8480b0d9caf635a4498a438bf4 upstream.
>
> At this point UBI volumes have already been free()'ed and fastmap can no
> longer access these data structures.

I don't see how this change can fix a use-after-free. If this function
can be called with *ubi already freed, then the rest of the function
body is also not safe to run. But I don't think that is the case.

ubi->fm_work doesn't depend on any other structure (except a global
workqueue, which won't go away).

It seems to me that the bug is really a race condition, and removing
the flush_work() makes it harder to hit that condition. The proper fix
would be to call flush_work() (or cancel_work_sync()) before the UBI
volumes are freed.

Ben.

> Reported-by: Martin Townsend <mtownsend1973@xxxxxxxxx>
> Fixes: 74cdaf24004a ("UBI: Fastmap: Fix memory leaks while closing the WL sub-system")
> Cc: stable@xxxxxxxxxxxxxxx
> Signed-off-by: Richard Weinberger <richard@xxxxxx>
> Signed-off-by: Greg Kroah-Hartman <gregkh@xxxxxxxxxxxxxxxxxxx>
>
> ---
> Âdrivers/mtd/ubi/fastmap-wl.c |ÂÂÂÂ1 -
> Â1 file changed, 1 deletion(-)
>
> --- a/drivers/mtd/ubi/fastmap-wl.c
> +++ b/drivers/mtd/ubi/fastmap-wl.c
> @@ -360,7 +360,6 @@ static void ubi_fastmap_close(struct ubi
> Â{
> Â int i;
> Â
> - flush_work(&ubi->fm_work);
> Â return_unused_pool_pebs(ubi, &ubi->fm_pool);
> Â return_unused_pool_pebs(ubi, &ubi->fm_wl_pool);
> Â
>
>
>
--
Ben Hutchings
Software Developer, Codethink Ltd.