Linux Overlay Filesystem development
 help / color / mirror / Atom feed
From: Eric Biggers <ebiggers@kernel.org>
To: Alexander Larsson <alexl@redhat.com>
Cc: miklos@szeredi.hu, linux-unionfs@vger.kernel.org,
	amir73il@gmail.com, tytso@mit.edu, fsverity@lists.linux.dev
Subject: Re: [PATCH v3 3/4] ovl: Validate verity xattr when resolving lowerdata
Date: Mon, 12 Jun 2023 12:09:44 -0700	[thread overview]
Message-ID: <20230612190944.GB847@sol.localdomain> (raw)
In-Reply-To: <dd294a44e8f401e6b5140029d8355f88748cd8fd.1686565330.git.alexl@redhat.com>

On Mon, Jun 12, 2023 at 12:28:17PM +0200, Alexander Larsson wrote:
> +int ovl_validate_verity(struct ovl_fs *ofs,
> +			struct path *metapath,
> +			struct path *datapath)
> +{
> +	u8 xattr_data[1+FS_VERITY_MAX_DIGEST_SIZE];
> +	u8 actual_digest[FS_VERITY_MAX_DIGEST_SIZE];
> +	enum hash_algo verity_algo;
> +	int xattr_len;
> +	int err;
> +
> +	if (!ofs->config.verity ||
> +	    /* Verity only works on regular files */
> +	    !S_ISREG(d_inode(metapath->dentry)->i_mode))
> +		return 0;
> +
> +	xattr_len = sizeof(xattr_data);
> +	err = ovl_get_verity_xattr(ofs, metapath, xattr_data, &xattr_len);
> +	if (err == -ENODATA) {
> +		if (ofs->config.require_verity) {
> +			pr_warn_ratelimited("metacopy file '%pd' has no overlay.verity xattr\n",
> +					    metapath->dentry);
> +			return -EIO;
> +		}
> +		return 0;
> +	}
> +	if (err < 0)
> +		return err;
> +
> +	err = ovl_ensure_verity_loaded(datapath);
> +	if (err < 0) {
> +		pr_warn_ratelimited("lower file '%pd' failed to load fs-verity info\n",
> +				    datapath->dentry);
> +		return -EIO;
> +	}
> +
> +	err = fsverity_get_digest(d_inode(datapath->dentry), actual_digest, &verity_algo);
> +	if (err < 0) {
> +		pr_warn_ratelimited("lower file '%pd' has no fs-verity digest\n", datapath->dentry);
> +		return -EIO;
> +	}
> +
> +	if (xattr_len != 1 + hash_digest_size[verity_algo] ||
> +	    xattr_data[0] != (u8) verity_algo ||
> +	    memcmp(xattr_data+1, actual_digest, xattr_len - 1) != 0) {
> +		pr_warn_ratelimited("lower file '%pd' has the wrong fs-verity digest\n",
> +				    datapath->dentry);
> +		return -EIO;
> +	}
> +
> +	return 0;
> +}

This means the overlayfs verity xattr contains the algorithm ID of the fsverity
digest as a HASH_ALGO_* value.

That works, but I think HASH_ALGO_* is somewhat of an IMA-ism.  fsverity
actually uses FS_VERITY_HASH_ALG_* everywhere else, including in the UAPI and in
fsverity-utils which includes libfsverity
(https://git.kernel.org/pub/scm/fs/fsverity/fsverity-utils.git/tree/include/libfsverity.h).

I'm guessing that you used HASH_ALGO_* not because you really wanted to, but
rather just because it's what fsverity_get_digest() happens to return, as IMA is
currently its only user.

Can you consider
https://lore.kernel.org/r/20230612190047.59755-1-ebiggers@kernel.org which would
make fsverity_get_digest() support both types of IDs?  Then you can use
FS_VERITY_HASH_ALG_*, which I think would make things slightly easier for you.

- Eric

  parent reply	other threads:[~2023-06-12 19:09 UTC|newest]

Thread overview: 44+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-06-12 10:27 [PATCH v3 0/4] ovl: Add support for fs-verity checking of lowerdata Alexander Larsson
2023-06-12 10:27 ` [PATCH v3 1/4] fsverity: Export fsverity_get_digest Alexander Larsson
2023-06-12 10:27 ` [PATCH v3 2/4] ovl: Add framework for verity support Alexander Larsson
2023-06-12 16:32   ` Eric Biggers
2023-06-13  5:18     ` Amir Goldstein
2023-06-13  6:37       ` Eric Biggers
2023-06-13  8:08         ` Alexander Larsson
2023-06-13  9:34         ` Amir Goldstein
2023-06-13 18:22           ` Eric Biggers
2023-06-14  5:24             ` Amir Goldstein
2023-06-14  7:57               ` Alexander Larsson
2023-06-15 23:52                 ` Eric Biggers
2023-06-16  8:11                   ` Alexander Larsson
2023-06-17 19:47                     ` Eric Biggers
2023-06-19  7:58                       ` Alexander Larsson
2023-06-12 10:27 ` [PATCH v3 3/4] ovl: Validate verity xattr when resolving lowerdata Alexander Larsson
2023-06-12 10:28   ` Alexander Larsson
2023-06-12 19:09   ` Eric Biggers [this message]
2023-06-13 11:41     ` Alexander Larsson
2023-06-13 17:57       ` Eric Biggers
2023-06-14  3:28         ` Eric Biggers
2023-06-14  5:39           ` Amir Goldstein
2023-06-14  7:19           ` Alexander Larsson
2023-06-12 10:28 ` [PATCH v3 4/4] ovl: Handle verity during copy-up Alexander Larsson
2023-06-12 10:52   ` Amir Goldstein
2023-06-12 10:54 ` [PATCH v3 0/4] ovl: Add support for fs-verity checking of lowerdata Amir Goldstein
2023-06-12 11:09   ` Alexander Larsson
2023-06-12 14:53     ` Alexander Larsson
2023-06-12 15:05       ` Amir Goldstein
2023-06-14  6:14       ` Amir Goldstein
2023-06-14  7:07         ` Eric Biggers
2023-06-14  7:16         ` Alexander Larsson
2023-06-22  9:36           ` Amir Goldstein
2023-06-22  9:51             ` Alexander Larsson
2023-06-22 11:45               ` Amir Goldstein
2023-06-26 13:01                 ` Amir Goldstein
2023-07-03  8:11                   ` Alexander Larsson
2023-07-06  7:10                     ` Amir Goldstein
2023-07-06  7:50                       ` Alexander Larsson
2023-06-22 16:12             ` Eric Biggers
2023-06-22 18:07               ` Amir Goldstein
2023-06-13 13:57 ` Alexander Larsson
2023-06-13 17:59   ` Eric Biggers
2023-06-14  7:15     ` Alexander Larsson

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20230612190944.GB847@sol.localdomain \
    --to=ebiggers@kernel.org \
    --cc=alexl@redhat.com \
    --cc=amir73il@gmail.com \
    --cc=fsverity@lists.linux.dev \
    --cc=linux-unionfs@vger.kernel.org \
    --cc=miklos@szeredi.hu \
    --cc=tytso@mit.edu \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox