Re: [PATCH v13 02/23] fsverity: expose ensure_fsverity_info()

Andrey Albershteyn <[email protected]> Mon, 27 Jul 2026 13:40:01 +0200
Newsgroups dev.linux.lists.fsverity,net.sourceforge.lists.linux-f2fs-devel,org.kernel.vger.linux-btrfs,org.kernel.vger.linux-ext4,org.kernel.vger.linux-fsdevel,org.kernel.vger.linux-xfs
Message-ID <[email protected]>
On 2026-07-24 16:37:44, Eric Biggers wrote:
> On Tue, Jul 21, 2026 at 08:40:39PM +0200, Andrey Albershteyn wrote:
> > +/**
> > + * 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.
> > + *
> > + * Return: 0 on success, -errno on failure
> > + */
> > +int fsverity_ensure_verity_info(struct inode *inode)
> 
> There really should be a note here that if the file is also encrypted,
> then the encryption key has to have been set up first.  This was already
> gotten wrong when it was proposed for overlayfs to call this.

Sure I will add a note.

> Do we also need a more specific contract than "-errno on failure"?  The
> caller in xchk_inode_setup_verity() tries to distinguish between
> "metadata validation errors" and "runtime errors" by checking for a
> bunch of different error codes, and I'm not sure what that means
> exactly.

The scrub checks that if incore fsverity flag is set on the inode
we should be able to read verity info. If metadata is invalid,
"metadata validation error" happens, then scrub will clear fsverity
flag on incore and on-disk inode.

Not sure if this can be improved much, any new error codes won't
trigger scrub. Passing int *corrupted everywhere also doesn't seem
to help and changing everything to EFSCORRUPTED will change
file_open return code.

-- 
- Andrey