public inbox for linux-integrity@vger.kernel.org
 help / color / mirror / Atom feed
From: Vitaly Chikunov <vt@altlinux.org>
To: Stefan Berger <stefanb@linux.ibm.com>
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 11:11:37 +0300	[thread overview]
Message-ID: <20210905081137.nsslgto7mqsfxn2b@altlinux.org> (raw)
In-Reply-To: <cee7b810-e9fd-9924-a8dd-9cc1e3211bd7@linux.ibm.com>

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.

(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

Thanks,


  reply	other threads:[~2021-09-05  8:11 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 [this message]
2021-09-05 11:52     ` Stefan Berger
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=20210905081137.nsslgto7mqsfxn2b@altlinux.org \
    --to=vt@altlinux.org \
    --cc=bmeneg@redhat.com \
    --cc=dmitry.kasatkin@gmail.com \
    --cc=linux-integrity@vger.kernel.org \
    --cc=stefanb@linux.ibm.com \
    --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