linux-crypto.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Herbert Xu <herbert@gondor.apana.org.au>
To: Harsha Harsha <harsha.harsha@amd.com>
Cc: davem@davemloft.net, linux-crypto@vger.kernel.org,
	linux-kernel@vger.kernel.org,
	linux-arm-kernel@lists.infradead.org, michals@xilinx.com,
	saratcha@xilinx.com, git@amd.com,
	Dhaval Shah <dhaval.r.shah@amd.com>
Subject: Re: [PATCH V2 3/4] crypto: xilinx: Add ZynqMP RSA driver
Date: Fri, 31 Mar 2023 17:03:25 +0800	[thread overview]
Message-ID: <ZCah3f/Z8nzdHITy@gondor.apana.org.au> (raw)
In-Reply-To: <20230321053446.4303-4-harsha.harsha@amd.com>

On Tue, Mar 21, 2023 at 11:04:45AM +0530, Harsha Harsha wrote:
>
> +static inline int xilinx_copy_and_save_keypart(u8 **kpbuf, unsigned int *kplen,
> +					       const u8 *buf, size_t sz)
> +{
> +	int nskip;
> +
> +	for (nskip = 0; nskip < sz; nskip++)
> +		if (buf[nskip])
> +			break;
> +
> +	*kplen = sz - nskip;
> +	*kpbuf = kmemdup(buf + nskip, *kplen, GFP_KERNEL);
> +	if (!*kpbuf)
> +		return -ENOMEM;
> +
> +	return 0;
> +}

...

> +static int xilinx_rsa_setkey(struct crypto_akcipher *tfm, const void *key,
> +			     unsigned int keylen, bool private)
> +{
> +	struct xilinx_rsa_tfm_ctx *tctx = akcipher_tfm_ctx(tfm);
> +	struct rsa_key raw_key;
> +	int ret;
> +
> +	if (private)
> +		ret = rsa_parse_priv_key(&raw_key, key, keylen);
> +	else
> +		ret = rsa_parse_pub_key(&raw_key, key, keylen);
> +	if (ret)
> +		goto n_key;
> +
> +	ret = xilinx_copy_and_save_keypart(&tctx->n_buf, &tctx->n_len,
> +					   raw_key.n, raw_key.n_sz);

What happens when you call setkey twice? Wouldn't this leak memory?

Cheers,
-- 
Email: Herbert Xu <herbert@gondor.apana.org.au>
Home Page: http://gondor.apana.org.au/~herbert/
PGP Key: http://gondor.apana.org.au/~herbert/pubkey.txt

  parent reply	other threads:[~2023-03-31  9:04 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-03-21  5:34 [PATCH V2 0/4] crypto: Add Xilinx ZynqMP RSA driver support Harsha Harsha
2023-03-21  5:34 ` [PATCH V2 1/4] firmware: xilinx: Get the SoC family specific data for crypto operation Harsha Harsha
2023-03-21  5:34 ` [PATCH V2 2/4] firmware: xilinx: Add ZynqMP RSA API for RSA encrypt/decrypt operation Harsha Harsha
2023-03-21  5:34 ` [PATCH V2 3/4] crypto: xilinx: Add ZynqMP RSA driver Harsha Harsha
2023-03-23  8:36   ` kernel test robot
2023-03-31  9:03   ` Herbert Xu [this message]
2023-04-03  9:47     ` Harsha, Harsha
2023-03-21  5:34 ` [PATCH V2 4/4] MAINTAINERS: Add maintainer for Xilinx " Harsha Harsha

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=ZCah3f/Z8nzdHITy@gondor.apana.org.au \
    --to=herbert@gondor.apana.org.au \
    --cc=davem@davemloft.net \
    --cc=dhaval.r.shah@amd.com \
    --cc=git@amd.com \
    --cc=harsha.harsha@amd.com \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-crypto@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=michals@xilinx.com \
    --cc=saratcha@xilinx.com \
    /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;
as well as URLs for NNTP newsgroup(s).