From: Pierrick Bouvier <pierrick.bouvier@linaro.org>
To: Paolo Bonzini <pbonzini@redhat.com>, qemu-devel@nongnu.org
Cc: dorjoychy111@gmail.com
Subject: Re: [PATCH] eif: cope with huge section offsets
Date: Wed, 6 Nov 2024 09:47:33 -0800 [thread overview]
Message-ID: <04fd0b86-4371-494e-a331-3d5d735f0d77@linaro.org> (raw)
In-Reply-To: <20241106174241.556373-1-pbonzini@redhat.com>
On 11/6/24 09:42, Paolo Bonzini wrote:
> Check for overflow to avoid that fseek() receives a sign-extended value.
>
> Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
> ---
> include/qemu/osdep.h | 4 ++++
> hw/core/eif.c | 4 ++++
> 2 files changed, 8 insertions(+)
>
> diff --git a/include/qemu/osdep.h b/include/qemu/osdep.h
> index fe7c3c5f673..fdff07fd992 100644
> --- a/include/qemu/osdep.h
> +++ b/include/qemu/osdep.h
> @@ -297,6 +297,10 @@ void QEMU_ERROR("code path is reachable")
> #error building with G_DISABLE_ASSERT is not supported
> #endif
>
> +#ifndef OFF_MAX
> +#define OFF_MAX (sizeof (off_t) == 8 ? INT64_MAX : INT32_MAX)
> +#endif
> +
> #ifndef O_LARGEFILE
> #define O_LARGEFILE 0
> #endif
> diff --git a/hw/core/eif.c b/hw/core/eif.c
> index 7f3b2edc9a7..cbcd80de58b 100644
> --- a/hw/core/eif.c
> +++ b/hw/core/eif.c
> @@ -115,6 +115,10 @@ static bool read_eif_header(FILE *f, EifHeader *header, uint32_t *crc,
>
> for (int i = 0; i < MAX_SECTIONS; ++i) {
> header->section_offsets[i] = be64_to_cpu(header->section_offsets[i]);
> + if (header->section_offsets[i] > OFF_MAX) {
Maybe we could add a comment that sections_offsets is unsigned, as it
can be confusing to read value > INT_MAX without more context.
> + error_setg(errp, "Invalid EIF image. Section offset out of bounds");
> + return false;
> + }
> }
>
> for (int i = 0; i < MAX_SECTIONS; ++i) {
Else,
Reviewed-by: Pierrick Bouvier <pierrick.bouvier@linaro.org>
next prev parent reply other threads:[~2024-11-06 17:48 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-11-06 17:42 [PATCH] eif: cope with huge section offsets Paolo Bonzini
2024-11-06 17:47 ` Pierrick Bouvier [this message]
2024-11-06 17:49 ` Paolo Bonzini
2024-11-06 17:54 ` Pierrick Bouvier
2024-11-06 17:58 ` Paolo Bonzini
2024-11-06 18:07 ` Dorjoy Chowdhury
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=04fd0b86-4371-494e-a331-3d5d735f0d77@linaro.org \
--to=pierrick.bouvier@linaro.org \
--cc=dorjoychy111@gmail.com \
--cc=pbonzini@redhat.com \
--cc=qemu-devel@nongnu.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).