ima-evm-utils: miscellanous bug fixes
cover ima-evm-utils: miscellanous bug fixes
While testing in RHEL7 the latest 'next-testing' branch changes the build failed due to an "out" label being placed at the end of the function calc_bootaggr() with no instructions for systems with OpenSSL version less then 1.1. Corrected it by putting a simple no-op 'return' there (the function returns nothing).
The other bugs are a simple memory leak, also on calc_bootaggr(), when _DigestUpdate() returns error; and an overflow while reading the boot_aggregate buffer due to the lack of the null char at the end.
Bruno Meneguele (3):
ima-evm-utils: fix empty label at end of function.
ima-evm-utils: fix memory leak in case of error
ima-evm-utils: fix overflow on printing boot_aggregate
src/evmctl.c | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-)
Signature · 1 line
2.26.2
PATCH 1/3 ima-evm-utils: fix empty label at end of function.
Distros running older OpenSSL versions (<= 1.1) fail to build due to the empty label at the end of calc_bootaggr(). For these, that label is no-op.
--- src/evmctl.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
src/evmctl.c +1 -1
@@ -2167,7 +2167,7 @@ out:#if OPENSSL_VERSION_NUMBER >=0x10100000 EVP_MD_CTX_free (pctx);#endif - +return ; }/*
Signature · 1 line
2.26.2
PATCH 2/3 ima-evm-utils: fix memory leak in case of error
In reply to Bruno MenegueleOpenSSL context should be freed in case of versions >= 1.1 before leaving the function in case EVP_DigestUpdate() returns any error.
--- src/evmctl.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
src/evmctl.c +2 -2
@@ -2143,7 +2143,7 @@ static void calc_bootaggr(struct tpm_bank_info *bank) err =EVP_DigestUpdate (pctx, bank->pcr[i], bank->digest_size);if (!err) {log_err ("EVP_DigestUpdate() failed\n" ); -return ; + goto out; } }
@@ -2152,7 +2152,7 @@ static void calc_bootaggr(struct tpm_bank_info *bank) err =EVP_DigestUpdate (pctx, bank->pcr[i], bank->digest_size);if (!err) {log_err ("EVP_DigestUpdate() failed\n" ); -return ; + goto out; } } }
Signature · 1 line
2.26.2
PATCH 3/3 ima-evm-utils: fix overflow on printing boot_aggregate
In reply to Bruno MenegueleThere was no room for placing the '\0' at the end of boot_aggregate value, thus printf() was reading 1 byte beyond the array limit.
--- src/evmctl.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)
src/evmctl.c +3 -1
@@ -2252,7 +2252,8 @@ static int cmd_ima_bootaggr(struct command *cmd) bootaggr_len +=strlen (tpm_banks[i].algo_name) +1 ; bootaggr_len += (tpm_banks[i].digest_size *2 ) +1 ; } - bootaggr =malloc (bootaggr_len); +/* Make room for the leading \0 */ + bootaggr =malloc (bootaggr_len +1 );/* * Calculate and convert the per TPM 2.0 PCR bank algorithm
@@ -2266,6 +2267,7 @@ static int cmd_ima_bootaggr(struct command *cmd)calc_bootaggr (&tpm_banks[i]); offset +=append_bootaggr (bootaggr + offset, tpm_banks + i); } + bootaggr[bootaggr_len] ='\0' ;printf ("%s" , bootaggr);free (bootaggr);return 0 ;
Signature · 1 line
2.26.2
Mimi Zohar
maintainerRe: [PATCH 3/3] ima-evm-utils: fix overflow on printing boot_aggregate
src/evmctl.c static int cmd_ima_bootaggr(struct command *cmd) · line 2255
Quoted 10 lines · Bruno Meneguele
src/evmctl.c +1
-1@@ -2252,7 +2252,8 @@ static int cmd_ima_bootaggr(struct command *cmd) bootaggr_len +=strlen (tpm_banks[i].algo_name) +1 ; bootaggr_len += (tpm_banks[i].digest_size *2 ) +1 ; } - bootaggr =malloc (bootaggr_len); +/* Make room for the leading \0 */
^Trailing null
Mimi
Quoted 4 lines
src/evmctl.c +1
-0+ bootaggr =malloc (bootaggr_len +1 );/* * Calculate and convert the per TPM 2.0 PCR bank algorithm
Re: [PATCH 3/3] ima-evm-utils: fix overflow on printing boot_aggregate
Quoted 14 lines · Mimi Zohar
src/evmctl.c static int cmd_ima_bootaggr(struct command *cmd) · line 2255
Quoted 10 lines · Bruno Meneguele
src/evmctl.c +1
-1@@ -2252,7 +2252,8 @@ static int cmd_ima_bootaggr(struct command *cmd) bootaggr_len +=strlen (tpm_banks[i].algo_name) +1 ; bootaggr_len += (tpm_banks[i].digest_size *2 ) +1 ; } - bootaggr =malloc (bootaggr_len); +/* Make room for the leading \0 */ ^Trailing null
hahah.. of course.
Thanks :)
Quoted 7 lines
Mimi
Quoted 4 lines
src/evmctl.c +1
-0+ bootaggr =malloc (bootaggr_len +1 );/* * Calculate and convert the per TPM 2.0 PCR bank algorithm
Signature · 2 lines
bmeneg PGP Key: http://bmeneg.com/pubkey.txt
Quoted 9 lines · Bruno Meneguele
While testing in RHEL7 the latest 'next-testing' branch changes the build failed due to an "out" label being placed at the end of the function
calc_bootaggr()with no instructions for systems with OpenSSL version less then 1.1. Corrected it by putting a simple no-op 'return' there (the function returns nothing).The other bugs are a simple memory leak, also on
calc_bootaggr(), when_DigestUpdate()returns error; and an overflow while reading theboot_aggregatebuffer due to the lack of the null char at the end.
Applied, thanks!
Mimi