For subpage-sized blocks, this commit now encrypts all blocks mapped by a page range.
Signed-off-by: Chandan Rajendra <chan...@linux.ibm.com> --- fs/crypto/crypto.c | 37 +++++++++++++++++++++++++------------ 1 file changed, 25 insertions(+), 12 deletions(-) diff --git a/fs/crypto/crypto.c b/fs/crypto/crypto.c index 4f0d832cae71..2d65b431563f 100644 --- a/fs/crypto/crypto.c +++ b/fs/crypto/crypto.c @@ -242,18 +242,26 @@ struct page *fscrypt_encrypt_page(const struct inode *inode, { struct fscrypt_ctx *ctx; struct page *ciphertext_page = page; + int i, page_nr_blks; int err; BUG_ON(len % FS_CRYPTO_BLOCK_SIZE != 0); + page_nr_blks = len >> inode->i_blkbits; + if (inode->i_sb->s_cop->flags & FS_CFLG_OWN_PAGES) { /* with inplace-encryption we just encrypt the page */ - err = fscrypt_do_page_crypto(inode, FS_ENCRYPT, lblk_num, page, - ciphertext_page, len, offs, - gfp_flags); - if (err) - return ERR_PTR(err); - + for (i = 0; i < page_nr_blks; i++) { + err = fscrypt_do_page_crypto(inode, FS_ENCRYPT, + lblk_num, page, + ciphertext_page, + i_blocksize(inode), offs, + gfp_flags); + if (err) + return ERR_PTR(err); + ++lblk_num; + offs += i_blocksize(inode); + } return ciphertext_page; } @@ -269,12 +277,17 @@ struct page *fscrypt_encrypt_page(const struct inode *inode, goto errout; ctx->control_page = page; - err = fscrypt_do_page_crypto(inode, FS_ENCRYPT, lblk_num, - page, ciphertext_page, len, offs, - gfp_flags); - if (err) { - ciphertext_page = ERR_PTR(err); - goto errout; + + for (i = 0; i < page_nr_blks; i++) { + err = fscrypt_do_page_crypto(inode, FS_ENCRYPT, lblk_num, + page, ciphertext_page, + i_blocksize(inode), offs, gfp_flags); + if (err) { + ciphertext_page = ERR_PTR(err); + goto errout; + } + ++lblk_num; + offs += i_blocksize(inode); } SetPagePrivate(ciphertext_page); set_page_private(ciphertext_page, (unsigned long)ctx); -- 2.19.1 _______________________________________________ Linux-f2fs-devel mailing list Linux-f2fs-devel@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel