1
0
Fork 0
alistair23-linux/drivers/mtd
Zhihao Cheng da3bb6fa23 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:43:33 +01:00
..
chips mtd: cfi_cmdset_0002: don't free cfi->cfiq in error path of cfi_amdstd_setup() 2020-10-01 13:17:16 +02:00
devices mtd: phram: fix a double free issue in error path 2020-04-23 10:36:45 +02:00
hyperbus mtd: hyperbus: fix dependency and build error 2019-08-29 14:31:23 +02:00
lpddr mtd: lpddr: fix excessive stack usage with clang 2020-10-29 09:57:46 +01:00
maps mtd: pismo: Simplify getting the adapter of a client 2019-09-15 23:50:39 +02:00
nand mtd: spinand: gigadevice: Add QE Bit 2020-10-29 09:57:51 +01:00
parsers mtd: parser: cmdline: Support MTD names containing one or more colons 2020-10-01 13:18:08 +02:00
spi-nor mtd: spi-nor: Split mt25qu512a (n25q512a) entry into two 2020-02-11 04:35:45 -08: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-11-05 11:43:33 +01:00
Kconfig mtd: parsers: Move CMDLINE parser 2019-09-15 23:50:50 +02:00
Makefile mtd: parsers: Move CMDLINE parser 2019-09-15 23:50:50 +02:00
ftl.c treewide: Use array_size() in vmalloc() 2018-06-12 16:19:22 -07:00
inftlcore.c treewide: Replace GPLv2 boilerplate/reference with SPDX - rule 156 2019-05-30 11:26:35 -07:00
inftlmount.c treewide: Replace GPLv2 boilerplate/reference with SPDX - rule 156 2019-05-30 11:26:35 -07:00
mtd_blkdevs.c treewide: Replace GPLv2 boilerplate/reference with SPDX - rule 102 2019-05-24 17:39:00 +02:00
mtdblock.c treewide: Replace GPLv2 boilerplate/reference with SPDX - rule 102 2019-05-24 17:39:00 +02:00
mtdblock_ro.c treewide: Replace GPLv2 boilerplate/reference with SPDX - rule 102 2019-05-24 17:39:00 +02:00
mtdchar.c mtd: properly check all write ioctls for permissions 2020-08-11 15:33:35 +02:00
mtdconcat.c mtd: concat: implement _is_locked mtd operation 2019-07-07 20:39:16 +02:00
mtdcore.c mtd: Fix mtd not registered due to nvmem name collision 2020-05-27 17:46:22 +02:00
mtdcore.h mtd: Provide fs_context-aware mount_mtd() replacement 2019-09-05 14:34:23 -04:00
mtdoops.c mtd: mtdoops: Don't write panic data twice 2020-10-29 09:57:47 +01:00
mtdpart.c treewide: Replace GPLv2 boilerplate/reference with SPDX - rule 102 2019-05-24 17:39:00 +02:00
mtdsuper.c mtd: Kill mount_mtd() 2019-09-05 14:34:26 -04:00
mtdswap.c treewide: Replace GPLv2 boilerplate/reference with SPDX - rule 336 2019-06-05 17:37:07 +02: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 treewide: Add SPDX license identifier for more missed files 2019-05-21 10:50:45 +02:00
sm_ftl.c mtd: sm_ftl: Fix memory leak in sm_init_zone() error path 2019-09-15 23:50:50 +02: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