]> git.proxmox.com Git - mirror_ubuntu-zesty-kernel.git/blobdiff - security/keys/keyctl.c
KEYS: Add payload preparsing opportunity prior to key instantiate or update
[mirror_ubuntu-zesty-kernel.git] / security / keys / keyctl.c
index 3364fbf46807bb384e61a761f2f6f2fab9ebb888..505d40be196c0e4803442c6ff2228ccc5e07bcf8 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 */