Skip to content

Commit 6efca5f

Browse files
bwhackskelmously
authored andcommitted
keys: Guard against null match function in keyring_search_aux()
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> CVE-2017-2647 (cherry picked from commit c53ee259ad3da891e191dee7af119af340f9c01b linux-stable) Signed-off-by: Tyler Hicks <tyhicks@canonical.com> Acked-by: Khalid Elmously <khalid.elmously@canonical.com> Acked-by: Stefan Bader <stefan.bader@canonical.com> Signed-off-by: Khalid Elmously <khalid.elmously@canonical.com>
1 parent a2be323 commit 6efca5f

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

security/keys/keyring.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -849,6 +849,9 @@ key_ref_t keyring_search_aux(key_ref_t keyring_ref,
849849
return ERR_PTR(err);
850850
}
851851

852+
if (!ctx->match)
853+
return ERR_PTR(-ENOKEY);
854+
852855
rcu_read_lock();
853856
ctx->now = current_kernel_time();
854857
if (search_nested_keyrings(keyring, ctx))
@@ -880,9 +883,6 @@ key_ref_t keyring_search(key_ref_t keyring,
880883
KEYRING_SEARCH_DO_STATE_CHECK),
881884
};
882885

883-
if (!ctx.match)
884-
return ERR_PTR(-ENOKEY);
885-
886886
return keyring_search_aux(keyring, &ctx);
887887
}
888888
EXPORT_SYMBOL(keyring_search);

0 commit comments

Comments
 (0)