From: sashiko-bot@kernel.org
To: "Pavitrakumar Managutte" <pavitrakumarm@vayavyalabs.com>,
linux-crypto@vger.kernel.org, devicetree@vger.kernel.org,
herbert@gondor.apana.org.au, robh@kernel.org
Cc: krzk@kernel.org, conor+dt@kernel.org, ruud.derwig@gf.com,
rbannerm@synopsys.com, manjunath.hadli@vayavyalabs.com,
adityak@vayavyalabs.com, navami.telsang@vayavyalabs.com,
bhoomikak@vayavyalabs.com, nazim.khan@vayavyalabs.com
Subject: Re: [PATCH v29 2/4] crypto: spacc - Add SPAcc ahash support
Date: Sat, 14 Nov 2026 14:52:32 +0000 [thread overview]
Message-ID: <sashiko-outbox-214649@kernel.org> (raw)
In-Reply-To: <20261114142212.716906-3-pavitrakumarm@vayavyalabs.com>
Thank you for your contribution! Sashiko AI review found 3 potential
issues to consider:
- [High] crypto: spacc: salg leak or priv ref underflow in
spacc_probe_hashes()
- [Low] crypto: spacc: wrong field logged for AUX in spacc_init()
- [Low] crypto: spacc - missing stack key zeroization in context
read/write helpers
--
commit 7f65f106112a1ad39dd6972a667e410520c333a1
Author: Pavitrakumar Managutte <pavitrakumarm@vayavyalabs.com>
crypto: spacc - Add SPAcc ahash support
This commit introduces the Synopsys DesignWare SPAcc crypto accelerator
driver along with ahash support for MD5, SHA-1, SHA-2, SHA-3, HMAC, and
SM4 CMAC/XCBC algorithms.
> diff --git a/drivers/crypto/dwc-spacc/spacc_ahash.c b/drivers/crypto/dwc-spacc/spacc_ahash.c
> new file mode 100644
> index 0000000000000..2e12ac7974fcd
> --- /dev/null
> +++ b/drivers/crypto/dwc-spacc/spacc_ahash.c
[ ... ]
> +static void spacc_hash_alg_destroy(struct crypto_alg *alg)
> +{
> + struct spacc_alg *salg = container_of(alg, struct spacc_alg,
> + alg.hash.base.halg.base);
> + struct spacc_priv *priv = salg->priv;
> +
> + kfree(salg);
> + kref_put(&priv->ref, spacc_priv_release);
> +}
[ ... ]
> +static int spacc_register_hash(struct spacc_alg *salg)
> +{
> + int rc = 0;
> + struct spacc_priv *priv = salg->priv;
> +
> + salg->calg = &salg->alg.hash.base.halg.base;
> + salg->alg.hash = spacc_hash_template;
> +
> + /* Unkeyed digests must not advertise a setkey. */
> + if (!spacc_mode_is_keyed(salg->mode->id))
> + salg->alg.hash.base.setkey = NULL;
> +
> + rc = spacc_init_calg(salg->calg, salg->mode);
> + if (rc)
> + return rc;
> +
> + salg->alg.hash.base.halg.digestsize = salg->mode->hashlen;
> + {
> + struct crypto_ahash *fb;
> +
> + /* statesize must equal the software fallback's exported state. */
> + fb = crypto_alloc_ahash(salg->calg->cra_name, 0,
> + CRYPTO_ALG_ASYNC);
> + if (IS_ERR(fb))
> + return PTR_ERR(fb);
> + salg->alg.hash.base.halg.statesize = crypto_ahash_statesize(fb);
> + crypto_free_ahash(fb);
> + }
> +
> + rc = crypto_engine_register_ahash(&salg->alg.hash);
> + if (rc < 0)
> + return rc;
> +
> + guard(mutex)(&priv->hash_alg_mutex);
> + list_add(&salg->list, &priv->hash_alg_list);
> +
> + return 0;
> +}
> +
> +int spacc_probe_hashes(struct platform_device *spacc_pdev)
> +{
[ ... ]
> + if (spacc_is_mode_keysize_supported(&priv->spacc,
> + possible_hashes[index].id & 0xFF,
> + possible_hashes[index].hashlen, 1)) {
> + salg = kmalloc_obj(*salg, GFP_KERNEL);
> + if (!salg) {
> + rc = -ENOMEM;
> + goto err_unregister;
> + }
> +
> + salg->mode = &possible_hashes[index];
> + salg->dev = &spacc_pdev->dev;
> + salg->priv = priv;
> + kref_get(&priv->ref);
> +
> + rc = spacc_register_hash(salg);
> + if (rc < 0) {
> + kref_put(&priv->ref, spacc_priv_release);
> + continue;
> + }
> + registered++;
> + }
> + }
[Severity: High]
Can a failure in spacc_register_hash() leak salg or underflow priv->ref?
If spacc_register_hash() fails before crypto_check_alg() initializes
cra_refcnt (for example in spacc_init_calg() or crypto_alloc_ahash()),
spacc_hash_alg_destroy() never runs and spacc_probe_hashes() never frees
salg.
Conversely, if crypto_engine_register_ahash() fails inside
__crypto_register_alg() (for example with -EEXIST when a second SPAcc
device probes with the same "spacc-<alg>" cra_driver_name),
crypto_register_alg() calls crypto_alg_put() -> spacc_hash_alg_destroy(),
which frees salg and drops priv->ref. The error path in
spacc_probe_hashes() then calls kref_put(&priv->ref, spacc_priv_release) a
second time, freeing priv while spacc_probe_hashes() is still using it.
Taking priv->ref inside spacc_register_hash() right before
crypto_engine_register_ahash() and freeing salg directly on earlier errors
would avoid both issues.
> diff --git a/drivers/crypto/dwc-spacc/spacc_core.c b/drivers/crypto/dwc-spacc/spacc_core.c
> new file mode 100644
> index 0000000000000..490451cfc5bdb
> --- /dev/null
> +++ b/drivers/crypto/dwc-spacc/spacc_core.c
[ ... ]
> + if (spacc->config.version >= 0x48)
> + dev_dbg(spacc->dptr,
> + " TYPE : %lx (%s)\n", SPACC_ID_TYPE(id),
> + version_string[SPACC_ID_TYPE(id) & 1]);
> +
> + dev_dbg(spacc->dptr, " AUX : %x\n", info->spacc_version.qos);
[Severity: Low]
Should this print info->spacc_version.aux instead of
info->spacc_version.qos?
> diff --git a/drivers/crypto/dwc-spacc/spacc_manager.c b/drivers/crypto/dwc-spacc/spacc_manager.c
> new file mode 100644
> index 0000000000000..d883cc0e9b05c
> --- /dev/null
> +++ b/drivers/crypto/dwc-spacc/spacc_manager.c
[ ... ]
> +/* Write appropriate context data which depends on operation and mode */
> +int spacc_write_context(struct spacc_device *spacc, int job_idx, int op,
> + const unsigned char *key, int ksz,
> + const unsigned char *iv, int ivsz)
> +{
> + int buflen;
> + int ret = 0;
> + unsigned char buf[300] __aligned(sizeof(u32));
> + struct spacc_ctx *ctx = NULL;
> + struct spacc_job *job = NULL;
[ ... ]
> + return ret;
> +}
> +
> +int spacc_read_context(struct spacc_device *spacc, int job_idx,
> + int op, unsigned char *key, int ksz,
> + unsigned char *iv, int ivsz)
> +{
> + int buflen;
> + int ret = 0;
> + unsigned char buf[300] __aligned(sizeof(u32));
> + struct spacc_ctx *ctx = NULL;
> + struct spacc_job *job = NULL;
[ ... ]
> + return ret;
> +}
[Severity: Low]
Should spacc_write_context() and spacc_read_context() clear buf with
memzero_explicit() before returning so cipher and hash keys are not left on
the stack?
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261114142212.716906-1-pavitrakumarm@vayavyalabs.com?part=2
next prev parent reply other threads:[~2026-11-14 14:52 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-14 14:22 [PATCH v29 0/4] crypto: spacc - Add SPAcc Crypto Driver Pavitrakumar Managutte
2026-11-14 14:22 ` [PATCH v29 1/4] dt-bindings: crypto: Document support for SPAcc Pavitrakumar Managutte
2026-11-14 14:22 ` [PATCH v29 2/4] crypto: spacc - Add SPAcc ahash support Pavitrakumar Managutte
2026-11-14 14:52 ` sashiko-bot [this message]
2026-11-14 14:22 ` [PATCH v29 3/4] crypto: spacc - add spacc autodetect support Pavitrakumar Managutte
2026-11-14 14:22 ` [PATCH v29 4/4] crypto: spacc - Add SPAcc Kconfig and Makefile Pavitrakumar Managutte
2026-11-14 14:48 ` sashiko-bot
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=sashiko-outbox-214649@kernel.org \
--to=sashiko-bot@kernel.org \
--cc=adityak@vayavyalabs.com \
--cc=bhoomikak@vayavyalabs.com \
--cc=conor+dt@kernel.org \
--cc=devicetree@vger.kernel.org \
--cc=herbert@gondor.apana.org.au \
--cc=krzk@kernel.org \
--cc=linux-crypto@vger.kernel.org \
--cc=manjunath.hadli@vayavyalabs.com \
--cc=navami.telsang@vayavyalabs.com \
--cc=nazim.khan@vayavyalabs.com \
--cc=pavitrakumarm@vayavyalabs.com \
--cc=rbannerm@synopsys.com \
--cc=robh@kernel.org \
--cc=ruud.derwig@gf.com \
--cc=sashiko-reviews@lists.linux.dev \
/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