86ffd40d11
- Switch method of splitting off hw-s390x-virtio-gpu-ccw.so as a module to what was accepted upstream (bsc#1181103) * Patches dropped: hw-s390x-modularize-virtio-gpu-ccw.patch * Patches added: s390x-add-have_virtio_ccw.patch s390x-modularize-virtio-gpu-ccw.patch s390x-move-S390_ADAPTER_SUPPRESSIBLE.patch - Fix OOB access in sdhci interface (CVE-2020-17380, bsc#1175144, CVE-2020-25085, bsc#1176681, CVE-2021-3409, bsc#1182282) hw-sd-sd-Actually-perform-the-erase-oper.patch hw-sd-sd-Fix-build-error-when-DEBUG_SD-i.patch hw-sd-sdhci-Correctly-set-the-controller.patch hw-sd-sdhci-Don-t-transfer-any-data-when.patch hw-sd-sdhci-Don-t-write-to-SDHC_SYSAD-re.patch hw-sd-sdhci-Limit-block-size-only-when-S.patch hw-sd-sdhci-Reset-the-data-pointer-of-s-.patch hw-sd-sd-Move-the-sd_block_-read-write-a.patch hw-sd-sd-Skip-write-protect-groups-check.patch - Fix potential privilege escalation in virtiofsd tool (CVE-2021-20263, bsc#1183373) tools-virtiofsd-Replace-the-word-whiteli.patch viriofsd-Add-support-for-FUSE_HANDLE_KIL.patch virtiofsd-extract-lo_do_open-from-lo_ope.patch virtiofsd-optionally-return-inode-pointe.patch virtiofsd-prevent-opening-of-special-fil.patch virtiofs-drop-remapped-security.capabili.patch virtiofsd-Save-error-code-early-at-the-f.patch - Fix OOB access (stack overflow) in rtl8139 NIC emulation (CVE-2021-3416, bsc#1182968) net-introduce-qemu_receive_packet.patch rtl8139-switch-to-use-qemu_receive_packe.patch - Fix OOB access (stack overflow) in other NIC emulations (CVE-2021-3416) cadence_gem-switch-to-use-qemu_receive_p.patch dp8393x-switch-to-use-qemu_receive_packe.patch e1000-switch-to-use-qemu_receive_packet-.patch lan9118-switch-to-use-qemu_receive_packe.patch msf2-mac-switch-to-use-qemu_receive_pack.patch pcnet-switch-to-use-qemu_receive_packet-.patch sungem-switch-to-use-qemu_receive_packet.patch tx_pkt-switch-to-use-qemu_receive_packet.patch - Fix heap overflow in MSIx emulation (CVE-2020-27821, bsc#1179686) memory-clamp-cached-translation-in-case-.patch - Include upstream patches designated as stable material and reviewed for applicability to include here hw-arm-virt-Disable-pl011-clock-migratio.patch xen-block-Fix-removal-of-backend-instanc.patch - Fix package scripts to not use hard coded paths for temporary working directories and log files (bsc#1182425) OBS-URL: https://build.opensuse.org/request/show/882222 OBS-URL: https://build.opensuse.org/package/show/Virtualization/qemu?expand=0&rev=632
138 lines
5.2 KiB
Diff
138 lines
5.2 KiB
Diff
From: Paolo Bonzini <pbonzini@redhat.com>
|
|
Date: Tue, 1 Dec 2020 09:29:56 -0500
|
|
Subject: memory: clamp cached translation in case it points to an MMIO region
|
|
|
|
Git-commit: 4bfb024bc76973d40a359476dc0291f46e435442
|
|
References: bsc#1179686, CVE-2020-27821
|
|
|
|
In using the address_space_translate_internal API, address_space_cache_init
|
|
forgot one piece of advice that can be found in the code for
|
|
address_space_translate_internal:
|
|
|
|
/* MMIO registers can be expected to perform full-width accesses based only
|
|
* on their address, without considering adjacent registers that could
|
|
* decode to completely different MemoryRegions. When such registers
|
|
* exist (e.g. I/O ports 0xcf8 and 0xcf9 on most PC chipsets), MMIO
|
|
* regions overlap wildly. For this reason we cannot clamp the accesses
|
|
* here.
|
|
*
|
|
* If the length is small (as is the case for address_space_ldl/stl),
|
|
* everything works fine. If the incoming length is large, however,
|
|
* the caller really has to do the clamping through memory_access_size.
|
|
*/
|
|
|
|
address_space_cache_init is exactly one such case where "the incoming length
|
|
is large", therefore we need to clamp the resulting length---not to
|
|
memory_access_size though, since we are not doing an access yet, but to
|
|
the size of the resulting section. This ensures that subsequent accesses
|
|
to the cached MemoryRegionSection will be in range.
|
|
|
|
With this patch, the enclosed testcase notices that the used ring does
|
|
not fit into the MSI-X table and prints a "qemu-system-x86_64: Cannot map used"
|
|
error.
|
|
|
|
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
|
|
Signed-off-by: Bruce Rogers <brogers@suse.com>
|
|
---
|
|
softmmu/physmem.c | 10 ++++++++
|
|
tests/qtest/fuzz-test.c | 51 +++++++++++++++++++++++++++++++++++++++++
|
|
2 files changed, 61 insertions(+)
|
|
|
|
diff --git a/softmmu/physmem.c b/softmmu/physmem.c
|
|
index 3027747c0302c0904db2568eabb8..2cd1de4a2c46814f10c60fc1b8e5 100644
|
|
--- a/softmmu/physmem.c
|
|
+++ b/softmmu/physmem.c
|
|
@@ -3255,6 +3255,7 @@ int64_t address_space_cache_init(MemoryRegionCache *cache,
|
|
AddressSpaceDispatch *d;
|
|
hwaddr l;
|
|
MemoryRegion *mr;
|
|
+ Int128 diff;
|
|
|
|
assert(len > 0);
|
|
|
|
@@ -3263,6 +3264,15 @@ int64_t address_space_cache_init(MemoryRegionCache *cache,
|
|
d = flatview_to_dispatch(cache->fv);
|
|
cache->mrs = *address_space_translate_internal(d, addr, &cache->xlat, &l, true);
|
|
|
|
+ /*
|
|
+ * cache->xlat is now relative to cache->mrs.mr, not to the section itself.
|
|
+ * Take that into account to compute how many bytes are there between
|
|
+ * cache->xlat and the end of the section.
|
|
+ */
|
|
+ diff = int128_sub(cache->mrs.size,
|
|
+ int128_make64(cache->xlat - cache->mrs.offset_within_region));
|
|
+ l = int128_get64(int128_min(diff, int128_make64(l)));
|
|
+
|
|
mr = cache->mrs.mr;
|
|
memory_region_ref(mr);
|
|
if (memory_access_is_direct(mr, is_write)) {
|
|
diff --git a/tests/qtest/fuzz-test.c b/tests/qtest/fuzz-test.c
|
|
index 9cb4c42bdea5cefa23473ed41b10..28739248e24d0b41d8ea5defebb8 100644
|
|
--- a/tests/qtest/fuzz-test.c
|
|
+++ b/tests/qtest/fuzz-test.c
|
|
@@ -47,6 +47,55 @@ static void test_lp1878642_pci_bus_get_irq_level_assert(void)
|
|
qtest_outl(s, 0x5d02, 0xebed205d);
|
|
}
|
|
|
|
+/*
|
|
+ * Here a MemoryRegionCache pointed to an MMIO region but had a
|
|
+ * larger size than the underlying region.
|
|
+ */
|
|
+static void test_mmio_oob_from_memory_region_cache(void)
|
|
+{
|
|
+ QTestState *s;
|
|
+
|
|
+ s = qtest_init("-M pc-q35-5.2 -display none -m 512M "
|
|
+ "-device virtio-scsi,num_queues=8,addr=03.0 ");
|
|
+
|
|
+ qtest_outl(s, 0xcf8, 0x80001811);
|
|
+ qtest_outb(s, 0xcfc, 0x6e);
|
|
+ qtest_outl(s, 0xcf8, 0x80001824);
|
|
+ qtest_outl(s, 0xcf8, 0x80001813);
|
|
+ qtest_outl(s, 0xcfc, 0xa080000);
|
|
+ qtest_outl(s, 0xcf8, 0x80001802);
|
|
+ qtest_outl(s, 0xcfc, 0x5a175a63);
|
|
+ qtest_outb(s, 0x6e08, 0x9e);
|
|
+ qtest_writeb(s, 0x9f003, 0xff);
|
|
+ qtest_writeb(s, 0x9f004, 0x01);
|
|
+ qtest_writeb(s, 0x9e012, 0x0e);
|
|
+ qtest_writeb(s, 0x9e01b, 0x0e);
|
|
+ qtest_writeb(s, 0x9f006, 0x01);
|
|
+ qtest_writeb(s, 0x9f008, 0x01);
|
|
+ qtest_writeb(s, 0x9f00a, 0x01);
|
|
+ qtest_writeb(s, 0x9f00c, 0x01);
|
|
+ qtest_writeb(s, 0x9f00e, 0x01);
|
|
+ qtest_writeb(s, 0x9f010, 0x01);
|
|
+ qtest_writeb(s, 0x9f012, 0x01);
|
|
+ qtest_writeb(s, 0x9f014, 0x01);
|
|
+ qtest_writeb(s, 0x9f016, 0x01);
|
|
+ qtest_writeb(s, 0x9f018, 0x01);
|
|
+ qtest_writeb(s, 0x9f01a, 0x01);
|
|
+ qtest_writeb(s, 0x9f01c, 0x01);
|
|
+ qtest_writeb(s, 0x9f01e, 0x01);
|
|
+ qtest_writeb(s, 0x9f020, 0x01);
|
|
+ qtest_writeb(s, 0x9f022, 0x01);
|
|
+ qtest_writeb(s, 0x9f024, 0x01);
|
|
+ qtest_writeb(s, 0x9f026, 0x01);
|
|
+ qtest_writeb(s, 0x9f028, 0x01);
|
|
+ qtest_writeb(s, 0x9f02a, 0x01);
|
|
+ qtest_writeb(s, 0x9f02c, 0x01);
|
|
+ qtest_writeb(s, 0x9f02e, 0x01);
|
|
+ qtest_writeb(s, 0x9f030, 0x01);
|
|
+ qtest_outb(s, 0x6e10, 0x00);
|
|
+ qtest_quit(s);
|
|
+}
|
|
+
|
|
int main(int argc, char **argv)
|
|
{
|
|
const char *arch = qtest_get_arch();
|
|
@@ -58,6 +107,8 @@ int main(int argc, char **argv)
|
|
test_lp1878263_megasas_zero_iov_cnt);
|
|
qtest_add_func("fuzz/test_lp1878642_pci_bus_get_irq_level_assert",
|
|
test_lp1878642_pci_bus_get_irq_level_assert);
|
|
+ qtest_add_func("fuzz/test_mmio_oob_from_memory_region_cache",
|
|
+ test_mmio_oob_from_memory_region_cache);
|
|
}
|
|
|
|
return g_test_run();
|