kernel_optimize_test/drivers/mtd/ubi
Zhihao Cheng d005f8c658 ubi: check kthread_should_stop() after the setting of task state
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>
2020-09-17 22:55:59 +02:00
..
attach.c mtd: Convert fallthrough comments into statements 2020-03-30 10:14:54 +02:00
block.c
build.c ubi: Relax the 'no MLC' rule and allow MLCs operating in SLC mode 2020-05-11 09:51:42 +02:00
cdev.c
debug.c ubi: Fix seq_file usage in detailed_erase_block_info debugfs file 2020-05-17 23:38:21 +02:00
debug.h
eba.c treewide: Remove uninitialized_var() usage 2020-07-16 12:35:15 -07:00
fastmap-wl.c ubi: fastmap: Free fastmap next anchor peb during detach 2020-08-02 23:56:13 +02:00
fastmap.c ubi: Select fastmap anchor PEBs considering wear level rules 2020-06-02 22:53:05 +02:00
gluebi.c
io.c mm: remove the pgprot argument to __vmalloc 2020-06-02 10:59:11 -07:00
kapi.c
Kconfig
Makefile
misc.c
ubi-media.h ubi: ubi-media.h: Replace zero-length array with flexible-array member 2020-03-30 23:02:37 +02:00
ubi.h This pull request contains a single change for UBI: 2020-06-10 13:24:40 -07:00
upd.c
vmt.c
vtbl.c ubi: Free the normal volumes in error paths of ubi_attach_mtd_dev() 2020-01-16 23:35:59 +01:00
wl.c ubi: check kthread_should_stop() after the setting of task state 2020-09-17 22:55:59 +02:00
wl.h