From: sashiko-bot@kernel.org
To: "Guangshuo Li" <liguangshuo@mail.sdu.edu.cn>
Cc: linux-sound@vger.kernel.org
Subject: Re: [PATCH] slimbus: qcom-ngd-ctrl: Fix potential DMA buffer leaks on teardown
Date: Wed, 18 Nov 2026 14:31:07 +0000 [thread overview]
Message-ID: <sashiko-outbox-221213@kernel.org> (raw)
In-Reply-To: <20261118-324f82bd41-slimbus-qcom-0@mail.sdu.edu.cn>
Thank you for your contribution! Sashiko AI review found 1 potential
issue to consider:
- [High] slimbus: qcom-ngd-ctrl: NULL deref and UAF after
qcom_slim_ngd_exit_dma()
--
commit 2b691a90537a94bfedb91b63d4fb5eae146f115d
Author: Guangshuo Li <liguangshuo@mail.sdu.edu.cn>
slimbus: qcom-ngd-ctrl: Fix potential DMA buffer leaks on teardown
This commit frees the coherent RX and TX DMA message buffers during DMA
teardown and clears the released DMA channel pointers on initialization
failure.
> diff --git a/drivers/slimbus/qcom-ngd-ctrl.c b/drivers/slimbus/qcom-ngd-ctrl.c
> index eb983b6d1815f..e604f4e2b7624 100644
> --- a/drivers/slimbus/qcom-ngd-ctrl.c
> +++ b/drivers/slimbus/qcom-ngd-ctrl.c
[ ... ]
> @@ -1210,11 +1214,19 @@ static int qcom_slim_ngd_exit_dma(struct qcom_slim_ngd_ctrl *ctrl)
> {
> if (ctrl->dma_rx_channel) {
> dmaengine_terminate_sync(ctrl->dma_rx_channel);
> + dma_free_coherent(ctrl->dev,
> + QCOM_SLIM_NGD_DESC_NUM * SLIM_MSGQ_BUF_LEN,
> + ctrl->rx_base, ctrl->rx_phys_base);
> + ctrl->rx_base = NULL;
> dma_release_channel(ctrl->dma_rx_channel);
> }
>
> if (ctrl->dma_tx_channel) {
> dmaengine_terminate_sync(ctrl->dma_tx_channel);
> + dma_free_coherent(ctrl->dev,
> + (QCOM_SLIM_NGD_DESC_NUM + 1) * SLIM_MSGQ_BUF_LEN,
> + ctrl->tx_base, ctrl->tx_phys_base);
> + ctrl->tx_base = NULL;
> dma_release_channel(ctrl->dma_tx_channel);
> }
[Severity: High]
Can freeing ctrl->tx_base and setting it to NULL here cause a NULL pointer
dereference or use-after-free in qcom_slim_ngd_xfer_msg()?
qcom_slim_ngd_tx_msg_get() computes the descriptor buffer address from
ctrl->tx_base without checking whether ctrl->tx_base is NULL:
drivers/slimbus/qcom-ngd-ctrl.c:qcom_slim_ngd_tx_msg_get() {
...
desc = &ctrl->txdesc[ctrl->tx_tail];
desc->base = ctrl->tx_base + ctrl->tx_tail * SLIM_MSGQ_BUF_LEN;
desc->comp = comp;
ctrl->tx_tail = (ctrl->tx_tail + 1) % QCOM_SLIM_NGD_DESC_NUM;
spin_unlock_irqrestore(&ctrl->tx_buf_lock, flags);
return desc->base;
}
When ctrl->tx_base is NULL and ctrl->tx_tail is non-zero (or on the second
call after the first call advances ctrl->tx_tail from 0 to 1),
qcom_slim_ngd_tx_msg_get() returns a non-NULL small offset pointer, which
qcom_slim_ngd_xfer_msg() immediately dereferences at *pbuf = 0.
This is reachable when qcom_slim_ngd_runtime_suspend() calls
qcom_slim_ngd_exit_dma() and the subsequent qcom_slim_qmi_power_request()
fails (such as with -EBUSY), aborting suspend while ctrl->state remains
QCOM_SLIM_NGD_CTRL_IDLE with ctrl->tx_base set to NULL; or when
qcom_slim_ngd_runtime_resume() returns 0 after qcom_slim_ngd_power_up()
fails before reinitializing DMA.
In addition, qcom_slim_ngd_exit_dma() frees ctrl->tx_base without holding
ctrl->tx_buf_lock or ctrl->tx_lock and before ctrl->m_work is flushed, so a
concurrent transfer can also write into the freed coherent buffer:
CPU0 CPU1
qcom_slim_ngd_xfer_msg()
pbuf = qcom_slim_ngd_tx_msg_get()
qcom_slim_ngd_exit_dma()
dma_free_coherent(..., ctrl->tx_base, ...)
ctrl->tx_base = NULL;
*pbuf = 0; <-- use-after-free
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261118-324f82bd41-slimbus-qcom-0@mail.sdu.edu.cn?part=1
prev parent reply other threads:[~2026-11-18 14:31 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-18 14:16 [PATCH] slimbus: qcom-ngd-ctrl: Fix potential DMA buffer leaks on teardown Guangshuo Li
2026-11-18 14:31 ` sashiko-bot [this message]
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-221213@kernel.org \
--to=sashiko-bot@kernel.org \
--cc=liguangshuo@mail.sdu.edu.cn \
--cc=linux-sound@vger.kernel.org \
--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