KEYS: don't let add_key() update an uninstantiated key
[pandora-kernel.git] / security / keys / key.c
index d3b2f6e..04c809f 100644 (file)
@@ -847,6 +847,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;
 }