Skip to content

Commit 70fd196

Browse files
RSmirnov512jarkkojs
authored andcommitted
KEYS: prevent NULL pointer dereference in find_asymmetric_key()
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: [email protected] # v5.17+ Fixes: 7d30198 ("keys: X.509 public key issuer lookup without AKID") Suggested-by: Sergey Shtylyov <[email protected]> Signed-off-by: Roman Smirnov <[email protected]> Reviewed-by: Sergey Shtylyov <[email protected]> Reviewed-by: Jarkko Sakkinen <[email protected]> Signed-off-by: Jarkko Sakkinen <[email protected]>
1 parent 652bfcb commit 70fd196

File tree

1 file changed

+4
-3
lines changed

1 file changed

+4
-3
lines changed

crypto/asymmetric_keys/asymmetric_type.c

Lines changed: 4 additions & 3 deletions
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)