From: Atul Akella <atul.akella@gmail.com>
To: linux-remoteproc@vger.kernel.org
Cc: Atul Akella <atul.akella@gmail.com>,
stable@vger.kernel.org, Bjorn Andersson <andersson@kernel.org>,
Mathieu Poirier <mathieu.poirier@linaro.org>,
Matthias Brugger <matthias.bgg@gmail.com>,
AngeloGioacchino Del Regno
<angelogioacchino.delregno@collabora.com>,
Tzung-Bi Shih <tzungbi@kernel.org>,
linux-kernel@vger.kernel.org,
linux-arm-kernel@lists.infradead.org,
linux-mediatek@lists.infradead.org
Subject: [PATCH 2/2] remoteproc: mtk_scp: Fix bounds check in mt8192_scp_da_to_va()
Date: Mon, 5 Oct 2026 11:25:18 +0000 [thread overview]
Message-ID: <bc3f565d08f6948aed9172c01c7c38b4cafa2ec1.1791198233.git.atul.akella@gmail.com> (raw)
In-Reply-To: <cover.1791198233.git.atul.akella@gmail.com>
mt8192_scp_da_to_va() translates a device address to a pointer into
SCP SRAM, L1TCM or DRAM. Its bounds checks have two problems:
- (da + len) is computed in u64 and wraps for a large da or len.
With da = 0xfffffffffffffff0 and len = 0x20, the sum is 0x10 and
passes "<= base + size" while da >= base also holds.
- offset is an int but is assigned from a u64 difference, so it is
truncated before being added to the region's base pointer.
da and len come from the firmware's ELF program headers
(p_paddr/p_memsz) via rproc_da_to_va(), and the returned pointer is
then written to by the ELF loader, so a malformed firmware image can
make the loader write outside the intended region.
Use a u64 offset and compare len against the remaining region size
instead of adding it to da. Apply this to the SRAM, L1TCM and DRAM
regions.
Fixes: ca23ecfdbd44 ("remoteproc/mediatek: support L1TCM")
Cc: stable@vger.kernel.org
Signed-off-by: Atul Akella <atul.akella@gmail.com>
---
drivers/remoteproc/mtk_scp.c | 24 ++++++++++++------------
1 file changed, 12 insertions(+), 12 deletions(-)
diff --git a/drivers/remoteproc/mtk_scp.c b/drivers/remoteproc/mtk_scp.c
index d18ae676260a..b1d83265fc26 100644
--- a/drivers/remoteproc/mtk_scp.c
+++ b/drivers/remoteproc/mtk_scp.c
@@ -775,30 +775,30 @@ static void *mt8183_scp_da_to_va(struct mtk_scp *scp, u64 da, size_t len)
static void *mt8192_scp_da_to_va(struct mtk_scp *scp, u64 da, size_t len)
{
- int offset;
+ u64 offset;
const struct mtk_scp_sizes_data *scp_sizes;
scp_sizes = scp->data->scp_sizes;
- if (da >= scp->sram_phys &&
- (da + len) <= scp->sram_phys + scp->sram_size) {
+ if (da >= scp->sram_phys) {
offset = da - scp->sram_phys;
- return (void __force *)scp->sram_base + offset;
+ if (offset <= scp->sram_size && len <= scp->sram_size - offset)
+ return (void __force *)scp->sram_base + offset;
}
/* optional memory region */
- if (scp->cluster->l1tcm_size &&
- da >= scp->cluster->l1tcm_phys &&
- (da + len) <= scp->cluster->l1tcm_phys + scp->cluster->l1tcm_size) {
+ if (scp->cluster->l1tcm_size && da >= scp->cluster->l1tcm_phys) {
offset = da - scp->cluster->l1tcm_phys;
- return (void __force *)scp->cluster->l1tcm_base + offset;
+ if (offset <= scp->cluster->l1tcm_size &&
+ len <= scp->cluster->l1tcm_size - offset)
+ return (void __force *)scp->cluster->l1tcm_base + offset;
}
/* optional memory region */
- if (scp_sizes->max_dram_size &&
- da >= scp->dma_addr &&
- (da + len) <= scp->dma_addr + scp_sizes->max_dram_size) {
+ if (scp_sizes->max_dram_size && da >= scp->dma_addr) {
offset = da - scp->dma_addr;
- return scp->cpu_addr + offset;
+ if (offset <= scp_sizes->max_dram_size &&
+ len <= scp_sizes->max_dram_size - offset)
+ return scp->cpu_addr + offset;
}
return NULL;
--
2.43.0
prev parent reply other threads:[~2026-10-05 11:26 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <cover.1791198233.git.atul.akella@gmail.com>
2026-10-05 11:25 ` [PATCH 1/2] remoteproc: mtk_scp: Fix bounds check in mt8183_scp_da_to_va() Atul Akella
2026-10-05 11:25 ` Atul Akella [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=bc3f565d08f6948aed9172c01c7c38b4cafa2ec1.1791198233.git.atul.akella@gmail.com \
--to=atul.akella@gmail.com \
--cc=andersson@kernel.org \
--cc=angelogioacchino.delregno@collabora.com \
--cc=linux-arm-kernel@lists.infradead.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mediatek@lists.infradead.org \
--cc=linux-remoteproc@vger.kernel.org \
--cc=mathieu.poirier@linaro.org \
--cc=matthias.bgg@gmail.com \
--cc=stable@vger.kernel.org \
--cc=tzungbi@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
all inboxes | Powered by JetHome®