From: Mengmeng Zhao <[email protected]>

Contents encryption needs the crypto layer to reach the data pages of
the bio: blk-crypto_fallback kmaps and memcpys them, which a device
mapping does not allow.  Refuse the iterator in __iomap_dio_rw()
before any bio is submitted instead of depending on each filesystem
to keep dmabuf away from encrypted inodes, and in
iomap_file_init_dma_buf_io_ctx() so that registration on an encrypted
file fails up front.

Signed-off-by: Mengmeng Zhao <[email protected]>
Signed-off-by: Li Wang <[email protected]>
---
 fs/iomap/direct-io.c | 10 ++++++++++
 1 file changed, 10 insertions(+)

diff --git a/fs/iomap/direct-io.c b/fs/iomap/direct-io.c
index fc40f4367ee7..aec47b70b084 100644
--- a/fs/iomap/direct-io.c
+++ b/fs/iomap/direct-io.c
@@ -728,6 +728,14 @@ __iomap_dio_rw(struct kiocb *iocb, struct iov_iter *iter,
        if (iov_iter_is_dmabuf_map(iter) && (dio_flags & IOMAP_DIO_BOUNCE))
                return ERR_PTR(-EOPNOTSUPP);
 
+       /*
+        * Contents encryption walks the bio pages in the crypto layer, which
+        * a dmabuf bio has none of.  Reject before any bio is submitted.
+        */
+       if (iov_iter_is_dmabuf_map(iter) &&
+           fscrypt_needs_contents_encryption(inode))
+               return ERR_PTR(-EOPNOTSUPP);
+
        dio = kmalloc_obj(*dio);
        if (!dio)
                return ERR_PTR(-ENOMEM);
@@ -940,6 +948,8 @@ int iomap_file_init_dma_buf_io_ctx(struct file *file, 
struct block_device *bdev,
 
        if (IS_DAX(inode))
                return -EOPNOTSUPP;
+       if (fscrypt_needs_contents_encryption(inode))
+               return -EOPNOTSUPP;
        return bdev_init_dma_buf_io_ctx(file, bdev, ctx);
 }
 EXPORT_SYMBOL_GPL(iomap_file_init_dma_buf_io_ctx);
-- 
2.43.0


Reply via email to