From: David Howells <dhowells@redhat.com>
To: d.kasatkin@samsung.com, zohar@us.ibm.com
Cc: keyrings@linux-nfs.org, linux-security-module@vger.kernel.org,
linux-kernel@vger.kernel.org
Subject: [PATCH 8/9] KEYS: Implement keyctl control for encrypted keys
Date: Mon, 04 Nov 2013 16:23:14 +0000 [thread overview]
Message-ID: <20131104162314.10177.68684.stgit@warthog.procyon.org.uk> (raw)
In-Reply-To: <20131104162216.10177.98067.stgit@warthog.procyon.org.uk>
Implement "keyctl control" for encrypted keys rather than trying to do this
with the update method (which won't function correctly when add_key() tries to
update an existing key).
Provide a command to change the master key:
keyctl control <keyid> "encrypted change-master-key <m-key-id>"
Signed-off-by: David Howells <dhowells@redhat.com>
---
security/keys/encrypted-keys/encrypted.c | 56 ++++++++++++++++++++++++++++++
1 file changed, 56 insertions(+)
diff --git a/security/keys/encrypted-keys/encrypted.c b/security/keys/encrypted-keys/encrypted.c
index 9e1e005c7596..f9e7b808fa47 100644
--- a/security/keys/encrypted-keys/encrypted.c
+++ b/security/keys/encrypted-keys/encrypted.c
@@ -884,6 +884,61 @@ out:
}
/*
+ * encrypted_control - control an encrypted key in a type-specific way
+ */
+static long encrypted_control(struct key *key, char *command,
+ char *reply, size_t reply_size)
+{
+ static const char expected_command[] = "encrypted change-master-key ";
+ struct encrypted_key_payload *epayload, *new_epayload;
+ char *new_master_desc = NULL;
+ const char *format = NULL;
+ size_t datalen;
+ int ret;
+
+ if (memcmp(command, expected_command, sizeof(expected_command) - 1) != 0)
+ return -EINVAL;
+ command += sizeof(expected_command) - 1;
+ datalen = strlen(command);
+
+ if (datalen <= 0 || datalen > 32767)
+ return -EINVAL;
+
+ ret = datablob_parse(command, &format, &new_master_desc, NULL, NULL);
+ if (ret < 0)
+ return ret;
+
+ down_write(&key->sem);
+ epayload = rcu_dereference_protected(key->payload.rcudata, &key->sem);
+
+ ret = valid_master_desc(new_master_desc, epayload->master_desc);
+ if (ret < 0) {
+ up_write(&key->sem);
+ return ret;
+ }
+
+ new_epayload = encrypted_key_alloc(key, epayload->format,
+ new_master_desc, epayload->datalen);
+ if (IS_ERR(new_epayload)) {
+ up_write(&key->sem);
+ return PTR_ERR(new_epayload);
+ }
+
+ __ekey_init(new_epayload, epayload->format, new_master_desc,
+ epayload->datalen);
+
+ memcpy(new_epayload->iv, epayload->iv, ivsize);
+ memcpy(new_epayload->payload_data, epayload->payload_data,
+ epayload->payload_datalen);
+
+ rcu_assign_keypointer(key, new_epayload);
+
+ up_write(&key->sem);
+ call_rcu(&epayload->rcu, encrypted_rcu_free);
+ return 0;
+}
+
+/*
* encrypted_read - format and copy the encrypted data to userspace
*
* The resulting datablob format is:
@@ -974,6 +1029,7 @@ struct key_type key_type_encrypted = {
.destroy = encrypted_destroy,
.describe = user_describe,
.read = encrypted_read,
+ .control = encrypted_control,
};
EXPORT_SYMBOL_GPL(key_type_encrypted);
next prev parent reply other threads:[~2013-11-04 18:24 UTC|newest]
Thread overview: 25+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-11-04 16:22 [RFC][PATCH 0/9] encrypted keys & key control op David Howells
2013-11-04 16:22 ` [PATCH 1/9] KEYS: The RSA public key algorithm needs to select MPILIB David Howells
2013-11-04 16:22 ` [PATCH 2/9] KEYS: Provide a generic instantiation function David Howells
2013-11-04 16:22 ` [PATCH 3/9] KEYS: struct key_preparsed_payload should have two payload pointers David Howells
2013-11-04 16:22 ` [PATCH 4/9] KEYS: Allow expiry time to be set when preparsing a key David Howells
2013-11-04 16:22 ` [PATCH 5/9] KEYS: Call ->free_preparse() even after ->preparse() returns an error David Howells
2013-11-04 16:23 ` [PATCH 6/9] KEYS: Trusted: Use key preparsing David Howells
2013-11-13 16:49 ` Mimi Zohar
2013-11-14 15:50 ` David Howells
2013-11-04 16:23 ` [PATCH 7/9] KEYS: Add a keyctl function to alter/control a key in type-dependent way David Howells
2013-11-04 16:23 ` David Howells [this message]
2013-11-04 16:23 ` [PATCH 9/9] KEYS: Fix encrypted key type update method David Howells
2013-11-13 18:45 ` Mimi Zohar
2013-11-14 17:59 ` David Howells
2013-11-17 3:51 ` Mimi Zohar
2013-11-17 9:17 ` David Howells
2013-11-17 13:43 ` Mimi Zohar
2013-11-06 17:20 ` [RFC][PATCH 0/9] encrypted keys & key control op Dmitry Kasatkin
2013-11-06 17:42 ` David Howells
2013-11-11 12:14 ` Mimi Zohar
2013-11-11 16:32 ` Mimi Zohar
2013-11-11 22:34 ` David Howells
2013-11-12 0:26 ` Mimi Zohar
2013-11-12 16:19 ` David Howells
2013-11-11 22:35 ` 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=20131104162314.10177.68684.stgit@warthog.procyon.org.uk \
--to=dhowells@redhat.com \
--cc=d.kasatkin@samsung.com \
--cc=keyrings@linux-nfs.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-security-module@vger.kernel.org \
--cc=zohar@us.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
all inboxes | Powered by JetHome®