From: Evan Green <evgreen@chromium.org>
To: Eric Biggers <ebiggers@kernel.org>
Cc: LKML <linux-kernel@vger.kernel.org>,
Matthew Garrett <mgarrett@aurora.tech>,
Daniil Lunev <dlunev@google.com>,
zohar@linux.ibm.com, "James E.J. Bottomley" <jejb@linux.ibm.com>,
linux-integrity@vger.kernel.org, Jonathan Corbet <corbet@lwn.net>,
"Rafael J. Wysocki" <rjw@rjwysocki.net>,
Gwendal Grignou <gwendal@chromium.org>,
Jarkko Sakkinen <jarkko@kernel.org>,
Linux PM <linux-pm@vger.kernel.org>,
Len Brown <len.brown@intel.com>, Pavel Machek <pavel@ucw.cz>,
"Rafael J. Wysocki" <rafael@kernel.org>
Subject: Re: [PATCH 08/10] PM: hibernate: Mix user key in encrypted hibernate
Date: Wed, 3 Aug 2022 13:48:08 -0700 [thread overview]
Message-ID: <CAE=gft4_M=9TsbHFEVQO-3BRrQsDia0Mwt0C9OpA6fMcnaDsrw@mail.gmail.com> (raw)
In-Reply-To: <YumpwkIz+S+zDfol@sol.localdomain>
On Tue, Aug 2, 2022 at 3:48 PM Eric Biggers <ebiggers@kernel.org> wrote:
>
> On Wed, May 04, 2022 at 04:21:00PM -0700, Evan Green wrote:
> > +/*
> > + * Allow user mode to fold in key material for the data portion of the hibernate
> > + * image.
> > + */
> > +struct uswsusp_user_key {
> > + /* Kernel returns the metadata size. */
> > + __kernel_loff_t meta_size;
> > + __u32 key_len;
> > + __u8 key[16];
> > + __u32 pad;
> > +};
>
> Shouldn't the key field be 32 bytes?
>
Short answer: yes, it should, will fix. Long answer: I had used a
hardcoded AEAD algorithm of "gcm(aes)", and was envisioning it being
AES128. But making it accommodate 32 bytes now before this gets set in
stone is a better idea.
> > +/* Derive a key from the kernel and user keys for data encryption. */
> > +static int snapshot_use_user_key(struct snapshot_data *data)
> > +{
> > + struct shash_desc *desc;
> > + u8 digest[SHA256_DIGEST_SIZE];
> > + struct trusted_key_payload *payload;
> > + struct crypto_shash *tfm;
> > + int ret;
> > +
> > + tfm = crypto_alloc_shash("sha256", 0, 0);
> > + if (IS_ERR(tfm)) {
> > + ret = -EINVAL;
> > + goto err_rel;
> > + }
> > +
> > + desc = kmalloc(sizeof(struct shash_desc) +
> > + crypto_shash_descsize(tfm), GFP_KERNEL);
> > + if (!desc) {
> > + ret = -ENOMEM;
> > + goto err_rel;
> > + }
> > +
> > + desc->tfm = tfm;
> > + ret = crypto_shash_init(desc);
> > + if (ret != 0)
> > + goto err_free;
> > +
> > + /*
> > + * Hash the kernel key and the user key together. This folds in the user
> > + * key, but not in a way that gives the user mode predictable control
> > + * over the key bits. Hash in all 32 bytes of the key even though only 16
> > + * are in active use as extra salt.
> > + */
> > + payload = data->key->payload.data[0];
> > + crypto_shash_update(desc, payload->key, MIN_KEY_SIZE);
> > + crypto_shash_update(desc, data->user_key, sizeof(data->user_key));
> > + crypto_shash_final(desc, digest);
> > + ret = crypto_aead_setkey(data->aead_tfm,
> > + digest,
> > + SNAPSHOT_ENCRYPTION_KEY_SIZE);
> > +
> > +err_free:
> > + kfree(desc);
> > +
> > +err_rel:
> > + crypto_free_shash(tfm);
> > + return ret;
> > +}
>
> Just select CRYPTO_LIB_SHA256, and you can use sha256_init/update/final which
> would be much simpler. Similarly with sha256_data() that is added by the next
> patch; you could just call sha256().
Good idea, will do. Thanks!
>
> - Eric
next prev parent reply other threads:[~2022-08-03 20:48 UTC|newest]
Thread overview: 42+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-05-04 23:20 [PATCH 00/10] Encrypted Hibernation Evan Green
2022-05-04 23:20 ` [PATCH 01/10] tpm: Add support for in-kernel resetting of PCRs Evan Green
2022-05-04 23:20 ` [PATCH 02/10] tpm: Allow PCR 23 to be restricted to kernel-only use Evan Green
2022-05-04 23:20 ` [PATCH 03/10] security: keys: trusted: Parse out individual components of the key blob Evan Green
2022-05-04 23:20 ` [PATCH 04/10] security: keys: trusted: Allow storage of PCR values in creation data Evan Green
2022-08-02 23:00 ` Eric Biggers
2022-08-03 20:48 ` Evan Green
2022-05-04 23:20 ` [PATCH 05/10] security: keys: trusted: Verify " Evan Green
2022-05-04 23:20 ` [PATCH 06/10] PM: hibernate: Add kernel-based encryption Evan Green
2022-08-29 21:45 ` TPM: hibernate with IMA PCR 10 Ken Goldman
2022-08-29 21:51 ` Matthew Garrett
2022-08-31 2:48 ` Jarkko Sakkinen
2022-09-07 20:47 ` Evan Green
2022-09-07 23:57 ` Mimi Zohar
2022-09-08 5:25 ` Jarkko Sakkinen
2022-09-11 2:40 ` Mimi Zohar
2022-09-20 4:36 ` Jarkko Sakkinen
2022-09-21 20:15 ` Mimi Zohar
2022-09-23 13:30 ` Jarkko Sakkinen
2022-09-27 16:03 ` Evan Green
2022-09-28 9:42 ` Jonathan McDowell
2022-05-04 23:20 ` [PATCH 07/10] PM: hibernate: Use TPM-backed keys to encrypt image Evan Green
2022-05-04 23:21 ` [PATCH 08/10] PM: hibernate: Mix user key in encrypted hibernate Evan Green
2022-05-06 16:08 ` Pavel Machek
2022-05-09 16:44 ` Evan Green
2022-05-10 12:29 ` Pavel Machek
2022-05-10 16:02 ` Evan Green
2022-08-02 22:48 ` Eric Biggers
2022-08-03 20:48 ` Evan Green [this message]
2022-05-04 23:21 ` [PATCH 09/10] PM: hibernate: Verify the digest encryption key Evan Green
2022-08-02 22:51 ` Eric Biggers
2022-05-04 23:21 ` [PATCH 10/10] PM: hibernate: seal the encryption key with a PCR policy Evan Green
2022-05-06 16:08 ` [PATCH 00/10] Encrypted Hibernation Pavel Machek
2022-05-09 16:43 ` Evan Green
2022-05-17 16:06 ` Rafael J. Wysocki
2022-05-17 17:34 ` Evan Green
2022-06-16 15:42 ` Evan Green
2022-08-01 22:32 ` Evan Green
2022-08-02 18:36 ` Matthew Garrett
2022-08-04 0:59 ` Jarkko Sakkinen
2022-08-04 21:55 ` Evan Green
2022-08-06 18:21 ` Jarkko Sakkinen
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='CAE=gft4_M=9TsbHFEVQO-3BRrQsDia0Mwt0C9OpA6fMcnaDsrw@mail.gmail.com' \
--to=evgreen@chromium.org \
--cc=corbet@lwn.net \
--cc=dlunev@google.com \
--cc=ebiggers@kernel.org \
--cc=gwendal@chromium.org \
--cc=jarkko@kernel.org \
--cc=jejb@linux.ibm.com \
--cc=len.brown@intel.com \
--cc=linux-integrity@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-pm@vger.kernel.org \
--cc=mgarrett@aurora.tech \
--cc=pavel@ucw.cz \
--cc=rafael@kernel.org \
--cc=rjw@rjwysocki.net \
--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;
as well as URLs for NNTP newsgroup(s).