* [PATCH 1/3] ima-evm-utils: address new compiler complaints
@ 2020-07-15 20:37 Mimi Zohar
2020-07-15 20:37 ` [PATCH 2/3] ima-evm-utils: reading public keys Mimi Zohar
` (2 more replies)
0 siblings, 3 replies; 5+ messages in thread
From: Mimi Zohar @ 2020-07-15 20:37 UTC (permalink / raw)
To: linux-integrity; +Cc: Mimi Zohar, Petr Vorel, Bruno Meneguele
Address the new compiler complaints:
- while reading the template data
- while reading the exported TPM 1.2 PCRs
- while reading the TPM event log
Reported-by: Petr Vorel <pvorel@suse.cz>
Signed-off-by: Mimi Zohar <zohar@linux.ibm.com>
---
src/evmctl.c | 27 +++++++++++++++++++++------
1 file changed, 21 insertions(+), 6 deletions(-)
diff --git a/src/evmctl.c b/src/evmctl.c
index 8439bec0d7ee..cd5d96f1714b 100644
--- a/src/evmctl.c
+++ b/src/evmctl.c
@@ -1380,7 +1380,7 @@ static char *misc_pcrs = "/sys/class/misc/tpm0/device/pcrs";
static int tpm_pcr_read(struct tpm_bank_info *tpm_banks, int len)
{
FILE *fp = NULL;
- char *p, pcr_str[7], buf[70]; /* length of the TPM string */
+ char *p, pcr_str[8], buf[70]; /* length of the TPM string */
int result = -1;
int i = 0;
@@ -1399,7 +1399,7 @@ static int tpm_pcr_read(struct tpm_bank_info *tpm_banks, int len)
for (;;) {
p = fgets(buf, sizeof(buf), fp);
- if (!p)
+ if (!p || i > 99)
break;
sprintf(pcr_str, "PCR-%2.2d", i);
if (!strncmp(p, pcr_str, 6))
@@ -1980,11 +1980,21 @@ static int ima_measurement(const char *file)
* in the template data hash calculation.
*/
len = fread(&field_len, sizeof(field_len), 1, fp);
- if (field_len > TCG_EVENT_NAME_LEN_MAX)
+ if (len <= 0) {
+ log_errno("Failed reading file name length\n");
+ goto out;
+ }
+ if (field_len > TCG_EVENT_NAME_LEN_MAX) {
log_err("file pathname is too long\n");
+ goto out;
+ }
- fread(entry.template + SHA_DIGEST_LENGTH,
- field_len, 1, fp);
+ len = fread(entry.template + SHA_DIGEST_LENGTH,
+ field_len, 1, fp);
+ if (len != field_len) {
+ log_errno("Failed reading file name\n");
+ goto out;
+ }
/*
* The template data is fixed sized, zero out
@@ -2069,6 +2079,7 @@ static int read_binary_bios_measurements(char *file, struct tpm_bank_info *bank)
FILE *fp;
SHA_CTX c;
int err = 0;
+ int len;
int i;
fp = fopen(file, "r");
@@ -2100,7 +2111,11 @@ static int read_binary_bios_measurements(char *file, struct tpm_bank_info *bank)
err = 1;
break;
}
- fread(event.data, event.header.len, 1, fp);
+ len = fread(event.data, event.header.len, 1, fp);
+ if (len != event.header.len) {
+ log_errno("Failed reading event data (short read)\n");
+ break;
+ }
}
fclose(fp);
--
2.7.5
^ permalink raw reply related [flat|nested] 5+ messages in thread
* [PATCH 2/3] ima-evm-utils: reading public keys
2020-07-15 20:37 [PATCH 1/3] ima-evm-utils: address new compiler complaints Mimi Zohar
@ 2020-07-15 20:37 ` Mimi Zohar
2020-07-15 20:37 ` [PATCH 3/3] ima-evm-utils: add missing license info Mimi Zohar
2020-07-16 1:56 ` [PATCH 1/3 v1] ima-evm-utils: address new compiler complaints Mimi Zohar
2 siblings, 0 replies; 5+ messages in thread
From: Mimi Zohar @ 2020-07-15 20:37 UTC (permalink / raw)
To: linux-integrity; +Cc: Mimi Zohar, Petr Vorel, Bruno Meneguele
Not being able to read the public key is not necessarily an error.
Emit a message based on log level.
Signed-off-by: Mimi Zohar <zohar@linux.ibm.com>
---
src/libimaevm.c | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/src/libimaevm.c b/src/libimaevm.c
index b8d576969aa4..16e07e82b9e3 100644
--- a/src/libimaevm.c
+++ b/src/libimaevm.c
@@ -323,7 +323,8 @@ EVP_PKEY *read_pub_pkey(const char *keyfile, int x509)
fp = fopen(keyfile, "r");
if (!fp) {
- log_err("Failed to open keyfile: %s\n", keyfile);
+ if (imaevm_params.verbose > LOG_INFO)
+ log_info("Failed to open keyfile: %s\n", keyfile);
return NULL;
}
--
2.7.5
^ permalink raw reply related [flat|nested] 5+ messages in thread
* [PATCH 3/3] ima-evm-utils: add missing license info
2020-07-15 20:37 [PATCH 1/3] ima-evm-utils: address new compiler complaints Mimi Zohar
2020-07-15 20:37 ` [PATCH 2/3] ima-evm-utils: reading public keys Mimi Zohar
@ 2020-07-15 20:37 ` Mimi Zohar
2020-07-16 1:56 ` [PATCH 1/3 v1] ima-evm-utils: address new compiler complaints Mimi Zohar
2 siblings, 0 replies; 5+ messages in thread
From: Mimi Zohar @ 2020-07-15 20:37 UTC (permalink / raw)
To: linux-integrity
Cc: Mimi Zohar, Petr Vorel, Bruno Meneguele, Patrick Uiterwijk
src/utils.c contains some common functions.
Fixes: 03f99ea6d05b ("ima-evm-utils: Add support for Intel TSS2 for PCR reading")
Reported-by: Petr Vorel <pvorel@suse.cz>
Cc: Patrick Uiterwijk <patrick@puiterwijk.org>
Signed-off-by: Mimi Zohar <zohar@linux.ibm.com>
---
src/utils.c | 7 +++++++
1 file changed, 7 insertions(+)
diff --git a/src/utils.c b/src/utils.c
index 416a88c6dbe4..fbb6a4b540af 100644
--- a/src/utils.c
+++ b/src/utils.c
@@ -1,3 +1,10 @@
+// SPDX-License-Identifier: GPL-2.0
+/*
+ * utils: set of common functions
+ *
+ * Copyright (C) 2020 Patrick Uiterwijk <patrick@puiterwijk.org>
+ * Copyright (C) 2010 Cyril Hrubis <chrubis@suse.cz>
+ */
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
--
2.7.5
^ permalink raw reply related [flat|nested] 5+ messages in thread
* Re: [PATCH 1/3 v1] ima-evm-utils: address new compiler complaints
2020-07-15 20:37 [PATCH 1/3] ima-evm-utils: address new compiler complaints Mimi Zohar
2020-07-15 20:37 ` [PATCH 2/3] ima-evm-utils: reading public keys Mimi Zohar
2020-07-15 20:37 ` [PATCH 3/3] ima-evm-utils: add missing license info Mimi Zohar
@ 2020-07-16 1:56 ` Mimi Zohar
2020-07-16 8:15 ` Petr Vorel
2 siblings, 1 reply; 5+ messages in thread
From: Mimi Zohar @ 2020-07-16 1:56 UTC (permalink / raw)
To: linux-integrity; +Cc: Petr Vorel, Bruno Meneguele
Address the new compiler complaints:
- while reading the template data
- while reading the exported TPM 1.2 PCRs
- while reading the TPM event log
Reported-by: Petr Vorel <pvorel@suse.cz>
Signed-off-by: Mimi Zohar <zohar@linux.ibm.com>
---
Changelog v1:
- Fix fread() tests
src/evmctl.c | 27 +++++++++++++++++++++------
1 file changed, 21 insertions(+), 6 deletions(-)
diff --git a/src/evmctl.c b/src/evmctl.c
index 8439bec0d7ee..f910e2752516 100644
--- a/src/evmctl.c
+++ b/src/evmctl.c
@@ -1380,7 +1380,7 @@ static char *misc_pcrs = "/sys/class/misc/tpm0/device/pcrs";
static int tpm_pcr_read(struct tpm_bank_info *tpm_banks, int len)
{
FILE *fp = NULL;
- char *p, pcr_str[7], buf[70]; /* length of the TPM string */
+ char *p, pcr_str[8], buf[70]; /* length of the TPM string */
int result = -1;
int i = 0;
@@ -1399,7 +1399,7 @@ static int tpm_pcr_read(struct tpm_bank_info *tpm_banks, int len)
for (;;) {
p = fgets(buf, sizeof(buf), fp);
- if (!p)
+ if (!p || i > 99)
break;
sprintf(pcr_str, "PCR-%2.2d", i);
if (!strncmp(p, pcr_str, 6))
@@ -1980,11 +1980,21 @@ static int ima_measurement(const char *file)
* in the template data hash calculation.
*/
len = fread(&field_len, sizeof(field_len), 1, fp);
- if (field_len > TCG_EVENT_NAME_LEN_MAX)
+ if (len <= 0) {
+ log_errno("Failed reading file name length\n");
+ goto out;
+ }
+ if (field_len > TCG_EVENT_NAME_LEN_MAX) {
log_err("file pathname is too long\n");
+ goto out;
+ }
- fread(entry.template + SHA_DIGEST_LENGTH,
- field_len, 1, fp);
+ len = fread(entry.template + SHA_DIGEST_LENGTH,
+ field_len, 1, fp);
+ if (len != 1) {
+ log_errno("Failed reading file name\n");
+ goto out;
+ }
/*
* The template data is fixed sized, zero out
@@ -2069,6 +2079,7 @@ static int read_binary_bios_measurements(char *file, struct tpm_bank_info *bank)
FILE *fp;
SHA_CTX c;
int err = 0;
+ int len;
int i;
fp = fopen(file, "r");
@@ -2100,7 +2111,11 @@ static int read_binary_bios_measurements(char *file, struct tpm_bank_info *bank)
err = 1;
break;
}
- fread(event.data, event.header.len, 1, fp);
+ len = fread(event.data, event.header.len, 1, fp);
+ if (len != 1) {
+ log_errno("Failed reading event data (short read)\n");
+ break;
+ }
}
fclose(fp);
--
2.7.5
^ permalink raw reply related [flat|nested] 5+ messages in thread
end of thread, other threads:[~2020-07-16 8:15 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-07-15 20:37 [PATCH 1/3] ima-evm-utils: address new compiler complaints Mimi Zohar
2020-07-15 20:37 ` [PATCH 2/3] ima-evm-utils: reading public keys Mimi Zohar
2020-07-15 20:37 ` [PATCH 3/3] ima-evm-utils: add missing license info Mimi Zohar
2020-07-16 1:56 ` [PATCH 1/3 v1] ima-evm-utils: address new compiler complaints Mimi Zohar
2020-07-16 8:15 ` Petr Vorel
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).