From: Herbert Xu <herbert@gondor.apana.org.au>
To: ZhaoJinming <zhaojinming@uniontech.com>
Cc: "Horia Geantă" <horia.geanta@nxp.com>,
"Pankaj Gupta" <pankaj.gupta@nxp.com>,
"Gaurav Jain" <gaurav.jain@nxp.com>,
"David S . Miller" <davem@davemloft.net>,
"Tudor Ambarus" <tudor-dan.ambarus@nxp.com>,
"Radu Alexe" <radu.alexe@nxp.com>,
linux-crypto@vger.kernel.org, linux-kernel@vger.kernel.org,
stable@vger.kernel.org
Subject: Re: [PATCH] crypto: caam - fix double-free in caam_rsa_set_priv_key_form()
Date: Fri, 2 Oct 2026 20:10:19 +1000 [thread overview]
Message-ID: <ar-DCzGGyqB7cxm9@gondor.apana.org.au> (raw)
In-Reply-To: <FF2F0DC4D3930E6A+20260923101457.204629-1-zhaojinming@uniontech.com>
On Wed, Sep 23, 2026 at 06:14:57PM +0800, ZhaoJinming wrote:
> caam_rsa_set_priv_key_form() frees the partially allocated key
> components (p, q, tmp1, tmp2, dp, dq) with kfree_sensitive() on its
> error path, but does not set those pointers to NULL afterward.
>
> When the function returns an error, caam_rsa_set_priv_key() jumps to
> its err label and calls caam_rsa_free_key(), which frees all of those
> same pointers again, resulting in a double-free.
>
> This is reachable when the allocation of q, tmp1, tmp2, dp, dq or qinv
> fails, e.g. under memory pressure, or for a malformed key whose CRT
> members decode to zero length and make caam_read_rsa_crt() return NULL.
>
> Set each pointer to NULL right after freeing it so that the subsequent
> caam_rsa_free_key() call becomes a no-op for the already-freed fields.
>
> Fixes: 52e26d77b8b3 ("crypto: caam - add support for RSA key form 2")
> Cc: stable@vger.kernel.org
> Signed-off-by: ZhaoJinming <zhaojinming@uniontech.com>
> ---
> drivers/crypto/caam/caampkc.c | 6 ++++++
> 1 file changed, 6 insertions(+)
Patch applied. Thanks.
--
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
prev parent reply other threads:[~2026-10-02 10:10 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-09-23 10:14 ZhaoJinming
2026-09-28 9:27 ` [EXT] " Sahil Malhotra (OSS)
2026-10-02 10:10 ` Herbert Xu [this message]
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=ar-DCzGGyqB7cxm9@gondor.apana.org.au \
--to=herbert@gondor.apana.org.au \
--cc=davem@davemloft.net \
--cc=gaurav.jain@nxp.com \
--cc=horia.geanta@nxp.com \
--cc=linux-crypto@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=pankaj.gupta@nxp.com \
--cc=radu.alexe@nxp.com \
--cc=stable@vger.kernel.org \
--cc=tudor-dan.ambarus@nxp.com \
--cc=zhaojinming@uniontech.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
all inboxes | Powered by JetHome®