public inbox for linux-integrity@vger.kernel.org
 help / color / mirror / Atom feed
From: Stefan Berger <stefanb@linux.ibm.com>
To: Vitaly Chikunov <vt@altlinux.org>
Cc: Mimi Zohar <zohar@linux.vnet.ibm.com>,
	Dmitry Kasatkin <dmitry.kasatkin@gmail.com>,
	linux-integrity@vger.kernel.org,
	Bruno Meneguele <bmeneg@redhat.com>
Subject: Re: [PATCH ima-evm-utils v4] evmctl: Use secure heap for private keys and passwords
Date: Sun, 5 Sep 2021 07:52:10 -0400	[thread overview]
Message-ID: <301ace0b-397e-6e83-37c0-6dc4794597ee@linux.ibm.com> (raw)
In-Reply-To: <20210905081137.nsslgto7mqsfxn2b@altlinux.org>


On 9/5/21 4:11 AM, Vitaly Chikunov wrote:
> Stefan,
>
> On Sat, Sep 04, 2021 at 09:10:50PM -0400, Stefan Berger wrote:
>> On 9/4/21 6:50 AM, Vitaly Chikunov wrote:
>>> After CRYPTO_secure_malloc_init OpenSSL will automatically store private
>>> keys in secure heap. OPENSSL_secure_malloc(3):
>>>
>>>     If a secure heap is used, then private key BIGNUM values are stored
>>>     there. This protects long-term storage of private keys, but will not
>>>     necessarily put all intermediate values and computations there.
>>>
>>> Additionally, we try to keep user passwords in secure heap too.
>>> This facility is only available since OpenSSL_1_1_0-pre1.
>>> Signed-off-by: Vitaly Chikunov <vt@altlinux.org>
>>> Reviewed-by: Bruno Meneguele <bmeneg@redhat.com>
>>> Cc: Stefan Berger <stefanb@linux.ibm.com>
>>> ---
>>> Change since v3:
>>> - Undo secure heap handling from (file2bin and) calc_evm_hmac since this
>>>     is debugging tool only. Add comment about this.
>>> - Since there is only code removals and new comments I keep Reviewed-by
>>>     tag.
>>>
>>>    src/evmctl.c | 97 +++++++++++++++++++++++++++++++++++++++++++++-------
>>>    1 file changed, 85 insertions(+), 12 deletions(-)
>>>
>>> @@ -2596,15 +2616,41 @@ static struct option opts[] = {
>>>    };
>>> +/*
>>> + * Copy password from optarg into secure heap, so it could be
>>> + * freed in the same way as a result of get_password().
>>> + */
>>> +static char *optarg_password(char *optarg)
>>> +{
>>
>> Mimi applied my patch that takes the password from an environment variable
>> to the next-testing branch. The code there (imaevm_params.keypass  =
>> getenv("..."))would have to change as well calling this function here. Even
>> though the man page of getenv says that 'The caller must take care not to
>> modify this string, since that would change the environment of the process'
>> we should be able to overwrite the env variable's password value just like
>> here. Maybe for this purpose rename this function to dup_password() ?
> `/proc/<pid>/environ' is never world readable (unlike `cmdline'), so we
> don't even need to overwrite it there. But, we can.

Or you could add an option for whether to overwrite the source...


>
> (Btw, I found the 'EVMCTL_KEY_PASSWORD' patch.)
>
>>> @@ -2643,6 +2691,7 @@ int main(int argc, char *argv[])
>>>    	ENGINE *eng = NULL;
>>>    	unsigned long keyid;
>>>    	char *eptr;
>>> +	char *keypass = NULL; /* @secure heap */
>>>    #if !(OPENSSL_VERSION_NUMBER < 0x10100000)
>>>    	OPENSSL_init_crypto(
>>> @@ -2651,6 +2700,17 @@ int main(int argc, char *argv[])
>>>    #endif
>>>    			    OPENSSL_INIT_ENGINE_ALL_BUILTIN, NULL);
>>>    #endif
>>> +#if OPENSSL_VERSION_NUMBER > 0x10100000
>>> +	/*
>>> +	 * This facility is available since OpenSSL_1_1_0-pre1.
>>
>> Shouldn't the comparison then not include 0x10100000?
>>
>> #if OPENSSL_VERSION_NUMBER >= 0x10100000
> The number is from `include/openssl/opensslv.h' from the time when
> relevant commit is already applied. So, I use `>'. It seems good match
> for OpenSSL_1_1_0-pre1 too:
>
>    $ git grep OPENSSL_VERSION_NUMBER OpenSSL_1_1_0-pre1:include/openssl/opensslv.h
>    OpenSSL_1_1_0-pre1:include/openssl/opensslv.h:# define OPENSSL_VERSION_NUMBER  0x10100001L

You are right. I had checkout out this commit here:

commit abd30777cc72029e8a44e4b67201cae8ed3d19c1 (HEAD -> OpenSSL_1_1_0, 
tag: OpenSSL_1_1_0)
Author: Matt Caswell <matt@openssl.org>
Date:   Thu Aug 25 16:29:18 2016 +0100

     Prepare for 1.1.0 release

     Reviewed-by: Richard Levitte <levitte@openssl.org


It shows this here:

$ grep -r OPENSSL_VERSION_NUM ./include/
./include/openssl/crypto.h:#  define SSLEAY_VERSION_NUMBER 
OPENSSL_VERSION_NUMBER
./include/openssl/opensslv.h:# define OPENSSL_VERSION_NUMBER 0x1010000fL

There's an 'f' at the 'end'.

   Stefan


>
> Thanks,
>

  reply	other threads:[~2021-09-05 11:52 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-09-04 10:50 [PATCH ima-evm-utils v4] evmctl: Use secure heap for private keys and passwords Vitaly Chikunov
2021-09-05  1:10 ` Stefan Berger
2021-09-05  8:11   ` Vitaly Chikunov
2021-09-05 11:52     ` Stefan Berger [this message]
2021-09-10 14:55 ` Mimi Zohar
2021-09-10 18:13   ` Vitaly Chikunov
2021-09-13 17:51     ` Mimi Zohar
2021-09-13 18:07       ` Vitaly Chikunov
2021-09-10 19:03   ` 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=301ace0b-397e-6e83-37c0-6dc4794597ee@linux.ibm.com \
    --to=stefanb@linux.ibm.com \
    --cc=bmeneg@redhat.com \
    --cc=dmitry.kasatkin@gmail.com \
    --cc=linux-integrity@vger.kernel.org \
    --cc=vt@altlinux.org \
    --cc=zohar@linux.vnet.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