[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <31254e743b73a43f6f27679678318d0d8744a355.camel@linux.ibm.com>
Date: Mon, 21 Mar 2022 15:48:51 -0400
From: Mimi Zohar <zohar@...ux.ibm.com>
To: Stefan Berger <stefanb@...ux.ibm.com>,
linux-integrity@...r.kernel.org
Cc: Eric Biggers <ebiggers@...nel.org>, linux-fscrypt@...r.kernel.org,
linux-kernel@...r.kernel.org
Subject: Re: [PATCH v6 2/5] ima: define a new template field named 'd-ngv2'
and templates
On Mon, 2022-03-21 at 08:53 -0400, Stefan Berger wrote:
> > /*
> > * 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
> > */
> > - u8 buffer[CRYPTO_MAX_ALG_NAME + 2 + IMA_MAX_DIGEST_SIZE] = { 0 };
> > + u8 buffer[DIGEST_TYPE_MAXLEN + CRYPTO_MAX_ALG_NAME + 2 +
> > + IMA_MAX_DIGEST_SIZE] = { 0 };
>
> Should it not be DIGEST_TYPE_MAXLEN + 1 /* for ':' */ +
> CRYPTO_MAX_ALG_NAME + ....
DIGEST_TYPE_MAXLEN is hard coded as 16.
>
> > enum data_formats fmt = DATA_FMT_DIGEST;
> > u32 offset = 0;
> >
> > - if (hash_algo < HASH_ALGO__LAST) {
> > - fmt = DATA_FMT_DIGEST_WITH_ALGO;
> > - offset += snprintf(buffer, CRYPTO_MAX_ALG_NAME + 1, "%s",
> > + if (digest_type < digest_type_size && hash_algo < HASH_ALGO__LAST) {
>
> It's a bit difficult to see what the digest_type has to do with size...
> Maybe digest_type should be a enum and the comparison here should be
> digest_type != DIGEST_TYPE_NONE or something like it..
digest_type_size is the size of the array. It's defined as "static int
digest_type_size = ARRAY_SIZE(digest_type_name);", with the first
element as "ima".
> > +
> > +/*
> > + * 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;
> > + u32 cur_digestsize = 0;
> > + u8 digest_type = 0;
>
> What does '0' mean? I think this should definitely be an enum or at
> least #define.
The first element of the array is "ima". Should I define two macros
similar to kernel_read_file_id and kernel_read_file_str for just two
strings?
thanks,
Mimi
Powered by blists - more mailing lists