linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Mimi Zohar <zohar@linux.ibm.com>
To: Eric Biggers <ebiggers@kernel.org>
Cc: linux-integrity@vger.kernel.org,
	Stefan Berger <stefanb@linux.ibm.com>,
	linux-fscrypt@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH v7 2/5] ima: define a new template field named 'd-ngv2' and templates
Date: Wed, 27 Apr 2022 22:03:51 -0400	[thread overview]
Message-ID: <1f76429bfe89ee37a19f2d8ad0cf1a31ff9da798.camel@linux.ibm.com> (raw)
In-Reply-To: <YkyUdM5hmKf4noS7@gmail.com>

On Tue, 2022-04-05 at 19:11 +0000, Eric Biggers wrote:
> On Fri, Mar 25, 2022 at 06:38:21PM -0400, Mimi Zohar wrote:
> >  static int ima_eventdigest_init_common(const u8 *digest, u32 digestsize,
> > -				       u8 hash_algo,
> > +				       u8 digest_type, u8 hash_algo,
> >  				       struct ima_field_data *field_data)
> >  {
> >  	/*
> >  	 * digest formats:
> >  	 *  - DATA_FMT_DIGEST: digest
> >  	 *  - DATA_FMT_DIGEST_WITH_ALGO: [<hash algo>] + ':' + '\0' + digest,
> > +	 *  - DATA_FMT_DIGEST_WITH_TYPE_AND_ALGO:
> > +	 *	[<digest type> + ':' + <hash algo>] + ':' + '\0' + digest,
> > +	 *    where <hash type> is either "ima" or "verity",
> >  	 *    where <hash algo> is provided if the hash algorithm is not
> >  	 *    SHA1 or MD5
> 
> This says both "hash type" and "digest type".  It should be one or the other.
> 
> The square brackets are meant to indicate that the part within it is optional,
> right?  Are they in the right place?  I don't see how this matches the code.
> There is also no explanation for why or when <digest type> is optional with
> DATA_FMT_DIGEST_WITH_TYPE_AND_ALGO.

Agreed.

> 
> > +	if (digest_type < DIGEST_TYPE__LAST && hash_algo < HASH_ALGO__LAST) {
> > +		fmt = DATA_FMT_DIGEST_WITH_TYPE_AND_ALGO;
> > +		offset += snprintf(buffer, DIGEST_TYPE_NAME_LEN_MAX +
> > +				   CRYPTO_MAX_ALG_NAME + 1, "%*s:%s",
> > +				   (int)strlen(digest_type_name[digest_type]),
> > +				   digest_type_name[digest_type],
> >  				   hash_algo_name[hash_algo]);
> >  		buffer[offset] = ':';
> >  		offset += 2;
> 
> There's no need to use %*s if the length argument is just going to be strlen().
> It should just use %s.

Using "%*s" prevents having a trailing NULL.

> 
> Also, this is not correct use of snprintf(), given that the string is
> unconditionally appended to at the offset which snprintf() returns.  So it is
> not providing buffer overflow protection.  It might as well just be:
> 
>                 offset += 1 + sprintf(buffer, "%s:%s:",
>                                       digest_type_name[digest_type],
>                                       hash_algo_name[hash_algo]);
> 
> and likewise for the other case:
> 
>                 offset += 1 + sprintf(buffer, "%s:", hash_algo_name[hash_algo]);
> 
> > +/*
> > + * This function writes the digest of an event (without size limit),
> > + * prefixed with both the hash type and algorithm.
> > + */
> > +int ima_eventdigest_ngv2_init(struct ima_event_data *event_data,
> > +			      struct ima_field_data *field_data)
> > +{
> > +	u8 *cur_digest = NULL, hash_algo = HASH_ALGO_SHA1;
> 
> Why is this defaulting to SHA-1?

Violation records contain 0's in the file hash and the template data
hash fields. Changing the default hash algorithm would result in larger
violation digests without any real benefit other than cosmetic.  Will
make the change anyway in the next version.

thanks,

Mimi


  reply	other threads:[~2022-04-28  2:04 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
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 [this message]
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=1f76429bfe89ee37a19f2d8ad0cf1a31ff9da798.camel@linux.ibm.com \
    --to=zohar@linux.ibm.com \
    --cc=ebiggers@kernel.org \
    --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).