From patchwork Mon Oct 9 19:15:44 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eric Biggers X-Patchwork-Id: 823446 X-Patchwork-Delegate: richard@nod.at Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=none (mailfrom) smtp.mailfrom=lists.infradead.org (client-ip=65.50.211.133; helo=bombadil.infradead.org; envelope-from=linux-mtd-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org; receiver=) Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="bdwJ9HHM"; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="BbemtTru"; dkim-atps=neutral Received: from bombadil.infradead.org (bombadil.infradead.org [65.50.211.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 3y9r7R0bKtz9t44 for ; Tue, 10 Oct 2017 06:35:31 +1100 (AEDT) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:MIME-Version:Cc:List-Subscribe: List-Help:List-Post:List-Archive:List-Unsubscribe:List-Id:References: In-Reply-To:Message-Id:Date:Subject:To:From:Reply-To:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Owner; bh=ydwCfx1qXs5ooOOcX4sHMD9KhivuVF4SMiZkyiCpvII=; b=bdwJ9HHMiUMwHAVPNynZx7JO+u KmLTdMZwZN951KktTk4tABw465MHVkyjmD5V3yGZ0oH+gQpZIrBWl5BJahtHyXQ7pL1ndOI9uxZBq LpCLhmciyISv73jLdqH7XsmxCh/Ze66w59qDe5eOKUc7CIN+nzAwfCi1ldj+hpTODtk4iiqa44Hat rGxdF3Q7XTUYHxWlunDXvidIZnPVnLDQ5cEgUzFt5SthD5u46SBgtvEP41cbzvrXlesW4lfhMGn46 K/bzIqtz29UAKtxOTvGo9eUd2v2JzCrjkxaLy0bIF9dudlmEZ7BcURCF0Wbbo+yL0U2bE5aMojVV/ eRVAFGsg==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.87 #1 (Red Hat Linux)) id 1e1dpl-0000eb-4Q; Mon, 09 Oct 2017 19:35:25 +0000 Received: from mail-pf0-x243.google.com ([2607:f8b0:400e:c00::243]) by bombadil.infradead.org with esmtps (Exim 4.87 #1 (Red Hat Linux)) id 1e1daM-0000GE-Gu for linux-mtd@lists.infradead.org; Mon, 09 Oct 2017 19:19:46 +0000 Received: by mail-pf0-x243.google.com with SMTP id m28so29746826pfi.0 for ; Mon, 09 Oct 2017 12:19:12 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=MPOPGjF3y0uBJ9sffhpGUHrATZ5LMTP+wi1hmVzD8Dg=; b=BbemtTrutCcH7jQ3Z7LWQEcNJkEGK6ZQZCVInuFdVClkc+xKsT0PMl+GlTui26xe1P YFOQAbLyKOVl1EyHpUhMsOcYYj8N2DENORvZME+YqowQJqeZDFzLpOpGRWmhU8ScGFuh k/Ptpl7GYqdjT05x3Lm8HUTJ7O7iPIhlYixgrLM8gc/xi5bxHAOzKhk8YI0MSZoLWN6Q /Ro7QU3bM/J9sLqrZANW+yb2CD+1CwS8fHww/bh5n+CacS61HTJI/adn6Ix1GBSdhGxo MIHEqiyjlz9JPxaurrZkduh7pFUBgf+dBthbiag0E28CEMhUjrXM91RxGp14EsnaBsC+ FgoA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=MPOPGjF3y0uBJ9sffhpGUHrATZ5LMTP+wi1hmVzD8Dg=; b=QQttOvcTyb7DxiNFitJtqdc06W8layaQR6WZEUVUi0a3n2Rm1LgQ8VjV1rbVuD/s25 3DpBwdp81z8MbfymDjgchsdlvJ1ZFfgQgGSqWSYVg4FSbQuw9o65LTJQ260fNV1KKHjv FJ559ENNCry3Va4ujCdYEMY/is2Bjq+HtDH7LDQLRwJL7JYJyWVWKMHHOH7TWUyWqiW5 wn4C3lHt2d2K31+bI791kY883+6JKE57BgQXGUn4xDMPffRhUt47AvG9IHrOIXkupp3/ bDbH5NGHBRZ0hfsGue5klu/EkqHB83LPPKC+uQg8DcTFTx/BewH7hrdACcnVqBF4OwPT XasA== X-Gm-Message-State: AMCzsaWwAhY43d8w8dfNyUXZr+KpiKF7gQTViZNlJxg1DFAJLaLVmEJV vAHVOni36szUYYZHs7Kw7xM= X-Google-Smtp-Source: AOwi7QD7yuugVLvBhVlXZRWqDOMVEVc25HUQgG2VSTZBwm+Jjo5olEvvHSbpLC08jv5dComaA5TDGQ== X-Received: by 10.84.129.70 with SMTP id 64mr9818378plb.287.1507576751881; Mon, 09 Oct 2017 12:19:11 -0700 (PDT) Received: from ebiggers-linuxstation.kir.corp.google.com ([100.66.174.81]) by smtp.gmail.com with ESMTPSA id n29sm17039819pgf.44.2017.10.09.12.19.11 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Mon, 09 Oct 2017 12:19:11 -0700 (PDT) From: Eric Biggers To: linux-fscrypt@vger.kernel.org, "Theodore Y . Ts'o" Subject: [PATCH v2 11/11] fscrypt: new helper function - fscrypt_prepare_setattr() Date: Mon, 9 Oct 2017 12:15:44 -0700 Message-Id: <20171009191544.43656-12-ebiggers3@gmail.com> X-Mailer: git-send-email 2.14.2.920.gcf0c67979c-goog In-Reply-To: <20171009191544.43656-1-ebiggers3@gmail.com> References: <20171009191544.43656-1-ebiggers3@gmail.com> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20171009_121931_179460_FE38AF0E X-CRM114-Status: GOOD ( 13.23 ) X-Spam-Score: -1.8 (-) X-Spam-Report: SpamAssassin version 3.4.1 on bombadil.infradead.org summary: Content analysis details: (-1.8 points) pts rule name description ---- ---------------------- -------------------------------------------------- -0.0 RCVD_IN_DNSWL_NONE RBL: Sender listed at http://www.dnswl.org/, no trust [2607:f8b0:400e:c00:0:0:0:243 listed in] [list.dnswl.org] -0.0 SPF_PASS SPF: sender matches SPF record 0.2 FREEMAIL_ENVFROM_END_DIGIT Envelope-from freemail username ends in digit (ebiggers3[at]gmail.com) 0.0 FREEMAIL_FROM Sender email is commonly abused enduser mail provider (ebiggers3[at]gmail.com) -1.9 BAYES_00 BODY: Bayes spam probability is 0 to 1% [score: 0.0000] -0.1 DKIM_VALID Message has at least one valid DKIM or DK signature 0.1 DKIM_SIGNED Message has a DKIM or DK signature, not necessarily valid -0.1 DKIM_VALID_AU Message has a valid DKIM or DK signature from author's domain X-BeenThere: linux-mtd@lists.infradead.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: Linux MTD discussion mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Eric Biggers , linux-f2fs-devel@lists.sourceforge.net, linux-mtd@lists.infradead.org, linux-fsdevel@vger.kernel.org, Jaegeuk Kim , linux-ext4@vger.kernel.org MIME-Version: 1.0 Sender: "linux-mtd" Errors-To: linux-mtd-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org From: Eric Biggers Introduce a helper function for filesystems to call when processing ->setattr() on a possibly-encrypted inode. It handles enforcing that an encrypted file can only be truncated if its encryption key is available. Acked-by: Dave Chinner Signed-off-by: Eric Biggers --- include/linux/fscrypt.h | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/include/linux/fscrypt.h b/include/linux/fscrypt.h index 2327859c8cd2..53437bfdfcbc 100644 --- a/include/linux/fscrypt.h +++ b/include/linux/fscrypt.h @@ -265,4 +265,29 @@ static inline int fscrypt_prepare_lookup(struct inode *dir, return 0; } +/** + * fscrypt_prepare_setattr - prepare to change a possibly-encrypted inode's attributes + * @dentry: dentry through which the inode is being changed + * @attr: attributes to change + * + * Prepare for ->setattr() on a possibly-encrypted inode. On an encrypted file, + * most attribute changes are allowed even without the encryption key. However, + * without the encryption key we do have to forbid truncates. This is needed + * because the size being truncated to may not be a multiple of the filesystem + * block size, and in that case we'd have to decrypt the final block, zero the + * portion past i_size, and re-encrypt it. (We *could* allow truncating to a + * filesystem block boundary, but it's simpler to just forbid all truncates --- + * and we already forbid all other contents modifications without the key.) + * + * Return: 0 on success, -ENOKEY if the key is missing, or another -errno code + * if a problem occurred while setting up the encryption key. + */ +static inline int fscrypt_prepare_setattr(struct dentry *dentry, + struct iattr *attr) +{ + if (attr->ia_valid & ATTR_SIZE) + return fscrypt_require_key(d_inode(dentry)); + return 0; +} + #endif /* _LINUX_FSCRYPT_H */