public inbox for linux-integrity@vger.kernel.org
 help / color / mirror / Atom feed
From: Stefan Berger <stefanb@linux.ibm.com>
To: Mimi Zohar <zohar@linux.ibm.com>, linux-integrity@vger.kernel.org
Subject: Re: [ima-evm-utils PATCH 12/12] Define and use a file specific "keypass" variable
Date: Wed, 22 Nov 2023 09:22:45 -0500	[thread overview]
Message-ID: <117e3af9-3372-42ea-bdaf-d5e190ddf196@linux.ibm.com> (raw)
In-Reply-To: <20231119165043.46960-13-zohar@linux.ibm.com>



On 11/19/23 11:50, Mimi Zohar wrote:
> Instead of relying on the "imaevm_params.keypass" global variable, which
> is not concurrency-safe, add keypass as a parameter to the static library
> functions definitions.  Update function callers.
> 
> To avoid library incompatablity, don't remove imaevm_params.keypass
> variable.
> 
> Signed-off-by: Mimi Zohar <zohar@linux.ibm.com>
> ---
>   src/evmctl.c    |  9 +++++----
>   src/libimaevm.c | 17 ++++++++---------
>   2 files changed, 13 insertions(+), 13 deletions(-)
> 
> diff --git a/src/evmctl.c b/src/evmctl.c
> index b802eeb1bf15..6d6160159a1f 100644
> --- a/src/evmctl.c
> +++ b/src/evmctl.c
> @@ -141,6 +141,7 @@ static bool evm_portable;
>   static bool veritysig;
>   static bool hwtpm;
>   static char *hash_algo;
> +static char *keypass;
>   
>   #define HMAC_FLAG_NO_UUID	0x0001
>   #define HMAC_FLAG_CAPS_SET	0x0002
> @@ -3082,9 +3083,9 @@ int main(int argc, char *argv[])
>   			break;
>   		case 'p':
>   			if (optarg)
> -				imaevm_params.keypass = optarg;
> +				keypass = optarg;
>   			else
> -				imaevm_params.keypass = get_password();
> +				keypass = get_password();
>   			break;
>   		case 'f':
>   			sigfile = 1;
> @@ -3226,8 +3227,8 @@ int main(int argc, char *argv[])
>   		}
>   	}
>   
> -	if (!imaevm_params.keypass)
> -		imaevm_params.keypass = getenv("EVMCTL_KEY_PASSWORD");
> +	if (!keypass)
> +		keypass = getenv("EVMCTL_KEY_PASSWORD");
>   
>   	if (imaevm_params.keyfile != NULL &&
>   	    imaevm_params.eng == NULL &&


The problem at this point in evmctl is that keypass is never passed to 
anywhere. You have to pass it to sign_hash().

> diff --git a/src/libimaevm.c b/src/libimaevm.c
> index 18b6a6f27237..10ec847da08a 100644
> --- a/src/libimaevm.c
> +++ b/src/libimaevm.c
> @@ -1124,7 +1124,8 @@ static int get_hash_algo_v1(const char *algo)
>   }
>   
>   static int sign_hash_v1(const char *hashalgo, const unsigned char *hash,
> -			int size, const char *keyfile, unsigned char *sig)
> +			int size, const char *keyfile, const char *keypass,
> +			unsigned char *sig)
>   {
>   	int len = -1, hashalgo_idx;
>   	SHA_CTX ctx;
> @@ -1158,7 +1159,7 @@ static int sign_hash_v1(const char *hashalgo, const unsigned char *hash,
>   	log_info("hash(%s): ", hashalgo);
>   	log_dump(hash, size);
>   
> -	key = read_priv_key(keyfile, imaevm_params.keypass);
> +	key = read_priv_key(keyfile, keypass);
>   	if (!key)
>   		return -1;
>   
> @@ -1211,7 +1212,8 @@ out:
>    * Return: -1 signing error, >0 length of signature
>    */
>   static int sign_hash_v2(const char *algo, const unsigned char *hash,
> -			int size, const char *keyfile, unsigned char *sig)
> +			int size, const char *keyfile, const char *keypass,
> +			unsigned char *sig)
>   {
>   	struct signature_v2_hdr *hdr;
>   	int len = -1;
> @@ -1246,7 +1248,7 @@ static int sign_hash_v2(const char *algo, const unsigned char *hash,
>   	log_info("hash(%s): ", algo);
>   	log_dump(hash, size);
>   
> -	pkey = read_priv_pkey(keyfile, imaevm_params.keypass);
> +	pkey = read_priv_pkey(keyfile, keypass);
>   	if (!pkey)
>   		return -1;
>   
> @@ -1316,14 +1318,11 @@ err:
>   
>   int sign_hash(const char *hashalgo, const unsigned char *hash, int size, const char *keyfile, const char *keypass, unsigned char *sig)
>   {
> -	if (keypass)
> -		imaevm_params.keypass = keypass;
> -

I hope all library callers, other than evmctl, passed the keypass in 
already, otherwise they could have set the password via 
imaevm_params.keypass global and passed in NULL and for them this will 
be a behavioral change. Anyway, you have no other choice to get rid of 
imaevm_params as much as possible, so I guess it's ok.

It looks like at this point imaevm_params.keypass doesn't have a single 
user anymore so you could rename it to 'unused1' or so in the stucture 
since it will have zero effect for anyone to set it.

>   	if (imaevm_params.x509)
> -		return sign_hash_v2(hashalgo, hash, size, keyfile, sig);
> +		return sign_hash_v2(hashalgo, hash, size, keyfile, keypass, sig);
>   #if CONFIG_SIGV1
>   	else
> -		return sign_hash_v1(hashalgo, hash, size, keyfile, sig);
> +		return sign_hash_v1(hashalgo, hash, size, keyfile, keypass, sig);
>   #endif
>   	log_info("Signature version 1 deprecated.");
>   	return -1;

  reply	other threads:[~2023-11-22 14:22 UTC|newest]

Thread overview: 28+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-11-19 16:50 [ima-evm-utils PATCH 00/12] Address non concurrency-safe libimaevm global variables Mimi Zohar
2023-11-19 16:50 ` [ima-evm-utils PATCH 01/12] Rename "public_keys" to "g_public_keys" Mimi Zohar
2023-11-22 12:44   ` Stefan Berger
2023-11-19 16:50 ` [ima-evm-utils PATCH 02/12] Free public keys list Mimi Zohar
2023-11-22 12:52   ` Stefan Berger
2023-11-19 16:50 ` [ima-evm-utils PATCH 03/12] Update library function definitions to include a "public_keys" parameter Mimi Zohar
2023-11-22 13:07   ` Stefan Berger
2023-11-19 16:50 ` [ima-evm-utils PATCH 04/12] Update a library function definition to include a "hash_algo" parameter Mimi Zohar
2023-11-22 13:14   ` Stefan Berger
2023-11-19 16:50 ` [ima-evm-utils PATCH 05/12] Update cmd_verify_ima() to define and use a local list of public keys Mimi Zohar
2023-11-22 13:16   ` Stefan Berger
2023-11-19 16:50 ` [ima-evm-utils PATCH 06/12] Update cmd_verify_evm " Mimi Zohar
2023-11-19 16:50 ` [ima-evm-utils PATCH 07/12] Update ima_measurements " Mimi Zohar
2023-11-22 13:24   ` Stefan Berger
2023-11-19 16:50 ` [ima-evm-utils PATCH 08/12] Define library ima_calc_hash2() function with a hash algorithm parameter Mimi Zohar
2023-11-22 13:26   ` Stefan Berger
2023-11-19 16:50 ` [ima-evm-utils PATCH 09/12] Use a local hash algorithm variable when verifying file signatures Mimi Zohar
2023-11-22 13:37   ` Stefan Berger
2023-11-22 14:14     ` Mimi Zohar
2023-11-22 14:33       ` Stefan Berger
2023-11-29 16:08         ` Mimi Zohar
2023-11-19 16:50 ` [ima-evm-utils PATCH 10/12] Update EVM signature verification to use a local hash algorithm variable Mimi Zohar
2023-11-22 13:55   ` Stefan Berger
2023-11-19 16:50 ` [ima-evm-utils PATCH 11/12] Use a file specific hash algorithm variable for signing files Mimi Zohar
2023-11-22 14:09   ` Stefan Berger
2023-11-19 16:50 ` [ima-evm-utils PATCH 12/12] Define and use a file specific "keypass" variable Mimi Zohar
2023-11-22 14:22   ` Stefan Berger [this message]
2023-11-29 16:07     ` Mimi Zohar

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=117e3af9-3372-42ea-bdaf-d5e190ddf196@linux.ibm.com \
    --to=stefanb@linux.ibm.com \
    --cc=linux-integrity@vger.kernel.org \
    --cc=zohar@linux.ibm.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox