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] loader: Check access size when calling rom_ptr() to avoid crashes
Date: Fri, 15 Jun 2018 10:33:42 +0200 [thread overview]
Message-ID: <5ab4dd7b-b717-5e58-41d8-1d996c515a10@redhat.com> (raw)
In-Reply-To: <1529045897-25260-1-git-send-email-thuth@redhat.com>
On 15.06.2018 08:58, 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)
>
> 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.
[...]
> diff --git a/hw/sparc/sun4m.c b/hw/sparc/sun4m.c
> index 0ee779f..2375cb2 100644
> --- a/hw/sparc/sun4m.c
> +++ b/hw/sparc/sun4m.c
> @@ -272,7 +272,7 @@ static unsigned long sun4m_load_kernel(const char *kernel_filename,
> }
> if (initrd_size > 0) {
> for (i = 0; i < 64 * TARGET_PAGE_SIZE; i += TARGET_PAGE_SIZE) {
> - ptr = rom_ptr(KERNEL_LOAD_ADDR + i);
> + ptr = rom_ptr(KERNEL_LOAD_ADDR + i, 24);
> if (ldl_p(ptr) == 0x48647253) { // HdrS
Darn, that should check for ptr != NULL ...
> stl_p(ptr + 16, INITRD_LOAD_ADDR);
> stl_p(ptr + 20, initrd_size);
> diff --git a/hw/sparc64/sun4u.c b/hw/sparc64/sun4u.c
> index 1bede85..8b09090 100644
> --- a/hw/sparc64/sun4u.c
> +++ b/hw/sparc64/sun4u.c
> @@ -186,7 +186,7 @@ static uint64_t sun4u_load_kernel(const char *kernel_filename,
> }
> if (*initrd_size > 0) {
> for (i = 0; i < 64 * TARGET_PAGE_SIZE; i += TARGET_PAGE_SIZE) {
> - ptr = rom_ptr(*kernel_addr + i);
> + ptr = rom_ptr(*kernel_addr + i, 32);
> if (ldl_p(ptr + 8) == 0x48647253) { /* HdrS */
... dito ...
I'll send a v2.
Thomas
prev parent reply other threads:[~2018-06-15 8:33 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-06-15 6:58 [Qemu-devel] [PATCH] loader: Check access size when calling rom_ptr() to avoid crashes Thomas Huth
2018-06-15 7:57 ` Cornelia Huck
2018-06-15 8:22 ` Thomas Huth
2018-06-15 8:33 ` 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=5ab4dd7b-b717-5e58-41d8-1d996c515a10@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).