diff options
| author | Virendra Thakur <virendra.thakur@kpit.com> | 2022-10-01 11:20:13 +0530 |
|---|---|---|
| committer | Richard Purdie <richard.purdie@linuxfoundation.org> | 2022-10-20 15:36:02 +0100 |
| commit | f30135af3af7d5233aa0c7f30ffabbf854729775 (patch) | |
| tree | 2461a7d237040f91a9b34a9e8ebd2d31526f63ea /meta | |
| parent | 1b2fb9a1a5516c80fef079c38e42066d70984773 (diff) | |
| download | poky-f30135af3af7d5233aa0c7f30ffabbf854729775.tar.gz | |
qemu: Fix CVE-2021-3750 for qemu
Add patch to fix CVE-2021-3750
(From OE-Core rev: e9e945a1d22b06d10ac07345b7cebcf232a809bb)
Signed-off-by: Virendra Thakur <virendra.thakur@kpit.com>
Signed-off-by: Steve Sakoman <steve@sakoman.com>
Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
Diffstat (limited to 'meta')
| -rw-r--r-- | meta/recipes-devtools/qemu/qemu.inc | 3 | ||||
| -rw-r--r-- | meta/recipes-devtools/qemu/qemu/CVE-2021-3750-1.patch | 59 | ||||
| -rw-r--r-- | meta/recipes-devtools/qemu/qemu/CVE-2021-3750-2.patch | 65 | ||||
| -rw-r--r-- | meta/recipes-devtools/qemu/qemu/CVE-2021-3750-3.patch | 156 |
4 files changed, 283 insertions, 0 deletions
diff --git a/meta/recipes-devtools/qemu/qemu.inc b/meta/recipes-devtools/qemu/qemu.inc index a493ac8add..816f9a7eac 100644 --- a/meta/recipes-devtools/qemu/qemu.inc +++ b/meta/recipes-devtools/qemu/qemu.inc | |||
| @@ -43,6 +43,9 @@ SRC_URI = "https://download.qemu.org/${BPN}-${PV}.tar.xz \ | |||
| 43 | file://CVE-2022-0358.patch \ | 43 | file://CVE-2022-0358.patch \ |
| 44 | file://CVE-2022-0216_1.patch \ | 44 | file://CVE-2022-0216_1.patch \ |
| 45 | file://CVE-2022-0216_2.patch \ | 45 | file://CVE-2022-0216_2.patch \ |
| 46 | file://CVE-2021-3750-1.patch \ | ||
| 47 | file://CVE-2021-3750-2.patch \ | ||
| 48 | file://CVE-2021-3750-3.patch \ | ||
| 46 | " | 49 | " |
| 47 | UPSTREAM_CHECK_REGEX = "qemu-(?P<pver>\d+(\.\d+)+)\.tar" | 50 | UPSTREAM_CHECK_REGEX = "qemu-(?P<pver>\d+(\.\d+)+)\.tar" |
| 48 | 51 | ||
diff --git a/meta/recipes-devtools/qemu/qemu/CVE-2021-3750-1.patch b/meta/recipes-devtools/qemu/qemu/CVE-2021-3750-1.patch new file mode 100644 index 0000000000..e898c20767 --- /dev/null +++ b/meta/recipes-devtools/qemu/qemu/CVE-2021-3750-1.patch | |||
| @@ -0,0 +1,59 @@ | |||
| 1 | From b9d383ab797f54ae5fa8746117770709921dc529 Mon Sep 17 00:00:00 2001 | ||
| 2 | From: =?utf8?q?Philippe=20Mathieu-Daud=C3=A9?= <philmd@redhat.com> | ||
| 3 | Date: Wed, 15 Dec 2021 19:24:19 +0100 | ||
| 4 | Subject: [PATCH] hw/intc/arm_gicv3: Check for !MEMTX_OK instead of MEMTX_ERROR | ||
| 5 | MIME-Version: 1.0 | ||
| 6 | Content-Type: text/plain; charset=utf8 | ||
| 7 | Content-Transfer-Encoding: 8bit | ||
| 8 | |||
| 9 | Quoting Peter Maydell: | ||
| 10 | |||
| 11 | "These MEMTX_* aren't from the memory transaction | ||
| 12 | API functions; they're just being used by gicd_readl() and | ||
| 13 | friends as a way to indicate a success/failure so that the | ||
| 14 | actual MemoryRegionOps read/write fns like gicv3_dist_read() | ||
| 15 | can log a guest error." | ||
| 16 | |||
| 17 | We are going to introduce more MemTxResult bits, so it is | ||
| 18 | safer to check for !MEMTX_OK rather than MEMTX_ERROR. | ||
| 19 | |||
| 20 | Reviewed-by: Peter Xu <peterx@redhat.com> | ||
| 21 | Reviewed-by: David Hildenbrand <david@redhat.com> | ||
| 22 | Reviewed-by: Peter Maydell <peter.maydell@linaro.org> | ||
| 23 | Reviewed-by: Stefan Hajnoczi <stefanha@redhat.com> | ||
| 24 | Signed-off-by: Philippe Mathieu-DaudÃf© <philmd@redhat.com> | ||
| 25 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> | ||
| 26 | Signed-off-by: Virendra Thakur <virendra.thakur@kpit.com> | ||
| 27 | |||
| 28 | CVE: CVE-2021-3750 | ||
| 29 | |||
| 30 | Upstream-Status: Backport [https://git.qemu.org/?p=qemu.git;a=commit;h=b9d383ab797f54ae5fa8746117770709921dc529] | ||
| 31 | --- | ||
| 32 | hw/intc/arm_gicv3_redist.c | 4 ++-- | ||
| 33 | 1 file changed, 2 insertions(+), 2 deletions(-) | ||
| 34 | |||
| 35 | diff --git a/hw/intc/arm_gicv3_redist.c b/hw/intc/arm_gicv3_redist.c | ||
| 36 | index c8ff3ec..99b11ca 100644 | ||
| 37 | --- a/hw/intc/arm_gicv3_redist.c | ||
| 38 | +++ b/hw/intc/arm_gicv3_redist.c | ||
| 39 | @@ -462,7 +462,7 @@ MemTxResult gicv3_redist_read(void *opaque, hwaddr offset, uint64_t *data, | ||
| 40 | break; | ||
| 41 | } | ||
| 42 | |||
| 43 | - if (r == MEMTX_ERROR) { | ||
| 44 | + if (r != MEMTX_OK) { | ||
| 45 | qemu_log_mask(LOG_GUEST_ERROR, | ||
| 46 | "%s: invalid guest read at offset " TARGET_FMT_plx | ||
| 47 | " size %u\n", __func__, offset, size); | ||
| 48 | @@ -521,7 +521,7 @@ MemTxResult gicv3_redist_write(void *opaque, hwaddr offset, uint64_t data, | ||
| 49 | break; | ||
| 50 | } | ||
| 51 | |||
| 52 | - if (r == MEMTX_ERROR) { | ||
| 53 | + if (r != MEMTX_OK) { | ||
| 54 | qemu_log_mask(LOG_GUEST_ERROR, | ||
| 55 | "%s: invalid guest write at offset " TARGET_FMT_plx | ||
| 56 | " size %u\n", __func__, offset, size); | ||
| 57 | -- | ||
| 58 | 1.8.3.1 | ||
| 59 | |||
diff --git a/meta/recipes-devtools/qemu/qemu/CVE-2021-3750-2.patch b/meta/recipes-devtools/qemu/qemu/CVE-2021-3750-2.patch new file mode 100644 index 0000000000..f163b4fab3 --- /dev/null +++ b/meta/recipes-devtools/qemu/qemu/CVE-2021-3750-2.patch | |||
| @@ -0,0 +1,65 @@ | |||
| 1 | From 58e74682baf4e1ad26b064d8c02e5bc99c75c5d9 Mon Sep 17 00:00:00 2001 | ||
| 2 | From: =?utf8?q?Philippe=20Mathieu-Daud=C3=A9?= <philmd@redhat.com> | ||
| 3 | Date: Wed, 15 Dec 2021 19:24:20 +0100 | ||
| 4 | Subject: [PATCH] softmmu/physmem: Simplify flatview_write and | ||
| 5 | address_space_access_valid | ||
| 6 | MIME-Version: 1.0 | ||
| 7 | Content-Type: text/plain; charset=utf8 | ||
| 8 | Content-Transfer-Encoding: 8bit | ||
| 9 | |||
| 10 | Remove unuseful local 'result' variables. | ||
| 11 | |||
| 12 | Reviewed-by: Peter Xu <peterx@redhat.com> | ||
| 13 | Reviewed-by: David Hildenbrand <david@redhat.com> | ||
| 14 | Reviewed-by: Alexander Bulekov <alxndr@bu.edu> | ||
| 15 | Reviewed-by: Stefan Hajnoczi <stefanha@redhat.com> | ||
| 16 | Signed-off-by: Philippe Mathieu-DaudÃf© <philmd@redhat.com> | ||
| 17 | Message-Id: <20211215182421.418374-3-philmd@redhat.com> | ||
| 18 | Signed-off-by: Thomas Huth <thuth@redhat.com> | ||
| 19 | Signed-off-by: Virendra Thakur <virendra.thakur@kpit.com> | ||
| 20 | |||
| 21 | CVE: CVE-2021-3750 | ||
| 22 | |||
| 23 | Upstream-Status: Backport [https://git.qemu.org/?p=qemu.git;a=commit;h=58e74682baf4e1ad26b064d8c02e5bc99c75c5d9] | ||
| 24 | --- | ||
| 25 | softmmu/physmem.c | 11 +++-------- | ||
| 26 | 1 file changed, 3 insertions(+), 8 deletions(-) | ||
| 27 | |||
| 28 | diff --git a/softmmu/physmem.c b/softmmu/physmem.c | ||
| 29 | index 43ae70f..3d968ca 100644 | ||
| 30 | --- a/softmmu/physmem.c | ||
| 31 | +++ b/softmmu/physmem.c | ||
| 32 | @@ -2826,14 +2826,11 @@ static MemTxResult flatview_write(FlatVi | ||
| 33 | hwaddr l; | ||
| 34 | hwaddr addr1; | ||
| 35 | MemoryRegion *mr; | ||
| 36 | - MemTxResult result = MEMTX_OK; | ||
| 37 | |||
| 38 | l = len; | ||
| 39 | mr = flatview_translate(fv, addr, &addr1, &l, true, attrs); | ||
| 40 | - result = flatview_write_continue(fv, addr, attrs, buf, len, | ||
| 41 | - addr1, l, mr); | ||
| 42 | - | ||
| 43 | - return result; | ||
| 44 | + return flatview_write_continue(fv, addr, attrs, buf, len, | ||
| 45 | + addr1, l, mr); | ||
| 46 | } | ||
| 47 | |||
| 48 | /* Called within RCU critical section. */ | ||
| 49 | @@ -3130,12 +3127,10 @@ bool address_space_access_valid(AddressS | ||
| 50 | MemTxAttrs attrs) | ||
| 51 | { | ||
| 52 | FlatView *fv; | ||
| 53 | - bool result; | ||
| 54 | |||
| 55 | RCU_READ_LOCK_GUARD(); | ||
| 56 | fv = address_space_to_flatview(as); | ||
| 57 | - result = flatview_access_valid(fv, addr, len, is_write, attrs); | ||
| 58 | - return result; | ||
| 59 | + return flatview_access_valid(fv, addr, len, is_write, attrs); | ||
| 60 | } | ||
| 61 | |||
| 62 | static hwaddr | ||
| 63 | -- | ||
| 64 | 1.8.3.1 | ||
| 65 | |||
diff --git a/meta/recipes-devtools/qemu/qemu/CVE-2021-3750-3.patch b/meta/recipes-devtools/qemu/qemu/CVE-2021-3750-3.patch new file mode 100644 index 0000000000..24668ad1a5 --- /dev/null +++ b/meta/recipes-devtools/qemu/qemu/CVE-2021-3750-3.patch | |||
| @@ -0,0 +1,156 @@ | |||
| 1 | From 3ab6fdc91b72e156da22848f0003ff4225690ced Mon Sep 17 00:00:00 2001 | ||
| 2 | From: =?utf8?q?Philippe=20Mathieu-Daud=C3=A9?= <philmd@redhat.com> | ||
| 3 | Date: Wed, 15 Dec 2021 19:24:21 +0100 | ||
| 4 | Subject: [PATCH] softmmu/physmem: Introduce MemTxAttrs::memory field and | ||
| 5 | MEMTX_ACCESS_ERROR | ||
| 6 | MIME-Version: 1.0 | ||
| 7 | Content-Type: text/plain; charset=utf8 | ||
| 8 | Content-Transfer-Encoding: 8bit | ||
| 9 | |||
| 10 | Add the 'memory' bit to the memory attributes to restrict bus | ||
| 11 | controller accesses to memories. | ||
| 12 | |||
| 13 | Introduce flatview_access_allowed() to check bus permission | ||
| 14 | before running any bus transaction. | ||
| 15 | |||
| 16 | Have read/write accessors return MEMTX_ACCESS_ERROR if an access is | ||
| 17 | restricted. | ||
| 18 | |||
| 19 | There is no change for the default case where 'memory' is not set. | ||
| 20 | |||
| 21 | Signed-off-by: Philippe Mathieu-DaudÃf© <philmd@redhat.com> | ||
| 22 | Message-Id: <20211215182421.418374-4-philmd@redhat.com> | ||
| 23 | Reviewed-by: Richard Henderson <richard.henderson@linaro.org> | ||
| 24 | Reviewed-by: Stefan Hajnoczi <stefanha@redhat.com> | ||
| 25 | [thuth: Replaced MEMTX_BUS_ERROR with MEMTX_ACCESS_ERROR, remove "inline"] | ||
| 26 | Signed-off-by: Thomas Huth <thuth@redhat.com> | ||
| 27 | Signed-off-by: Virendra Thakur <virendra.thakur@kpit.com> | ||
| 28 | |||
| 29 | CVE: CVE-2021-3750 | ||
| 30 | |||
| 31 | Upstream-Status: Backport [https://git.qemu.org/?p=qemu.git;a=commit;h=3ab6fdc91b72e156da22848f0003ff4225690ced] | ||
| 32 | --- | ||
| 33 | include/exec/memattrs.h | 9 +++++++++ | ||
| 34 | softmmu/physmem.c | 44 ++++++++++++++++++++++++++++++++++++++++++-- | ||
| 35 | 2 files changed, 51 insertions(+), 2 deletions(-) | ||
| 36 | |||
| 37 | diff --git a/include/exec/memattrs.h b/include/exec/memattrs.h | ||
| 38 | index 95f2d20..9fb98bc 100644 | ||
| 39 | --- a/include/exec/memattrs.h | ||
| 40 | +++ b/include/exec/memattrs.h | ||
| 41 | @@ -35,6 +35,14 @@ typedef struct MemTxAttrs { | ||
| 42 | unsigned int secure:1; | ||
| 43 | /* Memory access is usermode (unprivileged) */ | ||
| 44 | unsigned int user:1; | ||
| 45 | + /* | ||
| 46 | + * Bus interconnect and peripherals can access anything (memories, | ||
| 47 | + * devices) by default. By setting the 'memory' bit, bus transaction | ||
| 48 | + * are restricted to "normal" memories (per the AMBA documentation) | ||
| 49 | + * versus devices. Access to devices will be logged and rejected | ||
| 50 | + * (see MEMTX_ACCESS_ERROR). | ||
| 51 | + */ | ||
| 52 | + unsigned int memory:1; | ||
| 53 | /* Requester ID (for MSI for example) */ | ||
| 54 | unsigned int requester_id:16; | ||
| 55 | /* Invert endianness for this page */ | ||
| 56 | @@ -66,6 +74,7 @@ typedef struct MemTxAttrs { | ||
| 57 | #define MEMTX_OK 0 | ||
| 58 | #define MEMTX_ERROR (1U << 0) /* device returned an error */ | ||
| 59 | #define MEMTX_DECODE_ERROR (1U << 1) /* nothing at that address */ | ||
| 60 | +#define MEMTX_ACCESS_ERROR (1U << 2) /* access denied */ | ||
| 61 | typedef uint32_t MemTxResult; | ||
| 62 | |||
| 63 | #endif | ||
| 64 | diff --git a/softmmu/physmem.c b/softmmu/physmem.c | ||
| 65 | index 3d968ca..4e1b27a 100644 | ||
| 66 | --- a/softmmu/physmem.c | ||
| 67 | +++ b/softmmu/physmem.c | ||
| 68 | @@ -41,6 +41,7 @@ | ||
| 69 | #include "qemu/config-file.h" | ||
| 70 | #include "qemu/error-report.h" | ||
| 71 | #include "qemu/qemu-print.h" | ||
| 72 | +#include "qemu/log.h" | ||
| 73 | #include "exec/memory.h" | ||
| 74 | #include "exec/ioport.h" | ||
| 75 | #include "sysemu/dma.h" | ||
| 76 | @@ -2759,6 +2760,33 @@ static bool prepare_mmio_access(MemoryRe | ||
| 77 | return release_lock; | ||
| 78 | } | ||
| 79 | |||
| 80 | +/** | ||
| 81 | + * flatview_access_allowed | ||
| 82 | + * @mr: #MemoryRegion to be accessed | ||
| 83 | + * @attrs: memory transaction attributes | ||
| 84 | + * @addr: address within that memory region | ||
| 85 | + * @len: the number of bytes to access | ||
| 86 | + * | ||
| 87 | + * Check if a memory transaction is allowed. | ||
| 88 | + * | ||
| 89 | + * Returns: true if transaction is allowed, false if denied. | ||
| 90 | + */ | ||
| 91 | +static bool flatview_access_allowed(MemoryRegion *mr, MemTxAttrs attrs, | ||
| 92 | + hwaddr addr, hwaddr len) | ||
| 93 | +{ | ||
| 94 | + if (likely(!attrs.memory)) { | ||
| 95 | + return true; | ||
| 96 | + } | ||
| 97 | + if (memory_region_is_ram(mr)) { | ||
| 98 | + return true; | ||
| 99 | + } | ||
| 100 | + qemu_log_mask(LOG_GUEST_ERROR, | ||
| 101 | + "Invalid access to non-RAM device at " | ||
| 102 | + "addr 0x%" HWADDR_PRIX ", size %" HWADDR_PRIu ", " | ||
| 103 | + "region '%s'\n", addr, len, memory_region_name(mr)); | ||
| 104 | + return false; | ||
| 105 | +} | ||
| 106 | + | ||
| 107 | /* Called within RCU critical section. */ | ||
| 108 | static MemTxResult flatview_write_continue(FlatView *fv, hwaddr addr, | ||
| 109 | MemTxAttrs attrs, | ||
| 110 | @@ -2773,7 +2801,10 @@ static MemTxResult flatview_write_contin | ||
| 111 | const uint8_t *buf = ptr; | ||
| 112 | |||
| 113 | for (;;) { | ||
| 114 | - if (!memory_access_is_direct(mr, true)) { | ||
| 115 | + if (!flatview_access_allowed(mr, attrs, addr1, l)) { | ||
| 116 | + result |= MEMTX_ACCESS_ERROR; | ||
| 117 | + /* Keep going. */ | ||
| 118 | + } else if (!memory_access_is_direct(mr, true)) { | ||
| 119 | release_lock |= prepare_mmio_access(mr); | ||
| 120 | l = memory_access_size(mr, l, addr1); | ||
| 121 | /* XXX: could force current_cpu to NULL to avoid | ||
| 122 | @@ -2818,6 +2849,9 @@ static MemTxResult flatview_write(FlatVi | ||
| 123 | |||
| 124 | l = len; | ||
| 125 | mr = flatview_translate(fv, addr, &addr1, &l, true, attrs); | ||
| 126 | + if (!flatview_access_allowed(mr, attrs, addr, len)) { | ||
| 127 | + return MEMTX_ACCESS_ERROR; | ||
| 128 | + } | ||
| 129 | return flatview_write_continue(fv, addr, attrs, buf, len, | ||
| 130 | addr1, l, mr); | ||
| 131 | } | ||
| 132 | @@ -2836,7 +2870,10 @@ MemTxResult flatview_read_continue(FlatV | ||
| 133 | |||
| 134 | fuzz_dma_read_cb(addr, len, mr); | ||
| 135 | for (;;) { | ||
| 136 | - if (!memory_access_is_direct(mr, false)) { | ||
| 137 | + if (!flatview_access_allowed(mr, attrs, addr1, l)) { | ||
| 138 | + result |= MEMTX_ACCESS_ERROR; | ||
| 139 | + /* Keep going. */ | ||
| 140 | + } else if (!memory_access_is_direct(mr, false)) { | ||
| 141 | /* I/O case */ | ||
| 142 | release_lock |= prepare_mmio_access(mr); | ||
| 143 | l = memory_access_size(mr, l, addr1); | ||
| 144 | @@ -2879,6 +2916,9 @@ static MemTxResult flatview_read(FlatVie | ||
| 145 | |||
| 146 | l = len; | ||
| 147 | mr = flatview_translate(fv, addr, &addr1, &l, false, attrs); | ||
| 148 | + if (!flatview_access_allowed(mr, attrs, addr, len)) { | ||
| 149 | + return MEMTX_ACCESS_ERROR; | ||
| 150 | + } | ||
| 151 | return flatview_read_continue(fv, addr, attrs, buf, len, | ||
| 152 | addr1, l, mr); | ||
| 153 | } | ||
| 154 | -- | ||
| 155 | 1.8.3.1 | ||
| 156 | |||
