linux/fs/verity
Eric Biggers c349b233d6 fsverity: Set S_VERITY only after rollback is no longer possible
Commit f77f281b61 ("fsverity: use a hashtable to find the
fsverity_info") changed the implementation of FS_IOC_ENABLE_VERITY to
make concurrent reads start going through fsverity verification slightly
earlier than they did before.

Instead of it happening when enable_verity() calls fsverity_set_info(),
it now happens when ->end_enable_verity() sets S_VERITY.

However, ext4 and btrfs can roll back verity after they set S_VERITY,
causing a use-after-free.

Fix that by making ext4 and btrfs set S_VERITY only after rollback is no
longer possible.  On failure, don't roll back S_VERITY, but do roll back
the filesystem-specific verity flag.

Also update enable_verity() to handle any future instances of this bug
more safely by warning and *not* freeing the fsverity_info.

Finally, tweak some comments.  Clarify one, and move information from
another to its proper place in the comment for ->end_enable_verity().

Fixes: f77f281b61 ("fsverity: use a hashtable to find the fsverity_info")
Cc: stable@vger.kernel.org
Reviewed-by: Christoph Hellwig <hch@lst.de>
Link: https://patch.msgid.link/20261025204807.122875-1-ebiggers@kernel.org
Signed-off-by: Eric Biggers <ebiggers@kernel.org>
2026-10-28 10:53:43 -07:00
..
enable.c fsverity: Set S_VERITY only after rollback is no longer possible 2026-10-28 10:53:43 -07:00
fsverity_private.h fsverity: Tell LSMs about signature only after verity is enabled 2026-10-28 10:53:43 -07:00
hash_algs.c fsverity: Remove inode parameter from fsverity_hash_block() 2025-09-17 13:09:40 -05:00
init.c treewide: change inode->i_ino from unsigned long to u64 2026-03-06 14:31:28 +01:00
Kconfig fsverity: add dependency on 64K or smaller pages 2026-03-02 21:05:34 -08:00
Makefile fsverity: start consolidating pagecache code 2026-01-29 09:39:41 -08:00
measure.c fsverity: Explicitly require FMODE_READ to retrieve hashes 2026-10-28 10:52:54 -07:00
open.c fsverity: Tell LSMs about signature only after verity is enabled 2026-10-28 10:53:43 -07:00
pagecache.c fsverity: hoist pagecache_read from f2fs/ext4 to fsverity 2026-10-04 19:47:47 +02:00
read_metadata.c fsverity: Explicitly require FMODE_READ to retrieve hashes 2026-10-28 10:52:54 -07:00
signature.c fsverity: Tell LSMs about signature only after verity is enabled 2026-10-28 10:53:43 -07:00
verify.c fsverity: report validation errors through fserror to fsnotify 2026-10-04 19:30:50 +02:00