]> git.proxmox.com Git - mirror_ubuntu-artful-kernel.git/blobdiff - fs/crypto/keyinfo.c
fscrypt: make fscrypt_operations.key_prefix a string
[mirror_ubuntu-artful-kernel.git] / fs / crypto / keyinfo.c
index 80f145c8d5503f9e6845d482c29dc0efffd36e8e..eeb6fd67ea17faafc2a8d97dc910c374f62204bf 100644 (file)
@@ -77,26 +77,22 @@ out:
 
 static int validate_user_key(struct fscrypt_info *crypt_info,
                        struct fscrypt_context *ctx, u8 *raw_key,
-                       u8 *prefix, int prefix_size)
+                       const char *prefix)
 {
-       u8 *full_key_descriptor;
+       char *description;
        struct key *keyring_key;
        struct fscrypt_key *master_key;
        const struct user_key_payload *ukp;
-       int full_key_len = prefix_size + (FS_KEY_DESCRIPTOR_SIZE * 2) + 1;
        int res;
 
-       full_key_descriptor = kmalloc(full_key_len, GFP_NOFS);
-       if (!full_key_descriptor)
+       description = kasprintf(GFP_NOFS, "%s%*phN", prefix,
+                               FS_KEY_DESCRIPTOR_SIZE,
+                               ctx->master_key_descriptor);
+       if (!description)
                return -ENOMEM;
 
-       memcpy(full_key_descriptor, prefix, prefix_size);
-       sprintf(full_key_descriptor + prefix_size,
-                       "%*phN", FS_KEY_DESCRIPTOR_SIZE,
-                       ctx->master_key_descriptor);
-       full_key_descriptor[full_key_len - 1] = '\0';
-       keyring_key = request_key(&key_type_logon, full_key_descriptor, NULL);
-       kfree(full_key_descriptor);
+       keyring_key = request_key(&key_type_logon, description, NULL);
+       kfree(description);
        if (IS_ERR(keyring_key))
                return PTR_ERR(keyring_key);
 
@@ -251,15 +247,10 @@ retry:
        if (!raw_key)
                goto out;
 
-       res = validate_user_key(crypt_info, &ctx, raw_key,
-                       FS_KEY_DESC_PREFIX, FS_KEY_DESC_PREFIX_SIZE);
+       res = validate_user_key(crypt_info, &ctx, raw_key, FS_KEY_DESC_PREFIX);
        if (res && inode->i_sb->s_cop->key_prefix) {
-               u8 *prefix = NULL;
-               int prefix_size, res2;
-
-               prefix_size = inode->i_sb->s_cop->key_prefix(inode, &prefix);
-               res2 = validate_user_key(crypt_info, &ctx, raw_key,
-                                                       prefix, prefix_size);
+               int res2 = validate_user_key(crypt_info, &ctx, raw_key,
+                                            inode->i_sb->s_cop->key_prefix);
                if (res2) {
                        if (res2 == -ENOKEY)
                                res = -ENOKEY;