2016-12-03 14:57:04

by Pan Bian

[permalink] [raw]
Subject: [PATCH 1/1] crypto: asymmetric_keys: set error code on failure

From: Pan Bian <[email protected]>

In function public_key_verify_signature(), returns variable ret on
error paths. When the call to kmalloc() fails, the value of ret is 0,
and it is not set to an errno before returning. This patch fixes the
bug.

Bugzilla: https://bugzilla.kernel.org/show_bug.cgi?id=188891

Signed-off-by: Pan Bian <[email protected]>
---
crypto/asymmetric_keys/public_key.c | 4 +++-
1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/crypto/asymmetric_keys/public_key.c b/crypto/asymmetric_keys/public_key.c
index fd76b5f..1dc65ba 100644
--- a/crypto/asymmetric_keys/public_key.c
+++ b/crypto/asymmetric_keys/public_key.c
@@ -123,8 +123,10 @@ int public_key_verify_signature(const struct public_key *pkey,

outlen = crypto_akcipher_maxsize(tfm);
output = kmalloc(outlen, GFP_KERNEL);
- if (!output)
+ if (!output) {
+ ret = -ENOMEM;
goto error_free_req;
+ }

sg_init_one(&sig_sg, sig->s, sig->s_size);
sg_init_one(&digest_sg, output, outlen);
--
1.9.1


2016-12-12 16:10:18

by David Howells

[permalink] [raw]
Subject: Re: [PATCH 1/1] crypto: asymmetric_keys: set error code on failure

Pan Bian <[email protected]> wrote:

> outlen = crypto_akcipher_maxsize(tfm);
> output = kmalloc(outlen, GFP_KERNEL);
> - if (!output)
> + if (!output) {
> + ret = -ENOMEM;
> goto error_free_req;
> + }

This is preferred:

+ ret = -ENOMEM;
outlen = crypto_akcipher_maxsize(tfm);
output = kmalloc(outlen, GFP_KERNEL);
if (!output)
goto error_free_req;

I'll alter your patch.

David