From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-9.1 required=3.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,INCLUDES_PATCH,MAILING_LIST_MULTI,SIGNED_OFF_BY,SPF_HELO_NONE, SPF_PASS,T_DKIMWL_WL_HIGH,USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 89DF2C282DD for ; Thu, 23 May 2019 16:21:10 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 60DDA2175B for ; Thu, 23 May 2019 16:21:10 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1558628470; bh=OXgI1Anom05ui26ncqYa0NBQDzcnpGqcy+YcyYqHoZA=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-ID:From; b=oJMUqgX9WpTkcAxeGWVtmGyiEfTiAv0XIRRaxeFis9sb/06E9EKvlOwtKAerM45qO KVy1o9pAxZkHIhG+j64z5LdxSaKvGAT/JQ8pjHh9mMO10EbFCb89MzdH1pVfOgTEQe UdE9gaiHIYh06YObDvHtunkXkBLviiTEwdiH2+10= Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1731748AbfEWQVG (ORCPT ); Thu, 23 May 2019 12:21:06 -0400 Received: from mail.kernel.org ([198.145.29.99]:56244 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730790AbfEWQUi (ORCPT ); Thu, 23 May 2019 12:20:38 -0400 Received: from sol.localdomain (c-24-5-143-220.hsd1.ca.comcast.net [24.5.143.220]) (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 634A621873; Thu, 23 May 2019 16:20:37 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1558628437; bh=OXgI1Anom05ui26ncqYa0NBQDzcnpGqcy+YcyYqHoZA=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=GtWslty6zwFR4VyaGGbEH60JbdIURHw6kESwgz0h2HJBdwZQnCAox+mwi+Mhh2nQy o1zsAeZZqiy3LWOOx+4A09Fr0xSAzIGZYUr+qW+eqARJ2TGLPKieP76UDxJBKyn2dY FBiRN3y++ME4jazvWoLpe/TrrZfHTJ+dktLZSOLc= From: Eric Biggers To: linux-fscrypt@vger.kernel.org Cc: linux-fsdevel@vger.kernel.org, linux-ext4@vger.kernel.org, linux-f2fs-devel@lists.sourceforge.net, linux-integrity@vger.kernel.org, linux-api@vger.kernel.org, "Theodore Y . Ts'o" , Jaegeuk Kim , Victor Hsieh Subject: [PATCH v3 07/15] fs-verity: add the hook for file ->setattr() Date: Thu, 23 May 2019 09:18:03 -0700 Message-Id: <20190523161811.6259-8-ebiggers@kernel.org> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20190523161811.6259-1-ebiggers@kernel.org> References: <20190523161811.6259-1-ebiggers@kernel.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Sender: linux-fsdevel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-fsdevel@vger.kernel.org From: Eric Biggers Add a function fsverity_prepare_setattr() which filesystems that support fs-verity must call to deny truncates of verity files. Signed-off-by: Eric Biggers --- 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 e6d73d73b000d..f779a150b4ede 100644 --- a/fs/verity/open.c +++ b/fs/verity/open.c @@ -292,6 +292,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 3b60195e3c51a..29bb4d007ad16 100644 --- a/include/linux/fsverity.h +++ b/include/linux/fsverity.h @@ -40,6 +40,7 @@ struct fsverity_operations { /* 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 */ @@ -51,6 +52,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) { } -- 2.21.0