Commit 83bc0299 authored by Vitaly Chikunov's avatar Vitaly Chikunov Committed by Herbert Xu

KEYS: do not kmemdup digest in {public,tpm}_key_verify_signature

Treat (struct public_key_signature)'s digest same as its signature (s).
Since digest should be already in the kmalloc'd memory do not kmemdup
digest value before calling {public,tpm}_key_verify_signature.

Patch is split from the previous as suggested by Herbert Xu.
Suggested-by: default avatarDavid Howells <dhowells@redhat.com>
Cc: David Howells <dhowells@redhat.com>
Cc: keyrings@vger.kernel.org
Signed-off-by: default avatarVitaly Chikunov <vt@altlinux.org>
Reviewed-by: default avatarDenis Kenzior <denkenz@gmail.com>
Signed-off-by: default avatarHerbert Xu <herbert@gondor.apana.org.au>
parent c7381b01
...@@ -748,7 +748,6 @@ static int tpm_key_verify_signature(const struct key *key, ...@@ -748,7 +748,6 @@ static int tpm_key_verify_signature(const struct key *key,
char alg_name[CRYPTO_MAX_ALG_NAME]; char alg_name[CRYPTO_MAX_ALG_NAME];
uint8_t der_pub_key[PUB_KEY_BUF_SIZE]; uint8_t der_pub_key[PUB_KEY_BUF_SIZE];
uint32_t der_pub_key_len; uint32_t der_pub_key_len;
void *digest;
int ret; int ret;
pr_devel("==>%s()\n", __func__); pr_devel("==>%s()\n", __func__);
...@@ -780,14 +779,9 @@ static int tpm_key_verify_signature(const struct key *key, ...@@ -780,14 +779,9 @@ static int tpm_key_verify_signature(const struct key *key,
if (!req) if (!req)
goto error_free_tfm; goto error_free_tfm;
ret = -ENOMEM;
digest = kmemdup(sig->digest, sig->digest_size, GFP_KERNEL);
if (!digest)
goto error_free_req;
sg_init_table(src_sg, 2); sg_init_table(src_sg, 2);
sg_set_buf(&src_sg[0], sig->s, sig->s_size); sg_set_buf(&src_sg[0], sig->s, sig->s_size);
sg_set_buf(&src_sg[1], digest, sig->digest_size); sg_set_buf(&src_sg[1], sig->digest, sig->digest_size);
akcipher_request_set_crypt(req, src_sg, NULL, sig->s_size, akcipher_request_set_crypt(req, src_sg, NULL, sig->s_size,
sig->digest_size); sig->digest_size);
crypto_init_wait(&cwait); crypto_init_wait(&cwait);
...@@ -796,8 +790,6 @@ static int tpm_key_verify_signature(const struct key *key, ...@@ -796,8 +790,6 @@ static int tpm_key_verify_signature(const struct key *key,
crypto_req_done, &cwait); crypto_req_done, &cwait);
ret = crypto_wait_req(crypto_akcipher_verify(req), &cwait); ret = crypto_wait_req(crypto_akcipher_verify(req), &cwait);
kfree(digest);
error_free_req:
akcipher_request_free(req); akcipher_request_free(req);
error_free_tfm: error_free_tfm:
crypto_free_akcipher(tfm); crypto_free_akcipher(tfm);
......
...@@ -229,7 +229,6 @@ int public_key_verify_signature(const struct public_key *pkey, ...@@ -229,7 +229,6 @@ int public_key_verify_signature(const struct public_key *pkey,
struct akcipher_request *req; struct akcipher_request *req;
struct scatterlist src_sg[2]; struct scatterlist src_sg[2];
char alg_name[CRYPTO_MAX_ALG_NAME]; char alg_name[CRYPTO_MAX_ALG_NAME];
void *digest;
int ret; int ret;
pr_devel("==>%s()\n", __func__); pr_devel("==>%s()\n", __func__);
...@@ -262,14 +261,9 @@ int public_key_verify_signature(const struct public_key *pkey, ...@@ -262,14 +261,9 @@ int public_key_verify_signature(const struct public_key *pkey,
if (ret) if (ret)
goto error_free_req; goto error_free_req;
ret = -ENOMEM;
digest = kmemdup(sig->digest, sig->digest_size, GFP_KERNEL);
if (!digest)
goto error_free_req;
sg_init_table(src_sg, 2); sg_init_table(src_sg, 2);
sg_set_buf(&src_sg[0], sig->s, sig->s_size); sg_set_buf(&src_sg[0], sig->s, sig->s_size);
sg_set_buf(&src_sg[1], digest, sig->digest_size); sg_set_buf(&src_sg[1], sig->digest, sig->digest_size);
akcipher_request_set_crypt(req, src_sg, NULL, sig->s_size, akcipher_request_set_crypt(req, src_sg, NULL, sig->s_size,
sig->digest_size); sig->digest_size);
crypto_init_wait(&cwait); crypto_init_wait(&cwait);
...@@ -278,7 +272,6 @@ int public_key_verify_signature(const struct public_key *pkey, ...@@ -278,7 +272,6 @@ int public_key_verify_signature(const struct public_key *pkey,
crypto_req_done, &cwait); crypto_req_done, &cwait);
ret = crypto_wait_req(crypto_akcipher_verify(req), &cwait); ret = crypto_wait_req(crypto_akcipher_verify(req), &cwait);
kfree(digest);
error_free_req: error_free_req:
akcipher_request_free(req); akcipher_request_free(req);
error_free_tfm: error_free_tfm:
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment