mirror of
https://mirrors.bfsu.edu.cn/git/linux.git
synced 2024-11-23 12:14:10 +08:00
ima: fix reference leak in asymmetric_verify()
Don't leak a reference to the key if its algorithm is unknown.
Fixes: 947d705972
("ima: Support EC keys for signature verification")
Cc: <stable@vger.kernel.org> # v5.13+
Signed-off-by: Eric Biggers <ebiggers@google.com>
Reviewed-by: Stefan Berger <stefanb@linux.ibm.com>
Reviewed-by: Tianjia Zhang <tianjia.zhang@linux.alibaba.com>
Signed-off-by: Mimi Zohar <zohar@linux.ibm.com>
This commit is contained in:
parent
e783362eb5
commit
926fd9f23b
@ -109,22 +109,25 @@ int asymmetric_verify(struct key *keyring, const char *sig,
|
||||
|
||||
pk = asymmetric_key_public_key(key);
|
||||
pks.pkey_algo = pk->pkey_algo;
|
||||
if (!strcmp(pk->pkey_algo, "rsa"))
|
||||
if (!strcmp(pk->pkey_algo, "rsa")) {
|
||||
pks.encoding = "pkcs1";
|
||||
else if (!strncmp(pk->pkey_algo, "ecdsa-", 6))
|
||||
} else if (!strncmp(pk->pkey_algo, "ecdsa-", 6)) {
|
||||
/* edcsa-nist-p192 etc. */
|
||||
pks.encoding = "x962";
|
||||
else if (!strcmp(pk->pkey_algo, "ecrdsa") ||
|
||||
!strcmp(pk->pkey_algo, "sm2"))
|
||||
} else if (!strcmp(pk->pkey_algo, "ecrdsa") ||
|
||||
!strcmp(pk->pkey_algo, "sm2")) {
|
||||
pks.encoding = "raw";
|
||||
else
|
||||
return -ENOPKG;
|
||||
} else {
|
||||
ret = -ENOPKG;
|
||||
goto out;
|
||||
}
|
||||
|
||||
pks.digest = (u8 *)data;
|
||||
pks.digest_size = datalen;
|
||||
pks.s = hdr->sig;
|
||||
pks.s_size = siglen;
|
||||
ret = verify_signature(key, &pks);
|
||||
out:
|
||||
key_put(key);
|
||||
pr_debug("%s() = %d\n", __func__, ret);
|
||||
return ret;
|
||||
|
Loading…
Reference in New Issue
Block a user