From: sashiko-bot@kernel.org
To: "Jose Nieto" <jnieto.alaber@gmail.com>,
"Corentin Labbe" <clabbe@baylibre.com>,
"Herbert Xu" <herbert@gondor.apana.org.au>
Cc: linux-crypto@vger.kernel.org, linux-amlogic@lists.infradead.org,
devicetree@vger.kernel.org,
"Neil Armstrong" <neil.armstrong@linaro.org>,
"Martin Blumenstingl" <martin.blumenstingl@googlemail.com>,
"Krzysztof Kozlowski" <krzk+dt@kernel.org>,
"Rob Herring" <robh@kernel.org>,
"Conor Dooley" <conor+dt@kernel.org>,
"Alexey Romanov" <romanov.alexey2000@gmail.com>
Subject: Re: [PATCH v13 15/25] crypto: amlogic - Add support for G12-series
Date: Thu, 26 Nov 2026 19:55:03 +0000 [thread overview]
Message-ID: <sashiko-outbox-236129@kernel.org> (raw)
In-Reply-To: <20261126193241.1471372-16-jnieto.alaber@gmail.com>
Thank you for your contribution! Sashiko AI review found 6 potential
issues to consider:
- [High] crypto: amlogic: 0-byte SHA DMA desc and double complete in
hasher request
- [High] crypto: amlogic: OOB DMA length and shared keyiv race in
meson_cipher()
- [Medium] crypto: amlogic: debugfs leak and UAF on error_hasher in
meson_crypto_probe()
- [Medium] crypto: amlogic: unregister of failed alg in
meson_register_algs() rollback
- [Medium] crypto: amlogic: partial_addr DMA leak on
meson_kick_hardware() timeout
- [Medium] crypto: amlogic: engine/DMA leak and early IRQ in
meson_allocate_chanlist()
--
commit df12ec18bc93360a5cdf078f04efac1cfd6bdee7
Author: Alexey Romanov <romanov.alexey2000@gmail.com>
crypto: amlogic - Add support for G12-series
This commit adds platform data and the "amlogic,g12a-crypto" device tree
compatible entry to support the Amlogic G12-series crypto engine, including
hardware hasher support.
> diff --git a/drivers/crypto/amlogic/amlogic-gxl-core.c b/drivers/crypto/amlogic/amlogic-gxl-core.c
> index f530e238812eb..0fb0da20e06b2 100644
> --- a/drivers/crypto/amlogic/amlogic-gxl-core.c
> +++ b/drivers/crypto/amlogic/amlogic-gxl-core.c
> @@ -282,11 +282,23 @@ static const struct meson_pdata meson_gxl_pdata = {
> .support_192bit_key = true,
> };
>
> +static const struct meson_pdata meson_g12a_pdata = {
> + .descs_reg = 0x0,
> + .status_reg = 0x8,
> + .setup_desc_cnt = 1,
> + .hasher_supported = true,
[Severity: High]
Can enabling hasher_supported emit a bogus 0-length DMA descriptor from
physical address 0 during non-block-aligned update() requests, and double
complete failed hash requests?
In meson_hasher_do_one_request(), meson_setup_state_descs() writes a state
descriptor and increments ctx.tloffset before checking whether the
remaining bytes are shorter than blocksize and only buffered into
rctx->partial. The same state is reached when a single update() contains
one or more full blocks followed by a sub-block tail, because the full
block increments ctx.tloffset without setting DESC_LAST (as ctx->nbytes is
still non-zero). Once the trailing bytes are copied into rctx->partial,
ctx.nbytes and ctx.todo are both 0 while ctx.tloffset is non-zero, so
execution falls through to meson_setup_data_descs() and
meson_kick_hardware() with ctx.src_addr == 0 and ctx.todo == 0:
drivers/crypto/amlogic/amlogic-gxl-hasher.c:meson_hasher_do_one_request() {
...
meson_setup_state_descs(&ctx);
if (rctx->partial_size && rctx->partial_size < blocksize) {
ret = meson_fill_partial_buffer(&ctx, len);
if (ret)
goto fail;
} else if (len && len < blocksize) {
memcpy(rctx->partial, sg_virt(ctx.src_sg) + ctx.src_offset, len);
rctx->partial_size = len;
ctx.nbytes -= len;
ctx.src_offset += len;
}
...
if (!ctx.todo && !rctx->final_req && !ctx.tloffset)
continue;
if (meson_setup_data_descs(&ctx)) {
ret = meson_kick_hardware(&ctx);
...
}
Also in the hasher path:
- on final() requests (rctx->final_req == true), meson_hasher_do_one_request()
forces ctx.nbytes = 0, but meson_hasher_req_map() and
meson_hasher_req_unmap() only check !req->nbytes instead of
(!req->nbytes || rctx->final_req), and the loop reads
sg_dma_len(ctx.src_sg) whenever req->src is non-NULL even when
req->nbytes == 0 and req->src was never DMA-mapped.
- at the end of meson_hasher_do_one_request(), returning a negative ret
after calling crypto_finalize_hash_request(engine, req, ret) causes
crypto_pump_requests() to call crypto_request_complete() a second time
on the same request; do_one_request callbacks must return 0 after
finalizing the request.
[Severity: Medium]
Does meson_crypto_probe() leak mc->dbgfs_dir and leave a dangling mc
pointer in debugfs if meson_hasher_register() fails?
With hasher_supported set to true, meson_hasher_register() registers the
ahash algorithms and can now fail and jump to error_hasher.
meson_crypto_probe() creates the "gxl-crypto" debugfs directory and "stats"
file (with mc as seq->private) before calling meson_hasher_register(), but
the error_hasher unwind path does not call
debugfs_remove_recursive(mc->dbgfs_dir):
drivers/crypto/amlogic/amlogic-gxl-core.c:meson_crypto_probe() {
...
err = meson_hasher_register(mc);
if (err)
goto error_hasher;
return 0;
error_hasher:
meson_cipher_unregister(mc);
error_alg:
meson_free_chanlist(mc, mc->flow_cnt - 1);
return err;
}
When probe fails, devres frees mc while /sys/kernel/debug/gxl-crypto/stats
remains registered, causing a use-after-free in meson_debugfs_show() if the
file is read.
[Severity: Medium]
Does meson_kick_hardware() leak the rctx->partial_addr DMA mapping when
wait_for_completion_timeout() times out?
meson_fill_partial_buffer() maps rctx->partial via dma_map_single() and
sets rctx->partial_mapped = true. If wait_for_completion_timeout() returns
0 in meson_kick_hardware(), it returns -EINVAL before reaching the
dma_unmap_single() block for rctx->partial_addr, and the fail label in
meson_hasher_do_one_request() only unmaps req->src and ctx.state_addr:
drivers/crypto/amlogic/amlogic-gxl-hasher.c:meson_kick_hardware() {
...
if (ret == 0) {
dev_err(mc->dev, "DMA timeout for flow %d\n", rctx->flow);
return -EINVAL;
}
...
if (rctx->partial_mapped) {
dma_unmap_single(mc->dev, rctx->partial_addr,
rctx->partial_size, DMA_TO_DEVICE);
rctx->partial_mapped = false;
}
...
}
> + .support_192bit_key = false,
> +};
> +
> static const struct of_device_id meson_crypto_of_match_table[] = {
> {
> .compatible = "amlogic,gxl-crypto",
> .data = &meson_gxl_pdata,
> },
> + {
> + .compatible = "amlogic,g12a-crypto",
> + .data = &meson_g12a_pdata,
> + },
[Severity: High]
Can concurrent CBC requests on the same transform corrupt each other's IV
and DMA mapping through op->keyiv, and does meson_setup_keyiv_descs() read
past the end of op->keyiv when setup_desc_cnt > 1?
op->keyiv lives in struct meson_cipher_tfm_ctx (per-TFM) rather than
struct meson_cipher_req_ctx (per-request), while meson_skencrypt() and
meson_skdecrypt() dispatch requests across mc->flow_cnt crypto_engine
threads via meson_get_engine_number(). Concurrent CBC requests sharing a
TFM overwrite op->keyiv + AES_MAX_KEY_SIZE with their own areq->iv and race
on dma_map_single(), dma_sync_single_for_device(), and dma_unmap_single()
in meson_cipher() and meson_setup_keyiv_descs().
In addition, meson_setup_keyiv_descs() programs every descriptor in the
setup_desc_cnt loop with the full ctx->keyiv.len instead of the 16-byte
chunk length at offset = i * 16:
drivers/crypto/amlogic/amlogic-gxl-cipher.c:meson_setup_keyiv_descs() {
...
for (i = 0; i < mc->pdata->setup_desc_cnt; i++) {
struct meson_desc *desc =
&mc->chanlist[rctx->flow].tl[ctx->tloffset];
int offset = i * 16;
desc->t_src = cpu_to_le32(ctx->keyiv.addr + offset);
desc->t_dst = cpu_to_le32(offset);
desc->t_status = cpu_to_le32(DESC_OWN | DESC_MODE_KEY | ctx->keyiv.len);
ctx->tloffset++;
}
}
When setup_desc_cnt is 3 (GXL), descriptors i = 1 and i = 2 read up to
offset 32 + 48 = 80 bytes in CBC mode, 32 bytes past the 48-byte op->keyiv
buffer and outside its DMA mapping.
[Severity: Medium]
Does meson_register_algs() attempt to unregister the algorithm that just
failed to register on its error path?
meson_register_algs() sets algs[i].mc = mc before calling
crypto_engine_register_skcipher() or crypto_engine_register_ahash(). If
registration fails for entry i, it calls meson_unregister_algs() without
clearing algs[i].mc first:
drivers/crypto/amlogic/amlogic-gxl-core.c:meson_register_algs() {
...
for (i = 0; i < count; i++) {
algs[i].mc = mc;
switch (algs[i].type) {
case CRYPTO_ALG_TYPE_SKCIPHER:
err = crypto_engine_register_skcipher(&algs[i].alg.skcipher);
if (err) {
dev_err(mc->dev, "Fail to register %s\n",
algs[i].alg.skcipher.base.base.cra_name);
meson_unregister_algs(mc, algs, count);
return err;
}
break;
...
}
Because meson_unregister_algs() unregisters every entry with a non-NULL
algs[i].mc (and also never resets algs[i].mc = NULL afterward), it calls
crypto_engine_unregister_skcipher() or crypto_engine_unregister_ahash() on
the entry that failed registration, triggering a WARN() in
crypto_unregister_alg().
[Severity: Medium]
Does meson_allocate_chanlist() leak already-started crypto_engine threads
and coherent DMA buffers if requesting an IRQ fails on channel i > 0, and
can an early IRQ fire before init_completion()?
In meson_allocate_chanlist(), if platform_get_irq() or devm_request_irq()
fails on iteration i > 0, the function returns directly instead of
unwinding channels 0 .. i - 1 via meson_free_chanlist(), leaking their
running crypto_engine kthreads and dma_alloc_coherent() descriptor rings.
In the same loop, devm_request_irq() is called before
init_completion(&mc->chanlist[i].complete), so an interrupt arriving right
after registration calls complete() in meson_irq_handler() on an
uninitialized completion:
drivers/crypto/amlogic/amlogic-gxl-core.c:meson_allocate_chanlist() {
...
for (i = 0; i < mc->flow_cnt; i++) {
mc->chanlist[i].irq = platform_get_irq(pdev, i);
if (mc->chanlist[i].irq < 0)
return mc->chanlist[i].irq;
err = devm_request_irq(mc->dev, mc->chanlist[i].irq,
meson_irq_handler, 0, "aml-crypto", mc);
if (err < 0) {
dev_err(mc->dev, "Cannot request IRQ for flow %d\n", i);
return err;
}
init_completion(&mc->chanlist[i].complete);
...
}
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261126193241.1471372-1-jnieto.alaber@gmail.com?part=15
next prev parent reply other threads:[~2026-11-26 19:55 UTC|newest]
Thread overview: 39+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-26 19:32 [PATCH v13 00/25] crypto: amlogic: add support for G12/AXG/A1/S4 and misc fixes Jose Nieto
2026-11-26 19:32 ` [PATCH v13 01/25] dt-bindings: crypto: amlogic,gxl-crypto: correct clk and interrupt lines Jose Nieto
2026-11-26 19:43 ` sashiko-bot
2026-11-26 19:32 ` [PATCH v13 02/25] dt-bindings: crypto: amlogic,gxl-crypto: support new SoC's Jose Nieto
2026-11-26 19:32 ` [PATCH v13 03/25] crypto: amlogic - Don't hardcode IRQ count Jose Nieto
2026-11-26 19:42 ` sashiko-bot
2026-11-26 19:32 ` [PATCH v13 04/25] crypto: amlogic - Add platform data Jose Nieto
2026-11-26 19:32 ` [PATCH v13 05/25] crypto: amlogic - Remove clock input Jose Nieto
2026-11-26 19:44 ` sashiko-bot
2026-11-26 19:32 ` [PATCH v13 06/25] crypto: amlogic - Add MMIO helpers Jose Nieto
2026-11-26 19:32 ` [PATCH v13 07/25] crypto: amlogic - Move get_engine_number() Jose Nieto
2026-11-26 19:32 ` [PATCH v13 08/25] crypto: amlogic - Drop status field from meson_flow Jose Nieto
2026-11-26 19:32 ` [PATCH v13 09/25] crypto: amlogic - Move algs definition and cipher API to cipher.c Jose Nieto
2026-11-26 19:41 ` sashiko-bot
2026-11-26 19:32 ` [PATCH v13 10/25] crypto: amlogic - Cleanup defines Jose Nieto
2026-11-26 19:32 ` [PATCH v13 11/25] crypto: amlogic - Process more than MAXDESCS descriptors Jose Nieto
2026-11-26 19:45 ` sashiko-bot
2026-11-26 19:32 ` [PATCH v13 12/25] crypto: amlogic - Avoid kzalloc in engine thread Jose Nieto
2026-11-26 19:48 ` sashiko-bot
2026-11-26 19:32 ` [PATCH v13 13/25] crypto: amlogic - Introduce hasher Jose Nieto
2026-11-26 19:56 ` sashiko-bot
2026-11-26 19:32 ` [PATCH v13 14/25] crypto: amlogic - Use fallback for 192-bit keys Jose Nieto
2026-11-26 19:32 ` [PATCH v13 15/25] crypto: amlogic - Add support for G12-series Jose Nieto
2026-11-26 19:55 ` sashiko-bot [this message]
2026-11-26 19:32 ` [PATCH v13 16/25] crypto: amlogic - Add support for AXG-series Jose Nieto
2026-11-26 19:32 ` [PATCH v13 17/25] crypto: amlogic - Add support for A1-series Jose Nieto
2026-11-26 19:48 ` sashiko-bot
2026-11-26 19:32 ` [PATCH v13 18/25] crypto: amlogic: g12: drop CRYPTO_ALG_ALLOCATES_MEMORY Jose Nieto
2026-11-26 19:32 ` [PATCH v13 19/25] crypto: amlogic: hasher: add one-shot digest path Jose Nieto
2026-11-26 19:50 ` sashiko-bot
2026-11-26 19:32 ` [PATCH v13 20/25] crypto: amlogic: drop unused field and stale includes Jose Nieto
2026-11-26 19:32 ` [PATCH v13 21/25] arm64: dts: amlogic: gxl: correct crypto node definition Jose Nieto
2026-11-26 19:32 ` [PATCH v13 22/25] arm64: dts: amlogic: a1: add crypto node Jose Nieto
2026-11-26 20:01 ` sashiko-bot
2026-11-26 19:32 ` [PATCH v13 23/25] arm64: dts: amlogic: s4: " Jose Nieto
2026-11-26 20:02 ` sashiko-bot
2026-11-26 19:32 ` [PATCH v13 24/25] arm64: dts: amlogic: g12: " Jose Nieto
2026-11-26 19:32 ` [PATCH v13 25/25] arm64: dts: amlogic: axg: " Jose Nieto
2026-11-26 20:00 ` 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-236129@kernel.org \
--to=sashiko-bot@kernel.org \
--cc=clabbe@baylibre.com \
--cc=conor+dt@kernel.org \
--cc=devicetree@vger.kernel.org \
--cc=herbert@gondor.apana.org.au \
--cc=jnieto.alaber@gmail.com \
--cc=krzk+dt@kernel.org \
--cc=linux-amlogic@lists.infradead.org \
--cc=linux-crypto@vger.kernel.org \
--cc=martin.blumenstingl@googlemail.com \
--cc=neil.armstrong@linaro.org \
--cc=robh@kernel.org \
--cc=romanov.alexey2000@gmail.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