keys: Reuse keyring_index_key::desc_len in lookup_user_key()
authorEric Biggers <ebiggers@google.com>
Wed, 29 May 2019 21:01:52 +0000 (14:01 -0700)
committerDavid Howells <dhowells@redhat.com>
Thu, 30 May 2019 21:54:43 +0000 (22:54 +0100)
When lookup_user_key() checks whether the key is possessed, it should
use the key's existing index_key including the 'desc_len' field, rather
than recomputing the 'desc_len'.  This doesn't change the behavior; this
way is just simpler and faster.

Signed-off-by: Eric Biggers <ebiggers@google.com>
Signed-off-by: David Howells <dhowells@redhat.com>
Reviewed-by: James Morris <jamorris@linux.microsoft.com>
security/keys/process_keys.c

index ba5d3172cafe8b0764c0beb74e28088325b8c6cd..39aaa21462bf025e9128d7883c6a92030f601202 100644 (file)
@@ -688,9 +688,7 @@ try_again:
                key_ref = make_key_ref(key, 0);
 
                /* check to see if we possess the key */
-               ctx.index_key.type              = key->type;
-               ctx.index_key.description       = key->description;
-               ctx.index_key.desc_len          = strlen(key->description);
+               ctx.index_key                   = key->index_key;
                ctx.match_data.raw_data         = key;
                kdebug("check possessed");
                skey_ref = search_process_keyrings(&ctx);