Re: [PATCH 3/6] fs,fsverity: handle fsverity in generic_file_open

Jan Kara
2026-01-19T09:05:58Z

On Mon 19-01-26 07:22:44, Christoph Hellwig wrote:
> Call into fsverity_file_open from generic_file_open instead of requiring
> the file system to handle it explicitly.
>
> Signed-off-by: Christoph Hellwig <hch@lst.de>
...
> -int generic_file_open(struct inode * inode, struct file * filp)
> +int generic_file_open(struct inode *inode, struct file *filp)
> {
> if (!(filp->f_flags & O_LARGEFILE) && i_size_read(inode) > MAX_NON_LFS)
> return -EOVERFLOW;
> + if (IS_ENABLED(CONFIG_FS_VERITY) && IS_VERITY(inode)) {
> + if (filp->f_mode & FMODE_WRITE)
> + return -EPERM;
> + return fsverity_file_open(inode, filp);
> + }

Why do you check f_mode here when fsverity_file_open() checks for it as
well?

> -int __fsverity_file_open(struct inode *inode, struct file *filp)
> +/*
> + * When opening a verity file, deny the open if it is for writing. Otherwise,
> + * set up the inode's verity info if not already done.
> + *
> + * When combined with fscrypt, this must be called after fscrypt_file_open().
> + * Otherwise, we won't have the key set up to decrypt the verity metadata.
> + */
> +int fsverity_file_open(struct inode *inode, struct file *filp)
> {
> if (filp->f_mode & FMODE_WRITE)
> return -EPERM;
> return ensure_verity_info(inode);
> }
> -EXPORT_SYMBOL_GPL(__fsverity_file_open);

Honza
--
Jan Kara <jack@suse.com>
SUSE Labs, CR