diff options
| author | Vivek Kumbhar <vkumbhar@mvista.com> | 2023-02-08 10:59:20 +0530 |
|---|---|---|
| committer | Richard Purdie <richard.purdie@linuxfoundation.org> | 2023-02-24 16:41:41 +0000 |
| commit | 3c3039aac44a2783a6a5f8906b72e75771b5c879 (patch) | |
| tree | 4a37bf413bc6aaa0b9b995b70ff42b783997bcb1 /meta/recipes-devtools | |
| parent | 485370563552d99e158a907bba9143dc5cd3cea1 (diff) | |
| download | poky-3c3039aac44a2783a6a5f8906b72e75771b5c879.tar.gz | |
qemu: fix CVE-2021-3929 nvme DMA reentrancy issue leads to use-after-free
(From OE-Core rev: 18056190f72eef9a44397cd87d79022dd2a9d4e3)
Signed-off-by: Vivek Kumbhar <vkumbhar@mvista.com>
Signed-off-by: Steve Sakoman <steve@sakoman.com>
Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
Diffstat (limited to 'meta/recipes-devtools')
| -rw-r--r-- | meta/recipes-devtools/qemu/qemu.inc | 1 | ||||
| -rw-r--r-- | meta/recipes-devtools/qemu/qemu/CVE-2021-3929.patch | 78 |
2 files changed, 79 insertions, 0 deletions
diff --git a/meta/recipes-devtools/qemu/qemu.inc b/meta/recipes-devtools/qemu/qemu.inc index e9fcb239b4..36d0b9320f 100644 --- a/meta/recipes-devtools/qemu/qemu.inc +++ b/meta/recipes-devtools/qemu/qemu.inc | |||
| @@ -115,6 +115,7 @@ SRC_URI = "https://download.qemu.org/${BPN}-${PV}.tar.xz \ | |||
| 115 | file://CVE-2021-3638.patch \ | 115 | file://CVE-2021-3638.patch \ |
| 116 | file://CVE-2021-20196.patch \ | 116 | file://CVE-2021-20196.patch \ |
| 117 | file://CVE-2021-3507.patch \ | 117 | file://CVE-2021-3507.patch \ |
| 118 | file://CVE-2021-3929.patch \ | ||
| 118 | " | 119 | " |
| 119 | UPSTREAM_CHECK_REGEX = "qemu-(?P<pver>\d+(\.\d+)+)\.tar" | 120 | UPSTREAM_CHECK_REGEX = "qemu-(?P<pver>\d+(\.\d+)+)\.tar" |
| 120 | 121 | ||
diff --git a/meta/recipes-devtools/qemu/qemu/CVE-2021-3929.patch b/meta/recipes-devtools/qemu/qemu/CVE-2021-3929.patch new file mode 100644 index 0000000000..3df2f8886a --- /dev/null +++ b/meta/recipes-devtools/qemu/qemu/CVE-2021-3929.patch | |||
| @@ -0,0 +1,78 @@ | |||
| 1 | From 736b01642d85be832385063f278fe7cd4ffb5221 Mon Sep 17 00:00:00 2001 | ||
| 2 | From: Klaus Jensen <k.jensen@samsung.com> | ||
| 3 | Date: Fri, 17 Dec 2021 10:44:01 +0100 | ||
| 4 | Subject: [PATCH] hw/nvme: fix CVE-2021-3929 | ||
| 5 | MIME-Version: 1.0 | ||
| 6 | Content-Type: text/plain; charset=UTF-8 | ||
| 7 | Content-Transfer-Encoding: 8bit | ||
| 8 | |||
| 9 | This fixes CVE-2021-3929 "locally" by denying DMA to the iomem of the | ||
| 10 | device itself. This still allows DMA to MMIO regions of other devices | ||
| 11 | (e.g. doing P2P DMA to the controller memory buffer of another NVMe | ||
| 12 | device). | ||
| 13 | |||
| 14 | Fixes: CVE-2021-3929 | ||
| 15 | Reported-by: Qiuhao Li <Qiuhao.Li@outlook.com> | ||
| 16 | Reviewed-by: Keith Busch <kbusch@kernel.org> | ||
| 17 | Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org> | ||
| 18 | Signed-off-by: Klaus Jensen <k.jensen@samsung.com> | ||
| 19 | |||
| 20 | Upstream-Status: Backport [https://gitlab.com/qemu-project/qemu/-/commit/736b01642d85be832385] | ||
| 21 | CVE: CVE-2021-3929 | ||
| 22 | Signed-off-by: Vivek Kumbhar <vkumbhar@mvista.com> | ||
| 23 | --- | ||
| 24 | hw/block/nvme.c | 23 +++++++++++++++++++++++ | ||
| 25 | hw/block/nvme.h | 1 + | ||
| 26 | 2 files changed, 24 insertions(+) | ||
| 27 | |||
| 28 | diff --git a/hw/block/nvme.c b/hw/block/nvme.c | ||
| 29 | index 12d82542..e7d0750c 100644 | ||
| 30 | --- a/hw/block/nvme.c | ||
| 31 | +++ b/hw/block/nvme.c | ||
| 32 | @@ -52,8 +52,31 @@ | ||
| 33 | |||
| 34 | static void nvme_process_sq(void *opaque); | ||
| 35 | |||
| 36 | +static inline bool nvme_addr_is_iomem(NvmeCtrl *n, hwaddr addr) | ||
| 37 | +{ | ||
| 38 | + hwaddr hi, lo; | ||
| 39 | + | ||
| 40 | + /* | ||
| 41 | + * The purpose of this check is to guard against invalid "local" access to | ||
| 42 | + * the iomem (i.e. controller registers). Thus, we check against the range | ||
| 43 | + * covered by the 'bar0' MemoryRegion since that is currently composed of | ||
| 44 | + * two subregions (the NVMe "MBAR" and the MSI-X table/pba). Note, however, | ||
| 45 | + * that if the device model is ever changed to allow the CMB to be located | ||
| 46 | + * in BAR0 as well, then this must be changed. | ||
| 47 | + */ | ||
| 48 | + lo = n->bar0.addr; | ||
| 49 | + hi = lo + int128_get64(n->bar0.size); | ||
| 50 | + | ||
| 51 | + return addr >= lo && addr < hi; | ||
| 52 | +} | ||
| 53 | + | ||
| 54 | static void nvme_addr_read(NvmeCtrl *n, hwaddr addr, void *buf, int size) | ||
| 55 | { | ||
| 56 | + | ||
| 57 | + if (nvme_addr_is_iomem(n, addr)) { | ||
| 58 | + return NVME_DATA_TRAS_ERROR; | ||
| 59 | + } | ||
| 60 | + | ||
| 61 | if (n->cmbsz && addr >= n->ctrl_mem.addr && | ||
| 62 | addr < (n->ctrl_mem.addr + int128_get64(n->ctrl_mem.size))) { | ||
| 63 | memcpy(buf, (void *)&n->cmbuf[addr - n->ctrl_mem.addr], size); | ||
| 64 | diff --git a/hw/block/nvme.h b/hw/block/nvme.h | ||
| 65 | index 557194ee..5a2b119c 100644 | ||
| 66 | --- a/hw/block/nvme.h | ||
| 67 | +++ b/hw/block/nvme.h | ||
| 68 | @@ -59,6 +59,7 @@ typedef struct NvmeNamespace { | ||
| 69 | |||
| 70 | typedef struct NvmeCtrl { | ||
| 71 | PCIDevice parent_obj; | ||
| 72 | + MemoryRegion bar0; | ||
| 73 | MemoryRegion iomem; | ||
| 74 | MemoryRegion ctrl_mem; | ||
| 75 | NvmeBar bar; | ||
| 76 | -- | ||
| 77 | 2.30.2 | ||
| 78 | |||
