Merge tag 'fsverity-for-linus' of git://git.kernel.org/pub/scm/fs/fsverity/linux

Pull fsverity updates from Eric Biggers:
 "Patches from Andrey Albershteyn to prepare for XFS fsverity support:

   - Report verification errors through fserror, instead of only through
     an unstructured log message and generic I/O error return

   - Move the reporting of STATX_ATTR_VERITY into the VFS, so that each
     fsverity-capable filesystem doesn't need to do it. This also fixes
     a bug where btrfs didn't return STATX_ATTR_VERITY in
     attributes_mask

   - Make the VFS prevent enabling DAX on fsverity files, so that it
     will be handled in a single place for ext4 and XFS

   - Move ext4 and f2fs's code to read verity metadata from the
     pagecache into shared code, so that XFS will be able to use it too

   - Export fsverity_ensure_verity_info() for XFS scrub to use

   - Pass all-zeroes hash to ->write_merkle_tree_block() so that XFS
     will be able to implement an optimization for sparse files"

* tag 'fsverity-for-linus' of git://git.kernel.org/pub/scm/fs/fsverity/linux:
  fsverity: hoist statx reporting of fs-verity flag
  fsverity: don't allow setting DAX file attribute on fsverity files
  fsverity: hoist pagecache_read from f2fs/ext4 to fsverity
  fsverity: pass digest size and hash of the all-zeroes block to ->write
  fsverity: expose ensure_fsverity_info()
  fsverity: report validation errors through fserror to fsnotify
  MAINTAINERS: List the fsverity branches
This commit is contained in:
Linus Torvalds
2026-10-20 15:51:20 -10:00
14 changed files with 105 additions and 81 deletions
+2 -1
View File
@@ -10746,7 +10746,8 @@ M: Theodore Y. Ts'o <[email protected]>
L: [email protected]
S: Supported
Q: https://patchwork.kernel.org/project/fsverity/list/
T: git https://git.kernel.org/pub/scm/fs/fsverity/linux.git
T: git https://git.kernel.org/pub/scm/fs/fsverity/linux.git for-next
T: git https://git.kernel.org/pub/scm/fs/fsverity/linux.git for-current
F: Documentation/filesystems/fsverity.rst
F: fs/verity/
F: include/linux/fsverity.h
-3
View File
@@ -8252,7 +8252,6 @@ static int btrfs_getattr(const struct mnt_idmap *idmap,
struct inode *inode = d_inode(path->dentry);
u32 blocksize = btrfs_sb(inode->i_sb)->sectorsize;
u32 bi_flags = BTRFS_I(inode)->flags;
u32 bi_ro_flags = BTRFS_I(inode)->ro_flags;
stat->result_mask |= STATX_BTIME;
stat->btime.tv_sec = BTRFS_I(inode)->i_otime_sec;
@@ -8265,8 +8264,6 @@ static int btrfs_getattr(const struct mnt_idmap *idmap,
stat->attributes |= STATX_ATTR_IMMUTABLE;
if (bi_flags & BTRFS_INODE_NODUMP)
stat->attributes |= STATX_ATTR_NODUMP;
if (bi_ro_flags & BTRFS_INODE_RO_VERITY)
stat->attributes |= STATX_ATTR_VERITY;
stat->attributes_mask |= (STATX_ATTR_APPEND |
STATX_ATTR_COMPRESSED |
+5 -1
View File
@@ -793,11 +793,15 @@ out:
* @buf: Merkle tree block to write
* @pos: the position of the block in the Merkle tree (in bytes)
* @size: the Merkle tree block size (in bytes)
* @zero_digest: the hash of the all-zeroes block
* @digest_size: size of zero_digest, in bytes
*
* Returns 0 on success or negative error code on failure
*/
static int btrfs_write_merkle_tree_block(struct file *file, const void *buf,
u64 pos, unsigned int size)
u64 pos, unsigned int size,
const u8 *zero_digest,
unsigned int digest_size)
{
struct inode *inode = file_inode(file);
loff_t merkle_pos = merkle_file_pos(inode);
+1 -4
View File
@@ -6318,15 +6318,12 @@ int ext4_getattr(const struct mnt_idmap *idmap, const struct path *path,
stat->attributes |= STATX_ATTR_IMMUTABLE;
if (flags & EXT4_NODUMP_FL)
stat->attributes |= STATX_ATTR_NODUMP;
if (flags & EXT4_VERITY_FL)
stat->attributes |= STATX_ATTR_VERITY;
stat->attributes_mask |= (STATX_ATTR_APPEND |
STATX_ATTR_COMPRESSED |
STATX_ATTR_ENCRYPTED |
STATX_ATTR_IMMUTABLE |
STATX_ATTR_NODUMP |
STATX_ATTR_VERITY);
STATX_ATTR_NODUMP);
generic_fillattr(idmap, request_mask, inode, stat);
return 0;
+6 -30
View File
@@ -34,32 +34,6 @@ static inline loff_t ext4_verity_metadata_pos(const struct inode *inode)
return round_up(inode->i_size, 65536);
}
/*
* Read some verity metadata from the inode. __vfs_read() can't be used because
* we need to read beyond i_size.
*/
static int pagecache_read(struct inode *inode, void *buf, size_t count,
loff_t pos)
{
while (count) {
struct folio *folio;
size_t n;
folio = read_mapping_folio(inode->i_mapping, pos >> PAGE_SHIFT,
NULL);
if (IS_ERR(folio))
return PTR_ERR(folio);
n = memcpy_from_file_folio(buf, folio, pos, count);
folio_put(folio);
buf += n;
pos += n;
count -= n;
}
return 0;
}
/*
* Write some verity metadata to the inode for FS_IOC_ENABLE_VERITY.
* kernel_write() can't be used because the file descriptor is readonly.
@@ -311,8 +285,8 @@ static int ext4_get_verity_descriptor_location(struct inode *inode,
goto bad;
desc_size_pos -= sizeof(desc_size_disk);
err = pagecache_read(inode, &desc_size_disk, sizeof(desc_size_disk),
desc_size_pos);
err = fsverity_pagecache_read(inode, &desc_size_disk,
sizeof(desc_size_disk), desc_size_pos);
if (err)
return err;
desc_size = le32_to_cpu(desc_size_disk);
@@ -352,7 +326,7 @@ static int ext4_get_verity_descriptor(struct inode *inode, void *buf,
if (buf_size) {
if (desc_size > buf_size)
return -ERANGE;
err = pagecache_read(inode, buf, desc_size, desc_pos);
err = fsverity_pagecache_read(inode, buf, desc_size, desc_pos);
if (err)
return err;
}
@@ -374,7 +348,9 @@ static void ext4_readahead_merkle_tree(struct inode *inode, pgoff_t index,
}
static int ext4_write_merkle_tree_block(struct file *file, const void *buf,
u64 pos, unsigned int size)
u64 pos, unsigned int size,
const u8 *zero_digest,
unsigned int digest_size)
{
pos += ext4_verity_metadata_pos(file_inode(file));
+1 -4
View File
@@ -1075,15 +1075,12 @@ int f2fs_getattr(const struct mnt_idmap *idmap, const struct path *path,
stat->attributes |= STATX_ATTR_IMMUTABLE;
if (flags & F2FS_NODUMP_FL)
stat->attributes |= STATX_ATTR_NODUMP;
if (IS_VERITY(inode))
stat->attributes |= STATX_ATTR_VERITY;
stat->attributes_mask |= (STATX_ATTR_COMPRESSED |
STATX_ATTR_APPEND |
STATX_ATTR_ENCRYPTED |
STATX_ATTR_IMMUTABLE |
STATX_ATTR_NODUMP |
STATX_ATTR_VERITY);
STATX_ATTR_NODUMP);
generic_fillattr(idmap, request_mask, inode, stat);
+4 -30
View File
@@ -37,34 +37,6 @@ static inline loff_t f2fs_verity_metadata_pos(const struct inode *inode)
return round_up(inode->i_size, 65536);
}
/*
* Read some verity metadata from the inode. __vfs_read() can't be used because
* we need to read beyond i_size.
*/
static int pagecache_read(struct inode *inode, void *buf, size_t count,
loff_t pos)
{
while (count) {
size_t n = min_t(size_t, count,
PAGE_SIZE - offset_in_page(pos));
struct page *page;
page = read_mapping_page(inode->i_mapping, pos >> PAGE_SHIFT,
NULL);
if (IS_ERR(page))
return PTR_ERR(page);
memcpy_from_page(buf, page, offset_in_page(pos), n);
put_page(page);
buf += n;
pos += n;
count -= n;
}
return 0;
}
/*
* Write some verity metadata to the inode for FS_IOC_ENABLE_VERITY.
* kernel_write() can't be used because the file descriptor is readonly.
@@ -250,7 +222,7 @@ static int f2fs_get_verity_descriptor(struct inode *inode, void *buf,
if (buf_size) {
if (size > buf_size)
return -ERANGE;
res = pagecache_read(inode, buf, size, pos);
res = fsverity_pagecache_read(inode, buf, size, pos);
if (res)
return res;
}
@@ -272,7 +244,9 @@ static void f2fs_readahead_merkle_tree(struct inode *inode, pgoff_t index,
}
static int f2fs_write_merkle_tree_block(struct file *file, const void *buf,
u64 pos, unsigned int size)
u64 pos, unsigned int size,
const u8 *zero_digest,
unsigned int digest_size)
{
pos += f2fs_verity_metadata_pos(file_inode(file));
+8 -3
View File
@@ -235,10 +235,15 @@ static int fileattr_set_prepare(struct inode *inode,
/*
* It is only valid to set the DAX flag on regular files and
* directories on filesystems.
*
* DAX and fsverity are incompatible.
*/
if ((fa->fsx_xflags & FS_XFLAG_DAX) &&
!(S_ISREG(inode->i_mode) || S_ISDIR(inode->i_mode)))
return -EINVAL;
if (fa->fsx_xflags & FS_XFLAG_DAX) {
if (!(S_ISREG(inode->i_mode) || S_ISDIR(inode->i_mode)))
return -EINVAL;
if (old_ma->fsx_xflags & FS_XFLAG_VERITY)
return -EINVAL;
}
/* Extent size hints of zero turn off the flags. */
if (fa->fsx_extsize == 0)
+5 -1
View File
@@ -203,8 +203,12 @@ int vfs_getattr_nosec(const struct path *path, struct kstat *stat,
if (IS_DAX(inode))
stat->attributes |= STATX_ATTR_DAX;
if (IS_VERITY(inode))
stat->attributes |= STATX_ATTR_VERITY;
stat->attributes_mask |= (STATX_ATTR_AUTOMOUNT |
STATX_ATTR_DAX);
STATX_ATTR_DAX |
STATX_ATTR_VERITY);
idmap = mnt_idmap(path->mnt);
if (inode->i_op->getattr) {
+3 -1
View File
@@ -50,7 +50,9 @@ static int write_merkle_tree_block(struct file *file, const u8 *buf,
int err;
err = inode->i_sb->s_vop->write_merkle_tree_block(file, buf, pos,
params->block_size);
params->block_size,
params->zero_digest,
params->digest_size);
if (err)
fsverity_err(inode, "Error %d writing Merkle tree block %lu",
err, index);
+24 -2
View File
@@ -347,7 +347,28 @@ int fsverity_get_descriptor(struct inode *inode,
return 0;
}
static int ensure_verity_info(struct inode *inode)
/**
* fsverity_ensure_verity_info() - cache verity info if it's not already cached
* @inode: the inode for which verity info should be cached
*
* Ensure this inode has verity info attached to it, it's assumed the inode
* already has fsverity enabled. Read fsverity descriptor and creates verity
* based on that.
*
* This needs to be called at least once before any of the inode's data
* can be verified (and thus read at all) or the inode's fsverity digest
* retrieved. fsverity_file_open() calls this already, which handles
* normal file accesses. If a filesystem does any internal (i.e. not
* associated with a file descriptor) reads of the file's data or
* fsverity digest, it must call this explicitly before doing so.
*
* In case filesystem supports both fscrypt and fsverity, this should be called
* after fscrypt's encryption key is set up. Otherwise, the fsverity metadata is
* still encrypted. See fscrypt_file_open().
*
* Return: 0 on success, -errno on failure
*/
int fsverity_ensure_verity_info(struct inode *inode)
{
struct fsverity_info *vi = fsverity_get_info(inode), *found;
struct fsverity_descriptor *desc;
@@ -383,12 +404,13 @@ out_free_desc:
kfree(desc);
return err;
}
EXPORT_SYMBOL_GPL(fsverity_ensure_verity_info);
int __fsverity_file_open(struct inode *inode, struct file *filp)
{
if (filp->f_mode & FMODE_WRITE)
return -EPERM;
return ensure_verity_info(inode);
return fsverity_ensure_verity_info(inode);
}
EXPORT_SYMBOL_GPL(__fsverity_file_open);
+33
View File
@@ -78,3 +78,36 @@ void fsverity_fill_zerohash(struct folio *folio, size_t offset, size_t len,
vi->tree_params.digest_size);
}
EXPORT_SYMBOL_GPL(fsverity_fill_zerohash);
/**
* fsverity_pagecache_read() - read verity metadata via the pagecache
* @inode: copy from this inode's address space
* @buf: buffer to copy to
* @count: number of bytes to copy
* @pos: byte offset in the file to copy from
*
* Read some verity metadata from the inode. __vfs_read() can't be used because
* we need to read beyond i_size.
*/
int fsverity_pagecache_read(struct inode *inode, void *buf, size_t count,
loff_t pos)
{
while (count) {
struct folio *folio;
size_t n;
folio = read_mapping_folio(inode->i_mapping, pos >> PAGE_SHIFT,
NULL);
if (IS_ERR(folio))
return PTR_ERR(folio);
n = memcpy_from_file_folio(buf, folio, pos, count);
folio_put(folio);
buf += n;
pos += n;
count -= n;
}
return 0;
}
EXPORT_SYMBOL_GPL(fsverity_pagecache_read);
+4
View File
@@ -9,6 +9,7 @@
#include <linux/bio.h>
#include <linux/export.h>
#include <linux/fserror.h>
#define FS_VERITY_MAX_PENDING_BLOCKS 2
@@ -205,6 +206,8 @@ static bool verify_data_block(struct fsverity_info *vi,
if (memchr_inv(dblock->data, 0, params->block_size)) {
fsverity_err(inode,
"FILE CORRUPTED! Data past EOF is not zeroed");
fserror_report_data_lost(inode, data_pos,
params->block_size, GFP_NOFS);
return false;
}
return true;
@@ -312,6 +315,7 @@ corrupted:
data_pos, level - 1, params->hash_alg->name, hsize, want_hash,
params->hash_alg->name, hsize,
level == 0 ? dblock->real_hash : real_hash);
fserror_report_data_lost(inode, data_pos, params->block_size, GFP_NOFS);
error:
for (; level > 0; level--) {
kunmap_local(hblocks[level - 1].addr);
+9 -1
View File
@@ -124,6 +124,8 @@ struct fsverity_operations {
* @buf: the Merkle tree block to write
* @pos: the position of the block in the Merkle tree (in bytes)
* @size: the Merkle tree block size (in bytes)
* @zero_digest: the hash of the all-zeroes block
* @digest_size: size of zero_digest, in bytes
*
* This is only called between ->begin_enable_verity() and
* ->end_enable_verity().
@@ -131,7 +133,9 @@ struct fsverity_operations {
* Return: 0 on success, -errno on failure
*/
int (*write_merkle_tree_block)(struct file *file, const void *buf,
u64 pos, unsigned int size);
u64 pos, unsigned int size,
const u8 *zero_digest,
unsigned int digest_size);
};
#ifdef CONFIG_FS_VERITY
@@ -317,10 +321,14 @@ static inline int fsverity_file_open(struct inode *inode, struct file *filp)
return 0;
}
int fsverity_ensure_verity_info(struct inode *inode);
void fsverity_cleanup_inode(struct inode *inode);
struct page *generic_read_merkle_tree_page(struct inode *inode, pgoff_t index);
void generic_readahead_merkle_tree(struct inode *inode, pgoff_t index,
unsigned long nr_pages);
int fsverity_pagecache_read(struct inode *inode, void *buf, size_t count,
loff_t pos);
#endif /* _LINUX_FSVERITY_H */