Merge branch 'modules-next' of git://git.kernel.org/pub/scm/linux/kernel/git/rusty...
[firefly-linux-kernel-4.4.55.git] / security / keys / keyctl.c
index 305ecb76519c8a0aafa115d1847a8b24f3fb71bc..5d34b4e827d6349a46f6b892573e129e500e49db 100644 (file)
@@ -46,6 +46,9 @@ static int key_get_type_from_user(char *type,
  * Extract the description of a new key from userspace and either add it as a
  * new key to the specified keyring or update a matching key in that keyring.
  *
+ * If the description is NULL or an empty string, the key type is asked to
+ * generate one from the payload.
+ *
  * The keyring must be writable so that we can attach the key to it.
  *
  * If successful, the new key's serial number is returned, otherwise an error
@@ -72,10 +75,17 @@ SYSCALL_DEFINE5(add_key, const char __user *, _type,
        if (ret < 0)
                goto error;
 
-       description = strndup_user(_description, PAGE_SIZE);
-       if (IS_ERR(description)) {
-               ret = PTR_ERR(description);
-               goto error;
+       description = NULL;
+       if (_description) {
+               description = strndup_user(_description, PAGE_SIZE);
+               if (IS_ERR(description)) {
+                       ret = PTR_ERR(description);
+                       goto error;
+               }
+               if (!*description) {
+                       kfree(description);
+                       description = NULL;
+               }
        }
 
        /* pull the payload in if one was supplied */