Received: by 2002:a05:6a10:8c0a:0:0:0:0 with SMTP id go10csp4050287pxb; Mon, 8 Feb 2021 06:50:00 -0800 (PST) X-Google-Smtp-Source: ABdhPJwQsr6IABELjzPBrtq3R61JN4lcM2QEY6tWuZhHu2Hkss2EGwXFuXCzwQgRypqMDNWUi4hS X-Received: by 2002:a17:906:2293:: with SMTP id p19mr9261410eja.206.1612795800337; Mon, 08 Feb 2021 06:50:00 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1612795800; cv=none; d=google.com; s=arc-20160816; b=EAd4OD8kJTUfWa83pf4Aq4Nq6fAl0sqPukoY+Es2W7Hrm8rqb6M8fjgJpjP3NuOwKL whw5lkaloi8nTJ7D8MGIyOztUs3i8ysX+lPQb44ukfwcgHFrQGO0E/GXPt6Sfe2LFExE bl0kME+5dxHukGV9csjV6akcoe1mKsxtF1mwoWPaMtJcBecK6sZAYnqTV7IteTukh9c2 BllupljtH/XrRRiurUOLy5bmIe/Zw1QriO+uNttb9wFuUaMIW1rYfZeKMQqHU5fKeChQ fZqyZuWhFBSV+sFmsy90+5D3+NDiDVeuFUj+stsfCiKxaYsbWg/0soEAG78qINpgJXqM tdCQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:date:cc:to:from:subject :message-id; bh=c4Mx5CxJewBjmMsU2iR8kad/lHuGb8oCI62Zfxf5ops=; b=cW2iRAeTc9e/rjWSk+DeA2w8P0EqFPpBKaqSpKsW45ht6zRhqcIAuMI2cHBfnNlQY4 sZSHh04ACwepoNDgQvcsExmCC5x20FI2W/KuNGoM/jeKun1PAgv3QfYV01QT2Hl/omP+ 7xDA0rcYgjcQZ8hGw7j4JTY0QdRB4rx9aCWPprCppv6auHj17foqsULhZ1maCcY5i/X8 xN/2rAmlicGZRRdwqirVxSNBv87dOW0cAig9GvJxIYwC6RtATXflc1eiK+/XaVgSI6HK ivkYSOb3q8XOUJ7SCVBk2s0APHET4hYfZTW3HADPsMR/xWG1kx389+Cbojf0KhIPoN3d jdaQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id df22si11642632edb.163.2021.02.08.06.49.36; Mon, 08 Feb 2021 06:50:00 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232372AbhBHOsw (ORCPT + 99 others); Mon, 8 Feb 2021 09:48:52 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44870 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232142AbhBHOjg (ORCPT ); Mon, 8 Feb 2021 09:39:36 -0500 Received: from metis.ext.pengutronix.de (metis.ext.pengutronix.de [IPv6:2001:67c:670:201:290:27ff:fe1d:cc33]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0D920C06178B for ; Mon, 8 Feb 2021 06:38:47 -0800 (PST) Received: from ptx.hi.pengutronix.de ([2001:67c:670:100:1d::c0]) by metis.ext.pengutronix.de with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1l97gU-0008Bl-Bs; Mon, 08 Feb 2021 15:38:38 +0100 Received: from localhost ([127.0.0.1]) by ptx.hi.pengutronix.de with esmtp (Exim 4.92) (envelope-from ) id 1l97gT-0007SL-Cu; Mon, 08 Feb 2021 15:38:37 +0100 Message-ID: Subject: Re: Migration to trusted keys: sealing user-provided key? From: Jan =?ISO-8859-1?Q?L=FCbbe?= To: Mimi Zohar , Jarkko Sakkinen , Ahmad Fatoum , James Bottomley , David Howells , keyrings@vger.kernel.org, Sumit Garg Cc: linux-integrity@vger.kernel.org, linux-kernel@vger.kernel.org, linux-security-module@vger.kernel.org, kernel@pengutronix.de Date: Mon, 08 Feb 2021 15:38:36 +0100 In-Reply-To: References: <74830d4f-5a76-8ba8-aad0-0d79f7c01af9@pengutronix.de> <6dc99fd9ffbc5f405c5f64d0802d1399fc6428e4.camel@kernel.org> <8b9477e150d7c939dc0def3ebb4443efcc83cd85.camel@pengutronix.de> <64472434a367060ddce6e03425156b8312a5ad6c.camel@pengutronix.de> <0be34899c9686b95cd22aa016f466523579cbeed.camel@pengutronix.de> Content-Type: text/plain; charset="UTF-8" User-Agent: Evolution 3.38.3-1 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-SA-Exim-Connect-IP: 2001:67c:670:100:1d::c0 X-SA-Exim-Mail-From: jlu@pengutronix.de X-SA-Exim-Scanned: No (on metis.ext.pengutronix.de); SAEximRunCond expanded to false X-PTX-Original-Recipient: linux-kernel@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Mon, 2021-02-01 at 14:46 -0500, Mimi Zohar wrote: > On Mon, 2021-02-01 at 17:38 +0100, Jan Lübbe wrote: > > On Mon, 2021-02-01 at 11:11 -0500, Mimi Zohar wrote: > > > On Mon, 2021-02-01 at 16:31 +0100, Jan Lübbe wrote: > > > > On Sun, 2021-01-31 at 09:29 -0500, Mimi Zohar wrote: > > > > > > > Usage:: > > > > > > > > > >     keyctl add encrypted name "new [format] key-type:master-key-name keylen" > > > > >         ring > > > > >     keyctl add encrypted name "load hex_blob" ring > > > > > > > > 'load' (as I understand the code) only accepts an encrypted blob. > > > > > > > > So the only way I see to have an encrypted key with a non-random key data would > > > > be: > > > > - create a random temporary master key and load a copy as a user key > > > > - encrypt the chosen key data with the temporary master key (using a new > > > > userspace reimplementation of the kernel encrypted key blob format) > > > > - use keyctl add encrypted dmcrypt "load " > > > > - create new trusted master key (OP-TEE or CAAM in our case) as > > > > - use keyctl update to switch to the new trusted master key > > > > - use keyctl pipe on the trusted and encrypted keys and store both for loading > > > > on later boots > > > > > > > > If we'd support importing a pre-existing key into a trusted or encrypted key, > > > > we'd do instead: > > > > - use keyctl add trusted dmcrypt "import " > > > > - use keyctl pipe on the trusted key and store it for loading on later boots > > > > > > > > This way, users wouldn't need to care which backend is used by trusted keys > > > > (TPM/OP-TEE/CAAM/...). That would make use-cases where a random key is not > > > > suitable as straight-forward as the those where a random key is OK. > > > > > > As I said above, the "encrypted" key update doesn't change the key data > > > used for encrypting/decrypting storage in the dm-crypt case, it just > > > updates the key under which it is encrypted/signed. > > > > Yes, that's clear. I only used it to demonstrate how a workaround for importing > > key material into an encrypted key could look like. > > > > > Yes, the reason for using an encrypted "trusted" key, as opposed to an > > > encrypted "user" key, is that the "trusted" key is encrypted/decrypted > > > by the TPM and never exposed to userspace in the clear. > > > > Yes, and that's the main reason I'd like to use trusted keys with dm-crypt: a > > much lower chance of exposing this key somewhere it could be extracted. > > > > > It doesn't sound like you're wanting to update the storage key in the > > > field, just the key used to encrypt/decrypt that key. So I'm still not > > > clear as to why you would want an initial non-random encrypted key. > > > Providing that key on the command line certaining isn't a good idea. > > > > Some of our customers have systems in the field which use non-mainline patches > > for access to the CAAM [1], which also have the downside of exposing the > > decrypted key material directly to userspace. In that thread you suggested to > > use trusted keys instead. With Sumit's work that rework is finally within reach. > > :) > > > > > > In those systems, we have data that's encrypted with a pre-existing dm-crypt or > > ecryptfs key. As we update those systems in the field to newer kernels, we want > > to get rid of those custom patches, but can't reencrypt everything. > > > > So the approach would be to perform a one-time migration when updating a device: > > - use our old interface to decrypt the key and 'import' it into a trusted key > > - use keyctl pipe and save the re-encrypted key to disk > > - destroy the old encrypted key > > After this migration, the key material is no longer available to userspace (only > > to dm-crypt). > > > > > > Another use-case for supporting key import that we want to support is analysis > > of broken devices returned from the field: > > - generate an encryption key per device in the factory > > - encrypt it to a private key in escrow and archive it for later use > > - import it into a trusted key on the device > > - keyctl pipe it to a file on the device for use on boot > > > > Later, when you need to do an analysis, you can get the key from escrow even if > > the device cannot boot any longer. > > The first use case doesn't sound like a valid reason for upstreaming > such support. It's a one time update to migrate everyone to a newer > kernel. That you can carry independently of upstream. In terms of the > second use case, do you really want the ability and the resulting > responsibility of being able to decrypt user's data? Please think > this through carefully, before you decide you really want/need this > feature. As it seems that this feature would not be appropriate for all use-cases and threat models, I wonder if making it optional would be acceptable. Something like: config TRUSTED_KEYS_IMPORT bool "Allow creating TRUSTED KEYS from existing key material" depends on TRUSTED_KEYS help This option adds support for creating new trusted keys from existing  key material supplied by userspace, instead of using random numbers. As with random trusted keys, userspace cannot extract the plain-text  key material again and will only ever see encrypted blobs. This option should *only* be enabled for use in a trusted environment (such as during debugging/development or in a secured factory). Also, consider using 'keyctl padd' instead of 'keyctl add'  to avoid exposing the plain-text key on the process command line. If you are unsure as to whether this is required, answer N. Best regards, Jan -- Pengutronix e.K. | | Steuerwalder Str. 21 | http://www.pengutronix.de/ | 31137 Hildesheim, Germany | Phone: +49-5121-206917-0 | Amtsgericht Hildesheim, HRA 2686 | Fax: +49-5121-206917-5555 |