All of lore.kernel.org
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Bartosz Golaszewski" <bartosz.golaszewski@oss.qualcomm.com>
Cc: dmaengine@vger.kernel.org, Frank.Li@kernel.org, vkoul@kernel.org
Subject: Re: [PATCH v23 07/14] crypto: qce - Cancel work on device detach
Date: Tue, 21 Jul 2026 13:47:46 +0000	[thread overview]
Message-ID: <20260721134747.3C39E1F00A3A@smtp.kernel.org> (raw)
In-Reply-To: <20260721-qcom-qce-cmd-descr-v23-7-1be02deffda9@oss.qualcomm.com>

Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider:

New issues:
- [High] Incorrect devres registration order causes Use-After-Free and Use-After-Destroy vulnerabilities during driver teardown.

Pre-existing issues:
- [High] The driver acquires a sleeping lock (`mutex`) in a crypto enqueue path that can be called from atomic contexts.
--

--- Patch [7]: [PATCH v23 07/14] crypto: qce - Cancel work on device detach ---
commit c537ce289434b17e2b6ebcb9c83403711f835f30
Author: Bartosz Golaszewski <bartosz.golaszewski@oss.qualcomm.com>

crypto: qce - Cancel work on device detach

The patch adds a devres action to cancel the done_work workqueue on device
detach or probe error. It moves the work initialization earlier and ensures
DMA transfers are terminated during DMA release.

Closes: https://sashiko.dev/#/patchset/20260427-qcom-qce-cmd-descr-v16-0-945fd1cafbbc%40oss.qualcomm.com?part=7

> diff --git a/drivers/crypto/qce/core.c b/drivers/crypto/qce/core.c
> index ac74f69914d61..b52a26ffff5ee 100644
> --- a/drivers/crypto/qce/core.c
> +++ b/drivers/crypto/qce/core.c

[ ... ]

> @@ -226,6 +233,11 @@ static int qce_crypto_probe(struct platform_device *pdev)
>  	if (ret)
>  		return ret;
>  
> +	INIT_WORK(&qce->done_work, qce_req_done_work);
> +	ret = devm_add_action_or_reset(dev, qce_cancel_work, &qce->done_work);
> +	if (ret)
> +		return ret;
> +

[Severity: High]
Will registering the devres action for work cancellation here cause a
use-after-free and use-after-destroy during driver teardown?

Because devres actions are executed in reverse order (LIFO), registering
the work cancellation before DMA and mutex initialization means the work
will be cancelled last during unbind or probe failure.

The teardown sequence would be:
1. mutex_destroy(&qce->lock)
2. qce_dma_release() (terminates DMA, releases channels, frees dma->result_buf)
3. qce_cancel_work()

If qce_req_done_work() is already scheduled or executing concurrently,
it will attempt to acquire the destroyed qce->lock, then dequeue
pending requests and submit new operations using the freed DMA channels
and result_buf.

>  	ret = devm_qce_dma_request(qce->dev, &qce->dma);
>  	if (ret)
>  		return ret;
> @@ -238,7 +250,6 @@ static int qce_crypto_probe(struct platform_device *pdev)
>  	if (ret)
>  		return ret;
>  
> -	INIT_WORK(&qce->done_work, qce_req_done_work);
>  	crypto_init_queue(&qce->queue, QCE_QUEUE_LENGTH);
>  
>  	qce->async_req_enqueue = qce_async_request_enqueue;

[Severity: High]
This is a pre-existing issue, but could qce_async_request_enqueue() trigger
a kernel warning by acquiring a sleeping lock in an atomic context?

The crypto API allows asynchronous algorithms to have their enqueue functions
invoked from atomic contexts, such as a softirq. However,
qce_async_request_enqueue() calls qce_handle_queue(), which attempts to
acquire a mutex:

drivers/crypto/qce/core.c:qce_handle_queue() {
	...
	scoped_guard(mutex, &qce->lock) {
		...
	}
	...
}

Can this result in a "BUG: sleeping function called from invalid context"
when processing network traffic like IPsec in softirq?

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20260721-qcom-qce-cmd-descr-v23-0-1be02deffda9@oss.qualcomm.com?part=7

  reply	other threads:[~2026-07-21 13:47 UTC|newest]

Thread overview: 37+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-07-21 13:33 [PATCH v23 00/14] crypto/dmaengine: qce: introduce BAM locking and use DMA for register I/O Bartosz Golaszewski
2026-07-21 13:33 ` [PATCH v23 01/14] dmaengine: constify struct dma_descriptor_metadata_ops Bartosz Golaszewski
2026-07-21 13:33 ` [PATCH v23 02/14] dmaengine: qcom: bam_dma: free interrupt before the clock in error path Bartosz Golaszewski
2026-07-21 13:48   ` sashiko-bot
2026-07-21 13:33 ` [PATCH v23 03/14] dmaengine: qcom: bam_dma: convert tasklet to a BH workqueue Bartosz Golaszewski
2026-07-21 13:52   ` sashiko-bot
2026-07-21 13:33 ` [PATCH v23 04/14] dmaengine: qcom: bam_dma: Extend the driver's device match data Bartosz Golaszewski
2026-07-21 13:33 ` [PATCH v23 05/14] dmaengine: qcom: bam_dma: Add pipe_lock_supported flag support Bartosz Golaszewski
2026-07-21 13:45   ` sashiko-bot
2026-07-21 13:33 ` [PATCH v23 06/14] dmaengine: qcom: bam_dma: add support for BAM locking Bartosz Golaszewski
2026-07-21 13:48   ` sashiko-bot
2026-07-22  8:59     ` Stephan Gerhold
2026-07-22  9:34       ` Bartosz Golaszewski
2026-07-22 12:47         ` Stephan Gerhold
2026-07-22 14:11           ` Bartosz Golaszewski
2026-07-22 14:20             ` Stephan Gerhold
2026-07-22 15:37               ` Bartosz Golaszewski
2026-07-22 16:24                 ` Stephan Gerhold
2026-07-21 18:07   ` Mukesh Savaliya
2026-07-21 13:33 ` [PATCH v23 07/14] crypto: qce - Cancel work on device detach Bartosz Golaszewski
2026-07-21 13:47   ` sashiko-bot [this message]
2026-07-21 13:33 ` [PATCH v23 08/14] crypto: qce - Include algapi.h in the core.h header Bartosz Golaszewski
2026-07-21 13:33 ` [PATCH v23 09/14] crypto: qce - Remove unused ignore_buf Bartosz Golaszewski
2026-07-21 13:46   ` sashiko-bot
2026-07-21 13:33 ` [PATCH v23 10/14] crypto: qce - Simplify arguments of devm_qce_dma_request() Bartosz Golaszewski
2026-07-21 13:44   ` sashiko-bot
2026-07-21 13:33 ` [PATCH v23 11/14] crypto: qce - Use existing devres APIs in devm_qce_dma_request() Bartosz Golaszewski
2026-07-21 13:47   ` sashiko-bot
2026-07-21 18:16   ` Mukesh Savaliya
2026-07-21 13:33 ` [PATCH v23 12/14] crypto: qce - Map crypto memory for DMA Bartosz Golaszewski
2026-07-21 13:48   ` sashiko-bot
2026-07-21 18:20   ` Mukesh Savaliya
2026-07-22  9:17     ` Bartosz Golaszewski
2026-07-21 13:33 ` [PATCH v23 13/14] crypto: qce - Add BAM DMA support for crypto register I/O Bartosz Golaszewski
2026-07-21 13:50   ` sashiko-bot
2026-07-21 13:33 ` [PATCH v23 14/14] crypto: qce - Communicate the base physical address to the dmaengine Bartosz Golaszewski
2026-07-21 13:55   ` 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=20260721134747.3C39E1F00A3A@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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.