From: Changwei Zou <changwei.zou@canonical.com>
To: herbert@gondor.apana.org.au, sahil.malhotra@nxp.com
Cc: davem@davemloft.net, horia.geanta@nxp.com, pankaj.gupta@nxp.com,
gaurav.jain@nxp.com, iuliana.prodan@nxp.com,
martin.kepplinger-novakovic@ginzinger.com, lukas@wunner.de,
sahil.malhotra@oss.nxp.com, changwei.zou@canonical.com,
linux-crypto@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: [PATCH v2 1/2] crypto: caam - Fix wrong unmap operations
Date: Mon, 5 Oct 2026 08:01:59 +1100 [thread overview]
Message-ID: <20261004210200.290119-2-changwei.zou@canonical.com> (raw)
In-Reply-To: <20261004210200.290119-1-changwei.zou@canonical.com>
Both akcipher_do_one_req() and akcipher_enqueue_req() call rsa_pub_unmap()
regardless of the key type. priv_form only takes values FORM1/FORM2/FORM3
with no distinct public key enumerator.
Use key->d to distinguish public from private key operations, then
dispatch to the correct unmap function based on key->priv_form.
caam_rsa_set_priv_key_form() implicitly relies on zero-initialization
for priv_form. Set priv_form = FORM1 explicitly at the head of the function
for clarity and robustness.
Fixes: bf53795025a2 ("crypto: caam - add crypto_engine support for RSA algorithms")
Signed-off-by: Changwei Zou <changwei.zou@canonical.com>
Assisted-by: OpenCode:claude-sonnet-4.6
Reviewed-by: Sahil Malhotra <sahil.malhotra@nxp.com>
---
drivers/crypto/caam/caampkc.c | 43 +++++++++++++++++++++++++----------
1 file changed, 31 insertions(+), 12 deletions(-)
diff --git a/drivers/crypto/caam/caampkc.c b/drivers/crypto/caam/caampkc.c
index cb001aa1de66..840271840cce 100644
--- a/drivers/crypto/caam/caampkc.c
+++ b/drivers/crypto/caam/caampkc.c
@@ -379,6 +379,7 @@ static int akcipher_do_one_req(struct crypto_engine *engine, void *areq)
struct crypto_akcipher *tfm = crypto_akcipher_reqtfm(req);
struct caam_rsa_req_ctx *req_ctx = akcipher_request_ctx(req);
struct caam_rsa_ctx *ctx = akcipher_tfm_ctx_dma(tfm);
+ struct caam_rsa_key *key = &ctx->key;
struct device *jrdev = ctx->dev;
u32 *desc = req_ctx->edesc->hw_desc;
int ret;
@@ -391,7 +392,21 @@ static int akcipher_do_one_req(struct crypto_engine *engine, void *areq)
return ret;
if (ret != -EINPROGRESS) {
- rsa_pub_unmap(jrdev, req_ctx->edesc, req);
+ if (key->d) {
+ switch (key->priv_form) {
+ case FORM1:
+ rsa_priv_f1_unmap(jrdev, req_ctx->edesc, req);
+ break;
+ case FORM2:
+ rsa_priv_f2_unmap(jrdev, req_ctx->edesc, req);
+ break;
+ case FORM3:
+ rsa_priv_f3_unmap(jrdev, req_ctx->edesc, req);
+ break;
+ }
+ } else {
+ rsa_pub_unmap(jrdev, req_ctx->edesc, req);
+ }
rsa_io_unmap(jrdev, req_ctx->edesc, req);
kfree(req_ctx->edesc);
} else {
@@ -691,17 +706,19 @@ static int akcipher_enqueue_req(struct device *jrdev,
ret = caam_jr_enqueue(jrdev, desc, cbk, req);
if ((ret != -EINPROGRESS) && (ret != -EBUSY)) {
- switch (key->priv_form) {
- case FORM1:
- rsa_priv_f1_unmap(jrdev, edesc, req);
- break;
- case FORM2:
- rsa_priv_f2_unmap(jrdev, edesc, req);
- break;
- case FORM3:
- rsa_priv_f3_unmap(jrdev, edesc, req);
- break;
- default:
+ if (key->d) {
+ switch (key->priv_form) {
+ case FORM1:
+ rsa_priv_f1_unmap(jrdev, edesc, req);
+ break;
+ case FORM2:
+ rsa_priv_f2_unmap(jrdev, edesc, req);
+ break;
+ case FORM3:
+ rsa_priv_f3_unmap(jrdev, edesc, req);
+ break;
+ }
+ } else {
rsa_pub_unmap(jrdev, edesc, req);
}
rsa_io_unmap(jrdev, edesc, req);
@@ -992,6 +1009,8 @@ static int caam_rsa_set_priv_key_form(struct caam_rsa_ctx *ctx,
size_t q_sz = raw_key->q_sz;
unsigned aligned_size;
+ rsa_key->priv_form = FORM1;
+
rsa_key->p = caam_read_raw_data(raw_key->p, &p_sz);
if (!rsa_key->p)
return -ENOMEM;
--
2.43.0
next prev parent reply other threads:[~2026-10-04 21:02 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-10-04 21:01 [PATCH v2 0/2] crypto: caam - Fix RSA destination buffer handling Changwei Zou
2026-10-04 21:01 ` Changwei Zou [this message]
2026-10-04 21:02 ` [PATCH v2 2/2] crypto: caam - Use bounce buffer for unaligned RSA destination buffers Changwei Zou
2026-10-17 8:14 ` Stephane Debusne
2026-10-17 10:20 ` Changwei Zou
2026-10-17 15:39 ` Stephane Debusne
2026-10-08 7:38 ` [PATCH v2 0/2] crypto: caam - Fix RSA destination buffer handling Herbert Xu
2026-10-20 3:21 ` Changwei Zou
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=20261004210200.290119-2-changwei.zou@canonical.com \
--to=changwei.zou@canonical.com \
--cc=davem@davemloft.net \
--cc=gaurav.jain@nxp.com \
--cc=herbert@gondor.apana.org.au \
--cc=horia.geanta@nxp.com \
--cc=iuliana.prodan@nxp.com \
--cc=linux-crypto@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=lukas@wunner.de \
--cc=martin.kepplinger-novakovic@ginzinger.com \
--cc=pankaj.gupta@nxp.com \
--cc=sahil.malhotra@nxp.com \
--cc=sahil.malhotra@oss.nxp.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®