From: Mukesh Ojha <quic_mojha@quicinc.com>
To: Auditya Bhattaram <quic_audityab@quicinc.com>,
<andersson@kernel.org>, <konrad.dybcio@linaro.org>
Cc: <linux-arm-msm@vger.kernel.org>, <linux-kernel@vger.kernel.org>,
<stable@vger.kernel.org>
Subject: Re: [PATCH v3] soc: qcom: mdt_loader: Add Upperbounds check for program header access
Date: Thu, 8 Feb 2024 19:59:20 +0530 [thread overview]
Message-ID: <b1991baf-e642-f811-14b0-ccd7c0cd56ec@quicinc.com> (raw)
In-Reply-To: <20240208123527.19725-1-quic_audityab@quicinc.com>
On 2/8/2024 6:05 PM, Auditya Bhattaram wrote:
> hash_index is evaluated by looping phdrs till QCOM_MDT_TYPE_HASH
> is found. Add an upperbound check to phdrs to access within elf size.
>
> Fixes: 64fb5eb87d58 ("soc: qcom: mdt_loader: Allow hash to reside in any segment")
> Cc: <stable@vger.kernel.org>
> Signed-off-by: Auditya Bhattaram <quic_audityab@quicinc.com>
> ---
> Changes in v3:
> - Corrected wrong patch versioning in the Subject.
> - Added error prints for Invalid access.
> Link to v2 https://lore.kernel.org/linux-arm-msm/9773d189-c896-d5c5-804c-e086c24987b4@quicinc.com/T/#t
> Link to v1 https://lore.kernel.org/linux-arm-msm/5d7a3b97-d840-4863-91a0-32c1d8e7532f@linaro.org/T/#t
> ---
> drivers/soc/qcom/mdt_loader.c | 5 +++++
> 1 file changed, 5 insertions(+)
>
> diff --git a/drivers/soc/qcom/mdt_loader.c b/drivers/soc/qcom/mdt_loader.c
> index 6f177e46fa0f..61e2377cc5c3 100644
> --- a/drivers/soc/qcom/mdt_loader.c
> +++ b/drivers/soc/qcom/mdt_loader.c
> @@ -145,6 +145,11 @@ void *qcom_mdt_read_metadata(const struct firmware *fw, size_t *data_len,
> if (phdrs[0].p_type == PT_LOAD)
> return ERR_PTR(-EINVAL);
>
> + if (((size_t)(phdrs + ehdr->e_phnum)) > ((size_t)ehdr + fw->size)) {
This change is valid only if somehow, ehdr->e_phnum gets corrupted or
changed via some engineering means and results in out-of-bounds access.
Acked-by: Mukesh Ojha <quic_mojha@quicinc.com>
> + dev_err(dev, "Invalid phdrs access: %s\n", fw_name);
Should it print ehdr->e_phnum as well to be more valid?
-Mukesh
> + return ERR_PTR(-EINVAL);
> + }
> +
> for (i = 1; i < ehdr->e_phnum; i++) {
> if ((phdrs[i].p_flags & QCOM_MDT_TYPE_MASK) == QCOM_MDT_TYPE_HASH) {
> hash_segment = i;
> --
> 2.17.1
>
>
next prev parent reply other threads:[~2024-02-08 14:29 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-02-08 12:35 [PATCH v3] soc: qcom: mdt_loader: Add Upperbounds check for program header access Auditya Bhattaram
2024-02-08 14:29 ` Mukesh Ojha [this message]
2024-02-09 5:45 ` Auditya Bhattaram
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=b1991baf-e642-f811-14b0-ccd7c0cd56ec@quicinc.com \
--to=quic_mojha@quicinc.com \
--cc=andersson@kernel.org \
--cc=konrad.dybcio@linaro.org \
--cc=linux-arm-msm@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=quic_audityab@quicinc.com \
--cc=stable@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;
as well as URLs for NNTP newsgroup(s).