From: Kees Cook <keescook@chromium.org>
To: Evan Green <evgreen@chromium.org>
Cc: linux-kernel@vger.kernel.org, corbet@lwn.net,
linux-pm@vger.kernel.org, rjw@rjwysocki.net,
gwendal@chromium.org, apronin@chromium.org,
Pavel Machek <pavel@ucw.cz>,
Matthew Garrett <mgarrett@aurora.tech>,
linux-integrity@vger.kernel.org, jejb@linux.ibm.com,
zohar@linux.ibm.com, dlunev@google.com,
Eric Biggers <ebiggers@kernel.org>,
Ben Boeckel <me@benboeckel.net>,
jarkko@kernel.org, Len Brown <len.brown@intel.com>,
"Rafael J. Wysocki" <rafael@kernel.org>
Subject: Re: [PATCH v4 09/11] PM: hibernate: Mix user key in encrypted hibernate
Date: Thu, 10 Nov 2022 08:17:35 -0800 [thread overview]
Message-ID: <202211100816.FEF5A3305C@keescook> (raw)
In-Reply-To: <CAE=gft41=5uWwPfDZ=nyjcOzk21YCAeg6cheUNy-m0j79CgNfQ@mail.gmail.com>
On Wed, Nov 09, 2022 at 04:30:10PM -0800, Evan Green wrote:
> On Fri, Nov 4, 2022 at 11:54 AM Kees Cook <keescook@chromium.org> wrote:
> >
> > On Thu, Nov 03, 2022 at 11:01:17AM -0700, Evan Green wrote:
> > > Usermode may have their own data protection requirements when it comes
> > > to encrypting the hibernate image. For example, users may want a policy
> > > where the hibernate image is protected by a key derived both from
> > > platform-level security as well as authentication data (such as a
> > > password or PIN). This way, even if the platform is compromised (ie a
> > > stolen laptop), sensitive data cannot be exfiltrated via the hibernate
> > > image without additional data (like the user's password).
> > >
> > > The kernel is already doing the encryption, but will be protecting its
> > > key with the TPM alone. Allow usermode to mix in key content of their own
> > > for the data portion of the hibernate image, so that the image
> > > encryption key is determined both by a TPM-backed secret and
> > > user-defined data.
> > >
> > > To mix the user key in, we hash the kernel key followed by the user key,
> > > and use the resulting hash as the new key. This allows usermode to mix
> > > in its key material without giving it too much control over what key is
> > > actually driving the encryption (which might be used to attack the
> > > secret kernel key).
> > >
> > > Limiting this to the data portion allows the kernel to receive the page
> > > map and prepare its giant allocation even if this user key is not yet
> > > available (ie the user has not yet finished typing in their password).
> > > Once the user key becomes available, the data portion can be pushed
> > > through to the kernel as well. This enables "preloading" scenarios,
> > > where the hibernate image is loaded off of disk while the additional
> > > key material (eg password) is being collected.
> > >
> > > One annoyance of the "preloading" scheme is that hibernate image memory
> > > is effectively double-allocated: first by the usermode process pulling
> > > encrypted contents off of disk and holding it, and second by the kernel
> > > in its giant allocation in prepare_image(). An interesting future
> > > optimization would be to allow the kernel to accept and store encrypted
> > > page data before the user key is available. This would remove the
> > > double allocation problem, as usermode could push the encrypted pages
> > > loaded from disk immediately without storing them. The kernel could defer
> > > decryption of the data until the user key is available, while still
> > > knowing the correct page locations to store the encrypted data in.
> > >
> > > Signed-off-by: Evan Green <evgreen@chromium.org>
> > > ---
> > >
> > > (no changes since v2)
> > >
> > > Changes in v2:
> > > - Add missing static on snapshot_encrypted_byte_count()
> > > - Fold in only the used kernel key bytes to the user key.
> > > - Make the user key length 32 (Eric)
> > > - Use CRYPTO_LIB_SHA256 for less boilerplate (Eric)
> > >
> > > include/uapi/linux/suspend_ioctls.h | 15 ++-
> > > kernel/power/Kconfig | 1 +
> > > kernel/power/power.h | 1 +
> > > kernel/power/snapenc.c | 158 ++++++++++++++++++++++++++--
> > > kernel/power/snapshot.c | 5 +
> > > kernel/power/user.c | 4 +
> > > kernel/power/user.h | 12 +++
> > > 7 files changed, 185 insertions(+), 11 deletions(-)
> > >
> > > diff --git a/include/uapi/linux/suspend_ioctls.h b/include/uapi/linux/suspend_ioctls.h
> > > index b73026ef824bb9..f93a22eac52dc2 100644
> > > --- a/include/uapi/linux/suspend_ioctls.h
> > > +++ b/include/uapi/linux/suspend_ioctls.h
> > > @@ -25,6 +25,18 @@ struct uswsusp_key_blob {
> > > __u8 nonce[USWSUSP_KEY_NONCE_SIZE];
> > > } __attribute__((packed));
> > >
> > > +/*
> > > + * 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[32];
> >
> > Why is this 32? (Is there a non-literal we can put here?)
>
> Sure, I can make a new define for this: USWSUSP_USER_KEY_SIZE. Really
> it just needs to be enough key material that usermode feels like
> they've swizzled things up enough. I wanted to avoid using a
> particular implementation constant like AES_KEYSIZE_256 because I
> wanted that to be a kernel implementation detail, and also wanted to
> avoid adding additional header dependencies to suspend_ioctls.h.
Can this just use __aligned(8) etc?
--
Kees Cook
next prev parent reply other threads:[~2022-11-10 16:17 UTC|newest]
Thread overview: 34+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-11-03 18:01 [PATCH v4 00/11] Encrypted Hibernation Evan Green
2022-11-03 18:01 ` [PATCH v4 01/11] tpm: Add support for in-kernel resetting of PCRs Evan Green
2022-11-03 18:01 ` [PATCH v4 02/11] tpm: Export and rename tpm2_find_and_validate_cc() Evan Green
2022-11-04 18:25 ` Kees Cook
2022-11-07 11:37 ` Jarkko Sakkinen
2022-11-03 18:01 ` [PATCH v4 03/11] tpm: Allow PCR 23 to be restricted to kernel-only use Evan Green
2022-11-04 18:27 ` Kees Cook
2022-11-07 11:39 ` Jarkko Sakkinen
2022-11-07 18:15 ` Evan Green
2022-11-11 20:04 ` Evan Green
2022-11-23 23:03 ` Jarkko Sakkinen
2022-11-03 18:01 ` [PATCH v4 04/11] security: keys: trusted: Include TPM2 creation data Evan Green
2022-11-04 18:33 ` Kees Cook
2022-11-07 20:11 ` Evan Green
2022-11-10 0:29 ` Evan Green
2022-11-03 18:01 ` [PATCH v4 05/11] security: keys: trusted: Allow storage of PCR values in " Evan Green
2022-11-04 18:34 ` Kees Cook
2022-11-03 18:01 ` [PATCH v4 06/11] security: keys: trusted: Verify " Evan Green
2022-11-04 18:35 ` Kees Cook
2022-11-03 18:01 ` [PATCH v4 07/11] PM: hibernate: Add kernel-based encryption Evan Green
2022-11-04 18:38 ` Kees Cook
2022-11-10 0:29 ` Evan Green
2022-11-07 11:42 ` Jarkko Sakkinen
2022-11-03 18:01 ` [PATCH v4 08/11] PM: hibernate: Use TPM-backed keys to encrypt image Evan Green
2022-11-04 18:41 ` Kees Cook
2022-11-03 18:01 ` [PATCH v4 09/11] PM: hibernate: Mix user key in encrypted hibernate Evan Green
2022-11-04 18:54 ` Kees Cook
2022-11-10 0:30 ` Evan Green
2022-11-10 16:17 ` Kees Cook [this message]
2022-11-10 18:32 ` Evan Green
2022-11-03 18:01 ` [PATCH v4 10/11] PM: hibernate: Verify the digest encryption key Evan Green
2022-11-04 19:00 ` Kees Cook
2022-11-10 0:30 ` Evan Green
2022-11-03 18:01 ` [PATCH v4 11/11] PM: hibernate: seal the encryption key with a PCR policy Evan Green
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=202211100816.FEF5A3305C@keescook \
--to=keescook@chromium.org \
--cc=apronin@chromium.org \
--cc=corbet@lwn.net \
--cc=dlunev@google.com \
--cc=ebiggers@kernel.org \
--cc=evgreen@chromium.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=me@benboeckel.net \
--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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.