dm crypt: avoid accessing uninitialized tasklet
authorMike Snitzer <snitzer@kernel.org>
Wed, 8 Mar 2023 19:39:54 +0000 (14:39 -0500)
committerMike Snitzer <snitzer@kernel.org>
Thu, 9 Mar 2023 15:04:38 +0000 (10:04 -0500)
commitd9a02e016aaf5a57fb44e9a5e6da8ccd3b9e2e70
treebcfd9bcafbe00b23efcb5b164da11fb847ca65a0
parentfb294b1c0ba982144ca467a75e7d01ff26304e2b
dm crypt: avoid accessing uninitialized tasklet

When neither "no_read_workqueue" nor "no_write_workqueue" are enabled,
tasklet_trylock() in crypt_dec_pending() may still return false due to
an uninitialized state, and dm-crypt will unnecessarily do io completion
in io_queue workqueue instead of current context.

Fix this by adding an 'in_tasklet' flag to dm_crypt_io struct and
initialize it to false in crypt_io_init(). Set this flag to true in
kcryptd_queue_crypt() before calling tasklet_schedule(). If set
crypt_dec_pending() will punt io completion to a workqueue.

This also nicely avoids the tasklet_trylock/unlock hack when tasklets
aren't in use.

Fixes: 8e14f610159d ("dm crypt: do not call bio_endio() from the dm-crypt tasklet")
Cc: stable@vger.kernel.org
Reported-by: Hou Tao <houtao1@huawei.com>
Suggested-by: Ignat Korchagin <ignat@cloudflare.com>
Reviewed-by: Ignat Korchagin <ignat@cloudflare.com>
Signed-off-by: Mike Snitzer <snitzer@kernel.org>
drivers/md/dm-crypt.c