linux-stable/drivers/mtd
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
..
chips mtd: Replace HTTP links with HTTPS ones 2020-08-02 22:17:19 +02:00
devices lib/bch: Allow easy bit swapping 2020-05-24 20:48:11 +02:00
hyperbus mtd: hyperbus: Replace HTTP links with HTTPS ones 2020-08-02 22:17:05 +02:00
lpddr mtd: Convert fallthrough comments into statements 2020-03-30 10:14:54 +02:00
maps mtd: Replace HTTP links with HTTPS ones 2020-08-02 22:17:19 +02:00
nand MTD core changes: 2020-08-09 12:38:51 -07:00
parsers MTD core changes: 2020-08-09 12:38:51 -07:00
spi-nor mtd: revert "spi-nor: intel: provide a range for poll_timout" 2020-07-28 11:35:27 +03:00
tests treewide: Replace GPLv2 boilerplate/reference with SPDX - rule 326 2019-06-05 17:37:06 +02:00
ubi ubi: check kthread_should_stop() after the setting of task state 2020-09-17 22:55:59 +02:00
ftl.c
inftlcore.c treewide: Replace GPLv2 boilerplate/reference with SPDX - rule 156 2019-05-30 11:26:35 -07:00
inftlmount.c mtd: fix spelling mistake "BlockMultiplerBits" -> "BlockMultiplierBits" 2020-03-11 14:49:30 +01:00
Kconfig mtd: Support kmsg dumper based on pstore/blk 2020-05-31 19:49:01 -07:00
Makefile mtd: Support kmsg dumper based on pstore/blk 2020-05-31 19:49:01 -07:00
mtd_blkdevs.c
mtdblock.c mtd: clear cache_state to avoid writing to bad blocks repeatedly 2020-06-05 10:16:14 +02:00
mtdblock_ro.c
mtdchar.c mtd: properly check all write ioctls for permissions 2020-07-24 23:03:11 +02:00
mtdconcat.c mtd: concat: Fix a comment referring to an unknown symbol 2020-01-27 17:45:31 +01:00
mtdcore.c mtd: set master partition panic write flag 2020-06-15 19:39:24 +02:00
mtdcore.h mtd: Provide fs_context-aware mount_mtd() replacement 2019-09-05 14:34:23 -04:00
mtdoops.c treewide: Replace GPLv2 boilerplate/reference with SPDX - rule 336 2019-06-05 17:37:07 +02:00
mtdpart.c mtd: Add support for emulated SLC mode on MLC NANDs 2020-05-11 09:51:41 +02:00
mtdpstore.c iov_iter: Move unnecessary inclusion of crypto/hash.h 2020-06-30 09:34:23 -04:00
mtdsuper.c mtd: Kill mount_mtd() 2019-09-05 14:34:26 -04:00
mtdswap.c mtd: no need to check return value of debugfs_create functions 2019-11-14 10:57:38 +01:00
nftlcore.c treewide: Replace GPLv2 boilerplate/reference with SPDX - rule 156 2019-05-30 11:26:35 -07:00
nftlmount.c treewide: Replace GPLv2 boilerplate/reference with SPDX - rule 156 2019-05-30 11:26:35 -07:00
rfd_ftl.c
sm_ftl.c mtd: sm_ftl: fix NULL pointer warning 2020-01-09 20:09:55 +01:00
sm_ftl.h treewide: Replace GPLv2 boilerplate/reference with SPDX - rule 500 2019-06-19 17:09:55 +02:00
ssfdc.c treewide: Replace GPLv2 boilerplate/reference with SPDX - rule 500 2019-06-19 17:09:55 +02:00