Received: by 2002:a25:4158:0:0:0:0:0 with SMTP id o85csp2334191yba; Sat, 27 Apr 2019 21:32:55 -0700 (PDT) X-Google-Smtp-Source: APXvYqy1ZN56MNvWtcDGVkF+kxehvkJBuBoDj/olDlEflsLvWm3IUC47dD/e8UAIC+3UON60n/87 X-Received: by 2002:a63:f26:: with SMTP id e38mr53460776pgl.290.1556425975028; Sat, 27 Apr 2019 21:32:55 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1556425975; cv=none; d=google.com; s=arc-20160816; b=aJBsVHLW9M/C7zBtcoKujCh02GMiwIIDbTVVQsZaX8YLux8tBpBIVPemoCAuiT8r8Y 6Ym2FWOKBfZuNDd4R94csASnVDOCg2mTzr9Ifak6IRppK32nK25+Ec529Qfi7yLZWD7m x9oZmTmwRwqslKJQ+dd2+NF3vYhvk3HryIygbGw8IJ/iD734oncT/axpdcmXDOCg7vhO VeA8Wbgx+jBmDwP1t8O4u82AVGk+wEI6CpVxCODLRvbrysxuVQJNpMX1je0EXfOTHuuo mhthmKFdVNj0iqlFuWkiUTB7rHKvBbf5vmkuvsBXWxz/40K2+wHlh/YRMjzWjhMIcyc1 Ph6g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:message-id:content-transfer-encoding :mime-version:references:in-reply-to:date:subject:cc:to:from; bh=C/caAldOEO0gcrn1bI3B5TQl4ieFn8Fo91uV4fE9iXU=; b=ChdJ9H8wwS/bDLNEH3S6pmHXec0EnDAioJYk2PERAHyLlE5PJM51Qti+jTPn1HsDBE 3MBVg/yvkSpI3p9VhswedOafz5QMOc6c21ZyVxzfcbEVLhlFI9KqYeoGTReNS45xacLR hysNFl4OJfXs1odYWT50JoicRyGMbitPnewHbdzeC7quc2S4jJWhyZGRmXuqHHqzXqnR zUEN/8t6L+mw+omSM50avvKHbyb876M8vUKnSwWYFCbAnWcJArlxWT+lcEPggn8CQewT pGpKH1ykUTXmmlrROmsrJ7WES1JTBV/5DoimcgksBVSg880bAewHAPY8O74nhiC3/dBm SSDQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-ext4-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-ext4-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=ibm.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id j127si32011294pfb.25.2019.04.27.21.32.40; Sat, 27 Apr 2019 21:32:55 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-ext4-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-ext4-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-ext4-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=ibm.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726485AbfD1Ebb (ORCPT + 99 others); Sun, 28 Apr 2019 00:31:31 -0400 Received: from mx0a-001b2d01.pphosted.com ([148.163.156.1]:42976 "EHLO mx0a-001b2d01.pphosted.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726352AbfD1Ebb (ORCPT ); Sun, 28 Apr 2019 00:31:31 -0400 Received: from pps.filterd (m0098410.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.16.0.27/8.16.0.27) with SMTP id x3S4TAXF076627 for ; Sun, 28 Apr 2019 00:31:30 -0400 Received: from e16.ny.us.ibm.com (e16.ny.us.ibm.com [129.33.205.206]) by mx0a-001b2d01.pphosted.com with ESMTP id 2s54aw94vq-1 (version=TLSv1.2 cipher=AES256-GCM-SHA384 bits=256 verify=NOT) for ; Sun, 28 Apr 2019 00:31:30 -0400 Received: from localhost by e16.ny.us.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Sun, 28 Apr 2019 05:31:28 +0100 Received: from b01cxnp22033.gho.pok.ibm.com (9.57.198.23) by e16.ny.us.ibm.com (146.89.104.203) with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted; (version=TLSv1/SSLv3 cipher=AES256-GCM-SHA384 bits=256/256) Sun, 28 Apr 2019 05:31:25 +0100 Received: from b01ledav004.gho.pok.ibm.com (b01ledav004.gho.pok.ibm.com [9.57.199.109]) by b01cxnp22033.gho.pok.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id x3S4VO4532964666 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Sun, 28 Apr 2019 04:31:24 GMT Received: from b01ledav004.gho.pok.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 024E1112066; Sun, 28 Apr 2019 04:31:24 +0000 (GMT) Received: from b01ledav004.gho.pok.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 83232112062; Sun, 28 Apr 2019 04:31:20 +0000 (GMT) Received: from localhost.localdomain.com (unknown [9.85.75.21]) by b01ledav004.gho.pok.ibm.com (Postfix) with ESMTP; Sun, 28 Apr 2019 04:31:20 +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, hch@infradead.org Subject: [PATCH V2 12/13] fscrypt_zeroout_range: Encrypt all zeroed out blocks of a page Date: Sun, 28 Apr 2019 10:01:20 +0530 X-Mailer: git-send-email 2.19.1 In-Reply-To: <20190428043121.30925-1-chandan@linux.ibm.com> References: <20190428043121.30925-1-chandan@linux.ibm.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-TM-AS-GCONF: 00 x-cbid: 19042804-0072-0000-0000-000004222D91 X-IBM-SpamModules-Scores: X-IBM-SpamModules-Versions: BY=3.00011008; HX=3.00000242; KW=3.00000007; PH=3.00000004; SC=3.00000285; SDB=6.01195431; UDB=6.00626836; IPR=6.00976273; MB=3.00026628; MTD=3.00000008; XFM=3.00000015; UTC=2019-04-28 04:31:27 X-IBM-AV-DETECTION: SAVI=unused REMOTE=unused XFE=unused x-cbparentid: 19042804-0073-0000-0000-00004BFECE21 Message-Id: <20190428043121.30925-13-chandan@linux.ibm.com> X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:,, definitions=2019-04-28_03:,, 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-1904280030 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 adds code to encrypt all zeroed out blocks mapped by a page. Signed-off-by: Chandan Rajendra --- fs/crypto/bio.c | 40 ++++++++++++++++++---------------------- 1 file changed, 18 insertions(+), 22 deletions(-) diff --git a/fs/crypto/bio.c b/fs/crypto/bio.c index 856f4694902d..46dd2ec50c7d 100644 --- a/fs/crypto/bio.c +++ b/fs/crypto/bio.c @@ -108,29 +108,23 @@ EXPORT_SYMBOL(fscrypt_pullback_bio_page); int fscrypt_zeroout_range(const struct inode *inode, pgoff_t lblk, sector_t pblk, unsigned int len) { - struct fscrypt_ctx *ctx; struct page *ciphertext_page = NULL; struct bio *bio; + u64 total_bytes, page_bytes; int ret, err = 0; - BUG_ON(inode->i_sb->s_blocksize != PAGE_SIZE); - - ctx = fscrypt_get_ctx(inode, GFP_NOFS); - if (IS_ERR(ctx)) - return PTR_ERR(ctx); + total_bytes = len << inode->i_blkbits; - ciphertext_page = fscrypt_alloc_bounce_page(ctx, GFP_NOWAIT); - if (IS_ERR(ciphertext_page)) { - err = PTR_ERR(ciphertext_page); - goto errout; - } + while (total_bytes) { + page_bytes = min_t(u64, total_bytes, PAGE_SIZE); - while (len--) { - err = fscrypt_do_page_crypto(inode, FS_ENCRYPT, lblk, - ZERO_PAGE(0), ciphertext_page, - PAGE_SIZE, 0, GFP_NOFS); - if (err) + ciphertext_page = fscrypt_encrypt_page(inode, ZERO_PAGE(0), + page_bytes, 0, lblk, GFP_NOFS); + if (IS_ERR(ciphertext_page)) { + err = PTR_ERR(ciphertext_page); + ciphertext_page = NULL; goto errout; + } bio = bio_alloc(GFP_NOWAIT, 1); if (!bio) { @@ -141,9 +135,8 @@ int fscrypt_zeroout_range(const struct inode *inode, pgoff_t lblk, bio->bi_iter.bi_sector = pblk << (inode->i_sb->s_blocksize_bits - 9); bio_set_op_attrs(bio, REQ_OP_WRITE, 0); - ret = bio_add_page(bio, ciphertext_page, - inode->i_sb->s_blocksize, 0); - if (ret != inode->i_sb->s_blocksize) { + ret = bio_add_page(bio, ciphertext_page, page_bytes, 0); + if (ret != page_bytes) { /* should never happen! */ WARN_ON(1); bio_put(bio); @@ -156,12 +149,15 @@ int fscrypt_zeroout_range(const struct inode *inode, pgoff_t lblk, bio_put(bio); if (err) goto errout; - lblk++; - pblk++; + + lblk += page_bytes >> inode->i_blkbits; + pblk += page_bytes >> inode->i_blkbits; + total_bytes -= page_bytes; } err = 0; errout: - fscrypt_release_ctx(ctx); + if (!IS_ERR_OR_NULL(ciphertext_page)) + fscrypt_restore_control_page(ciphertext_page); return err; } EXPORT_SYMBOL(fscrypt_zeroout_range); -- 2.19.1