From: Thomas Huth <thuth@redhat.com>
To: qemu-devel@nongnu.org,
Christian Borntraeger <borntraeger@de.ibm.com>,
Cornelia Huck <cohuck@redhat.com>
Cc: Peter Maydell <peter.maydell@linaro.org>,
qemu-trivial@nongnu.org,
Mark Cave-Ayland <mark.cave-ayland@ilande.co.uk>,
qemu-s390x@nongnu.org, qemu-arm@nongnu.org,
Aurelien Jarno <aurelien@aurel32.net>,
Paolo Bonzini <pbonzini@redhat.com>,
Yongbok Kim <yongbok.kim@mips.com>,
Artyom Tarasenko <atar4qemu@gmail.com>
Subject: Re: [Qemu-devel] [PATCH v2] loader: Check access size when calling rom_ptr() to avoid crashes
Date: Fri, 15 Jun 2018 11:01:46 +0200 [thread overview]
Message-ID: <124f3592-df59-071c-08a0-aafdfc7e33f9@redhat.com> (raw)
In-Reply-To: <1529052300-23093-1-git-send-email-thuth@redhat.com>
On 15.06.2018 10:45, Thomas Huth wrote:
> The rom_ptr() function allows direct access to the ROM blobs that we
> load during startup. However, there are currently no checks for the
> size of the accesses, so it's currently possible to crash QEMU for
> example with:
>
> $ echo "Insane in the mainframe" > /tmp/test.txt
> $ s390x-softmmu/qemu-system-s390x -kernel /tmp/test.txt -append xyz
> Segmentation fault (core dumped)
> $ s390x-softmmu/qemu-system-s390x -kernel /tmp/test.txt -initrd /tmp/test.txt
> Segmentation fault (core dumped)
> $ echo -n HdrS > /tmp/hdr.txt
> $ sparc64-softmmu/qemu-system-sparc64 -kernel /tmp/hdr.txt -initrd /tmp/hdr.txt
> Segmentation fault (core dumped)
>
> We need a possibility to check the size of the ROM area that we want
> to access, thus let's add a size parameter to the rom_ptr() function
> to avoid these problems.
>
> Reviewed-by: Cornelia Huck <cohuck@redhat.com>
> Signed-off-by: Thomas Huth <thuth@redhat.com>
> ---
> v2:
> - Add sparc64 crash to the patch description
> - Added Cornelia's Rb from v1
> - NULL pointer check in the sparc machines
>
> hw/core/loader.c | 10 +++++-----
> hw/mips/mips_malta.c | 6 ++++--
> hw/s390x/ipl.c | 13 ++++++++++---
> hw/sparc/sun4m.c | 4 ++--
> hw/sparc64/sun4u.c | 4 ++--
> include/hw/loader.h | 2 +-
> target/arm/cpu.c | 2 +-
> 7 files changed, 25 insertions(+), 16 deletions(-)
>
> diff --git a/hw/core/loader.c b/hw/core/loader.c
> index 06bdbca..54be522 100644
> --- a/hw/core/loader.c
> +++ b/hw/core/loader.c
> @@ -191,7 +191,7 @@ void pstrcpy_targphys(const char *name, hwaddr dest, int buf_size,
> rom_add_blob_fixed(name, source, (nulp - source) + 1, dest);
> } else {
> rom_add_blob_fixed(name, source, buf_size, dest);
> - ptr = rom_ptr(dest + buf_size - 1);
> + ptr = rom_ptr(dest + buf_size - 1, sizeof(*ptr));
> *ptr = 0;
> }
> }
> @@ -1165,7 +1165,7 @@ void rom_reset_order_override(void)
> fw_cfg_reset_order_override(fw_cfg);
> }
>
> -static Rom *find_rom(hwaddr addr)
> +static Rom *find_rom(hwaddr addr, size_t size)
> {
> Rom *rom;
>
> @@ -1176,7 +1176,7 @@ static Rom *find_rom(hwaddr addr)
> if (rom->mr) {
> continue;
> }
> - if (rom->addr > addr) {
> + if (rom->addr > addr + size) {
Uh, not my day today, this check is wrong, I still get bad accesses in
the sparc32 code with valgrind. I'll sent a v3...
Thomas
prev parent reply other threads:[~2018-06-15 9:02 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-06-15 8:45 [Qemu-devel] [PATCH v2] loader: Check access size when calling rom_ptr() to avoid crashes Thomas Huth
2018-06-15 9:01 ` Thomas Huth [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=124f3592-df59-071c-08a0-aafdfc7e33f9@redhat.com \
--to=thuth@redhat.com \
--cc=atar4qemu@gmail.com \
--cc=aurelien@aurel32.net \
--cc=borntraeger@de.ibm.com \
--cc=cohuck@redhat.com \
--cc=mark.cave-ayland@ilande.co.uk \
--cc=pbonzini@redhat.com \
--cc=peter.maydell@linaro.org \
--cc=qemu-arm@nongnu.org \
--cc=qemu-devel@nongnu.org \
--cc=qemu-s390x@nongnu.org \
--cc=qemu-trivial@nongnu.org \
--cc=yongbok.kim@mips.com \
/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).