From: Mattijs Korpershoek <mkorpershoek@kernel.org>
To: Andrew Goodbody <andrew.goodbody@linaro.org>,
Tom Rini <trini@konsulko.com>,
Mattijs Korpershoek <mkorpershoek@kernel.org>,
Safae Ouajih <souajih@baylibre.com>
Cc: u-boot@lists.denx.de, Andrew Goodbody <andrew.goodbody@linaro.org>
Subject: Re: [PATCH v2] cmd: abootimg: Prevent use of unintialised variable
Date: Wed, 25 Jun 2025 18:10:52 +0200 [thread overview]
Message-ID: <87wm8zx0mr.fsf@kernel.org> (raw)
In-Reply-To: <20250625-abootimg_fix-v2-1-0d295dc1f1e2@linaro.org>
Hi Andrew,
Thank you for the patch.
On Wed, Jun 25, 2025 at 16:52, Andrew Goodbody <andrew.goodbody@linaro.org> wrote:
> vhdr can be used when not initialised so detect this condition
> and exit early to prevent the problem.
>
> This issue was found with Smatch.
>
> Fixes: 636da2039aea (android: boot: support boot image header version 3 and 4)
> Signed-off-by: Andrew Goodbody <andrew.goodbody@linaro.org>
> ---
> Changes in v2:
> - Add unmap_sysmem(hdr) in the new exit path
> - Link to v1: https://lore.kernel.org/r/20250625-abootimg_fix-v1-1-ce1645ac9879@linaro.org
> ---
> cmd/abootimg.c | 12 +++++++-----
> 1 file changed, 7 insertions(+), 5 deletions(-)
>
> diff --git a/cmd/abootimg.c b/cmd/abootimg.c
> index ae7a1a7c83b..31620aa3cfa 100644
> --- a/cmd/abootimg.c
> +++ b/cmd/abootimg.c
> @@ -98,18 +98,20 @@ static int abootimg_get_dtb_load_addr(int argc, char *const argv[])
> const struct andr_vnd_boot_img_hdr *vhdr;
>
> hdr = map_sysmem(abootimg_addr(), sizeof(*hdr));
> - if (get_avendor_bootimg_addr() != -1)
> + if (get_avendor_bootimg_addr() != -1) {
> vhdr = map_sysmem(get_avendor_bootimg_addr(), sizeof(*vhdr));
> + } else {
> + unmap_sysmem(hdr);
> + return CMD_RET_FAILURE;
> + }
It's valid for avendor_bootimg_adr() to be -1.
This is the case for boot image v2 and lower, where there is no
boot_vendor partition. (so there is no valid vhdr).
Per my understanding vhdr* is NULL if left unintialised. (I might be
wrong, please let me know).
android_image_get_data() handles the case where vendor_boot_hdr is NULL:
"""
if (((struct andr_boot_img_hdr_v0 *)boot_hdr)->header_version > 2) {
if (!vendor_boot_hdr) {
printf("For boot header v3+ vendor boot image has to be provided\n");
return false;
}
"""
So I don't think we should early return here.
If we do, we will probably break boot image v2 support.
>
> if (!android_image_get_data(hdr, vhdr, &img_data)) {
> - if (get_avendor_bootimg_addr() != -1)
> - unmap_sysmem(vhdr);
> + unmap_sysmem(vhdr);
> unmap_sysmem(hdr);
> return CMD_RET_FAILURE;
> }
>
> - if (get_avendor_bootimg_addr() != -1)
> - unmap_sysmem(vhdr);
> + unmap_sysmem(vhdr);
> unmap_sysmem(hdr);
>
> if (img_data.header_version < 2) {
>
> ---
> base-commit: 903eb123236ccbd8ef05d43507a2a910b785bd56
> change-id: 20250625-abootimg_fix-51600dc8356a
>
> Best regards,
> --
> Andrew Goodbody <andrew.goodbody@linaro.org>
next prev parent reply other threads:[~2025-06-25 16:11 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-06-25 15:52 [PATCH v2] cmd: abootimg: Prevent use of unintialised variable Andrew Goodbody
2025-06-25 15:57 ` Tom Rini
2025-06-25 16:10 ` Mattijs Korpershoek [this message]
2025-06-25 16:31 ` Andrew Goodbody
2025-06-27 6:43 ` Mattijs Korpershoek
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=87wm8zx0mr.fsf@kernel.org \
--to=mkorpershoek@kernel.org \
--cc=andrew.goodbody@linaro.org \
--cc=souajih@baylibre.com \
--cc=trini@konsulko.com \
--cc=u-boot@lists.denx.de \
/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