Received: by 2002:a25:ab43:0:0:0:0:0 with SMTP id u61csp2366628ybi; Thu, 20 Jun 2019 13:54:14 -0700 (PDT) X-Google-Smtp-Source: APXvYqwkT/N/Cc5fmBCCad504WbXsMEcB6L5o4sQvPWcg+lUOmmNDl7NqohPWPfyv0s4etU7MrO2 X-Received: by 2002:a63:9502:: with SMTP id p2mr4320933pgd.12.1561064054669; Thu, 20 Jun 2019 13:54:14 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1561064054; cv=none; d=google.com; s=arc-20160816; b=SDKy9wKKQD7AxNr5c3rm/o5qxr49iKuop8CbjYPTTfPXwNNy1uGgrupRN5My2it8SS u829TUv4yOpHqGOeNsYPNWBvv50rxf6zsrUJuGCGJBnfgTuifTUdGFmoTl6gdurUjJrz 9sB0TY6fsXiluVZeO8oKgHn2kglnktBo39MiZAoYVqRHlbXry85hEJJqeLOvdyzglfom IRpaNZc19PF40y4XXJHQRrVMloFqG5XbAcYfsFarE4pa7PlZ2YA+rGVF+BF2qVtzsHRP 8PZDyfhDdaq9gGg9oOB2IxsV59El4F6sDnJjDgFBACLtGrRyee5d9ortTzTE3VYe7Dbh r/RA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=Cwu9ueHy+VU+ZovKlIm3mKNVtRFs2hfaF9TCeIsRAFg=; b=kSnsBOGanesdFKU9OxpLChKXZ/DZTuNbXo2JkRYpu8Muh8PToKWufmq/8nVBhu55ns 8KKzk1XjzMUbfEt9ZnmiVHDGupgy53dWcU2sB+cjKEfpPHjP1Vze3SD3ZdQN5TXppuv7 q/H8PK1kxuSqD/WwIvjn5Kx/e4U/xeW0RrKm3wnO5VK4pSvT3ElToZTdg/TfitdgH/ro 7ZrYYUcFNGqplRdnSMl2SmrVSb27DOJEB4OPdINYiHVyQciVQFObpCjHjB4SmvISnSgy 3qHyWV3Z1RYM7KUj0ON7QzHWZFiDk2ToddUe2MndfrtT0he71ltwx1WI4WTcse7I4xwV 5nWQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=RrdlOl3N; spf=pass (google.com: best guess record for domain of linux-ext4-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-ext4-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id m63si671379pld.385.2019.06.20.13.53.56; Thu, 20 Jun 2019 13:54:14 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-ext4-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=@kernel.org header.s=default header.b=RrdlOl3N; spf=pass (google.com: best guess record for domain of linux-ext4-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-ext4-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726439AbfFTUxs (ORCPT + 99 others); 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 Content-Transfer-Encoding: 8bit Sender: linux-ext4-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-ext4@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. Reviewed-by: Theodore Ts'o 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 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) { } -- 2.22.0.410.gd8fdbe21b5-goog