linux-stable/drivers/mtd/ubi
Zhihao Cheng 06aa51f617 ubi: check kthread_should_stop() after the setting of task state
commit d005f8c658 upstream.

A detach hung is possible when a race occurs between the detach process
and the ubi background thread. The following sequences outline the race:

  ubi thread: if (list_empty(&ubi->works)...

  ubi detach: set_bit(KTHREAD_SHOULD_STOP, &kthread->flags)
              => by kthread_stop()
              wake_up_process()
              => ubi thread is still running, so 0 is returned

  ubi thread: set_current_state(TASK_INTERRUPTIBLE)
              schedule()
              => ubi thread will never be scheduled again

  ubi detach: wait_for_completion()
              => hung task!

To fix that, we need to check kthread_should_stop() after we set the
task state, so the ubi thread will either see the stop bit and exit or
the task state is reset to runnable such that it isn't scheduled out
indefinitely.

Signed-off-by: Zhihao Cheng <chengzhihao1@huawei.com>
Cc: <stable@vger.kernel.org>
Fixes: 801c135ce7 ("UBI: Unsorted Block Images")
Reported-by: syzbot+853639d0cb16c31c7a14@syzkaller.appspotmail.com
Signed-off-by: Richard Weinberger <richard@nod.at>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2020-11-05 11:07:03 +01:00
..
attach.c
block.c
build.c
cdev.c
debug.c ubi: Fix seq_file usage in detailed_erase_block_info debugfs file 2020-05-27 16:42:53 +02:00
debug.h
eba.c
fastmap-wl.c
fastmap.c ubi: Fix an error pointer dereference in error handling code 2020-02-14 16:32:18 -05:00
gluebi.c
io.c
kapi.c
Kconfig
Makefile
misc.c
ubi-media.h
ubi.h
upd.c
vmt.c
vtbl.c
wl.c ubi: check kthread_should_stop() after the setting of task state 2020-11-05 11:07:03 +01:00
wl.h