* [PATCH 6.18 0/2] Forbid truncate of fsverity files on btrfs
@ 2026-10-06 21:36 Eric Biggers
2026-10-06 21:36 ` [PATCH 6.18 1/2] fs,fsverity: reject size changes on fsverity files in setattr_prepare Eric Biggers
2026-10-06 21:36 ` [PATCH 6.18 2/2] fs,fsverity: remove check for fsverity being enabled in setattr_prepare() Eric Biggers
0 siblings, 2 replies; 6+ messages in thread
From: Eric Biggers @ 2026-10-06 21:36 UTC (permalink / raw)
To: stable; +Cc: fsverity, Eric Biggers
Backport the fix to forbid truncate(2) of fsverity files on btrfs (and
also the fix for that fix).
Andrey Albershteyn (1):
fs,fsverity: remove check for fsverity being enabled in
setattr_prepare()
Christoph Hellwig (1):
fs,fsverity: reject size changes on fsverity files in setattr_prepare
fs/attr.c | 12 +++++++++++-
fs/ext4/inode.c | 4 ----
fs/f2fs/file.c | 4 ----
fs/verity/open.c | 8 --------
include/linux/fsverity.h | 25 -------------------------
5 files changed, 11 insertions(+), 42 deletions(-)
base-commit: 725bd2f3c81d54edccb66fead01d4c0c222e2231
--
2.56.0
^ permalink raw reply [flat|nested] 6+ messages in thread* [PATCH 6.18 1/2] fs,fsverity: reject size changes on fsverity files in setattr_prepare 2026-10-06 21:36 [PATCH 6.18 0/2] Forbid truncate of fsverity files on btrfs Eric Biggers @ 2026-10-06 21:36 ` Eric Biggers 2026-10-07 6:32 ` Patch "fs,fsverity: reject size changes on fsverity files in setattr_prepare" has been added to the 6.18-stable tree gregkh 2026-10-06 21:36 ` [PATCH 6.18 2/2] fs,fsverity: remove check for fsverity being enabled in setattr_prepare() Eric Biggers 1 sibling, 1 reply; 6+ messages in thread From: Eric Biggers @ 2026-10-06 21:36 UTC (permalink / raw) To: stable; +Cc: fsverity, Christoph Hellwig, Jan Kara, Darrick J. Wong, Eric Biggers From: Christoph Hellwig <hch@lst.de> commit e9734653c523c744f03333ece6ae7a315187f05c upstream. Add the check to reject truncates of fsverity files directly to setattr_prepare instead of requiring the file system to handle it. Besides removing boilerplate code, this also fixes the complete lack of such check in btrfs. Fixes: 146054090b08 ("btrfs: initial fsverity support") Signed-off-by: Christoph Hellwig <hch@lst.de> Reviewed-by: Jan Kara <jack@suse.cz> Reviewed-by: "Darrick J. Wong" <djwong@kernel.org> Link: https://lore.kernel.org/r/20260128152630.627409-2-hch@lst.de Signed-off-by: Eric Biggers <ebiggers@kernel.org> --- fs/attr.c | 12 +++++++++++- fs/ext4/inode.c | 4 ---- fs/f2fs/file.c | 4 ---- fs/verity/open.c | 8 -------- include/linux/fsverity.h | 25 ------------------------- 5 files changed, 11 insertions(+), 42 deletions(-) diff --git a/fs/attr.c b/fs/attr.c index 795f231d00e8..2c94af08be18 100644 --- a/fs/attr.c +++ b/fs/attr.c @@ -169,7 +169,17 @@ int setattr_prepare(struct mnt_idmap *idmap, struct dentry *dentry, * ATTR_FORCE. */ if (ia_valid & ATTR_SIZE) { - int error = inode_newsize_ok(inode, attr->ia_size); + int error; + + /* + * Verity files are immutable, so deny truncates. This isn't + * covered by the open-time check because sys_truncate() takes a + * path, not an open file. + */ + if (IS_ENABLED(CONFIG_FS_VERITY) && IS_VERITY(inode)) + return -EPERM; + + error = inode_newsize_ok(inode, attr->ia_size); if (error) return error; } diff --git a/fs/ext4/inode.c b/fs/ext4/inode.c index 3b2891f18540..d2977c560c96 100644 --- a/fs/ext4/inode.c +++ b/fs/ext4/inode.c @@ -5898,10 +5898,6 @@ int ext4_setattr(struct mnt_idmap *idmap, struct dentry *dentry, if (error) return error; - error = fsverity_prepare_setattr(dentry, attr); - if (error) - return error; - if (is_quota_modification(idmap, inode, attr)) { error = dquot_initialize(inode); if (error) diff --git a/fs/f2fs/file.c b/fs/f2fs/file.c index 222b2a8bbc94..791f1cf198c1 100644 --- a/fs/f2fs/file.c +++ b/fs/f2fs/file.c @@ -1123,10 +1123,6 @@ int f2fs_setattr(struct mnt_idmap *idmap, struct dentry *dentry, if (err) return err; - err = fsverity_prepare_setattr(dentry, attr); - if (err) - return err; - if (unlikely(IS_IMMUTABLE(inode))) return -EPERM; diff --git a/fs/verity/open.c b/fs/verity/open.c index 77b1c977af02..2aa5eae5a540 100644 --- a/fs/verity/open.c +++ b/fs/verity/open.c @@ -384,14 +384,6 @@ int __fsverity_file_open(struct inode *inode, struct file *filp) } EXPORT_SYMBOL_GPL(__fsverity_file_open); -int __fsverity_prepare_setattr(struct dentry *dentry, struct iattr *attr) -{ - if (attr->ia_valid & ATTR_SIZE) - return -EPERM; - return 0; -} -EXPORT_SYMBOL_GPL(__fsverity_prepare_setattr); - void __fsverity_cleanup_inode(struct inode *inode) { struct fsverity_info **vi_addr = fsverity_info_addr(inode); diff --git a/include/linux/fsverity.h b/include/linux/fsverity.h index 5bc7280425a7..86fb1708676b 100644 --- a/include/linux/fsverity.h +++ b/include/linux/fsverity.h @@ -179,7 +179,6 @@ int fsverity_get_digest(struct inode *inode, /* open.c */ int __fsverity_file_open(struct inode *inode, struct file *filp); -int __fsverity_prepare_setattr(struct dentry *dentry, struct iattr *attr); void __fsverity_cleanup_inode(struct inode *inode); /** @@ -251,12 +250,6 @@ static inline int __fsverity_file_open(struct inode *inode, struct file *filp) return -EOPNOTSUPP; } -static inline int __fsverity_prepare_setattr(struct dentry *dentry, - struct iattr *attr) -{ - return -EOPNOTSUPP; -} - static inline void fsverity_cleanup_inode(struct inode *inode) { } @@ -338,22 +331,4 @@ static inline int fsverity_file_open(struct inode *inode, struct file *filp) return 0; } -/** - * 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 - */ -static inline int fsverity_prepare_setattr(struct dentry *dentry, - struct iattr *attr) -{ - if (IS_VERITY(d_inode(dentry))) - return __fsverity_prepare_setattr(dentry, attr); - return 0; -} - #endif /* _LINUX_FSVERITY_H */ -- 2.56.0 ^ permalink raw reply related [flat|nested] 6+ messages in thread
* Patch "fs,fsverity: reject size changes on fsverity files in setattr_prepare" has been added to the 6.18-stable tree 2026-10-06 21:36 ` [PATCH 6.18 1/2] fs,fsverity: reject size changes on fsverity files in setattr_prepare Eric Biggers @ 2026-10-07 6:32 ` gregkh 2026-10-07 6:41 ` sashiko-bot 0 siblings, 1 reply; 6+ messages in thread From: gregkh @ 2026-10-07 6:32 UTC (permalink / raw) To: djwong, ebiggers, fsverity, gregkh, hch, jack; +Cc: stable-commits This is a note to let you know that I've just added the patch titled fs,fsverity: reject size changes on fsverity files in setattr_prepare to the 6.18-stable tree which can be found at: http://www.kernel.org/git/?p=linux/kernel/git/stable/stable-queue.git;a=summary The filename of the patch is: fs-fsverity-reject-size-changes-on-fsverity-files-in-setattr_prepare.patch and it can be found in the queue-6.18 subdirectory. If you, or anyone else, feels it should not be added to the stable tree, please let <stable@vger.kernel.org> know about it. From stable+bounces-352117-greg=kroah.com@vger.kernel.org Tue Oct 6 23:38:38 2026 From: Eric Biggers <ebiggers@kernel.org> Date: Tue, 6 Oct 2026 23:36:04 +0200 Subject: fs,fsverity: reject size changes on fsverity files in setattr_prepare To: stable@vger.kernel.org Cc: fsverity@lists.linux.dev, Christoph Hellwig <hch@lst.de>, Jan Kara <jack@suse.cz>, "Darrick J. Wong" <djwong@kernel.org>, Eric Biggers <ebiggers@kernel.org> Message-ID: <20261006213605.46946-2-ebiggers@kernel.org> From: Christoph Hellwig <hch@lst.de> commit e9734653c523c744f03333ece6ae7a315187f05c upstream. Add the check to reject truncates of fsverity files directly to setattr_prepare instead of requiring the file system to handle it. Besides removing boilerplate code, this also fixes the complete lack of such check in btrfs. Fixes: 146054090b08 ("btrfs: initial fsverity support") Signed-off-by: Christoph Hellwig <hch@lst.de> Reviewed-by: Jan Kara <jack@suse.cz> Reviewed-by: "Darrick J. Wong" <djwong@kernel.org> Link: https://lore.kernel.org/r/20260128152630.627409-2-hch@lst.de Signed-off-by: Eric Biggers <ebiggers@kernel.org> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org> --- fs/attr.c | 12 +++++++++++- fs/ext4/inode.c | 4 ---- fs/f2fs/file.c | 4 ---- fs/verity/open.c | 8 -------- include/linux/fsverity.h | 25 ------------------------- 5 files changed, 11 insertions(+), 42 deletions(-) --- a/fs/attr.c +++ b/fs/attr.c @@ -169,7 +169,17 @@ int setattr_prepare(struct mnt_idmap *id * ATTR_FORCE. */ if (ia_valid & ATTR_SIZE) { - int error = inode_newsize_ok(inode, attr->ia_size); + int error; + + /* + * Verity files are immutable, so deny truncates. This isn't + * covered by the open-time check because sys_truncate() takes a + * path, not an open file. + */ + if (IS_ENABLED(CONFIG_FS_VERITY) && IS_VERITY(inode)) + return -EPERM; + + error = inode_newsize_ok(inode, attr->ia_size); if (error) return error; } --- a/fs/ext4/inode.c +++ b/fs/ext4/inode.c @@ -5898,10 +5898,6 @@ int ext4_setattr(struct mnt_idmap *idmap if (error) return error; - error = fsverity_prepare_setattr(dentry, attr); - if (error) - return error; - if (is_quota_modification(idmap, inode, attr)) { error = dquot_initialize(inode); if (error) --- a/fs/f2fs/file.c +++ b/fs/f2fs/file.c @@ -1123,10 +1123,6 @@ int f2fs_setattr(struct mnt_idmap *idmap if (err) return err; - err = fsverity_prepare_setattr(dentry, attr); - if (err) - return err; - if (unlikely(IS_IMMUTABLE(inode))) return -EPERM; --- a/fs/verity/open.c +++ b/fs/verity/open.c @@ -384,14 +384,6 @@ int __fsverity_file_open(struct inode *i } EXPORT_SYMBOL_GPL(__fsverity_file_open); -int __fsverity_prepare_setattr(struct dentry *dentry, struct iattr *attr) -{ - if (attr->ia_valid & ATTR_SIZE) - return -EPERM; - return 0; -} -EXPORT_SYMBOL_GPL(__fsverity_prepare_setattr); - void __fsverity_cleanup_inode(struct inode *inode) { struct fsverity_info **vi_addr = fsverity_info_addr(inode); --- a/include/linux/fsverity.h +++ b/include/linux/fsverity.h @@ -179,7 +179,6 @@ int fsverity_get_digest(struct inode *in /* open.c */ int __fsverity_file_open(struct inode *inode, struct file *filp); -int __fsverity_prepare_setattr(struct dentry *dentry, struct iattr *attr); void __fsverity_cleanup_inode(struct inode *inode); /** @@ -251,12 +250,6 @@ static inline int __fsverity_file_open(s return -EOPNOTSUPP; } -static inline int __fsverity_prepare_setattr(struct dentry *dentry, - struct iattr *attr) -{ - return -EOPNOTSUPP; -} - static inline void fsverity_cleanup_inode(struct inode *inode) { } @@ -338,22 +331,4 @@ static inline int fsverity_file_open(str return 0; } -/** - * 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 - */ -static inline int fsverity_prepare_setattr(struct dentry *dentry, - struct iattr *attr) -{ - if (IS_VERITY(d_inode(dentry))) - return __fsverity_prepare_setattr(dentry, attr); - return 0; -} - #endif /* _LINUX_FSVERITY_H */ Patches currently in stable-queue which might be from ebiggers@kernel.org are queue-6.18/fs-fsverity-reject-size-changes-on-fsverity-files-in-setattr_prepare.patch queue-6.18/fs-fsverity-remove-check-for-fsverity-being-enabled-in-setattr_prepare.patch queue-6.18/fsverity-add-dependency-on-64k-or-smaller-pages.patch queue-6.18/crypto-x86-aes-gcm-fix-always-true-check-for-last-aad-segment.patch ^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: Patch "fs,fsverity: reject size changes on fsverity files in setattr_prepare" has been added to the 6.18-stable tree 2026-10-07 6:32 ` Patch "fs,fsverity: reject size changes on fsverity files in setattr_prepare" has been added to the 6.18-stable tree gregkh @ 2026-10-07 6:41 ` sashiko-bot 0 siblings, 0 replies; 6+ messages in thread From: sashiko-bot @ 2026-10-07 6:41 UTC (permalink / raw) To: ebiggers, gregkh, djwong, fsverity, hch, jack; +Cc: stable-commits Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider: - [High] vfs: verity file truncation bypass when CONFIG_FS_VERITY is disabled -- commit 750dd8cb058f7ea5d2ca5305006f1c5e63c6eb32 Author: gregkh@linuxfoundation.org <gregkh@linuxfoundation.org> fs,fsverity: reject size changes on fsverity files in setattr_prepare This commit centralizes the check to reject truncates of fsverity files into setattr_prepare() in fs/attr.c. This removes boilerplate code from individual filesystems and fixes a missing truncation check in btrfs. Link: https://lore.kernel.org/r/20260128152630.627409-2-hch@lst.de > diff --git a/fs/attr.c b/fs/attr.c > index 795f231d00e8e..2c94af08be183 100644 > --- a/fs/attr.c > +++ b/fs/attr.c > @@ -169,7 +169,17 @@ int setattr_prepare(struct mnt_idmap *idmap, struct dentry *dentry, > * ATTR_FORCE. > */ > if (ia_valid & ATTR_SIZE) { > - int error = inode_newsize_ok(inode, attr->ia_size); > + int error; > + > + /* > + * Verity files are immutable, so deny truncates. This isn't > + * covered by the open-time check because sys_truncate() takes a > + * path, not an open file. > + */ > + if (IS_ENABLED(CONFIG_FS_VERITY) && IS_VERITY(inode)) > + return -EPERM; [Severity: High] Does this logic inadvertently permit truncating verity files when CONFIG_FS_VERITY is disabled? Before this patch, filesystems explicitly called fsverity_prepare_setattr(). When CONFIG_FS_VERITY was disabled, the fallback implementation safely returned -EOPNOTSUPP for any inode with the verity flag set. By short-circuiting the check here with IS_ENABLED(CONFIG_FS_VERITY), it appears an unprivileged user with DAC write access could use sys_truncate() to bypass the check and modify a verity file if the kernel was built without fsverity support. -- Sashiko AI review · https://sashiko.dev/#/patchset/2026100754-drizzle-shape-0a72@gregkh?part=1 ^ permalink raw reply [flat|nested] 6+ messages in thread
* [PATCH 6.18 2/2] fs,fsverity: remove check for fsverity being enabled in setattr_prepare() 2026-10-06 21:36 [PATCH 6.18 0/2] Forbid truncate of fsverity files on btrfs Eric Biggers 2026-10-06 21:36 ` [PATCH 6.18 1/2] fs,fsverity: reject size changes on fsverity files in setattr_prepare Eric Biggers @ 2026-10-06 21:36 ` Eric Biggers 2026-10-07 6:32 ` Patch "fs,fsverity: remove check for fsverity being enabled in setattr_prepare()" has been added to the 6.18-stable tree gregkh 1 sibling, 1 reply; 6+ messages in thread From: Eric Biggers @ 2026-10-06 21:36 UTC (permalink / raw) To: stable; +Cc: fsverity, Andrey Albershteyn, Christoph Hellwig, Eric Biggers From: Andrey Albershteyn <aalbersh@kernel.org> commit d2f96bcb89d36d488a10e3bcf819b98536968286 upstream. The check that fs-verity is available in the kernel is not necessary here. Filesystems could have fsverity files even without fs-verity enabled. In that case, truncate on fsverity file will succeed, what this check is trying to prevent. Fixes: e9734653c523 ("fs,fsverity: reject size changes on fsverity files in setattr_prepare") Cc: stable@vger.kernel.org Signed-off-by: Andrey Albershteyn <aalbersh@kernel.org> Reviewed-by: Christoph Hellwig <hch@lst.de> Link: https://patch.msgid.link/20260727094352.1734826-1-aalbersh@kernel.org Signed-off-by: Eric Biggers <ebiggers@kernel.org> --- fs/attr.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/fs/attr.c b/fs/attr.c index 2c94af08be18..3f2cce4e4ad1 100644 --- a/fs/attr.c +++ b/fs/attr.c @@ -176,7 +176,7 @@ int setattr_prepare(struct mnt_idmap *idmap, struct dentry *dentry, * covered by the open-time check because sys_truncate() takes a * path, not an open file. */ - if (IS_ENABLED(CONFIG_FS_VERITY) && IS_VERITY(inode)) + if (IS_VERITY(inode)) return -EPERM; error = inode_newsize_ok(inode, attr->ia_size); -- 2.56.0 ^ permalink raw reply related [flat|nested] 6+ messages in thread
* Patch "fs,fsverity: remove check for fsverity being enabled in setattr_prepare()" has been added to the 6.18-stable tree 2026-10-06 21:36 ` [PATCH 6.18 2/2] fs,fsverity: remove check for fsverity being enabled in setattr_prepare() Eric Biggers @ 2026-10-07 6:32 ` gregkh 0 siblings, 0 replies; 6+ messages in thread From: gregkh @ 2026-10-07 6:32 UTC (permalink / raw) To: aalbersh, ebiggers, fsverity, gregkh, hch; +Cc: stable-commits This is a note to let you know that I've just added the patch titled fs,fsverity: remove check for fsverity being enabled in setattr_prepare() to the 6.18-stable tree which can be found at: http://www.kernel.org/git/?p=linux/kernel/git/stable/stable-queue.git;a=summary The filename of the patch is: fs-fsverity-remove-check-for-fsverity-being-enabled-in-setattr_prepare.patch and it can be found in the queue-6.18 subdirectory. If you, or anyone else, feels it should not be added to the stable tree, please let <stable@vger.kernel.org> know about it. From stable+bounces-352118-greg=kroah.com@vger.kernel.org Tue Oct 6 23:39:37 2026 From: Eric Biggers <ebiggers@kernel.org> Date: Tue, 6 Oct 2026 23:36:05 +0200 Subject: fs,fsverity: remove check for fsverity being enabled in setattr_prepare() To: stable@vger.kernel.org Cc: fsverity@lists.linux.dev, Andrey Albershteyn <aalbersh@kernel.org>, Christoph Hellwig <hch@lst.de>, Eric Biggers <ebiggers@kernel.org> Message-ID: <20261006213605.46946-3-ebiggers@kernel.org> From: Andrey Albershteyn <aalbersh@kernel.org> commit d2f96bcb89d36d488a10e3bcf819b98536968286 upstream. The check that fs-verity is available in the kernel is not necessary here. Filesystems could have fsverity files even without fs-verity enabled. In that case, truncate on fsverity file will succeed, what this check is trying to prevent. Fixes: e9734653c523 ("fs,fsverity: reject size changes on fsverity files in setattr_prepare") Cc: stable@vger.kernel.org Signed-off-by: Andrey Albershteyn <aalbersh@kernel.org> Reviewed-by: Christoph Hellwig <hch@lst.de> Link: https://patch.msgid.link/20260727094352.1734826-1-aalbersh@kernel.org Signed-off-by: Eric Biggers <ebiggers@kernel.org> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org> --- fs/attr.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) --- a/fs/attr.c +++ b/fs/attr.c @@ -176,7 +176,7 @@ int setattr_prepare(struct mnt_idmap *id * covered by the open-time check because sys_truncate() takes a * path, not an open file. */ - if (IS_ENABLED(CONFIG_FS_VERITY) && IS_VERITY(inode)) + if (IS_VERITY(inode)) return -EPERM; error = inode_newsize_ok(inode, attr->ia_size); Patches currently in stable-queue which might be from ebiggers@kernel.org are queue-6.18/fs-fsverity-reject-size-changes-on-fsverity-files-in-setattr_prepare.patch queue-6.18/fs-fsverity-remove-check-for-fsverity-being-enabled-in-setattr_prepare.patch queue-6.18/fsverity-add-dependency-on-64k-or-smaller-pages.patch queue-6.18/crypto-x86-aes-gcm-fix-always-true-check-for-last-aad-segment.patch ^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2026-10-07 6:41 UTC | newest] Thread overview: 6+ messages (download: mbox.gz follow: Atom feed -- links below jump to the message on this page -- 2026-10-06 21:36 [PATCH 6.18 0/2] Forbid truncate of fsverity files on btrfs Eric Biggers 2026-10-06 21:36 ` [PATCH 6.18 1/2] fs,fsverity: reject size changes on fsverity files in setattr_prepare Eric Biggers 2026-10-07 6:32 ` Patch "fs,fsverity: reject size changes on fsverity files in setattr_prepare" has been added to the 6.18-stable tree gregkh 2026-10-07 6:41 ` sashiko-bot 2026-10-06 21:36 ` [PATCH 6.18 2/2] fs,fsverity: remove check for fsverity being enabled in setattr_prepare() Eric Biggers 2026-10-07 6:32 ` Patch "fs,fsverity: remove check for fsverity being enabled in setattr_prepare()" has been added to the 6.18-stable tree gregkh
This is an external index of several public inboxes, see mirroring instructions on how to clone and mirror all data and code used by this external index.