Linux cryptographic layer development
 help / color / mirror / Atom feed
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 v30 2/4] crypto: spacc - Add SPAcc ahash support
Date: Wed, 18 Nov 2026 06:59:02 +0000	[thread overview]
Message-ID: <sashiko-outbox-220280@kernel.org> (raw)
In-Reply-To: <20261118063504.835259-3-pavitrakumarm@vayavyalabs.com>

Thank you for your contribution! Sashiko AI review found 1 potential
issue to consider:
- [Medium] crypto: spacc: DMA leak on timeout in
  spacc_xof_stringsize_autodetect()
--

commit 375f3a6084b254b6c5dc8f9b677b8c0b4f921b54
Author: Pavitrakumar Managutte <pavitrakumarm@vayavyalabs.com>

crypto: spacc - Add SPAcc ahash support

This commit adds core device management, HAL, interrupt handling, and ahash
algorithm support for the Synopsys DesignWare SPAcc crypto accelerator.

> diff --git a/drivers/crypto/dwc-spacc/spacc_core.c b/drivers/crypto/dwc-spacc/spacc_core.c
> new file mode 100644
> index 0000000000000..b447716908af4
> --- /dev/null
> +++ b/drivers/crypto/dwc-spacc/spacc_core.c

[ ... ]

> +static int spacc_xof_stringsize_autodetect(struct spacc_device *spacc)
> +{
> +	void *virt;
> +	int ss, alg;
> +	int ret;
> +	bool match;
> +	dma_addr_t dma;
> +	struct pdu_ddt ddt;
> +	unsigned long buflen;
> +	unsigned char *buf;
> +	unsigned long spacc_ctrl[2] = {0xF400B400, 0xF400D400};
> +	unsigned char test_str[6] = {0x01, 0x20, 0x54, 0x45, 0x53, 0x54};
> +	unsigned char md[2][16] = {
> +			 {0xc3, 0x6d, 0x0a, 0x88, 0xfa, 0x37, 0x4c, 0x9b,
> +			  0x44, 0x74, 0xeb, 0x00, 0x5f, 0xe8, 0xca, 0x25},
> +			 {0x68, 0x77, 0x04, 0x11, 0xf8, 0xe3, 0xb0, 0x1e,
> +			  0x0d, 0xbf, 0x71, 0x6a, 0xe9, 0x87, 0x1a, 0x0d}};
> +
> +	buf = kzalloc(spacc->config.hash_page_size, GFP_KERNEL);
> +	if (!buf)
> +		return -ENOMEM;
> +
> +	virt = dma_alloc_coherent(spacc->dptr, SPACC_TEST_DMA_BUFF_SIZE,
> +				  &dma, GFP_KERNEL);
> +	if (!virt) {
> +		kfree(buf);
> +		return -EIO;
> +	}
> +
> +	if (pdu_ddt_init(spacc->dptr, &ddt, 1)) {
> +		kfree(buf);
> +		dma_free_coherent(spacc->dptr, SPACC_TEST_DMA_BUFF_SIZE,
> +				  virt, dma);
> +		return -EIO;
> +	}
> +
> +	pdu_ddt_add(spacc->dptr, &ddt, dma, SPACC_TEST_DMA_BUFF_SIZE);
> +
> +	/* populate registers for jobs */
> +	writel((u32)ddt.phys, spacc->regmap + SPACC_REG_SRC_PTR);
> +	writel((u32)ddt.phys, spacc->regmap + SPACC_REG_DST_PTR);
> +
> +	writel(16, spacc->regmap + SPACC_REG_PROC_LEN);
> +	writel(16, spacc->regmap + SPACC_REG_PRE_AAD_LEN);
> +	writel(16, spacc->regmap + SPACC_REG_ICV_LEN);
> +	writel(6, spacc->regmap + SPACC_REG_KEY_SZ);
> +	writel(0, spacc->regmap + SPACC_REG_SW_CTRL);
> +
> +	/* repeat for 2 algorithms, CSHAKE128 and KMAC128 */
> +	for (alg = 0; (alg < 2) && (spacc->config.string_size == 0); alg++) {
> +		for (ss = 0; ss < 4; ss++) {
> +			buflen = (32UL << ss);
> +			if (buflen > spacc->config.hash_page_size)
> +				break;
> +
> +			memset(virt, 0, SPACC_TEST_DMA_BUFF_SIZE);
> +
> +			memset(buf, 0, spacc->config.hash_page_size);
> +			memcpy(buf, test_str, sizeof(test_str));
> +			memcpy(buf + (buflen >> 1), test_str, sizeof(test_str));
> +
> +			pdu_to_dev_s(spacc->regmap + SPACC_CTX_HASH_KEY, buf,
> +				     spacc->config.hash_page_size >> 2);
> +
> +			writel(spacc_ctrl[alg], spacc->regmap + SPACC_REG_CTRL);
> +
> +			ret = spacc_wait_for_job_completion(spacc, virt,
> +							    md[alg], &match);
> +			if (ret)
> +				goto err_timeout;
> +
> +			if (match)
> +				spacc->config.string_size = (16 << ss);
> +		}
> +	}
> +
> +	/* reset registers */
> +	writel(0, spacc->regmap + SPACC_REG_IRQ_CTRL);
> +	writel(0, spacc->regmap + SPACC_REG_IRQ_EN);
> +	writel(0xFFFFFFFF, spacc->regmap + SPACC_REG_IRQ_STAT);
> +
> +	writel(0, spacc->regmap + SPACC_REG_SRC_PTR);
> +	writel(0, spacc->regmap + SPACC_REG_DST_PTR);
> +	writel(0, spacc->regmap + SPACC_REG_PROC_LEN);
> +	writel(0, spacc->regmap + SPACC_REG_ICV_LEN);
> +	writel(0, spacc->regmap + SPACC_REG_PRE_AAD_LEN);
> +
> +	kfree(buf);
> +	pdu_ddt_free(&ddt);
> +	dma_free_coherent(spacc->dptr, SPACC_TEST_DMA_BUFF_SIZE,
> +			  virt, dma);
> +
> +	return spacc->config.string_size ? 0 : -ENODEV;
> +
> +err_timeout:
> +	dev_err(spacc->dptr,
> +		"XOF autodetect job timed out, engine not responding\n");
> +	kfree(buf);
> +	return -ETIMEDOUT;
> +}

[Severity: Medium]
Does the err_timeout path in spacc_xof_stringsize_autodetect() leak virt
and ddt?

When spacc_wait_for_job_completion() returns -ETIMEDOUT, err_timeout only
frees buf and skips resetting the hardware registers, calling
pdu_ddt_free(&ddt), and calling dma_free_coherent() on virt.  Because
spacc_init() treats -ETIMEDOUT as a fatal error, spacc_init_device() then
unwinds through pdu_mem_deinit() -> dma_pool_destroy(priv->ddt4_pool) while
ddt is still allocated from that pool.

Also, when match is true, the inner ss loop does not break after setting
spacc->config.string_size, so it continues submitting test jobs for the
remaining ss values.

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261118063504.835259-1-pavitrakumarm@vayavyalabs.com?part=2

  reply	other threads:[~2026-11-18  6:59 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-18  6:35 [PATCH v30 0/4] crypto: spacc - Add SPAcc Crypto Driver Pavitrakumar Managutte
2026-11-18  6:35 ` [PATCH v30 1/4] dt-bindings: crypto: Document support for SPAcc Pavitrakumar Managutte
2026-11-18  6:35 ` [PATCH v30 2/4] crypto: spacc - Add SPAcc ahash support Pavitrakumar Managutte
2026-11-18  6:59   ` sashiko-bot [this message]
2026-11-18  6:35 ` [PATCH v30 3/4] crypto: spacc - add spacc autodetect support Pavitrakumar Managutte
2026-11-18  6:35 ` [PATCH v30 4/4] crypto: spacc - Add SPAcc Kconfig and Makefile Pavitrakumar Managutte
2026-11-18  7:02   ` 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-220280@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