Received: by 2002:a25:4158:0:0:0:0:0 with SMTP id o85csp2333675yba; Sat, 27 Apr 2019 21:31:54 -0700 (PDT) X-Google-Smtp-Source: APXvYqyi1mM0KO+8BMpzZxskaEDyk4QSPAMCZ+qoaxkeeo09RxXP3W+5iDHXngLXZKL/I3uauJny X-Received: by 2002:a17:902:380c:: with SMTP id l12mr54522122plc.320.1556425914381; Sat, 27 Apr 2019 21:31:54 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1556425914; cv=none; d=google.com; s=arc-20160816; b=Bwtups0y0JFpgOq+8+wUoLIkehNouha//vAKbR97FmEF4xuj+cfbkwhw0O2aJgc8Em aB4rcgyboVptJ991c1vgCwmWUreCDpseaqAdA4CGZc/dq5Ij0eScXfiLFZ/cz0Dk8JcG 0TY39FAwwHL/mZPIBjts4zigfWzkqnqFgB0P77mSTDpSXwYDLDoLTtVngywQjdaXlZ9s eiUizb4kRyesy4IZv7AxVyLaVki/xjKDY3jBpRPFNH4QUpC3H5JnB+k9Cq0FVeP+lay2 wBbHBy78vxK/F2LMnivHXvHPOuCfq9YFcO4j/EqycyrkUlxx0hvN/rOsTq09yaCALpC+ bL6Q== 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=ySLhVYxRZs3Cy8wXXM/haIg0PNK0kMiajvQZVBzo/nA=; b=FKUd9m3Bx6pHYrVkWBVdic/2ggvbPNeMnDmWXEDJCOGnNq0URMVD2Gi0+jINO55NNx z4LkUT+BVv5tvkd+ctb0Z6H+W1RYIm7n8zB9zCUH3obXLRrbZobauiThgePcNvIWy92n GBTBCYZCAgKf/Tq5jiQt2+u/i54D5PXADY4yr4sK2U98KaOkfcBCl7cS7MvCZczdcmd4 xZc3FygBzaHoyL7f8dMDSvvuMe6KFPJjBPflGiM54cz+LKYEgbIMo3Q+5u7inovv2rZM bw7XqdkAwdXmfPqCTFt1kckcQSlTIi9SbAEuE5I0KwVf6Wfd+Af+SDuABpCi3KkVSHF5 difA== 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 n13si28504287pgl.348.2019.04.27.21.31.40; Sat, 27 Apr 2019 21:31:54 -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 S1726417AbfD1EbO (ORCPT + 99 others); Sun, 28 Apr 2019 00:31:14 -0400 Received: from mx0b-001b2d01.pphosted.com ([148.163.158.5]:37104 "EHLO mx0a-001b2d01.pphosted.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1726483AbfD1EbO (ORCPT ); Sun, 28 Apr 2019 00:31:14 -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 x3S4TAcA094709 for ; Sun, 28 Apr 2019 00:31:13 -0400 Received: from e12.ny.us.ibm.com (e12.ny.us.ibm.com [129.33.205.202]) by mx0b-001b2d01.pphosted.com with ESMTP id 2s54cgh54b-1 (version=TLSv1.2 cipher=AES256-GCM-SHA384 bits=256 verify=NOT) for ; Sun, 28 Apr 2019 00:31:13 -0400 Received: from localhost by e12.ny.us.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Sun, 28 Apr 2019 05:31:12 +0100 Received: from b01cxnp22035.gho.pok.ibm.com (9.57.198.25) by e12.ny.us.ibm.com (146.89.104.199) 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:08 +0100 Received: from b01ledav004.gho.pok.ibm.com (b01ledav004.gho.pok.ibm.com [9.57.199.109]) by b01cxnp22035.gho.pok.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id x3S4V7Xb23199748 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Sun, 28 Apr 2019 04:31:07 GMT Received: from b01ledav004.gho.pok.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 20886112064; Sun, 28 Apr 2019 04:31:07 +0000 (GMT) Received: from b01ledav004.gho.pok.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 6AAB0112062; Sun, 28 Apr 2019 04:31:03 +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:03 +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 08/13] ext4: Decrypt all boundary blocks when doing buffered write Date: Sun, 28 Apr 2019 10:01:16 +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-0060-0000-0000-0000033598F7 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:11 X-IBM-AV-DETECTION: SAVI=unused REMOTE=unused XFE=unused x-cbparentid: 19042804-0061-0000-0000-0000491F9D84 Message-Id: <20190428043121.30925-9-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 With subpage sized blocks, ext4_block_write_begin() can have up to two blocks to decrypt. Hence this commit invokes fscrypt_decrypt_page() for each of those blocks. Signed-off-by: Chandan Rajendra --- fs/ext4/inode.c | 33 +++++++++++++++++++++++---------- 1 file changed, 23 insertions(+), 10 deletions(-) diff --git a/fs/ext4/inode.c b/fs/ext4/inode.c index 1327e04334df..51744a3c3964 100644 --- a/fs/ext4/inode.c +++ b/fs/ext4/inode.c @@ -1156,12 +1156,14 @@ static int ext4_block_write_begin(struct page *page, loff_t pos, unsigned len, unsigned to = from + len; struct inode *inode = page->mapping->host; unsigned block_start, block_end; - sector_t block; + sector_t block, page_blk_nr; int err = 0; unsigned blocksize = inode->i_sb->s_blocksize; unsigned bbits; - struct buffer_head *bh, *head, *wait[2], **wait_bh = wait; + struct buffer_head *bh, *head, *wait[2]; + int nr_wait = 0; bool decrypt = false; + int i; BUG_ON(!PageLocked(page)); BUG_ON(from > PAGE_SIZE); @@ -1213,25 +1215,36 @@ static int ext4_block_write_begin(struct page *page, loff_t pos, unsigned len, !buffer_unwritten(bh) && (block_start < from || block_end > to)) { ll_rw_block(REQ_OP_READ, 0, 1, &bh); - *wait_bh++ = bh; + wait[nr_wait++] = bh; decrypt = IS_ENCRYPTED(inode) && S_ISREG(inode->i_mode); } } /* * If we issued read requests, let them complete. */ - while (wait_bh > wait) { - wait_on_buffer(*--wait_bh); - if (!buffer_uptodate(*wait_bh)) + for (i = 0; i < nr_wait; i++) { + wait_on_buffer(wait[i]); + if (!buffer_uptodate(wait[i])) err = -EIO; } if (unlikely(err)) { page_zero_new_buffers(page, from, to); } else if (decrypt) { - err = fscrypt_decrypt_page(page->mapping->host, page, - PAGE_SIZE, 0, page->index); - if (err) - clear_buffer_uptodate(*wait_bh); + page_blk_nr = (sector_t)page->index << (PAGE_SHIFT - bbits); + + for (i = 0; i < nr_wait; i++) { + int err2; + + block = page_blk_nr + (bh_offset(wait[i]) >> bbits); + err2 = fscrypt_decrypt_page(page->mapping->host, page, + wait[i]->b_size, + bh_offset(wait[i]), + block); + if (err2) { + clear_buffer_uptodate(wait[i]); + err = err2; + } + } } return err; -- 2.19.1