Skip to content
This repository was archived by the owner on Oct 31, 2024. It is now read-only.

Commit a3765b4

Browse files
RSmirnov512gregkh
authored andcommitted
KEYS: prevent NULL pointer dereference in find_asymmetric_key()
commit 70fd196 upstream. In find_asymmetric_key(), if all NULLs are passed in the id_{0,1,2} arguments, the kernel will first emit WARN but then have an oops because id_2 gets dereferenced anyway. Add the missing id_2 check and move WARN_ON() to the final else branch to avoid duplicate NULL checks. Found by Linux Verification Center (linuxtesting.org) with Svace static analysis tool. Cc: stable@vger.kernel.org # v5.17+ Fixes: 7d30198 ("keys: X.509 public key issuer lookup without AKID") Suggested-by: Sergey Shtylyov <s.shtylyov@omp.ru> Signed-off-by: Roman Smirnov <r.smirnov@omp.ru> Reviewed-by: Sergey Shtylyov <s.shtylyov@omp.ru> Reviewed-by: Jarkko Sakkinen <jarkko@kernel.org> Signed-off-by: Jarkko Sakkinen <jarkko@kernel.org> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
1 parent c886061 commit a3765b4

File tree

1 file changed

+4
-3
lines changed

1 file changed

+4
-3
lines changed

crypto/asymmetric_keys/asymmetric_type.c

+4-3
Original file line numberDiff line numberDiff line change
@@ -60,17 +60,18 @@ struct key *find_asymmetric_key(struct key *keyring,
6060
char *req, *p;
6161
int len;
6262

63-
WARN_ON(!id_0 && !id_1 && !id_2);
64-
6563
if (id_0) {
6664
lookup = id_0->data;
6765
len = id_0->len;
6866
} else if (id_1) {
6967
lookup = id_1->data;
7068
len = id_1->len;
71-
} else {
69+
} else if (id_2) {
7270
lookup = id_2->data;
7371
len = id_2->len;
72+
} else {
73+
WARN_ON(1);
74+
return ERR_PTR(-EINVAL);
7475
}
7576

7677
/* Construct an identifier "id:<keyid>". */

0 commit comments

Comments
 (0)