usb: ohci: Proper handling of ed_rm_list to handle race condition between usb_kill_ur...
[pandora-kernel.git] / security / keys / key.c
index 4414abd..1f5c2c5 100644 (file)
@@ -305,6 +305,8 @@ struct key *key_alloc(struct key_type *type, const char *desc,
 
        if (!(flags & KEY_ALLOC_NOT_IN_QUOTA))
                key->flags |= 1 << KEY_FLAG_IN_QUOTA;
+       if (flags & KEY_ALLOC_UID_KEYRING)
+               key->flags |= 1 << KEY_FLAG_UID_KEYRING;
 
        memset(&key->type_data, 0, sizeof(key->type_data));
 
@@ -572,7 +574,7 @@ int key_reject_and_link(struct key *key,
 
        mutex_unlock(&key_construction_mutex);
 
-       if (keyring)
+       if (keyring && link_ret == 0)
                __key_link_end(keyring, key->type, prealloc);
 
        /* wake up anyone waiting for a key to be constructed */
@@ -847,6 +849,16 @@ key_ref_t key_create_or_update(key_ref_t keyring_ref,
        __key_link_end(keyring, ktype, prealloc);
        key_type_put(ktype);
 
+       key = key_ref_to_ptr(key_ref);
+       if (test_bit(KEY_FLAG_USER_CONSTRUCT, &key->flags)) {
+               ret = wait_for_key_construction(key, true);
+               if (ret < 0) {
+                       key_ref_put(key_ref);
+                       key_ref = ERR_PTR(ret);
+                       goto error;
+               }
+       }
+
        key_ref = __key_update(key_ref, payload, plen);
        goto error;
 }