https://github.com/torvalds/linux
Revision 6fc45b6ed921dc00dfb264dc08c7d67ee63d2656 authored by Mikulas Patocka on 17 November 2023, 17:21:14 UTC, committed by Mike Snitzer on 17 November 2023, 19:38:46 UTC
In delay_presuspend, we set the atomic variable may_delay and then stop
the timer and flush pending bios. The intention here is to prevent the
delay target from re-arming the timer again.

However, this test is racy. Suppose that one thread goes to delay_bio,
sees that dc->may_delay is one and proceeds; now, another thread executes
delay_presuspend, it sets dc->may_delay to zero, deletes the timer and
flushes pending bios. Then, the first thread continues and adds the bio to
delayed->list despite the fact that dc->may_delay is false.

Fix this bug by changing may_delay's type from atomic_t to bool and
only access it while holding the delayed_bios_lock mutex. Note that we
don't have to grab the mutex in delay_resume because there are no bios
in flight at this point.

Signed-off-by: Mikulas Patocka <mpatocka@redhat.com>
Cc: stable@vger.kernel.org
Signed-off-by: Mike Snitzer <snitzer@kernel.org>
1 parent b85ea95
History
Tip revision: 6fc45b6ed921dc00dfb264dc08c7d67ee63d2656 authored by Mikulas Patocka on 17 November 2023, 17:21:14 UTC
dm-delay: fix a race between delay_presuspend and delay_bio
Tip revision: 6fc45b6

back to top