From: Mathieu Poirier <mathieu.poirier@linaro.org>
To: Bjorn Andersson <bjorn.andersson@linaro.org>
Cc: Andy Gross <agross@kernel.org>, Ohad Ben-Cohen <ohad@wizery.com>,
Sibi Sankar <sibis@codeaurora.org>,
linux-arm-msm@vger.kernel.org, linux-remoteproc@vger.kernel.org,
linux-kernel@vger.kernel.org
Subject: Re: [PATCH] remoteproc: qcom_q6v5_mss: Validate p_filesz in ELF loader
Date: Wed, 13 Jan 2021 14:22:57 -0700 [thread overview]
Message-ID: <20210113212257.GB229796@xps15> (raw)
In-Reply-To: <20210107235053.745888-1-bjorn.andersson@linaro.org>
Hi Bjorn,
On Thu, Jan 07, 2021 at 03:50:53PM -0800, Bjorn Andersson wrote:
> Analog to the issue in the common mdt_loader code the MSS ELF loader
> does not validate that p_filesz bytes will fit in the memory region and
> that the loaded segments are not truncated. Fix this in the same way
> as proposed for the mdt_loader.
>
> Fixes: 135b9e8d1cd8 ("remoteproc: qcom_q6v5_mss: Validate modem blob firmware size before load")
> Signed-off-by: Bjorn Andersson <bjorn.andersson@linaro.org>
> ---
> drivers/remoteproc/qcom_q6v5_mss.c | 17 +++++++++++++++++
> 1 file changed, 17 insertions(+)
>
> diff --git a/drivers/remoteproc/qcom_q6v5_mss.c b/drivers/remoteproc/qcom_q6v5_mss.c
> index 66106ba25ba3..2b59e0cbdce1 100644
> --- a/drivers/remoteproc/qcom_q6v5_mss.c
> +++ b/drivers/remoteproc/qcom_q6v5_mss.c
> @@ -1210,6 +1210,14 @@ static int q6v5_mpss_load(struct q6v5 *qproc)
> goto release_firmware;
> }
>
> + if (phdr->p_filesz > phdr->p_memsz) {
> + dev_err(qproc->dev,
> + "refusing to load segment %d with p_filesz > p_memsz\n",
> + i);
> + ret = -EINVAL;
> + break;
Based on the error handling for the above and below conditions, I would have
expected a "goto release_firmware" rather than a "break".
> + }
> +
> ptr = memremap(qproc->mpss_phys + offset, phdr->p_memsz, MEMREMAP_WC);
> if (!ptr) {
> dev_err(qproc->dev,
> @@ -1241,6 +1249,15 @@ static int q6v5_mpss_load(struct q6v5 *qproc)
> goto release_firmware;
> }
>
> + if (seg_fw->size != phdr->p_filesz) {
> + dev_err(qproc->dev,
> + "failed to load segment %d from truncated file %s\n",
> + i, fw_name);
> + ret = -EINVAL;
> + memunmap(ptr);
> + break;
Same here.
> + }
> +
> release_firmware(seg_fw);
> }
Thanks,
Mathieu
>
> --
> 2.29.2
>
next prev parent reply other threads:[~2021-01-14 2:15 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-01-07 23:50 [PATCH] remoteproc: qcom_q6v5_mss: Validate p_filesz in ELF loader Bjorn Andersson
2021-01-13 21:22 ` Mathieu Poirier [this message]
2021-01-13 22:03 ` Bjorn Andersson
2021-01-19 15:57 ` Mathieu Poirier
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=20210113212257.GB229796@xps15 \
--to=mathieu.poirier@linaro.org \
--cc=agross@kernel.org \
--cc=bjorn.andersson@linaro.org \
--cc=linux-arm-msm@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-remoteproc@vger.kernel.org \
--cc=ohad@wizery.com \
--cc=sibis@codeaurora.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