]> git.baikalelectronics.ru Git - kernel.git/commit
writeback: avoid use-after-free after removing device
authorKhazhismel Kumykov <khazhy@chromium.org>
Mon, 1 Aug 2022 15:50:34 +0000 (08:50 -0700)
committerAndrew Morton <akpm@linux-foundation.org>
Sun, 28 Aug 2022 21:02:43 +0000 (14:02 -0700)
commit95b17eab539e7575f601253273f526b4e1d62717
tree311757d653b1ef1229b68692699e5b63949ba911
parent75ed33e12a1c56c6e939156a5ac156dc38cebed0
writeback: avoid use-after-free after removing device

When a disk is removed, bdi_unregister gets called to stop further
writeback and wait for associated delayed work to complete.  However,
wb_inode_writeback_end() may schedule bandwidth estimation dwork after
this has completed, which can result in the timer attempting to access the
just freed bdi_writeback.

Fix this by checking if the bdi_writeback is alive, similar to when
scheduling writeback work.

Since this requires wb->work_lock, and wb_inode_writeback_end() may get
called from interrupt, switch wb->work_lock to an irqsafe lock.

Link: https://lkml.kernel.org/r/20220801155034.3772543-1-khazhy@google.com
Fixes: 77b7dbd04e56 ("writeback: fix bandwidth estimate for spiky workload")
Signed-off-by: Khazhismel Kumykov <khazhy@google.com>
Reviewed-by: Jan Kara <jack@suse.cz>
Cc: Michael Stapelberg <stapelberg+linux@google.com>
Cc: Wu Fengguang <fengguang.wu@intel.com>
Cc: Alexander Viro <viro@zeniv.linux.org.uk>
Cc: <stable@vger.kernel.org>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
fs/fs-writeback.c
mm/backing-dev.c
mm/page-writeback.c