mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: yangmengfei1394@phytium.com.cn
To: herbert@gondor.apana.org.au, davem@davemloft.net
Cc: linux-crypto@vger.kernel.org, linux-kernel@vger.kernel.org,
	ymf <yangmengfei1394@phytium.com.cn>
Subject: [PATCH] Crypto: Fix one bug when use kernel ecdsa algorithm
Date: Wed, 10 May 2023 15:51:42 +0800	[thread overview]
Message-ID: <20230510075142.1638-1-yangmengfei1394@phytium.com.cn> (raw)

From: ymf <yangmengfei1394@phytium.com.cn>

We are trying to use kernel ecdsa algorithm to sign something.
When we call the crypto_akcipher_set_priv_key function, the
system collapses because it comes to NULL pointer.We find out
kerenl ecdsa algorithm has not offered the set_priv_key function.
So we think it might be necessary to check whether set_priv_key is
available when crypto_akcipher_set_priv_key is called.

Signed-off-by: ymf <yangmengfei1394@phytium.com.cn>
---
 include/crypto/akcipher.h | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/include/crypto/akcipher.h b/include/crypto/akcipher.h
index f35fd653e4e5..a68f0e23bf89 100644
--- a/include/crypto/akcipher.h
+++ b/include/crypto/akcipher.h
@@ -459,7 +459,9 @@ static inline int crypto_akcipher_set_priv_key(struct crypto_akcipher *tfm,
 					       unsigned int keylen)
 {
 	struct akcipher_alg *alg = crypto_akcipher_alg(tfm);
-
-	return alg->set_priv_key(tfm, key, keylen);
+	if (likely(alg->set_priv_key != NULL))
+		return alg->set_priv_key(tfm, key, keylen);
+	else
+		return -EPERM;
 }
 #endif
-- 
2.34.1


             reply	other threads:[~2023-05-10  7:56 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-05-10  7:51 yangmengfei1394 [this message]
2023-05-19  8:33 ` Herbert Xu
2023-05-22  3:30 ` [PATCH] Crypto module : rearrange the default functions of akcipher yangmengfei1394
2023-06-02 10:19   ` Herbert Xu

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20230510075142.1638-1-yangmengfei1394@phytium.com.cn \
    --to=yangmengfei1394@phytium.com.cn \
    --cc=davem@davemloft.net \
    --cc=herbert@gondor.apana.org.au \
    --cc=linux-crypto@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®