* [PATCH v2] crypto: mxs-dcp: handle zero-length skcipher requests
@ 2026-09-08 9:44 Linmao Li
2026-09-08 9:57 ` sashiko-bot
2026-09-09 21:03 ` Frank Li
0 siblings, 2 replies; 3+ messages in thread
From: Linmao Li @ 2026-09-08 9:44 UTC (permalink / raw)
To: Herbert Xu, David S. Miller
Cc: Frank Li, Sascha Hauer, Pengutronix Kernel Team, Fabio Estevam,
Leonard Crestez, Radu Solea, Franck LENORMAND, linux-crypto, imx,
linux-arm-kernel, linux-kernel, Linmao Li
The generic ECB and CBC implementations return success for zero-length
requests, but MXS-DCP queues them anyway. When such a request reaches
the worker, last_out_len remains zero. The CBC completion path then
subtracts AES_BLOCK_SIZE from this unsigned value when updating the IV,
causing the offset to underflow. On decryption, the resulting source
address precedes aes_in_buf.
Return success before enqueueing zero-length requests, matching the
generic implementations. This avoids the invalid source access and
leaves the IV unchanged.
Fixes: fadd7a6e616b ("crypto: mxs-dcp - Fix AES issues")
Signed-off-by: Linmao Li <lilinmao@kylinos.cn>
---
v2: Clarify commit message: describe zero-length return-0 as existing
generic ECB/CBC behavior rather than a general API rule (Frank Li).
drivers/crypto/mxs-dcp.c | 3 +++
1 file changed, 3 insertions(+)
diff --git a/drivers/crypto/mxs-dcp.c b/drivers/crypto/mxs-dcp.c
index 133ebc998236..60794b4d49fa 100644
--- a/drivers/crypto/mxs-dcp.c
+++ b/drivers/crypto/mxs-dcp.c
@@ -473,6 +473,9 @@ static int mxs_dcp_aes_enqueue(struct skcipher_request *req, int enc, int ecb)
struct dcp_aes_req_ctx *rctx = skcipher_request_ctx(req);
int ret;
+ if (!req->cryptlen)
+ return 0;
+
if (unlikely(actx->key_len != AES_KEYSIZE_128 && !actx->key_referenced))
return mxs_dcp_block_fallback(req, enc);
base-commit: 8d3ae59288f1e7d58d76558a6ee96d533bc5019f
--
2.25.1
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH v2] crypto: mxs-dcp: handle zero-length skcipher requests
2026-09-08 9:44 [PATCH v2] crypto: mxs-dcp: handle zero-length skcipher requests Linmao Li
@ 2026-09-08 9:57 ` sashiko-bot
2026-09-09 21:03 ` Frank Li
1 sibling, 0 replies; 3+ messages in thread
From: sashiko-bot @ 2026-09-08 9:57 UTC (permalink / raw)
To: Linmao Li; +Cc: Frank.Li, imx
Thank you for your contribution! Sashiko AI review found 4 potential issue(s) to consider:
Pre-existing issues:
- [High] Out-of-bounds read and 0-length hardware submission due to improper scatterlist trailing data handling.
- [High] Potential deadlock due to using spin_lock() instead of spin_lock_bh() in queue management.
- [High] Invalid memory access and API violation using sg_virt() and sg_dma_len() on unmapped scatterlists.
- [High] DMA channel is not halted or reset on timeout, risking memory corruption.
--
commit e69f94141c2ba5f872a9844bc79817c711aedefd
Author: Linmao Li <lilinmao@kylinos.cn>
crypto: mxs-dcp: handle zero-length skcipher requests
The generic ECB and CBC implementations return success for zero-length
requests, but MXS-DCP queues them anyway. When such a request reaches the
worker, the CBC completion path subtracts AES_BLOCK_SIZE from last_out_len,
causing the offset to underflow. This commit returns success before
enqueueing zero-length requests to avoid the invalid source access.
> diff --git a/drivers/crypto/mxs-dcp.c b/drivers/crypto/mxs-dcp.c
> index 133ebc9982362..60794b4d49fac 100644
> --- a/drivers/crypto/mxs-dcp.c
> +++ b/drivers/crypto/mxs-dcp.c
> @@ -473,6 +473,9 @@ static int mxs_dcp_aes_enqueue(struct skcipher_request *req, int enc, int ecb)
> struct dcp_aes_req_ctx *rctx = skcipher_request_ctx(req);
> int ret;
>
> + if (!req->cryptlen)
> + return 0;
> +
> if (unlikely(actx->key_len != AES_KEYSIZE_128 && !actx->key_referenced))
> return mxs_dcp_block_fallback(req, enc);
[Severity: High]
This isn't a bug introduced by this patch, but since this patch modifies
mxs_dcp_aes_enqueue(), could there be a deadlock here due to spin_lock()
usage?
The AES and SHA worker kthreads (dcp_chan_thread_aes and dcp_chan_thread_sha)
take the channel lock in process context:
drivers/crypto/mxs-dcp.c:dcp_chan_thread_aes() {
...
spin_lock(&sdcp->lock[chan]);
...
}
However, the enqueue functions take the same lock without disabling softirqs:
drivers/crypto/mxs-dcp.c:mxs_dcp_aes_enqueue() {
...
spin_lock(&sdcp->lock[actx->chan]);
ret = crypto_enqueue_request(&sdcp->queue[actx->chan], &req->base);
spin_unlock(&sdcp->lock[actx->chan]);
...
}
If a softirq (like IPsec network traffic) preempts the worker thread while the
lock is held, and attempts to enqueue a request, will it spin forever waiting
for the preempted kthread to release the lock? Should this use spin_lock_bh()
instead?
[Severity: High]
This is a pre-existing issue, but I noticed a potential out-of-bounds read
in mxs_dcp_aes_block_crypt() related to how scatterlist trailing data is
handled.
If a decryption request has a cryptlen that is a multiple of 4096 and the
scatterlist contains trailing data, the first 4096 bytes are processed,
making actx->fill = 4096. After submission, actx->fill becomes 0. For the
next element, limit_hit is true, and clen is 0.
Could this cause a 0-length hardware submission and an out-of-bounds read?
drivers/crypto/mxs-dcp.c:mxs_dcp_aes_block_crypt() {
...
if (actx->fill == out_off || sg_is_last(src) || limit_hit) {
...
last_out_len = actx->fill;
actx->fill = 0;
...
memcpy(req->iv, in_buf + (last_out_len - AES_BLOCK_SIZE),
AES_BLOCK_SIZE);
...
}
With last_out_len = 0, does the memcpy underflow the pointer (0 - 16) and read
16 bytes before the in_buf array?
[Severity: High]
This isn't a bug introduced by this patch, but I noticed a potential invalid
memory access in mxs_dcp_aes_block_crypt() when handling scatterlists.
The code extracts virtual addresses and DMA lengths directly from the unmapped
scatterlist:
drivers/crypto/mxs-dcp.c:mxs_dcp_aes_block_crypt() {
...
src_buf = sg_virt(src);
len = sg_dma_len(src);
...
}
Since the scatterlist is not mapped first, wouldn't sg_virt() return a NULL
pointer for HIGHMEM pages, leading to a panic during the subsequent memcpy?
Additionally, is it safe to read sg_dma_len() before a DMA mapping has
occurred, especially on platforms that require CONFIG_NEED_SG_DMA_LENGTH?
[Severity: High]
This is a pre-existing issue, but I see a risk of memory corruption in
mxs_dcp_start_dma() when handling timeouts.
When wait_for_completion_timeout() expires, the function simply returns:
drivers/crypto/mxs-dcp.c:mxs_dcp_start_dma() {
...
if (!wait_for_completion_timeout(&sdcp->completion[chan],
msecs_to_jiffies(1000)))
return -ETIMEDOUT;
...
}
Since the active DMA transfer is abandoned without halting the hardware
channel, could the hardware resume the transaction later? If the caller unmaps
the buffers and the worker reuses the shared bounce buffers (aes_in_buf,
aes_out_buf) for the next request, wouldn't a delayed DMA completion overwrite
these buffers while they are in use?
--
Sashiko AI review · https://sashiko.dev/#/patchset/20260908094437.1548278-1-lilinmao@kylinos.cn?part=1
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH v2] crypto: mxs-dcp: handle zero-length skcipher requests
2026-09-08 9:44 [PATCH v2] crypto: mxs-dcp: handle zero-length skcipher requests Linmao Li
2026-09-08 9:57 ` sashiko-bot
@ 2026-09-09 21:03 ` Frank Li
1 sibling, 0 replies; 3+ messages in thread
From: Frank Li @ 2026-09-09 21:03 UTC (permalink / raw)
To: Linmao Li
Cc: Herbert Xu, David S. Miller, Sascha Hauer,
Pengutronix Kernel Team, Fabio Estevam, Leonard Crestez,
Radu Solea, Franck LENORMAND, linux-crypto, imx, linux-arm-kernel,
linux-kernel
On Tue, Sep 08, 2026 at 05:44:37PM +0800, Linmao Li wrote:
> The generic ECB and CBC implementations return success for zero-length
> requests, but MXS-DCP queues them anyway. When such a request reaches
> the worker, last_out_len remains zero. The CBC completion path then
> subtracts AES_BLOCK_SIZE from this unsigned value when updating the IV,
> causing the offset to underflow. On decryption, the resulting source
> address precedes aes_in_buf.
>
> Return success before enqueueing zero-length requests, matching the
> generic implementations. This avoids the invalid source access and
> leaves the IV unchanged.
>
> Fixes: fadd7a6e616b ("crypto: mxs-dcp - Fix AES issues")
> Signed-off-by: Linmao Li <lilinmao@kylinos.cn>
> ---
Reviewed-by: Frank Li <Frank.Li@nxp.com>
> v2: Clarify commit message: describe zero-length return-0 as existing
> generic ECB/CBC behavior rather than a general API rule (Frank Li).
> drivers/crypto/mxs-dcp.c | 3 +++
> 1 file changed, 3 insertions(+)
>
> diff --git a/drivers/crypto/mxs-dcp.c b/drivers/crypto/mxs-dcp.c
> index 133ebc998236..60794b4d49fa 100644
> --- a/drivers/crypto/mxs-dcp.c
> +++ b/drivers/crypto/mxs-dcp.c
> @@ -473,6 +473,9 @@ static int mxs_dcp_aes_enqueue(struct skcipher_request *req, int enc, int ecb)
> struct dcp_aes_req_ctx *rctx = skcipher_request_ctx(req);
> int ret;
>
> + if (!req->cryptlen)
> + return 0;
> +
> if (unlikely(actx->key_len != AES_KEYSIZE_128 && !actx->key_referenced))
> return mxs_dcp_block_fallback(req, enc);
>
>
> base-commit: 8d3ae59288f1e7d58d76558a6ee96d533bc5019f
> --
> 2.25.1
>
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2026-09-09 21:03 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-09-08 9:44 [PATCH v2] crypto: mxs-dcp: handle zero-length skcipher requests Linmao Li
2026-09-08 9:57 ` sashiko-bot
2026-09-09 21:03 ` Frank Li
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox