Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-9.0 required=3.0 tests=HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH,MAILING_LIST_MULTI,SIGNED_OFF_BY,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 73F94C10F0E for ; Fri, 12 Apr 2019 17:11:04 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 45830218A3 for ; Fri, 12 Apr 2019 17:11:04 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727064AbfDLRLD (ORCPT ); Fri, 12 Apr 2019 13:11:03 -0400 Received: from mx0b-001b2d01.pphosted.com ([148.163.158.5]:43536 "EHLO mx0a-001b2d01.pphosted.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1726870AbfDLRLD (ORCPT ); Fri, 12 Apr 2019 13:11:03 -0400 Received: from pps.filterd (m0098414.ppops.net [127.0.0.1]) by mx0b-001b2d01.pphosted.com (8.16.0.27/8.16.0.27) with SMTP id x3CH9wZn112047 for ; Fri, 12 Apr 2019 13:11:01 -0400 Received: from e35.co.us.ibm.com (e35.co.us.ibm.com [32.97.110.153]) by mx0b-001b2d01.pphosted.com with ESMTP id 2rtw90m34v-1 (version=TLSv1.2 cipher=AES256-GCM-SHA384 bits=256 verify=NOT) for ; Fri, 12 Apr 2019 13:11:01 -0400 Received: from localhost by e35.co.us.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Fri, 12 Apr 2019 18:11:00 +0100 Received: from b03cxnp08025.gho.boulder.ibm.com (9.17.130.17) by e35.co.us.ibm.com (192.168.1.135) with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted; (version=TLSv1/SSLv3 cipher=AES256-GCM-SHA384 bits=256/256) Fri, 12 Apr 2019 18:10:57 +0100 Received: from b03ledav003.gho.boulder.ibm.com (b03ledav003.gho.boulder.ibm.com [9.17.130.234]) by b03cxnp08025.gho.boulder.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id x3CHAuXh24903718 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 12 Apr 2019 17:10:56 GMT Received: from b03ledav003.gho.boulder.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 40AA76A04F; Fri, 12 Apr 2019 17:10:56 +0000 (GMT) Received: from b03ledav003.gho.boulder.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 8DD706A05A; Fri, 12 Apr 2019 17:10:52 +0000 (GMT) Received: from localhost.localdomain.com (unknown [9.85.82.25]) by b03ledav003.gho.boulder.ibm.com (Postfix) with ESMTP; Fri, 12 Apr 2019 17:10:52 +0000 (GMT) From: Chandan Rajendra To: linux-fsdevel@vger.kernel.org, linux-ext4@vger.kernel.org, linux-f2fs-devel@lists.sourceforge.net, linux-fscrypt@vger.kernel.org Cc: Chandan Rajendra , tytso@mit.edu, adilger.kernel@dilger.ca, ebiggers@kernel.org, jaegeuk@kernel.org, yuchao0@huawei.com Subject: [RFC PATCH 11/14] fscrypt_encrypt_page: Loop across all blocks mapped by a page range Date: Fri, 12 Apr 2019 22:40:38 +0530 X-Mailer: git-send-email 2.19.1 In-Reply-To: <20190412171041.31995-1-chandan@linux.ibm.com> References: <20190412171041.31995-1-chandan@linux.ibm.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-TM-AS-GCONF: 00 x-cbid: 19041217-0012-0000-0000-000017263A39 X-IBM-SpamModules-Scores: X-IBM-SpamModules-Versions: BY=3.00010914; HX=3.00000242; KW=3.00000007; PH=3.00000004; SC=3.00000284; SDB=6.01188096; UDB=6.00622387; IPR=6.00968863; MB=3.00026412; MTD=3.00000008; XFM=3.00000015; UTC=2019-04-12 17:11:00 X-IBM-AV-DETECTION: SAVI=unused REMOTE=unused XFE=unused x-cbparentid: 19041217-0013-0000-0000-000056D87BDD Message-Id: <20190412171041.31995-12-chandan@linux.ibm.com> X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:,, definitions=2019-04-12_10:,, signatures=0 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 priorityscore=1501 malwarescore=0 suspectscore=0 phishscore=0 bulkscore=0 spamscore=0 clxscore=1015 lowpriorityscore=0 mlxscore=0 impostorscore=0 mlxlogscore=999 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1810050000 definitions=main-1904120115 Sender: linux-ext4-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-ext4@vger.kernel.org For subpage-sized blocks, this commit now encrypts all blocks mapped by a page range. Signed-off-by: Chandan Rajendra --- 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..84d11d8eb7e3 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