From patchwork Thu Jun 20 20:50:35 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eric Biggers X-Patchwork-Id: 11008033 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 A4EE976 for ; Thu, 20 Jun 2019 20:53:50 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 9754B28841 for ; Thu, 20 Jun 2019 20:53:50 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 8AF1E28856; Thu, 20 Jun 2019 20:53:50 +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=unavailable 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 397E228841 for ; Thu, 20 Jun 2019 20:53:50 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726323AbfFTUxs (ORCPT ); Thu, 20 Jun 2019 16:53:48 -0400 Received: from mail.kernel.org ([198.145.29.99]:56566 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726351AbfFTUxr (ORCPT ); Thu, 20 Jun 2019 16:53:47 -0400 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 B3768215EA; Thu, 20 Jun 2019 20:53:45 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1561064026; bh=7jX9aA8IE8stWz6zj6E8QX1HMCEanuNDjXJElYmTkkM=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=RrdlOl3Nwd/Z4Muo8ZjIxtOWBl5qWp/dIGg7LjnewU7tt7Oc58EzolLKFaB19T7SH zPIv3Vir4EoUPeSPcn6vMi0ZXVaMkLAmRIH/vELUvPvtPIEn9RJQqqrkvhx3XUedeX FYbK2BHPNvWVY3CvcWeKmDx8nc3BzX1FtUX1z5+s= From: Eric Biggers To: linux-fscrypt@vger.kernel.org Cc: linux-ext4@vger.kernel.org, linux-f2fs-devel@lists.sourceforge.net, linux-fsdevel@vger.kernel.org, linux-api@vger.kernel.org, linux-integrity@vger.kernel.org, Jaegeuk Kim , "Theodore Y . Ts'o" , Victor Hsieh , Chandan Rajendra , Dave Chinner , Christoph Hellwig , "Darrick J . Wong" , Linus Torvalds Subject: [PATCH v5 08/16] fs-verity: add the hook for file ->setattr() Date: Thu, 20 Jun 2019 13:50:35 -0700 Message-Id: <20190620205043.64350-9-ebiggers@kernel.org> X-Mailer: git-send-email 2.22.0.410.gd8fdbe21b5-goog In-Reply-To: <20190620205043.64350-1-ebiggers@kernel.org> References: <20190620205043.64350-1-ebiggers@kernel.org> MIME-Version: 1.0 Sender: linux-integrity-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-integrity@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP From: Eric Biggers Add a function fsverity_prepare_setattr() which filesystems that support fs-verity must call to deny truncates of verity files. Reviewed-by: Theodore Ts'o Signed-off-by: Eric Biggers Reviewed-by: Jaegeuk Kim --- fs/verity/open.c | 21 +++++++++++++++++++++ include/linux/fsverity.h | 7 +++++++ 2 files changed, 28 insertions(+) diff --git a/fs/verity/open.c b/fs/verity/open.c index 3a3bb27e23f5e3..21ae0ef254a695 100644 --- a/fs/verity/open.c +++ b/fs/verity/open.c @@ -296,6 +296,27 @@ 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) +{ + if (IS_VERITY(d_inode(dentry)) && (attr->ia_valid & ATTR_SIZE)) { + pr_debug("Denying truncate of verity file (ino %lu)\n", + d_inode(dentry)->i_ino); + return -EPERM; + } + return 0; +} +EXPORT_SYMBOL_GPL(fsverity_prepare_setattr); + /** * fsverity_cleanup_inode - free the inode's verity info, if present * diff --git a/include/linux/fsverity.h b/include/linux/fsverity.h index 1372c236c8770c..cbcc358d073652 100644 --- a/include/linux/fsverity.h +++ b/include/linux/fsverity.h @@ -46,6 +46,7 @@ static inline struct fsverity_info *fsverity_get_info(const struct inode *inode) /* open.c */ extern int fsverity_file_open(struct inode *inode, struct file *filp); +extern int fsverity_prepare_setattr(struct dentry *dentry, struct iattr *attr); extern void fsverity_cleanup_inode(struct inode *inode); #else /* !CONFIG_FS_VERITY */ @@ -62,6 +63,12 @@ static inline int fsverity_file_open(struct inode *inode, struct file *filp) return IS_VERITY(inode) ? -EOPNOTSUPP : 0; } +static inline int fsverity_prepare_setattr(struct dentry *dentry, + struct iattr *attr) +{ + return IS_VERITY(d_inode(dentry)) ? -EOPNOTSUPP : 0; +} + static inline void fsverity_cleanup_inode(struct inode *inode) { }