KEYS: Don't permit request_key() to construct a new keyring
authorDavid Howells <dhowells@redhat.com>
Mon, 19 Oct 2015 10:20:28 +0000 (11:20 +0100)
committerDavid Howells <dhowells@redhat.com>
Mon, 19 Oct 2015 10:24:51 +0000 (11:24 +0100)
If request_key() is used to find a keyring, only do the search part - don't
do the construction part if the keyring was not found by the search.  We
don't really want keyrings in the negative instantiated state since the
rejected/negative instantiation error value in the payload is unioned with
keyring metadata.

Now the kernel gives an error:

request_key("keyring", "#selinux,bdekeyring", "keyring", KEY_SPEC_USER_SESSION_KEYRING) = -1 EPERM (Operation not permitted)

Signed-off-by: David Howells <dhowells@redhat.com>
security/keys/request_key.c

index 486ef6f..0d62531 100644 (file)
@@ -440,6 +440,9 @@ static struct key *construct_key_and_link(struct keyring_search_context *ctx,
 
        kenter("");
 
+       if (ctx->index_key.type == &key_type_keyring)
+               return ERR_PTR(-EPERM);
+       
        user = key_user_lookup(current_fsuid());
        if (!user)
                return ERR_PTR(-ENOMEM);