]> git.hungrycats.org Git - linux/commitdiff
keys: Guard against null match function in keyring_search_aux()
authorBen Hutchings <ben@decadent.org.uk>
Sat, 1 Apr 2017 03:55:18 +0000 (04:55 +0100)
committerBen Hutchings <ben@decadent.org.uk>
Tue, 4 Apr 2017 21:21:57 +0000 (22:21 +0100)
The "dead" key type has no match operation, and a search for keys of
this type can cause a null dereference in keyring_search_iterator().
keyring_search() has a check for this, but request_keyring_and_link()
does not.  Move the check into keyring_search_aux(), covering both of
them.

This was fixed upstream by commit c06cfb08b88d ("KEYS: Remove
key_type::match in favour of overriding default by match_preparse"),
part of a series of large changes that are not suitable for
backporting.

CVE-2017-2647 / CVE-2017-6951

Reported-by: Igor Redko <redkoi@virtuozzo.com>
Reported-by: Andrey Ryabinin <aryabinin@virtuozzo.com>
References: https://bugzilla.redhat.com/show_bug.cgi?id=CVE-2017-2647
Reported-by: idl3r <idler1984@gmail.com>
References: https://www.spinics.net/lists/keyrings/msg01845.html
Signed-off-by: Ben Hutchings <ben@decadent.org.uk>
Cc: David Howells <dhowells@redhat.com>
security/keys/keyring.c

index 860345cb05f1d03c04b210ad038d4f797b95955b..796256db10047913990d671aa4f2e70742941fa9 100644 (file)
@@ -848,6 +848,9 @@ key_ref_t keyring_search_aux(key_ref_t keyring_ref,
                        return ERR_PTR(err);
        }
 
+       if (!ctx->match)
+               return ERR_PTR(-ENOKEY);
+
        rcu_read_lock();
        ctx->now = current_kernel_time();
        if (search_nested_keyrings(keyring, ctx))
@@ -879,9 +882,6 @@ key_ref_t keyring_search(key_ref_t keyring,
                                           KEYRING_SEARCH_DO_STATE_CHECK),
        };
 
-       if (!ctx.match)
-               return ERR_PTR(-ENOKEY);
-
        return keyring_search_aux(keyring, &ctx);
 }
 EXPORT_SYMBOL(keyring_search);