dm crypt: do not call bio_endio() from the dm-crypt tasklet
authorIgnat Korchagin <ignat@cloudflare.com>
Sat, 9 Jan 2021 15:17:06 +0000 (15:17 +0000)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Tue, 19 Jan 2021 17:27:22 +0000 (18:27 +0100)
commitfe40f6a6309fd4bbfd8290cc1ff517aaf1ac5abe
tree3fa025325eb7056b8f61e62eb616a52f79031eb3
parent8727884b7f80ed5b99b48141def9b3c491cffa54
dm crypt: do not call bio_endio() from the dm-crypt tasklet

commit 8e14f610159d524cd7aac37982826d3ef75c09e8 upstream.

Sometimes, when dm-crypt executes decryption in a tasklet, we may get
"BUG: KASAN: use-after-free in tasklet_action_common.constprop..."
with a kasan-enabled kernel.

When the decryption fully completes in the tasklet, dm-crypt will call
bio_endio(), which in turn will call clone_endio() from dm.c core code. That
function frees the resources associated with the bio, including per bio private
structures. For dm-crypt it will free the current struct dm_crypt_io, which
contains our tasklet object, causing use-after-free, when the tasklet is being
dequeued by the kernel.

To avoid this, do not call bio_endio() from the current tasklet context, but
delay its execution to the dm-crypt IO workqueue.

Fixes: 39d42fa96ba1 ("dm crypt: add flags to optionally bypass kcryptd workqueues")
Cc: <stable@vger.kernel.org> # v5.9+
Signed-off-by: Ignat Korchagin <ignat@cloudflare.com>
Signed-off-by: Mike Snitzer <snitzer@redhat.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
drivers/md/dm-crypt.c