KEYS: user: Use key preparsing
authorDavid Howells <dhowells@redhat.com>
Fri, 18 Jul 2014 17:56:35 +0000 (18:56 +0100)
committerDavid Howells <dhowells@redhat.com>
Tue, 22 Jul 2014 20:46:17 +0000 (21:46 +0100)
Make use of key preparsing in user-defined and logon keys so that quota size
determination can take place prior to keyring locking when a key is being
added.

Also the idmapper key types need to change to match as they use the
user-defined key type routines.

Signed-off-by: David Howells <dhowells@redhat.com>
Acked-by: Steve Dickson <steved@redhat.com>
Acked-by: Jeff Layton <jlayton@primarydata.com>
fs/nfs/idmap.c
include/keys/user-type.h
security/keys/user_defined.c

index 567983d2c0ebada3105f5c1ef42bc0c4595c2ca6..59b217a3266d17d170161cbe690cd8999735abaa 100644 (file)
@@ -174,7 +174,9 @@ static int nfs_map_numeric_to_string(__u32 id, char *buf, size_t buflen)
 
 static struct key_type key_type_id_resolver = {
        .name           = "id_resolver",
-       .instantiate    = user_instantiate,
+       .preparse       = user_preparse,
+       .free_preparse  = user_free_preparse,
+       .instantiate    = generic_key_instantiate,
        .match          = user_match,
        .revoke         = user_revoke,
        .destroy        = user_destroy,
@@ -394,7 +396,9 @@ static const struct rpc_pipe_ops idmap_upcall_ops = {
 
 static struct key_type key_type_id_resolver_legacy = {
        .name           = "id_legacy",
-       .instantiate    = user_instantiate,
+       .preparse       = user_preparse,
+       .free_preparse  = user_free_preparse,
+       .instantiate    = generic_key_instantiate,
        .match          = user_match,
        .revoke         = user_revoke,
        .destroy        = user_destroy,
index 5e452c84f1e6741bc1b85405b2fce971c12051f0..3ab1873a4bfab05571bdbc60a60c8a31df5dfde5 100644 (file)
@@ -37,7 +37,8 @@ extern struct key_type key_type_logon;
 
 struct key_preparsed_payload;
 
-extern int user_instantiate(struct key *key, struct key_preparsed_payload *prep);
+extern int user_preparse(struct key_preparsed_payload *prep);
+extern void user_free_preparse(struct key_preparsed_payload *prep);
 extern int user_update(struct key *key, struct key_preparsed_payload *prep);
 extern int user_match(const struct key *key, const void *criterion);
 extern void user_revoke(struct key *key);
index faa2caeb593f8524a059e79d58e09bf430a1f992..eee340011f2bd54d7b12f3f28a25ec3f8396b5fd 100644 (file)
@@ -27,7 +27,9 @@ static int logon_vet_description(const char *desc);
 struct key_type key_type_user = {
        .name                   = "user",
        .def_lookup_type        = KEYRING_SEARCH_LOOKUP_DIRECT,
-       .instantiate            = user_instantiate,
+       .preparse               = user_preparse,
+       .free_preparse          = user_free_preparse,
+       .instantiate            = generic_key_instantiate,
        .update                 = user_update,
        .match                  = user_match,
        .revoke                 = user_revoke,
@@ -47,7 +49,9 @@ EXPORT_SYMBOL_GPL(key_type_user);
 struct key_type key_type_logon = {
        .name                   = "logon",
        .def_lookup_type        = KEYRING_SEARCH_LOOKUP_DIRECT,
-       .instantiate            = user_instantiate,
+       .preparse               = user_preparse,
+       .free_preparse          = user_free_preparse,
+       .instantiate            = generic_key_instantiate,
        .update                 = user_update,
        .match                  = user_match,
        .revoke                 = user_revoke,
@@ -58,38 +62,37 @@ struct key_type key_type_logon = {
 EXPORT_SYMBOL_GPL(key_type_logon);
 
 /*
- * instantiate a user defined key
+ * Preparse a user defined key payload
  */
-int user_instantiate(struct key *key, struct key_preparsed_payload *prep)
+int user_preparse(struct key_preparsed_payload *prep)
 {
        struct user_key_payload *upayload;
        size_t datalen = prep->datalen;
-       int ret;
 
-       ret = -EINVAL;
        if (datalen <= 0 || datalen > 32767 || !prep->data)
-               goto error;
-
-       ret = key_payload_reserve(key, datalen);
-       if (ret < 0)
-               goto error;
+               return -EINVAL;
 
-       ret = -ENOMEM;
        upayload = kmalloc(sizeof(*upayload) + datalen, GFP_KERNEL);
        if (!upayload)
-               goto error;
+               return -ENOMEM;
 
        /* attach the data */
+       prep->quotalen = datalen;
+       prep->payload[0] = upayload;
        upayload->datalen = datalen;
        memcpy(upayload->data, prep->data, datalen);
-       rcu_assign_keypointer(key, upayload);
-       ret = 0;
-
-error:
-       return ret;
+       return 0;
 }
+EXPORT_SYMBOL_GPL(user_preparse);
 
-EXPORT_SYMBOL_GPL(user_instantiate);
+/*
+ * Free a preparse of a user defined key payload
+ */
+void user_free_preparse(struct key_preparsed_payload *prep)
+{
+       kfree(prep->payload[0]);
+}
+EXPORT_SYMBOL_GPL(user_free_preparse);
 
 /*
  * update a user defined key