ext4: decrypt only the needed block in __ext4_block_zero_page_range()
authorChandan Rajendra <chandan@linux.ibm.com>
Mon, 20 May 2019 16:29:51 +0000 (09:29 -0700)
committerEric Biggers <ebiggers@google.com>
Tue, 28 May 2019 17:27:53 +0000 (10:27 -0700)
In __ext4_block_zero_page_range(), only decrypt the block that actually
needs to be decrypted, rather than assuming blocksize == PAGE_SIZE and
decrypting the whole page.

This is in preparation for allowing encryption on ext4 filesystems with
blocksize != PAGE_SIZE.

Signed-off-by: Chandan Rajendra <chandan@linux.ibm.com>
(EB: rebase onto previous changes, improve the commit message, and use
 bh_offset())
Signed-off-by: Eric Biggers <ebiggers@google.com>
fs/ext4/inode.c

index 8e48feddad83edb0504914d3537e27f8dc1da354..f65357735a1ad06e068a25446fdd13e5e8a428a6 100644 (file)
@@ -4075,9 +4075,8 @@ static int __ext4_block_zero_page_range(handle_t *handle,
                if (S_ISREG(inode->i_mode) && IS_ENCRYPTED(inode)) {
                        /* We expect the key to be set. */
                        BUG_ON(!fscrypt_has_encryption_key(inode));
-                       BUG_ON(blocksize != PAGE_SIZE);
                        WARN_ON_ONCE(fscrypt_decrypt_pagecache_blocks(
-                                               page, PAGE_SIZE, 0));
+                                       page, blocksize, bh_offset(bh)));
                }
        }
        if (ext4_should_journal_data(inode)) {