> -----Original Message----- > From: Roberto Sassu > Sent: Monday, January 27, 2020 6:05 PM > To: zohar@xxxxxxxxxxxxx; jarkko.sakkinen@xxxxxxxxxxxxxxx; > james.bottomley@xxxxxxxxxxxxxxxxxxxxx; linux-integrity@xxxxxxxxxxxxxxx > Cc: linux-security-module@xxxxxxxxxxxxxxx; linux-kernel@xxxxxxxxxxxxxxx; > Silviu Vlasceanu <Silviu.Vlasceanu@xxxxxxxxxx>; Roberto Sassu > <roberto.sassu@xxxxxxxxxx> > Subject: [PATCH 6/8] ima: calculate and extend PCR with digests in > ima_template_entry > > This patch modifies ima_calc_field_array_hash() to calculate a template > digest for each allocated PCR bank and SHA1. It also passes the tpm_digest > array of the template entry to ima_pcr_extend() or in case of a violation, > the pre-initialized digests array filled with 0xff. > > Padding with zeros is still done if the mapping between TPM algorithm ID > and crypto ID is unknown. > > This patch calculates again the template digest when a measurement list is > restored. Copying only the SHA1 digest (due to the limitation of the > current measurement list format) is not sufficient, as hash collision > detection will be done on the digest calculated with the default IMA hash > algorithm. > > Signed-off-by: Roberto Sassu <roberto.sassu@xxxxxxxxxx> > --- > security/integrity/ima/ima_crypto.c | 26 ++++++++++++++++++++++- > security/integrity/ima/ima_queue.c | 30 ++++++++++++++++----------- > security/integrity/ima/ima_template.c | 14 +++++++++++-- > 3 files changed, 55 insertions(+), 15 deletions(-) > > diff --git a/security/integrity/ima/ima_crypto.c > b/security/integrity/ima/ima_crypto.c > index 63fb4bdf80b0..786340feebbb 100644 > --- a/security/integrity/ima/ima_crypto.c > +++ b/security/integrity/ima/ima_crypto.c > @@ -610,9 +610,33 @@ static int ima_calc_field_array_hash_tfm(struct > ima_field_data *field_data, > int ima_calc_field_array_hash(struct ima_field_data *field_data, > struct ima_template_entry *entry) > { > - int rc; > + u16 alg_id; > + int rc, i; > > rc = ima_calc_field_array_hash_tfm(field_data, entry, > ima_sha1_idx); > + if (rc) > + return rc; > + > + entry->digests[ima_sha1_idx].alg_id = TPM_ALG_SHA1; > + > + for (i = 0; i < ima_tpm_chip->nr_allocated_banks + 1; i++) { > + if (i == ima_sha1_idx) > + continue; > + > + alg_id = ima_tpm_chip->allocated_banks[i].alg_id; The line above should be executed for i < ima_tpm_chip->nr_allocated_banks. I will fix in the next version of the patch set. Roberto HUAWEI TECHNOLOGIES Duesseldorf GmbH, HRB 56063 Managing Director: Li Peng, Li Jian, Shi Yanli