[RFC PATCH v2 5/8] blk-crypto: refuse dma-buf bios in the fallback path

From: Mengmeng Zhao

Date: Fri Nov 13 2026 - 04:59:44 EST


From: Mengmeng Zhao <zhaomengmeng@xxxxxxxxxx>

The inline encryption fallback encrypts through the data pages of a bio,
which a dma-buf bio does not have: its vec pointer holds the
driver-private dma_buf_io_map. A crypt context the device supports
natively is programmed from the request instead, so refuse only where
the fallback is about to run.

blk_mq_submit_bio() is too late for this: submit_bio_noacct() has already
rejected a context the device does not support natively, while submitters
reach the fallback before the bio is queued. No in-tree submitter builds
such a bio today.

Signed-off-by: Mengmeng Zhao <zhaomengmeng@xxxxxxxxxx>
Signed-off-by: Li Wang <liwang@xxxxxxxxxx>
---
block/blk-crypto.c | 8 ++++++++
1 file changed, 8 insertions(+)

diff --git a/block/blk-crypto.c b/block/blk-crypto.c
index bc3a9f59574b..01b8d26040dc 100644
--- a/block/blk-crypto.c
+++ b/block/blk-crypto.c
@@ -271,6 +271,14 @@ bool __blk_crypto_submit_bio(struct bio *bio)
bio_endio_status(bio, BLK_STS_NOTSUPP);
return false;
}
+ /*
+ * The fallback encrypts from the data pages, which a dma-buf
+ * bio does not have.
+ */
+ if (op_is_dmabuf(bio->bi_opf)) {
+ bio_endio_status(bio, BLK_STS_NOTSUPP);
+ return false;
+ }
return blk_crypto_fallback_bio_prep(bio);
}

--
2.43.0