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 5/7] bus: mhi: Load DDR training data using device serial number
Date: Wed, 01 Jul 2026 10:57:03 +0000	[thread overview]
Message-ID: <20260701105703.ED7D21F000E9@smtp.kernel.org> (raw)
In-Reply-To: <20260701-sahara_protocol_new_v2-v6-5-3a78362c4741@oss.qualcomm.com>

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

Pre-existing issues:
- [Critical] On 32-bit systems, `dump_length` is truncated during `vzalloc`, leading to a massive heap buffer overflow when parsing memory dumps.
- [High] Lack of synchronization between `fw_work` and `read_data_work` allows a malicious or misbehaving device to trigger a Use-After-Free of firmware data.
- [High] Missing `cancel_work_sync` for `read_data_work` during driver removal leads to a Use-After-Free.
--

commit 089e41c25a9507e0cb3ce33fb65d0e86f16f5c04
Author: Kishore Batta <kishore.batta@oss.qualcomm.com>

bus: mhi: Load DDR training data using device serial number

This commit extends the firmware loading logic to first attempt loading a 
per-device DDR training image derived from the device's serial number. It
falls back to the default image if the per-device one is missing.

> diff --git a/drivers/bus/mhi/host/clients/sahara/sahara.c b/drivers/bus/mhi/host/clients/sahara/sahara.c
> --- a/drivers/bus/mhi/host/clients/sahara/sahara.c
> +++ b/drivers/bus/mhi/host/clients/sahara/sahara.c
> @@ -226,6 +227,27 @@ static int sahara_find_image(struct sahara_context *context, u32 image_id)
>  		return 0;
>  	}
>  
> +	/* DDR training special case: Try per-serial number file first */
> +	if (image_id == SAHARA_DDR_TRAINING_IMG_ID && context->fw_folder) {
> +		u32 serial_num = context->mhi_dev->mhi_cntrl->serial_number;
> +
> +		fw_path = kasprintf(GFP_KERNEL,
> +				    "qcom/%s/mdmddr_0x%x.mbn",
> +				    context->fw_folder, serial_num);
[ ... ]

While reviewing this driver, I noticed a few pre-existing issues in the same
file that might need attention.

[Severity: High]
This is a pre-existing issue, but is there a lack of synchronization between
fw_work and read_data_work that could allow a use-after-free of the firmware
data?

If a compromised device sends an end of image packet while streaming data,
fw_work executes sahara_end_of_image() and calls sahara_release_image(),
which frees the firmware:

drivers/bus/mhi/host/clients/sahara/sahara.c:sahara_release_image() {
    ...
    release_firmware(context->firmware);
    ...
}

Concurrently, read_data_work streams data using read_data_helper(), which
copies from the freed context->firmware->data:

drivers/bus/mhi/host/clients/sahara/sahara.c:read_data_helper() {
    ...
    memcpy(context->tx[buf_index],
           &context->firmware->data[context->read_data_offset],
           pkt_data_len);
    ...
}

Could this lead to memory corruption if a malicious device sends out-of-order
protocol packets?


[Severity: High]
This is a pre-existing issue, but does sahara_mhi_remove() fail to cancel
read_data_work before the context is freed?

drivers/bus/mhi/host/clients/sahara/sahara.c:sahara_mhi_remove() {
    ...
    sahara_release_image(context);
    mhi_unprepare_from_transfer(mhi_dev);
    ...
}

Since read_data_work is not canceled with cancel_work_sync(), can it continue
to execute concurrently after the device is removed?

The context structure is allocated with devm_kzalloc and will be freed when
the remove function returns, potentially resulting in a use-after-free if the
driver is unbound or the device is removed while streaming data.


[Severity: Critical]
This is a pre-existing issue, but on 32-bit systems, does this code truncate
dump_length during allocation?

In sahara_parse_dump_table(), dump_length is a 64-bit value representing the
total size of memory dumps:

drivers/bus/mhi/host/clients/sahara/sahara.c:sahara_parse_dump_table() {
    ...
    context->mem_dump_sz = dump_length;
    context->mem_dump = vzalloc(dump_length);
    ...
}

Because vzalloc() takes a 32-bit unsigned long on 32-bit systems, a length
greater than 4GB will be silently truncated.

However, the driver then proceeds to stream the full 64-bit length of data
from the device, copying it into the under-allocated buffer:

drivers/bus/mhi/host/clients/sahara/sahara.c:sahara_parse_dump_image() {
    ...
    memcpy(context->mem_dump_freespace, context->rx, context->rx_size);
    ...
}

Could a compromised MHI peripheral providing a crafted dump table trigger a
heap buffer overflow?

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

  reply	other threads:[~2026-07-01 10:57 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
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 [this message]
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=20260701105703.ED7D21F000E9@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