Merge tag 'keys-misc-20190619' of git://git.kernel.org/pub/scm/linux/kernel/git/dhowe...
[sfrench/cifs-2.6.git] / security / keys / request_key.c
index 8ae3b7b188015cd06eabf0e3252f01971d2a6cef..fcef7e26b94bc4aa481089de94f53d29959d4685 100644 (file)
@@ -20,7 +20,7 @@
 
 /**
  * complete_request_key - Complete the construction of a key.
- * @auth_key: The authorisation key.
+ * @authkey: The authorisation key.
  * @error: The success or failute of the construction.
  *
  * Complete the attempt to construct a key.  The key will be negated
@@ -339,7 +339,7 @@ static int construct_alloc_key(struct keyring_search_context *ctx,
                               struct key_user *user,
                               struct key **_key)
 {
-       struct assoc_array_edit *edit;
+       struct assoc_array_edit *edit = NULL;
        struct key *key;
        key_perm_t perm;
        key_ref_t key_ref;
@@ -368,6 +368,9 @@ static int construct_alloc_key(struct keyring_search_context *ctx,
        set_bit(KEY_FLAG_USER_CONSTRUCT, &key->flags);
 
        if (dest_keyring) {
+               ret = __key_link_lock(dest_keyring, &ctx->index_key);
+               if (ret < 0)
+                       goto link_lock_failed;
                ret = __key_link_begin(dest_keyring, &ctx->index_key, &edit);
                if (ret < 0)
                        goto link_prealloc_failed;
@@ -419,6 +422,8 @@ link_check_failed:
        return ret;
 
 link_prealloc_failed:
+       __key_link_end(dest_keyring, &ctx->index_key, edit);
+link_lock_failed:
        mutex_unlock(&user->cons_lock);
        key_put(key);
        kleave(" = %d [prelink]", ret);