diff mbox series

[RFC,V3,04/12] __fscrypt_decrypt_bio: Fix page offset and len args to fscrypt_decrypt_page

Message ID 20180522160110.1161-5-chandan@linux.vnet.ibm.com
State Changes Requested
Headers show
Series Ext4 encryption support for blocksize < pagesize | expand

Commit Message

Chandan Rajendra May 22, 2018, 4:01 p.m. UTC
For block size < page size scenario, the block to be decrypted can be
mapped at a non-zero page offset and the length of the block is less
than page size. Hence this commit fixes the corresponding arguments sent
to fscrypt_decrypt_page().

Signed-off-by: Chandan Rajendra <chandan@linux.vnet.ibm.com>
---
 fs/crypto/bio.c | 10 ++++++++--
 1 file changed, 8 insertions(+), 2 deletions(-)
diff mbox series

Patch

diff --git a/fs/crypto/bio.c b/fs/crypto/bio.c
index 778b826..32288c3 100644
--- a/fs/crypto/bio.c
+++ b/fs/crypto/bio.c
@@ -33,9 +33,15 @@  static void __fscrypt_decrypt_bio(struct bio *bio, bool done)
 
 	bio_for_each_segment_all(bv, bio, i) {
 		struct page *page = bv->bv_page;
-		int ret = fscrypt_decrypt_page(page->mapping->host, page,
-				PAGE_SIZE, 0, page->index);
+		struct inode *inode = page->mapping->host;
+		u64 blk;
+		int ret;
 
+		blk = page->index << (PAGE_SHIFT - inode->i_blkbits);
+		blk += bv->bv_offset >> inode->i_blkbits;
+
+		ret = fscrypt_decrypt_page(page->mapping->host, page,
+					bv->bv_len, bv->bv_offset, blk);
 		if (ret) {
 			WARN_ON_ONCE(1);
 			SetPageError(page);