Skip to content

Commit 9e9311e

Browse files
Dan Carpenterherbertx
authored andcommitted
KEYS: asymmetric: Fix error codes
These error paths should return the appropriate error codes instead of returning success. Fixes: 63ba4d6 ("KEYS: asymmetric: Use new crypto interface without scatterlists") Signed-off-by: Dan Carpenter <[email protected]> Signed-off-by: Herbert Xu <[email protected]>
1 parent d3dccb0 commit 9e9311e

File tree

1 file changed

+15
-5
lines changed

1 file changed

+15
-5
lines changed

crypto/asymmetric_keys/public_key.c

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -185,8 +185,10 @@ static int software_key_query(const struct kernel_pkey_params *params,
185185

186186
if (issig) {
187187
sig = crypto_alloc_sig(alg_name, 0, 0);
188-
if (IS_ERR(sig))
188+
if (IS_ERR(sig)) {
189+
ret = PTR_ERR(sig);
189190
goto error_free_key;
191+
}
190192

191193
if (pkey->key_is_private)
192194
ret = crypto_sig_set_privkey(sig, key, pkey->keylen);
@@ -208,8 +210,10 @@ static int software_key_query(const struct kernel_pkey_params *params,
208210
}
209211
} else {
210212
tfm = crypto_alloc_akcipher(alg_name, 0, 0);
211-
if (IS_ERR(tfm))
213+
if (IS_ERR(tfm)) {
214+
ret = PTR_ERR(tfm);
212215
goto error_free_key;
216+
}
213217

214218
if (pkey->key_is_private)
215219
ret = crypto_akcipher_set_priv_key(tfm, key, pkey->keylen);
@@ -300,8 +304,10 @@ static int software_key_eds_op(struct kernel_pkey_params *params,
300304

301305
if (issig) {
302306
sig = crypto_alloc_sig(alg_name, 0, 0);
303-
if (IS_ERR(sig))
307+
if (IS_ERR(sig)) {
308+
ret = PTR_ERR(sig);
304309
goto error_free_key;
310+
}
305311

306312
if (pkey->key_is_private)
307313
ret = crypto_sig_set_privkey(sig, key, pkey->keylen);
@@ -313,8 +319,10 @@ static int software_key_eds_op(struct kernel_pkey_params *params,
313319
ksz = crypto_sig_maxsize(sig);
314320
} else {
315321
tfm = crypto_alloc_akcipher(alg_name, 0, 0);
316-
if (IS_ERR(tfm))
322+
if (IS_ERR(tfm)) {
323+
ret = PTR_ERR(tfm);
317324
goto error_free_key;
325+
}
318326

319327
if (pkey->key_is_private)
320328
ret = crypto_akcipher_set_priv_key(tfm, key, pkey->keylen);
@@ -411,8 +419,10 @@ int public_key_verify_signature(const struct public_key *pkey,
411419

412420
key = kmalloc(pkey->keylen + sizeof(u32) * 2 + pkey->paramlen,
413421
GFP_KERNEL);
414-
if (!key)
422+
if (!key) {
423+
ret = -ENOMEM;
415424
goto error_free_tfm;
425+
}
416426

417427
memcpy(key, pkey->key, pkey->keylen);
418428
ptr = key + pkey->keylen;

0 commit comments

Comments
 (0)