[RFC PATCH v3 10/13] blk-crypto: refuse dma-buf bios in the fallback path

From: Nitesh Shetty

Date: Tue Dec 01 2026 - 11:55:48 EST


From: Mengmeng Zhao <zhaomengmeng@xxxxxxxxxx>

Without native inline encryption, blk-crypto encrypts through the
bio's data pages.
A dma-buf bio has none, so fail it before the fallback runs.
Devices with native support are not affected.
The check can't wait for blk_mq_submit_bio(), as submitters reach the
fallback before the bio is queued.
No in-tree user submits such a bio today.

Signed-off-by: Mengmeng Zhao <zhaomengmeng@xxxxxxxxxx>
Signed-off-by: Li Wang <liwang@xxxxxxxxxx>
Signed-off-by: Anuj Gupta <anuj20.g@xxxxxxxxxxx>
Signed-off-by: Nitesh Shetty <nj.shetty@xxxxxxxxxxx>
---
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.47.3