All of lore.kernel.org
 help / color / mirror / Atom feed
From: Mike Snitzer <snitzer@redhat.com>
To: Ondrej Kozina <okozina@redhat.com>
Cc: aryabinin@virtuozzo.com, dm-devel@redhat.com,
	mpatocka@redhat.com, mbroz@redhat.com
Subject: Re: [PATCH v3] dm-crypt: add ability to use keys from the kernel key retention service
Date: Mon, 21 Nov 2016 10:40:49 -0500	[thread overview]
Message-ID: <20161121154049.GA13248@redhat.com> (raw)
In-Reply-To: <1479740331-31573-1-git-send-email-okozina@redhat.com>

On Mon, Nov 21 2016 at  9:58P -0500,
Ondrej Kozina <okozina@redhat.com> wrote:

> Changes since v2:
>   - moved rcu_read_lock() closer to key payload processing (thanks Mikulas)
>   - updated dm-crypt documentation
>   - updated code comments and unified parameter names in kernel keyring function stubs
>     (#CONFIG_KEYS undefined)
> 
> The kernel key service is a generic way to store keys for the use of
> other subsystems. Currently there is no way to use kernel keys in dm-crypt.
> This patch aims to fix that. Instead of key userspace may pass a key
> description with preceding ':'. So message that constructs encryption
> mapping now looks like this:
> 
>   <cipher> [<key>|:<key_string>] <iv_offset> <dev_path> <start> [<#opt_params> <opt_params>]
> 
> where <key_string> is in format: <key_size>:<key_type>:<key_description>
> 
> Currently we only support two elementary key types: 'user' and 'logon'.
> Keys may be loaded in dm-crypt either via <key_string> or using
> classical method and pass the key in hex representation directly.
> 
> dm-crypt device initialised with a key passed in hex representation may be
> replaced with key passed in key_string format and vice versa.
> 
> (Patch is based on original work by Andrey Ryabinin)
> 
> Signed-off-by: Ondrej Kozina <okozina@redhat.com>

Other than the following cleanup patch that I've put ontop of your v3,
looks good to me.

diff --git a/drivers/md/dm-crypt.c b/drivers/md/dm-crypt.c
index 7c2bbef..8fcc924 100644
--- a/drivers/md/dm-crypt.c
+++ b/drivers/md/dm-crypt.c
@@ -1508,12 +1508,8 @@ static int crypt_set_keyring_key(struct crypt_config *cc, const char *key_string
 	if (!new_key_string)
 		return -ENOMEM;
 
-	/*
-	 * FIXME: are there any key descriptions we should disallow users
-	 * from loading to dm-crypt? i.e.: kernel keys starting with '.'
-	 */
-
-	key = request_key(strncmp(key_string, "user", 4) ? &key_type_logon : &key_type_user, key_desc + 1, NULL);
+	key = request_key(strncmp(key_string, "user", 4) ? &key_type_logon : &key_type_user,
+			  key_desc + 1, NULL);
 	if (IS_ERR(key)) {
 		kzfree(new_key_string);
 		return PTR_ERR(key);
@@ -1602,25 +1598,25 @@ static int crypt_set_key(struct crypt_config *cc, char *key)
 	if (!cc->key_size && strcmp(key, "-"))
 		goto out;
 
-	/* ':' means that the key is in kernel keyring */
-	if (key[0] == ':')
+	/* ':' means the key is in kernel keyring, short-circuit normal key processing */
+	if (key[0] == ':') {
 		r = crypt_set_keyring_key(cc, key + 1);
-	else {
-		/* clear the flag since following operations may invalidate previously valid key */
-		clear_bit(DM_CRYPT_KEY_VALID, &cc->flags);
+		goto out;
+	}
 
-		/* wipe references to any kernel keyring key */
-		kzfree(cc->key_string);
-		cc->key_string = NULL;
+	/* clear the flag since following operations may invalidate previously valid key */
+	clear_bit(DM_CRYPT_KEY_VALID, &cc->flags);
 
-		if (cc->key_size &&
-		    crypt_decode_key(cc->key, key, cc->key_size) < 0)
-			goto out;
+	/* wipe references to any kernel keyring key */
+	kzfree(cc->key_string);
+	cc->key_string = NULL;
 
-		r = crypt_setkey(cc);
-		if (!r)
-			set_bit(DM_CRYPT_KEY_VALID, &cc->flags);
-	}
+	if (cc->key_size && crypt_decode_key(cc->key, key, cc->key_size) < 0)
+		goto out;
+
+	r = crypt_setkey(cc);
+	if (!r)
+		set_bit(DM_CRYPT_KEY_VALID, &cc->flags);
 out:
 	/* Hex key string not needed after here, so wipe it. */
 	memset(key, '0', key_string_len);

  reply	other threads:[~2016-11-21 15:40 UTC|newest]

Thread overview: 22+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-08-09 13:56 [RFC] dm-crypt: add ability to use keys from the kernel key retention service Andrey Ryabinin
2016-08-09 13:56 ` Andrey Ryabinin
2016-08-10 11:16 ` Ondrej Kozina
2016-08-10 11:16   ` [dm-devel] " Ondrej Kozina
2016-08-11 15:01   ` Andrey Ryabinin
2016-08-11 15:01     ` Andrey Ryabinin
2016-11-07  9:38 ` [PATCH 0/3] Modified kernel keyring support patch Ondrej Kozina
2016-11-07  9:38 ` [PATCH 1/3] dm-crypt: mark key as invalid until properly loaded Ondrej Kozina
2016-11-07  9:38 ` [PATCH 2/3] dm-crypt: add ability to use keys from the kernel key retention service Ondrej Kozina
2016-11-07  9:38 ` [PATCH 3/3] dm-crypt: modifications to previous patch Ondrej Kozina
2016-11-13 17:22   ` Milan Broz
2016-11-16 20:47     ` [PATCH v2] dm-crypt: add ability to use keys from the kernel key retention service Ondrej Kozina
2016-11-17 16:35       ` Andrey Ryabinin
2016-11-17 19:31         ` Milan Broz
2016-11-17 20:06         ` Ondrej Kozina
2016-11-18 16:55           ` Andrey Ryabinin
2016-11-21 12:23           ` Ondrej Kozina
2016-12-01 17:20             ` [PATCH] dm-crypt: reject key strings containing whitespace chars Ondrej Kozina
2016-11-21 14:58       ` [PATCH v3] dm-crypt: add ability to use keys from the kernel key retention service Ondrej Kozina
2016-11-21 15:40         ` Mike Snitzer [this message]
2016-11-23 20:51           ` [PATCH] dm-crypt: check key payload pointer not null Ondrej Kozina
2016-11-24  9:28             ` David Howells

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=20161121154049.GA13248@redhat.com \
    --to=snitzer@redhat.com \
    --cc=aryabinin@virtuozzo.com \
    --cc=dm-devel@redhat.com \
    --cc=mbroz@redhat.com \
    --cc=mpatocka@redhat.com \
    --cc=okozina@redhat.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.