loader: Check access size when calling rom_ptr() to avoid crashes
commit0f0f8b611eeea663c8d3b6021918033e257411a1
authorThomas Huth <thuth@redhat.com>
Tue, 26 Jun 2018 09:35:40 +0000 (26 11:35 +0200)
committerCornelia Huck <cohuck@redhat.com>
Mon, 2 Jul 2018 08:37:38 +0000 (2 10:37 +0200)
tree69faeb3be924514248d41a232bf82e439c1da734
parent76ed4b18debfe597329d1f6a9eb2ec9ffa751ecd
loader: Check access size when calling rom_ptr() to avoid crashes

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.

Acked-by: Christian Borntraeger <borntraeger@de.ibm.com>
Signed-off-by: Thomas Huth <thuth@redhat.com>
Message-Id: <1530005740-25254-1-git-send-email-thuth@redhat.com>
Signed-off-by: Cornelia Huck <cohuck@redhat.com>
hw/core/loader.c
hw/mips/mips_malta.c
hw/s390x/ipl.c
hw/sparc/sun4m.c
hw/sparc64/sun4u.c
include/hw/loader.h
target/arm/cpu.c