From: James Bottomley Date: Sun, 19 Jan 2025 14:59:40 +0000 (-0500) Subject: efivarfs: prevent setting of zero size on the inodes in the cache X-Git-Tag: v6.14-rc1~99^2~8 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=8b4bc207f981bd87728d2e1c0cf6f4304f9d0159;p=thirdparty%2Fkernel%2Flinux.git efivarfs: prevent setting of zero size on the inodes in the cache Current efivarfs uses simple_setattr which allows the setting of any size in the inode cache. This is wrong because a zero size file is used to indicate an "uncommitted" variable, so by simple means of truncating the file (as root) any variable may be turned to look like it's uncommitted. Fix by adding an efivarfs_setattr routine which does not allow updating of the cached inode size (which now only comes from the underlying variable). Signed-off-by: James Bottomley Signed-off-by: Ard Biesheuvel --- diff --git a/fs/efivarfs/inode.c b/fs/efivarfs/inode.c index ec23da8405ff8..a4a6587ecd2ed 100644 --- a/fs/efivarfs/inode.c +++ b/fs/efivarfs/inode.c @@ -187,7 +187,24 @@ efivarfs_fileattr_set(struct mnt_idmap *idmap, return 0; } +/* copy of simple_setattr except that it doesn't do i_size updates */ +static int efivarfs_setattr(struct mnt_idmap *idmap, struct dentry *dentry, + struct iattr *iattr) +{ + struct inode *inode = d_inode(dentry); + int error; + + error = setattr_prepare(idmap, dentry, iattr); + if (error) + return error; + + setattr_copy(idmap, inode, iattr); + mark_inode_dirty(inode); + return 0; +} + static const struct inode_operations efivarfs_file_inode_operations = { .fileattr_get = efivarfs_fileattr_get, .fileattr_set = efivarfs_fileattr_set, + .setattr = efivarfs_setattr, };