Received: by 10.213.65.68 with SMTP id h4csp2119620imn; Sun, 8 Apr 2018 20:11:23 -0700 (PDT) X-Google-Smtp-Source: AIpwx489U/NFdZw1w/mELN3NLZuyIs1ng8Bgp23Nm7aTF6kDu7thsmMelulXSP35c+98PD53iA77 X-Received: by 2002:a17:902:549:: with SMTP id 67-v6mr38128597plf.276.1523243483202; Sun, 08 Apr 2018 20:11:23 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1523243483; cv=none; d=google.com; s=arc-20160816; b=M/sO+595PdlLRhvf3JvBdyeeTRWx6OnEbvnLspsFT8rl7CH749frs6HbYDSoN4lHvg liDvMeYa60nHomSwlvVEOOyFpXmaLmVmTiQZjqHJv0e4R9RA+S1ScXTWX6NDTT+dbZ33 4WIwWsTGHelnKPrqLC+8hWFYQy10woVafLJQ/ukFXtAITOCgj/mG1ZxqTvv+rf+M/Aa/ j4o5dEwn2D9mZ5rlwJ+o/2x4LEDtw9UlzYgLlFCWMAmqQr1/ytOy79vThwLv5ay/5x/o 40oN5GbioNNBwjW5yHSlxH3oLsJ9qxYyX0jDje7YGbcnMzXwkadYkKAf2bcDl2JL03tg T0VQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:content-transfer-encoding :spamdiagnosticmetadata:spamdiagnosticoutput:content-language :accept-language:in-reply-to:references:message-id:date:thread-index :thread-topic:subject:cc:to:from:dkim-signature :arc-authentication-results; bh=dsrIqCC+lQv71TbdL8mmGYzH+rZk44CNOMFDQ9Y1yf4=; b=c3MVZCLk3/uFofUhG731+tcm332HdcAxkFz8w6gHJB2Rkx99Hhu3vLiWieimR0YRCB TamxmMAogE/rjfKKAVYaWn2Z6TO5bT1eNSlIXzZckgng9hupS2W3c8If4X9nUReq/NH1 BU9CpQf8fpuOTPxAHM/2CJ/pX2m6QTrmW0T1vXVlMdjD1+/iDGOgUSW5Tp7908954IBO rTXAagunzP35i8Y09X1OK8v8dOb8Hn8QvTh5LFFO7q9tFYrIWRo+XkyXJ7mvQQnKejts nadFPjngVaOE6NITKT4dBnyWO5qeHo4O3EXL9Wu8ZPOmbRgBz9FQs8FXFFLciRCPCR9u xQWQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@microsoft.com header.s=selector1 header.b=azqtTU5w; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=microsoft.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id k6si5068714pfi.83.2018.04.08.20.10.46; Sun, 08 Apr 2018 20:11:23 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@microsoft.com header.s=selector1 header.b=azqtTU5w; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=microsoft.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1757638AbeDICQD (ORCPT + 99 others); Sun, 8 Apr 2018 22:16:03 -0400 Received: from mail-dm3nam03on0104.outbound.protection.outlook.com ([104.47.41.104]:17478 "EHLO NAM03-DM3-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1756091AbeDIAae (ORCPT ); Sun, 8 Apr 2018 20:30:34 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version; bh=dsrIqCC+lQv71TbdL8mmGYzH+rZk44CNOMFDQ9Y1yf4=; b=azqtTU5wIXz3Gxa+G+M7DGiYCWZae7K4PJz06PgdIfFjeujxmKJ+drHiTJjQ2a4OSvlTY3M0Tp/CijLkVOv5VhZ3M5R9IS2H2/NTwA7VkvAW1Hm+H1lbpArD7dC3ZUczakhr0SQPnT1cDCF6rSNG1kobeda0ZNhXRAnx5+yqBTE= Received: from DM5PR2101MB1032.namprd21.prod.outlook.com (52.132.128.13) by DM5PR2101MB0807.namprd21.prod.outlook.com (10.167.110.154) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.696.3; Mon, 9 Apr 2018 00:30:28 +0000 Received: from DM5PR2101MB1032.namprd21.prod.outlook.com ([fe80::8109:aef0:a777:7059]) by DM5PR2101MB1032.namprd21.prod.outlook.com ([fe80::8109:aef0:a777:7059%2]) with mapi id 15.20.0696.003; Mon, 9 Apr 2018 00:30:28 +0000 From: Sasha Levin To: "stable@vger.kernel.org" , "linux-kernel@vger.kernel.org" CC: Eric Biggers , Theodore Ts'o , Sasha Levin Subject: [PATCH AUTOSEL for 4.9 140/293] ext4: require key for truncate(2) of encrypted file Thread-Topic: [PATCH AUTOSEL for 4.9 140/293] ext4: require key for truncate(2) of encrypted file Thread-Index: AQHTz5knzMXPRYytnEqNP6l05Oz3vQ== Date: Mon, 9 Apr 2018 00:24:42 +0000 Message-ID: <20180409002239.163177-140-alexander.levin@microsoft.com> References: <20180409002239.163177-1-alexander.levin@microsoft.com> In-Reply-To: <20180409002239.163177-1-alexander.levin@microsoft.com> Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-originating-ip: [52.168.54.252] x-ms-publictraffictype: Email x-microsoft-exchange-diagnostics: 1;DM5PR2101MB0807;7:WpMaW993SODGrKTyE8RrrKwEtlA3c6lclasMf+QeNP4RCMxEVerO39LZmAYLZm+m+eWiA96sVbp2WzQkkogHi0w4Tfm4pCiptSi0N9rHYSGzqEpCE4HG2ym21ruunbYT2ic23H6YkcIv8yFaewakXheaUHtJc+UrvBKP1hElIoWj3C83iiQG2R6NeZPxMsQnU4UqP5cYAw+7tCl2dHWghTVbHNGX8z6mDvIOwMbNzBJQZqVpfW5R3aIhV5rm4znF;20:lQtEFz0Wr1qSCdxdR5OyGWD1/IiP1vw2rmf0c0L6V7IDIi3fOq71AcTCwPK6YGGh1THG6Av8+UJdKAeUcHv9pFR1rRIWL2gunKm+KK+XuXSM7Yz50Wy3Cxv3rLNaTs/PvZbX2fDiAjwKtxRRHzmYW9KriY0EBPjUbYba/FOOFWc= x-ms-office365-filtering-ht: Tenant X-MS-Office365-Filtering-Correlation-Id: 5659d917-20d7-4723-37b7-08d59db11858 x-microsoft-antispam: UriScan:;BCL:0;PCL:0;RULEID:(7020095)(4652020)(48565401081)(5600026)(4604075)(3008032)(4534165)(4627221)(201703031133081)(201702281549075)(2017052603328)(7193020);SRVR:DM5PR2101MB0807; x-ms-traffictypediagnostic: DM5PR2101MB0807: authentication-results: spf=none (sender IP is ) smtp.mailfrom=Alexander.Levin@microsoft.com; x-microsoft-antispam-prvs: x-exchange-antispam-report-test: UriScan:(28532068793085)(89211679590171)(211936372134217)(153496737603132)(240460790083961); x-exchange-antispam-report-cfa-test: BCL:0;PCL:0;RULEID:(8211001083)(61425038)(6040522)(2401047)(5005006)(8121501046)(93006095)(93001095)(10201501046)(3231221)(944501327)(52105095)(3002001)(6055026)(61426038)(61427038)(6041310)(20161123562045)(20161123558120)(20161123564045)(20161123560045)(201703131423095)(201702281528075)(20161123555045)(201703061421075)(201703061406153)(6072148)(201708071742011);SRVR:DM5PR2101MB0807;BCL:0;PCL:0;RULEID:;SRVR:DM5PR2101MB0807; x-forefront-prvs: 0637FCE711 x-forefront-antispam-report: SFV:NSPM;SFS:(10019020)(39380400002)(39860400002)(396003)(366004)(376002)(346002)(199004)(189003)(14454004)(4326008)(54906003)(25786009)(53936002)(2900100001)(1076002)(3280700002)(6486002)(186003)(2616005)(68736007)(110136005)(11346002)(10090500001)(6116002)(107886003)(3846002)(36756003)(8676002)(72206003)(22452003)(66066001)(26005)(6512007)(478600001)(3660700001)(81156014)(86362001)(81166006)(86612001)(7736002)(305945005)(8936002)(10290500003)(6436002)(105586002)(6666003)(316002)(575784001)(76176011)(5660300001)(476003)(106356001)(2906002)(6506007)(446003)(2501003)(99286004)(5250100002)(486006)(102836004)(97736004)(22906009)(217873001);DIR:OUT;SFP:1102;SCL:1;SRVR:DM5PR2101MB0807;H:DM5PR2101MB1032.namprd21.prod.outlook.com;FPR:;SPF:None;LANG:en;PTR:InfoNoRecords;A:1;MX:1; received-spf: None (protection.outlook.com: microsoft.com does not designate permitted sender hosts) x-microsoft-antispam-message-info: lgD6XSJajIk/IxXVkg3fBdd8KgrZvBMu086MhW7IcIGxTUOV2PnauSCDKYQXUYmbwIy7DPvG8rXv7y3iMSqiuhnT3GuVzU9Sja093CG8Xw5odZAft9Ska/ouJ9HxvPEmSpKtrSwjSgqkXRIry841e3Ts1x0pXyWjAd8FpsuACBG6l4brlVPW9lJ0dxzS4UarVA5PGYByclmyuw1nbt3p/37SYh807a9tr69LeYLKiqkiqeQL1bfMp6oN1F1WHYYWN1Sl3mA+YpD0J/cbEq074AwgeLHHoBPyV7zgwhqnkDxcRKVbRsVGADWToH5wQqChNk+NvatigJmxllshNgzIbo8OQw5UGiyK+lsTsOVXe0bwHTwTbcLnm7RepZbz2ixI7RaHXxEQKj7mItlmuIu+Vth4P5SdINBdwKwnnc3hS60= spamdiagnosticoutput: 1:99 spamdiagnosticmetadata: NSPM Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 X-OriginatorOrg: microsoft.com X-MS-Exchange-CrossTenant-Network-Message-Id: 5659d917-20d7-4723-37b7-08d59db11858 X-MS-Exchange-CrossTenant-originalarrivaltime: 09 Apr 2018 00:24:42.5344 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: 72f988bf-86f1-41af-91ab-2d7cd011db47 X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM5PR2101MB0807 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Eric Biggers [ Upstream commit 63136858aecbe86dbd3c3289a3f46ba1b5f92239 ] Currently, filesystems allow truncate(2) on an encrypted file without the encryption key. However, it's impossible to correctly handle the case where the size being truncated to is not a multiple of the filesystem block size, because that would require decrypting the final block, zeroing the part beyond i_size, then encrypting the block. As other modifications to encrypted file contents are prohibited without the key, just prohibit truncate(2) as well, making it fail with ENOKEY. Signed-off-by: Eric Biggers Signed-off-by: Theodore Ts'o Signed-off-by: Sasha Levin --- fs/ext4/inode.c | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/fs/ext4/inode.c b/fs/ext4/inode.c index 5cccec68a0a5..58d57c56ec62 100644 --- a/fs/ext4/inode.c +++ b/fs/ext4/inode.c @@ -5166,6 +5166,14 @@ int ext4_setattr(struct dentry *dentry, struct iattr= *attr) loff_t oldsize =3D inode->i_size; int shrink =3D (attr->ia_size <=3D inode->i_size); =20 + if (ext4_encrypted_inode(inode)) { + error =3D fscrypt_get_encryption_info(inode); + if (error) + return error; + if (!fscrypt_has_encryption_key(inode)) + return -ENOKEY; + } + if (!(ext4_test_inode_flag(inode, EXT4_INODE_EXTENTS))) { struct ext4_sb_info *sbi =3D EXT4_SB(inode->i_sb); =20 --=20 2.15.1