diff options
author | Eric Biggers <ebiggers@google.com> | 2019-07-22 09:26:22 -0700 |
---|---|---|
committer | Eric Biggers <ebiggers@google.com> | 2019-07-28 16:59:16 -0700 |
commit | c1d9b584e2cf3f0562d8fcf34574c044d17853a1 (patch) | |
tree | 9c0c25b8bb3e53a55ffb9d86faae9cff7c56d012 /fs | |
parent | fd2d1acfcadfe2e42567afaec5e989b38061a7d2 (diff) | |
download | linux-c1d9b584e2cf3f0562d8fcf34574c044d17853a1.tar.bz2 |
fs-verity: add the hook for file ->setattr()
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 <tytso@mit.edu>
Reviewed-by: Jaegeuk Kim <jaegeuk@kernel.org>
Signed-off-by: Eric Biggers <ebiggers@google.com>
Diffstat (limited to 'fs')
-rw-r--r-- | fs/verity/open.c | 21 |
1 files changed, 21 insertions, 0 deletions
diff --git a/fs/verity/open.c b/fs/verity/open.c index 8013f77f907e..2cb2fe8082bf 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 * * Filesystems must call this on inode eviction to free ->i_verity_info. |