mirror of
https://github.com/Fishwaldo/linux-bl808.git
synced 2025-03-21 06:24:12 +00:00
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>
This commit is contained in:
parent
fd2d1acfca
commit
c1d9b584e2
2 changed files with 28 additions and 0 deletions
|
@ -295,6 +295,27 @@ int fsverity_file_open(struct inode *inode, struct file *filp)
|
||||||
}
|
}
|
||||||
EXPORT_SYMBOL_GPL(fsverity_file_open);
|
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
|
* fsverity_cleanup_inode() - free the inode's verity info, if present
|
||||||
*
|
*
|
||||||
|
|
|
@ -46,6 +46,7 @@ static inline struct fsverity_info *fsverity_get_info(const struct inode *inode)
|
||||||
/* open.c */
|
/* open.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 void fsverity_cleanup_inode(struct inode *inode);
|
extern void fsverity_cleanup_inode(struct inode *inode);
|
||||||
|
|
||||||
#else /* !CONFIG_FS_VERITY */
|
#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;
|
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)
|
static inline void fsverity_cleanup_inode(struct inode *inode)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue