Skip to content

Commit f387759

Browse files
robertosassugregkh
authored andcommitted
ima: Call ima_calc_boot_aggregate() in ima_eventdigest_init()
commit 6cc7c26 upstream. If the template field 'd' is chosen and the digest to be added to the measurement entry was not calculated with SHA1 or MD5, it is recalculated with SHA1, by using the passed file descriptor. However, this cannot be done for boot_aggregate, because there is no file descriptor. This patch adds a call to ima_calc_boot_aggregate() in ima_eventdigest_init(), so that the digest can be recalculated also for the boot_aggregate entry. Cc: stable@vger.kernel.org # 3.13.x Fixes: 3ce1217 ("ima: define template fields library and new helpers") Reported-by: Takashi Iwai <tiwai@suse.de> Signed-off-by: Roberto Sassu <roberto.sassu@huawei.com> Signed-off-by: Mimi Zohar <zohar@linux.ibm.com> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
1 parent 6471238 commit f387759

4 files changed

Lines changed: 24 additions & 5 deletions

File tree

‎security/integrity/ima/ima.h‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ extern int ima_policy_flag;
5252
extern int ima_hash_algo;
5353
extern int ima_appraise;
5454
extern struct tpm_chip *ima_tpm_chip;
55+
extern const char boot_aggregate_name[];
5556

5657
/* IMA event related data */
5758
struct ima_event_data {
@@ -140,7 +141,7 @@ int ima_calc_buffer_hash(const void *buf, loff_t len,
140141
int ima_calc_field_array_hash(struct ima_field_data *field_data,
141142
struct ima_template_desc *desc, int num_fields,
142143
struct ima_digest_data *hash);
143-
int __init ima_calc_boot_aggregate(struct ima_digest_data *hash);
144+
int ima_calc_boot_aggregate(struct ima_digest_data *hash);
144145
void ima_add_violation(struct file *file, const unsigned char *filename,
145146
struct integrity_iint_cache *iint,
146147
const char *op, const char *cause);

‎security/integrity/ima/ima_crypto.c‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -665,8 +665,8 @@ static void __init ima_pcrread(u32 idx, struct tpm_digest *d)
665665
* hash algorithm for reading the TPM PCRs as for calculating the boot
666666
* aggregate digest as stored in the measurement list.
667667
*/
668-
static int __init ima_calc_boot_aggregate_tfm(char *digest, u16 alg_id,
669-
struct crypto_shash *tfm)
668+
static int ima_calc_boot_aggregate_tfm(char *digest, u16 alg_id,
669+
struct crypto_shash *tfm)
670670
{
671671
struct tpm_digest d = { .alg_id = alg_id, .digest = {0} };
672672
int rc;
@@ -694,7 +694,7 @@ static int __init ima_calc_boot_aggregate_tfm(char *digest, u16 alg_id,
694694
return rc;
695695
}
696696

697-
int __init ima_calc_boot_aggregate(struct ima_digest_data *hash)
697+
int ima_calc_boot_aggregate(struct ima_digest_data *hash)
698698
{
699699
struct crypto_shash *tfm;
700700
u16 crypto_id, alg_id;

‎security/integrity/ima/ima_init.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
#include "ima.h"
2222

2323
/* name for boot aggregate entry */
24-
static const char boot_aggregate_name[] = "boot_aggregate";
24+
const char boot_aggregate_name[] = "boot_aggregate";
2525
struct tpm_chip *ima_tpm_chip;
2626

2727
/* Add the boot aggregate to the IMA measurement list and extend

‎security/integrity/ima/ima_template_lib.c‎

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -288,6 +288,24 @@ int ima_eventdigest_init(struct ima_event_data *event_data,
288288
goto out;
289289
}
290290

291+
if ((const char *)event_data->filename == boot_aggregate_name) {
292+
if (ima_tpm_chip) {
293+
hash.hdr.algo = HASH_ALGO_SHA1;
294+
result = ima_calc_boot_aggregate(&hash.hdr);
295+
296+
/* algo can change depending on available PCR banks */
297+
if (!result && hash.hdr.algo != HASH_ALGO_SHA1)
298+
result = -EINVAL;
299+
300+
if (result < 0)
301+
memset(&hash, 0, sizeof(hash));
302+
}
303+
304+
cur_digest = hash.hdr.digest;
305+
cur_digestsize = hash_digest_size[HASH_ALGO_SHA1];
306+
goto out;
307+
}
308+
291309
if (!event_data->file) /* missing info to re-calculate the digest */
292310
return -EINVAL;
293311

0 commit comments

Comments
 (0)