linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Mimi Zohar <zohar@linux.ibm.com>
To: "Guozihua (Scott)" <guozihua@huawei.com>,
	linux-integrity@vger.kernel.org
Cc: Eric Biggers <ebiggers@kernel.org>,
	Stefan Berger <stefanb@linux.ibm.com>,
	linux-fscrypt@vger.kernel.org, linux-kernel@vger.kernel.org,
	Eric Biggers <ebiggers@google.com>
Subject: Re: [PATCH v7 1/5] fs-verity: define a function to return the integrity protected file digest
Date: Mon, 28 Mar 2022 09:51:01 -0400	[thread overview]
Message-ID: <152f1bfa9a07354183ca808a036d5e3fef664ea8.camel@linux.ibm.com> (raw)
In-Reply-To: <0e803aad-5ae6-349b-b17e-89a832306925@huawei.com>

Hi Scott,

On Mon, 2022-03-28 at 11:45 +0800, Guozihua (Scott) wrote:
> > +
> > +/**
> > + * fsverity_get_digest() - get a verity file's digest
> > + * @inode: inode to get digest of
> > + * @digest: (out) pointer to the digest
> > + * @alg: (out) pointer to the hash algorithm enumeration
> > + *
> > + * Return the file hash algorithm and digest of an fsverity protected file.
> > + * Assumption: before calling fsverity_get_digest(), the file must have been
> > + * opened.
> > + *
> > + * Return: 0 on success, -errno on failure
> > + */
> > +int fsverity_get_digest(struct inode *inode,
> > +                     u8 digest[FS_VERITY_MAX_DIGEST_SIZE],
> > +                     enum hash_algo *alg)
> > +{
> > +     const struct fsverity_info *vi;
> > +     const struct fsverity_hash_alg *hash_alg;
> > +     int i;
> > +
> > +     vi = fsverity_get_info(inode);
> > +     if (!vi)
> > +             return -ENODATA; /* not a verity file */
> > +
> > +     hash_alg = vi->tree_params.hash_alg;
> > +     memset(digest, 0, FS_VERITY_MAX_DIGEST_SIZE);
> 
> Hi Mimi,
> 
> I would suggest moving this memset downward right before the memcpy.

By doing it here, any existing garbage stored in the digest is cleared
before returning a failure.

thanks,

Mimi
> 
> > +
> > +     /* convert the verity hash algorithm name to a hash_algo_name enum */
> > +     i = match_string(hash_algo_name, HASH_ALGO__LAST, hash_alg->name);
> > +     if (i < 0)
> > +             return -EINVAL;
> > +     *alg = i;
> > +
> > +     if (WARN_ON_ONCE(hash_alg->digest_size != hash_digest_size[*alg]))
> > +             return -EINVAL;
> > +     memcpy(digest, vi->file_digest, hash_alg->digest_size);
> > +
> > +     pr_debug("file digest %s:%*phN\n", hash_algo_name[*alg],
> > +              hash_digest_size[*alg], digest);
> > +
> > +     return 0;



  reply	other threads:[~2022-03-28 13:51 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-03-25 22:38 [PATCH v7 0/5] ima: support fs-verity digests and signatures Mimi Zohar
2022-03-25 22:38 ` [PATCH v7 1/5] fs-verity: define a function to return the integrity protected file digest Mimi Zohar
2022-03-28  3:45   ` Guozihua (Scott)
2022-03-28 13:51     ` Mimi Zohar [this message]
2022-03-25 22:38 ` [PATCH v7 2/5] ima: define a new template field named 'd-ngv2' and templates Mimi Zohar
2022-03-28  6:14   ` Guozihua (Scott)
2022-03-28 13:50     ` Mimi Zohar
2022-04-05 19:11   ` Eric Biggers
2022-04-28  2:03     ` Mimi Zohar
2022-03-25 22:38 ` [PATCH v7 3/5] ima: permit fsverity's file digests in the IMA measurement list Mimi Zohar
2022-04-05 19:28   ` Eric Biggers
2022-04-28  2:03     ` Mimi Zohar
2022-03-25 22:38 ` [PATCH v7 4/5] ima: support fs-verity file digest based version 3 signatures Mimi Zohar
2022-04-05 20:31   ` Eric Biggers
2022-04-28  2:05     ` Mimi Zohar
2022-03-25 22:38 ` [PATCH v7 5/5] fsverity: update the documentation Mimi Zohar
2022-04-05 20:35   ` Eric Biggers

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=152f1bfa9a07354183ca808a036d5e3fef664ea8.camel@linux.ibm.com \
    --to=zohar@linux.ibm.com \
    --cc=ebiggers@google.com \
    --cc=ebiggers@kernel.org \
    --cc=guozihua@huawei.com \
    --cc=linux-fscrypt@vger.kernel.org \
    --cc=linux-integrity@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=stefanb@linux.ibm.com \
    /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;
as well as URLs for NNTP newsgroup(s).