From: Konrad Dybcio <konrad.dybcio@oss.qualcomm.com>
To: Oleksandr Suvorov <cryosay@gmail.com>,
Bjorn Andersson <andersson@kernel.org>,
Konrad Dybcio <konradybcio@kernel.org>
Cc: linux-arm-msm@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH] soc: qcom: cmd-db: bound database walks to the mapped region
Date: Wed, 14 Oct 2026 09:24:49 +0200 [thread overview]
Message-ID: <bb87b142-075d-48b6-a737-f13170d76d5e@oss.qualcomm.com> (raw)
In-Reply-To: <20261013091611.2592612-1-cryosay@gmail.com>
On 10/13/26 11:16 AM, Oleksandr Suvorov wrote:
> The command DB is read from a reserved memory region mapped with the
> size given in the device tree. The per-slave entry count and header
> offset, and each entry's data offset and length, are taken from the
> blob and used without checking them against the size of that mapping.
>
> cmd_db_get_header() walks rsc_hdr->cnt entries for every slave when an
> ID is not found, and cmd_db_read_aux_data() and the debugfs dump return
> or print len bytes at a blob-supplied offset. A count or offset that
> reaches beyond the mapping makes these read outside it.
>
> Keep the mapped size from probe and add cmd_db_in_bounds() to check a
> range against it. Skip a slave whose entry array is out of range,
> return -EINVAL from cmd_db_read_aux_data() for out-of-range data, and
> mark such entries in the debugfs dump. Warn once for the first two.
>
> Also set the size before cmd_db_header becomes visible to callers, so
> a lookup never sees a header with a zero size.
>
> Signed-off-by: Oleksandr Suvorov <cryosay@gmail.com>
>
> ---
GPT also suggests this additional diff to block a smaller-than-the-header
cmd-db region:
rmem = of_reserved_mem_lookup(pdev->dev.of_node);
if (!rmem) {
dev_err(&pdev->dev, "failed to acquire memory region\n");
return -EINVAL;
}
+ if (rmem->size < offsetof(struct cmd_db_header, data)) {
+ dev_err(&pdev->dev, "Command DB region is too small\n");
+ return -EINVAL;
+ }
+
header = devm_memremap(&pdev->dev, rmem->base, rmem->size, MEMREMAP_WC);
Konrad
prev parent reply other threads:[~2026-10-14 7:24 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-10-13 9:16 Oleksandr Suvorov
2026-10-14 7:24 ` Konrad Dybcio [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=bb87b142-075d-48b6-a737-f13170d76d5e@oss.qualcomm.com \
--to=konrad.dybcio@oss.qualcomm.com \
--cc=andersson@kernel.org \
--cc=cryosay@gmail.com \
--cc=konradybcio@kernel.org \
--cc=linux-arm-msm@vger.kernel.org \
--cc=linux-kernel@vger.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®