From patchwork Tue Dec 11 22:46:50 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eric Biggers X-Patchwork-Id: 10725185 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 3592A18A7 for ; Tue, 11 Dec 2018 22:48:12 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 247D92B5FB for ; Tue, 11 Dec 2018 22:48:12 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 173282B6AE; Tue, 11 Dec 2018 22:48:12 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-8.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 96F802B6AA for ; Tue, 11 Dec 2018 22:48:11 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726240AbeLKWsL (ORCPT ); Tue, 11 Dec 2018 17:48:11 -0500 Received: from mail.kernel.org ([198.145.29.99]:40534 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726474AbeLKWsJ (ORCPT ); Tue, 11 Dec 2018 17:48:09 -0500 Received: from ebiggers-linuxstation.mtv.corp.google.com (unknown [104.132.1.77]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id E078320870; Tue, 11 Dec 2018 22:48:07 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1544568488; bh=SHkkvyY4w64zhSll4AyolqAPU4FeSczOfsuzY0H80ns=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=KggRvIWO4sbCaezzoh6rtlpgaKuYo0j7/D2mNcVukoix9tKw7oOZETip0ULq7x5uy slA+g8J0TP+4Scfgt6K/I04GGWKCdrqlQt4ochhoFoS/kDEM5GMgbfJ6mMvknJiv18 PDMHFn05IWzXAVXWNQsozpTds6vvQkdRAKCxxd6s= From: Eric Biggers To: linux-fscrypt@vger.kernel.org, "Theodore Y . Ts'o" Cc: Chandan Rajendra , Krzysztof Kozlowski , linux-ext4@vger.kernel.org, Tony Lindgren , Kirill Tkhai Subject: [PATCH 1/2] fsverity: Move verity status check to fsverity_file_open Date: Tue, 11 Dec 2018 14:46:50 -0800 Message-Id: <20181211224651.112510-2-ebiggers@kernel.org> X-Mailer: git-send-email 2.20.0.405.gbc1bbc6f85-goog In-Reply-To: <20181211224651.112510-1-ebiggers@kernel.org> References: <20181211224651.112510-1-ebiggers@kernel.org> MIME-Version: 1.0 Sender: linux-fscrypt-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-fscrypt@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP From: Chandan Rajendra Instead of conditionally checking for verity status of an inode before invoking fsverity_file_open(), this commit moves the check inside the definition of fsverity_file_open(). Signed-off-by: Chandan Rajendra (EB: fix the !CONFIG_FS_VERITY case and inline the IS_VERITY() check) Signed-off-by: Eric Biggers --- fs/ext4/file.c | 8 +++----- fs/f2fs/file.c | 8 +++----- fs/verity/setup.c | 18 ++---------------- include/linux/fsverity.h | 25 +++++++++++++++++++++++-- 4 files changed, 31 insertions(+), 28 deletions(-) diff --git a/fs/ext4/file.c b/fs/ext4/file.c index 30fbd663354f9..b404a857cd487 100644 --- a/fs/ext4/file.c +++ b/fs/ext4/file.c @@ -444,11 +444,9 @@ static int ext4_file_open(struct inode * inode, struct file * filp) if (ret) return ret; - if (IS_VERITY(inode)) { - ret = fsverity_file_open(inode, filp); - if (ret) - return ret; - } + ret = fsverity_file_open(inode, filp); + if (ret) + return ret; /* * Set up the jbd2_inode if we are opening the inode for diff --git a/fs/f2fs/file.c b/fs/f2fs/file.c index c2746f10e119f..6eea508d8656e 100644 --- a/fs/f2fs/file.c +++ b/fs/f2fs/file.c @@ -491,11 +491,9 @@ static int f2fs_file_open(struct inode *inode, struct file *filp) if (err) return err; - if (IS_VERITY(inode)) { - err = fsverity_file_open(inode, filp); - if (err) - return err; - } + err = fsverity_file_open(inode, filp); + if (err) + return err; filp->f_mode |= FMODE_NOWAIT; diff --git a/fs/verity/setup.c b/fs/verity/setup.c index 08b609127531b..4ecaeb89166b4 100644 --- a/fs/verity/setup.c +++ b/fs/verity/setup.c @@ -755,21 +755,7 @@ static int setup_fsverity_info(struct inode *inode) return 0; } -/** - * fsverity_file_open - prepare to open a verity file - * @inode: the inode being opened - * @filp: the struct file being set up - * - * When opening a verity file, deny the open if it is for writing. Otherwise, - * set up the inode's ->i_verity_info (if not already done) by parsing the - * verity metadata at the end of the file. - * - * When combined with fscrypt, this must be called after fscrypt_file_open(). - * Otherwise, we won't have the key set up to decrypt the verity metadata. - * - * Return: 0 on success, -errno on failure - */ -int fsverity_file_open(struct inode *inode, struct file *filp) +int __fsverity_file_open(struct inode *inode, struct file *filp) { if (filp->f_mode & FMODE_WRITE) { pr_debug("Denying opening verity file (ino %lu) for write\n", @@ -779,7 +765,7 @@ int fsverity_file_open(struct inode *inode, struct file *filp) return setup_fsverity_info(inode); } -EXPORT_SYMBOL_GPL(fsverity_file_open); +EXPORT_SYMBOL_GPL(__fsverity_file_open); /** * fsverity_prepare_setattr - prepare to change a verity inode's attributes diff --git a/include/linux/fsverity.h b/include/linux/fsverity.h index ea8c418bd7d53..0ce170c2c1676 100644 --- a/include/linux/fsverity.h +++ b/include/linux/fsverity.h @@ -25,7 +25,7 @@ extern int fsverity_ioctl_enable(struct file *filp, const void __user *arg); extern int fsverity_ioctl_measure(struct file *filp, void __user *arg); /* setup.c */ -extern int fsverity_file_open(struct inode *inode, struct file *filp); +extern int __fsverity_file_open(struct inode *inode, struct file *filp); extern int fsverity_prepare_setattr(struct dentry *dentry, struct iattr *attr); extern int fsverity_prepare_getattr(struct inode *inode); extern void fsverity_cleanup_inode(struct inode *inode); @@ -58,7 +58,7 @@ static inline int fsverity_ioctl_measure(struct file *filp, void __user *arg) /* setup.c */ -static inline int fsverity_file_open(struct inode *inode, struct file *filp) +static inline int __fsverity_file_open(struct inode *inode, struct file *filp) { return -EOPNOTSUPP; } @@ -108,4 +108,25 @@ static inline bool fsverity_check_hole(struct inode *inode, struct page *page) #endif /* ! CONFIG_FS_VERITY */ +/** + * fsverity_file_open - prepare to open a verity file + * @inode: the inode being opened + * @filp: the struct file being set up + * + * When opening a verity file, deny the open if it is for writing. Otherwise, + * set up the inode's ->i_verity_info (if not already done) by parsing the + * verity metadata at the end of the file. + * + * When combined with fscrypt, this must be called after fscrypt_file_open(). + * Otherwise, we won't have the key set up to decrypt the verity metadata. + * + * Return: 0 on success, -errno on failure + */ +static inline int fsverity_file_open(struct inode *inode, struct file *filp) +{ + if (IS_VERITY(inode)) + return __fsverity_file_open(inode, filp); + return 0; +} + #endif /* _LINUX_FSVERITY_H */ From patchwork Tue Dec 11 22:46:51 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eric Biggers X-Patchwork-Id: 10725187 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 689B491E for ; Tue, 11 Dec 2018 22:48:12 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 584F42B5FB for ; Tue, 11 Dec 2018 22:48:12 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 4CA8029FE9; Tue, 11 Dec 2018 22:48:12 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-8.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id C7EF029FE9 for ; Tue, 11 Dec 2018 22:48:11 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726474AbeLKWsL (ORCPT ); Tue, 11 Dec 2018 17:48:11 -0500 Received: from mail.kernel.org ([198.145.29.99]:40552 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726256AbeLKWsJ (ORCPT ); Tue, 11 Dec 2018 17:48:09 -0500 Received: from ebiggers-linuxstation.mtv.corp.google.com (unknown [104.132.1.77]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 442702086D; Tue, 11 Dec 2018 22:48:08 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1544568488; bh=+I541+AWUZvY5Rgv2jxFKuVLXxY47Cd2DEsxv2nayD0=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=B2DpTIu3l/yVO2Zax1fnCHYJXYHIK/YRe7q8yR2EB4muVPgIrPyRWDyzkGHfXrLgs kvVWoAko6sykuTQPgM0XqjsLrCO77NJtv2zea2/R3tNWeGx34Hs/4W3He6sHIVtQo3 mS456bfbzlNNYfjgxRV/6qloisACeINKQxFjmQgU= From: Eric Biggers To: linux-fscrypt@vger.kernel.org, "Theodore Y . Ts'o" Cc: Chandan Rajendra , Krzysztof Kozlowski , linux-ext4@vger.kernel.org, Tony Lindgren , Kirill Tkhai Subject: [PATCH 2/2] fsverity: Move verity status check to fsverity_prepare_setattr Date: Tue, 11 Dec 2018 14:46:51 -0800 Message-Id: <20181211224651.112510-3-ebiggers@kernel.org> X-Mailer: git-send-email 2.20.0.405.gbc1bbc6f85-goog In-Reply-To: <20181211224651.112510-1-ebiggers@kernel.org> References: <20181211224651.112510-1-ebiggers@kernel.org> MIME-Version: 1.0 Sender: linux-fscrypt-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-fscrypt@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP From: Chandan Rajendra Instead of conditionally checking for verity status of an inode before invoking fsverity_prepare_setattr(), this commit moves the check inside the definition of fsverity_prepare_setattr(). Signed-off-by: Chandan Rajendra (EB: fix the !CONFIG_FS_VERITY case and inline the IS_VERITY() check) Signed-off-by: Eric Biggers --- fs/ext4/inode.c | 8 +++----- fs/f2fs/file.c | 8 +++----- fs/verity/setup.c | 14 ++------------ include/linux/fsverity.h | 25 ++++++++++++++++++++++--- 4 files changed, 30 insertions(+), 25 deletions(-) diff --git a/fs/ext4/inode.c b/fs/ext4/inode.c index b83ab0e812483..817b67c3083be 100644 --- a/fs/ext4/inode.c +++ b/fs/ext4/inode.c @@ -5510,11 +5510,9 @@ int ext4_setattr(struct dentry *dentry, struct iattr *attr) if (error) return error; - if (IS_VERITY(inode)) { - error = fsverity_prepare_setattr(dentry, attr); - if (error) - return error; - } + error = fsverity_prepare_setattr(dentry, attr); + if (error) + return error; if (is_quota_modification(inode, attr)) { error = dquot_initialize(inode); diff --git a/fs/f2fs/file.c b/fs/f2fs/file.c index 6eea508d8656e..b73609a43baa7 100644 --- a/fs/f2fs/file.c +++ b/fs/f2fs/file.c @@ -798,11 +798,9 @@ int f2fs_setattr(struct dentry *dentry, struct iattr *attr) if (err) return err; - if (IS_VERITY(inode)) { - err = fsverity_prepare_setattr(dentry, attr); - if (err) - return err; - } + err = fsverity_prepare_setattr(dentry, attr); + if (err) + return err; if (is_quota_modification(inode, attr)) { err = dquot_initialize(inode); diff --git a/fs/verity/setup.c b/fs/verity/setup.c index 4ecaeb89166b4..2b707589999c4 100644 --- a/fs/verity/setup.c +++ b/fs/verity/setup.c @@ -767,17 +767,7 @@ int __fsverity_file_open(struct inode *inode, struct file *filp) } EXPORT_SYMBOL_GPL(__fsverity_file_open); -/** - * fsverity_prepare_setattr - prepare to change a verity inode's attributes - * @dentry: dentry through which the inode is being changed - * @attr: attributes to change - * - * Verity files are immutable, so deny truncates. This isn't covered by the - * open-time check because sys_truncate() takes a path, not a file descriptor. - * - * Return: 0 on success, -errno on failure - */ -int fsverity_prepare_setattr(struct dentry *dentry, struct iattr *attr) +int __fsverity_prepare_setattr(struct dentry *dentry, struct iattr *attr) { if (attr->ia_valid & ATTR_SIZE) { pr_debug("Denying truncate of verity file (ino %lu)\n", @@ -786,7 +776,7 @@ int fsverity_prepare_setattr(struct dentry *dentry, struct iattr *attr) } return 0; } -EXPORT_SYMBOL_GPL(fsverity_prepare_setattr); +EXPORT_SYMBOL_GPL(__fsverity_prepare_setattr); /** * fsverity_prepare_getattr - prepare to get a verity inode's attributes diff --git a/include/linux/fsverity.h b/include/linux/fsverity.h index 0ce170c2c1676..099fc34936fa6 100644 --- a/include/linux/fsverity.h +++ b/include/linux/fsverity.h @@ -26,7 +26,8 @@ extern int fsverity_ioctl_measure(struct file *filp, void __user *arg); /* setup.c */ extern int __fsverity_file_open(struct inode *inode, struct file *filp); -extern int fsverity_prepare_setattr(struct dentry *dentry, struct iattr *attr); +extern int __fsverity_prepare_setattr(struct dentry *dentry, + struct iattr *attr); extern int fsverity_prepare_getattr(struct inode *inode); extern void fsverity_cleanup_inode(struct inode *inode); extern loff_t fsverity_full_i_size(const struct inode *inode); @@ -63,8 +64,8 @@ static inline int __fsverity_file_open(struct inode *inode, struct file *filp) return -EOPNOTSUPP; } -static inline int fsverity_prepare_setattr(struct dentry *dentry, - struct iattr *attr) +static inline int __fsverity_prepare_setattr(struct dentry *dentry, + struct iattr *attr) { return -EOPNOTSUPP; } @@ -129,4 +130,22 @@ static inline int fsverity_file_open(struct inode *inode, struct file *filp) return 0; } +/** + * fsverity_prepare_setattr - prepare to change a verity inode's attributes + * @dentry: dentry through which the inode is being changed + * @attr: attributes to change + * + * Verity files are immutable, so deny truncates. This isn't covered by the + * open-time check because sys_truncate() takes a path, not a file descriptor. + * + * Return: 0 on success, -errno on failure + */ +static inline int fsverity_prepare_setattr(struct dentry *dentry, + struct iattr *attr) +{ + if (IS_VERITY(d_inode(dentry))) + return __fsverity_prepare_setattr(dentry, attr); + return 0; +} + #endif /* _LINUX_FSVERITY_H */