From: sashiko-bot@kernel.org
To: "Bartosz Golaszewski" <bartosz.golaszewski@oss.qualcomm.com>
Cc: Frank.Li@kernel.org, dmaengine@vger.kernel.org, vkoul@kernel.org
Subject: Re: [PATCH v24 11/14] crypto: qce - Use existing devres APIs in devm_qce_dma_request()
Date: Thu, 23 Jul 2026 17:22:19 +0000 [thread overview]
Message-ID: <20260723172227.4AD2C1F000E9@smtp.kernel.org> (raw)
In-Reply-To: <20260723-qcom-qce-cmd-descr-v24-11-4f87bb4d9938@oss.qualcomm.com>
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
Pre-existing issues:
- [High] The `qce_req_done_work` workqueue can execute after DMA channels and buffers are freed and the mutex is destroyed during driver unbind or probe failure, leading to a Use-After-Free.
--
--- Patch [11]: [PATCH v24 11/14] crypto: qce - Use existing devres APIs in devm_qce_dma_request() ---
commit cf8f5860fd6dc6e67b916d54bc1e6df1f121860b
Author: Bartosz Golaszewski <brgl@kernel.org>
crypto: qce - Use existing devres APIs in devm_qce_dma_request()
This commit switches devm_qce_dma_request() to use devm_kmalloc() and
devm_dma_alloc_chan(). This allows dropping the manual release function
and shrinking the error handling paths.
> diff --git a/drivers/crypto/qce/dma.c b/drivers/crypto/qce/dma.c
> index d60efb5c26d88..26347e9fc078a 100644
> --- a/drivers/crypto/qce/dma.c
> +++ b/drivers/crypto/qce/dma.c
[ ... ]
> @@ -12,49 +12,34 @@
>
> #define QCE_IGNORE_BUF_SZ (2 * QCE_BAM_BURST_SIZE)
>
> -static void qce_dma_release(void *data)
> +static void qce_dma_terminate(void *data)
> {
> struct qce_dma_data *dma = data;
>
> dmaengine_terminate_sync(dma->txchan);
> dmaengine_terminate_sync(dma->rxchan);
> - dma_release_channel(dma->txchan);
> - dma_release_channel(dma->rxchan);
> - kfree(dma->result_buf);
> }
>
> int devm_qce_dma_request(struct qce_device *qce)
> {
> struct qce_dma_data *dma = &qce->dma;
> struct device *dev = qce->dev;
> - int ret;
>
> - dma->txchan = dma_request_chan(dev, "tx");
> + dma->result_buf = devm_kmalloc(dev, QCE_RESULT_BUF_SZ + QCE_IGNORE_BUF_SZ, GFP_KERNEL);
> + if (!dma->result_buf)
> + return -ENOMEM;
> +
> + dma->txchan = devm_dma_request_chan(dev, "tx");
> if (IS_ERR(dma->txchan))
> return dev_err_probe(dev, PTR_ERR(dma->txchan),
> "Failed to get TX DMA channel\n");
[Severity: High]
This is a pre-existing issue, but does relying on devm unwinding here expose
a use-after-free during driver unbind?
Because qce_cancel_work is registered via devm_add_action_or_reset() early
in qce_crypto_probe() (before the DMA and mutex allocations), devres LIFO
cleanup will run it last.
This means during unbind, devm_mutex_init() unwinds, followed by these
devm DMA and buffer allocations, and finally qce_cancel_work executes.
If a DMA callback fires just before qce_dma_terminate executes, it can
schedule qce->done_work on the system workqueue. The pending
qce_req_done_work() can then execute concurrently with or after these
resources are freed:
drivers/crypto/qce/core.c:qce_req_done_work() {
...
scoped_guard(mutex, &qce->lock) {
req = qce->req;
qce->req = NULL;
}
if (req)
crypto_request_complete(req, qce->result);
qce_handle_queue(qce, NULL);
}
Could this lead to locking a destroyed mutex and accessing the freed
DMA channels and memory buffer if userspace keeps an AF_ALG socket open
with pending requests?
> - dma->rxchan = dma_request_chan(dev, "rx");
> - if (IS_ERR(dma->rxchan)) {
> - ret = dev_err_probe(dev, PTR_ERR(dma->rxchan),
> - "Failed to get RX DMA channel\n");
> - goto error_rx;
> - }
> -
[ ... ]
--
Sashiko AI review · https://sashiko.dev/#/patchset/20260723-qcom-qce-cmd-descr-v24-0-4f87bb4d9938@oss.qualcomm.com?part=11
next prev parent reply other threads:[~2026-07-23 17:22 UTC|newest]
Thread overview: 23+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-07-23 17:09 [PATCH v24 00/14] crypto/dmaengine: qce: introduce BAM locking and use DMA for register I/O Bartosz Golaszewski
2026-07-23 17:09 ` [PATCH v24 01/14] dmaengine: constify struct dma_descriptor_metadata_ops Bartosz Golaszewski
2026-07-23 17:09 ` [PATCH v24 02/14] dmaengine: qcom: bam_dma: free interrupt before the clock in error path Bartosz Golaszewski
2026-07-23 17:26 ` sashiko-bot
2026-07-23 17:09 ` [PATCH v24 03/14] dmaengine: qcom: bam_dma: convert tasklet to a BH workqueue Bartosz Golaszewski
2026-07-23 17:25 ` sashiko-bot
2026-07-23 17:09 ` [PATCH v24 04/14] dmaengine: qcom: bam_dma: Extend the driver's device match data Bartosz Golaszewski
2026-07-23 17:09 ` [PATCH v24 05/14] dmaengine: qcom: bam_dma: Add pipe_lock_supported flag support Bartosz Golaszewski
2026-07-23 17:09 ` [PATCH v24 06/14] dmaengine: qcom: bam_dma: add support for BAM locking Bartosz Golaszewski
2026-07-23 17:28 ` sashiko-bot
2026-07-23 17:09 ` [PATCH v24 07/14] crypto: qce - Cancel work on device detach Bartosz Golaszewski
2026-07-23 17:23 ` sashiko-bot
2026-07-23 17:09 ` [PATCH v24 08/14] crypto: qce - Include algapi.h in the core.h header Bartosz Golaszewski
2026-07-23 17:09 ` [PATCH v24 09/14] crypto: qce - Remove unused ignore_buf Bartosz Golaszewski
2026-07-23 17:09 ` [PATCH v24 10/14] crypto: qce - Simplify arguments of devm_qce_dma_request() Bartosz Golaszewski
2026-07-23 17:09 ` [PATCH v24 11/14] crypto: qce - Use existing devres APIs in devm_qce_dma_request() Bartosz Golaszewski
2026-07-23 17:22 ` sashiko-bot [this message]
2026-07-23 17:09 ` [PATCH v24 12/14] crypto: qce - Map crypto memory for DMA Bartosz Golaszewski
2026-07-23 17:23 ` sashiko-bot
2026-07-23 17:09 ` [PATCH v24 13/14] crypto: qce - Add BAM DMA support for crypto register I/O Bartosz Golaszewski
2026-07-23 17:32 ` sashiko-bot
2026-07-23 17:09 ` [PATCH v24 14/14] crypto: qce - Communicate the base physical address to the dmaengine Bartosz Golaszewski
2026-07-23 17:27 ` [PATCH v24 00/14] crypto/dmaengine: qce: introduce BAM locking and use DMA for register I/O Eric Biggers
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=20260723172227.4AD2C1F000E9@smtp.kernel.org \
--to=sashiko-bot@kernel.org \
--cc=Frank.Li@kernel.org \
--cc=bartosz.golaszewski@oss.qualcomm.com \
--cc=dmaengine@vger.kernel.org \
--cc=sashiko-reviews@lists.linux.dev \
--cc=vkoul@kernel.org \
/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