]> git.ipfire.org Git - thirdparty/kernel/linux.git/commit
dm-delay: fix bugs introduced by kthread mode
authorMikulas Patocka <mpatocka@redhat.com>
Fri, 17 Nov 2023 17:22:47 +0000 (18:22 +0100)
committerMike Snitzer <snitzer@kernel.org>
Fri, 17 Nov 2023 19:41:14 +0000 (14:41 -0500)
commit38cfff568169ff9f99784948f79f62ca1af5a187
tree1fa6c1c54e4ba0909a52bfd4ebf39023ab7a950b
parent6fc45b6ed921dc00dfb264dc08c7d67ee63d2656
dm-delay: fix bugs introduced by kthread mode

This commit fixes the following bugs introduced by commit 70bbeb29fab0
("dm delay: for short delays, use kthread instead of timers and wq"):

* the function flush_worker_fn has no exit path - on unload, this
  function will just loop and consume 100% CPU without any progress

* the wake-up mechanism in flush_worker_fn is racy - a wake up will be
  missed if the process adds entries to the delayed_bios list just
  before set_current_state(TASK_INTERRUPTIBLE)

* flush_delayed_bios_fast submits a bio while holding a global mutex;
  this may deadlock if we have multiple stacked dm-delay devices and
  the underlying device attempts to acquire the mutex too

* if the target constructor fails, it will call delay_dtr. delay_dtr
  would attempt to free dc->timer_lock without it being initialized by
  the constructor.

* if the target constructor's kthread allocation fails, delay_dtr
  would crash trying to dereference dc->worker because it is non-NULL
  due to ERR_PTR.

Fixes: 70bbeb29fab0 ("dm delay: for short delays, use kthread instead of timers and wq")
Signed-off-by: Mikulas Patocka <mpatocka@redhat.com>
Signed-off-by: Mike Snitzer <snitzer@kernel.org>
drivers/md/dm-delay.c