dri-devel Archive on lore.kernel.org
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Kishore Batta" <kishore.batta@oss.qualcomm.com>
Cc: dri-devel@lists.freedesktop.org
Subject: Re: [PATCH v6 3/7] bus: mhi: Centralize Sahara firmware image table selection at probe time
Date: Wed, 01 Jul 2026 10:47:44 +0000	[thread overview]
Message-ID: <20260701104744.D3FBE1F00A3A@smtp.kernel.org> (raw)
In-Reply-To: <20260701-sahara_protocol_new_v2-v6-3-3a78362c4741@oss.qualcomm.com>

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

Pre-existing issues:
- [High] Missing cancellation of `read_data_work` during device removal leads to a Use-After-Free.
- [High] Lack of synchronization between concurrent device command processing and data streaming leads to Use-After-Free and TX buffer corruption.
--

commit 812426ed0db5b6e824926f5d8eecb24c749a578e
Author: Kishore Batta <kishore.batta@oss.qualcomm.com>

bus: mhi: Centralize Sahara firmware image table selection at probe time

This commit refactors the Sahara driver to select firmware image tables using
a controller provided mapping table at probe time. It centralizes device
specific conditionals that were previously scattered across the driver. This
prepares the driver for extending support to new devices.

[ ... ]

> diff --git a/drivers/bus/mhi/host/clients/sahara/sahara.c b/drivers/bus/mhi/host/clients/sahara/sahara.c
> index 858dc5bc39c1a..e339c67e236af 100644
> --- a/drivers/bus/mhi/host/clients/sahara/sahara.c
> +++ b/drivers/bus/mhi/host/clients/sahara/sahara.c
> @@ -179,48 +179,7 @@ struct sahara_context {
>  	u32				read_data_length;
>  	bool				is_mem_dump_mode;
>  	bool				non_streaming;
[ ... ]
> +	const char			*fw_folder;
>  };

[Severity: High]
This is a pre-existing issue, but can the device removal path cause a
use-after-free here?

In drivers/bus/mhi/host/clients/sahara/sahara.c:sahara_mhi_remove(),
the teardown cancels other work items:

    cancel_work_sync(&context->fw_work);
    cancel_work_sync(&context->dump_work);
    cancel_work_sync(&context->cmd_work);

However, it seems cancel_work_sync(&context->read_data_work) is omitted.
If a device in streaming mode is actively transferring firmware data via
read_data_work, and the driver is unbound, devres will free the device-managed
context structure. 

Will the pending or sleeping sahara_read_data_processing() work item then
continue to run and access the freed context and its firmware buffer?

[Severity: High]
This is a pre-existing issue, but is there a lack of synchronization between
concurrent device command processing and data streaming that could corrupt
the TX buffer?

If read_data_work is running to stream a firmware image, and a faulty or
compromised device sends an out-of-band message (like END_OF_IMAGE_CMD) on
the downlink channel, fw_work will run concurrently with read_data_work.

fw_work calls sahara_end_of_image(), which frees context->firmware and writes a
response to context->tx[0]:

    sahara_release_image(context);
    ...
    context->tx[0]->cmd = cpu_to_le32(SAHARA_DONE_CMD);

Concurrently, read_data_helper() executed from read_data_work accesses the
freed firmware and writes to the same TX buffer:

    memcpy(context->tx[buf_index],
           &context->firmware->data[context->read_data_offset],
           pkt_data_len);

Does this sequence result in a use-after-free and packet corruption before
queuing it to MHI?

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20260701-sahara_protocol_new_v2-v6-0-3a78362c4741@oss.qualcomm.com?part=3

  reply	other threads:[~2026-07-01 10:47 UTC|newest]

Thread overview: 28+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-07-01 10:37 [PATCH v6 0/7] Qualcomm Sahara protocol enhancements Kishore Batta
2026-07-01 10:37 ` [PATCH v6 1/7] Add documentation for Sahara protocol Kishore Batta
2026-07-01 10:42   ` sashiko-bot
2026-07-08  4:46   ` Randy Dunlap
2026-07-13  7:20     ` Kishore Batta
2026-07-01 10:37 ` [PATCH v6 2/7] bus: mhi: Move Sahara protocol driver under MHI host client drivers Kishore Batta
2026-07-01 10:50   ` sashiko-bot
2026-07-01 10:37 ` [PATCH v6 3/7] bus: mhi: Centralize Sahara firmware image table selection at probe time Kishore Batta
2026-07-01 10:47   ` sashiko-bot [this message]
2026-07-01 10:37 ` [PATCH v6 4/7] bus: mhi: Add QDU100 Sahara variant and firmware fallback Kishore Batta
2026-07-01 10:53   ` sashiko-bot
2026-07-09  6:19   ` Manivannan Sadhasivam
2026-07-13  7:25     ` Kishore Batta
2026-07-13 17:11       ` Manivannan Sadhasivam
2026-07-13 14:16     ` Kishore Batta
2026-07-13 16:19       ` Manivannan Sadhasivam
2026-07-01 10:37 ` [PATCH v6 5/7] bus: mhi: Load DDR training data using device serial number Kishore Batta
2026-07-01 10:57   ` sashiko-bot
2026-07-09  6:21   ` Manivannan Sadhasivam
2026-07-13  7:27     ` Kishore Batta
2026-07-01 10:37 ` [PATCH v6 6/7] bus: mhi: Capture DDR training data via command mode Kishore Batta
2026-07-01 10:51   ` sashiko-bot
2026-07-01 10:37 ` [PATCH v6 7/7] bus: mhi: Expose DDR training data via controller sysfs Kishore Batta
2026-07-01 10:52   ` sashiko-bot
2026-07-09  6:57   ` Manivannan Sadhasivam
2026-07-13  7:30     ` Kishore Batta
2026-07-13 17:08       ` Manivannan Sadhasivam
2026-07-22 12:22   ` Manivannan Sadhasivam

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=20260701104744.D3FBE1F00A3A@smtp.kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=dri-devel@lists.freedesktop.org \
    --cc=kishore.batta@oss.qualcomm.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