kernel-fxtec-pro1x/drivers/mtd
Zhihao Cheng 9aa191b69a ubi: check kthread_should_stop() after the setting of task state
commit d005f8c6588efcfbe88099b6edafc6f58c84a9c1 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:08:52 +01:00
..
chips mtd: cfi_cmdset_0002: don't free cfi->cfiq in error path of cfi_amdstd_setup() 2020-10-01 13:14:26 +02:00
devices
lpddr mtd: lpddr: fix excessive stack usage with clang 2020-10-29 09:55:16 +01:00
maps
nand mtd: rawnand: sunxi: Fix the probe error path 2020-10-14 10:31:22 +02:00
parsers
spi-nor
tests
ubi ubi: check kthread_should_stop() after the setting of task state 2020-11-05 11:08:52 +01:00
afs.c
ar7part.c
bcm47xxpart.c
bcm63xxpart.c
cmdlinepart.c mtd: parser: cmdline: Support MTD names containing one or more colons 2020-10-01 13:14:48 +02:00
ftl.c
inftlcore.c
inftlmount.c
Kconfig
Makefile
mtd_blkdevs.c
mtdblock.c
mtdblock_ro.c
mtdchar.c mtd: properly check all write ioctls for permissions 2020-08-11 15:32:32 +02:00
mtdconcat.c
mtdcore.c
mtdcore.h
mtdoops.c mtd: mtdoops: Don't write panic data twice 2020-10-29 09:55:17 +01:00
mtdpart.c
mtdsuper.c
mtdswap.c
nftlcore.c
nftlmount.c
ofpart.c
redboot.c
rfd_ftl.c
sm_ftl.c
sm_ftl.h
ssfdc.c