Skip to content

Commit ea3243c

Browse files
[AUTO-CHERRYPICK] [High] Patch qemu for CVE-2023-1544, CVE-2023-2861 - branch main (#13348)
Co-authored-by: Kevin Lockwood <57274670+kevin-b-lockwood@users.noreply.github.com>
1 parent f9a9a89 commit ea3243c

3 files changed

Lines changed: 218 additions & 1 deletion

File tree

SPECS/qemu/CVE-2023-1544.patch

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
From 85fc35afa93c7320d1641d344d0c5dfbe341d087 Mon Sep 17 00:00:00 2001
2+
From: Yuval Shaia <yuval.shaia.ml@gmail.com>
3+
Date: Wed, 1 Mar 2023 16:29:26 +0200
4+
Subject: [PATCH] hw/pvrdma: Protect against buggy or malicious guest driver
5+
6+
Guest driver allocates and initialize page tables to be used as a ring
7+
of descriptors for CQ and async events.
8+
The page table that represents the ring, along with the number of pages
9+
in the page table is passed to the device.
10+
Currently our device supports only one page table for a ring.
11+
12+
Let's make sure that the number of page table entries the driver
13+
reports, do not exceeds the one page table size.
14+
15+
Reported-by: Soul Chen <soulchen8650@gmail.com>
16+
Signed-off-by: Yuval Shaia <yuval.shaia.ml@gmail.com>
17+
Fixes: CVE-2023-1544
18+
Message-ID: <20230301142926.18686-1-yuval.shaia.ml@gmail.com>
19+
Signed-off-by: Thomas Huth <thuth@redhat.com>
20+
---
21+
hw/rdma/vmw/pvrdma_main.c | 16 +++++++++++++++-
22+
1 file changed, 15 insertions(+), 1 deletion(-)
23+
24+
diff --git a/hw/rdma/vmw/pvrdma_main.c b/hw/rdma/vmw/pvrdma_main.c
25+
index 4fc67120256..55b338046e6 100644
26+
--- a/hw/rdma/vmw/pvrdma_main.c
27+
+++ b/hw/rdma/vmw/pvrdma_main.c
28+
@@ -91,19 +91,33 @@ static int init_dev_ring(PvrdmaRing *ring, PvrdmaRingState **ring_state,
29+
dma_addr_t dir_addr, uint32_t num_pages)
30+
{
31+
uint64_t *dir, *tbl;
32+
- int rc = 0;
33+
+ int max_pages, rc = 0;
34+
35+
if (!num_pages) {
36+
rdma_error_report("Ring pages count must be strictly positive");
37+
return -EINVAL;
38+
}
39+
40+
+ /*
41+
+ * Make sure we can satisfy the requested number of pages in a single
42+
+ * TARGET_PAGE_SIZE sized page table (taking into account that first entry
43+
+ * is reserved for ring-state)
44+
+ */
45+
+ max_pages = TARGET_PAGE_SIZE / sizeof(dma_addr_t) - 1;
46+
+ if (num_pages > max_pages) {
47+
+ rdma_error_report("Maximum pages on a single directory must not exceed %d\n",
48+
+ max_pages);
49+
+ return -EINVAL;
50+
+ }
51+
+
52+
dir = rdma_pci_dma_map(pci_dev, dir_addr, TARGET_PAGE_SIZE);
53+
if (!dir) {
54+
rdma_error_report("Failed to map to page directory (ring %s)", name);
55+
rc = -ENOMEM;
56+
goto out;
57+
}
58+
+
59+
+ /* We support only one page table for a ring */
60+
tbl = rdma_pci_dma_map(pci_dev, dir[0], TARGET_PAGE_SIZE);
61+
if (!tbl) {
62+
rdma_error_report("Failed to map to page table (ring %s)", name);
63+
--
64+
GitLab
65+

SPECS/qemu/CVE-2023-2861.patch

Lines changed: 144 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,144 @@
1+
From db34ce8e5b917f08456e9e0d3f02a4d737c00441 Mon Sep 17 00:00:00 2001
2+
From: Kevin Lockwood <v-klockwood@microsoft.com>
3+
Date: Tue, 8 Apr 2025 16:56:52 -0700
4+
Subject: [PATCH] [High] Patch qemu for CVE-2023-2861
5+
6+
Link: https://gitlab.com/qemu-project/qemu/-/commit/f6b0de53fb87ddefed348a39284c8e2f28dc4eda
7+
---
8+
fsdev/virtfs-proxy-helper.c | 27 +++++++++++++++++++++++--
9+
hw/9pfs/9p-util.h | 40 +++++++++++++++++++++++++++++++++++++
10+
2 files changed, 65 insertions(+), 2 deletions(-)
11+
12+
diff --git a/fsdev/virtfs-proxy-helper.c b/fsdev/virtfs-proxy-helper.c
13+
index 15c0e79b0..f9e4669a5 100644
14+
--- a/fsdev/virtfs-proxy-helper.c
15+
+++ b/fsdev/virtfs-proxy-helper.c
16+
@@ -26,6 +26,7 @@
17+
#include "qemu/xattr.h"
18+
#include "9p-iov-marshal.h"
19+
#include "hw/9pfs/9p-proxy.h"
20+
+#include "hw/9pfs/9p-util.h"
21+
#include "fsdev/9p-iov-marshal.h"
22+
23+
#define PROGNAME "virtfs-proxy-helper"
24+
@@ -338,6 +339,28 @@ static void resetugid(int suid, int sgid)
25+
}
26+
}
27+
28+
+/*
29+
+ * Open regular file or directory. Attempts to open any special file are
30+
+ * rejected.
31+
+ *
32+
+ * returns file descriptor or -1 on error
33+
+ */
34+
+static int open_regular(const char *pathname, int flags, mode_t mode)
35+
+{
36+
+ int fd;
37+
+
38+
+ fd = open(pathname, flags, mode);
39+
+ if (fd < 0) {
40+
+ return fd;
41+
+ }
42+
+
43+
+ if (close_if_special_file(fd) < 0) {
44+
+ return -1;
45+
+ }
46+
+
47+
+ return fd;
48+
+}
49+
+
50+
/*
51+
* send response in two parts
52+
* 1) ProxyHeader
53+
@@ -682,7 +705,7 @@ static int do_create(struct iovec *iovec)
54+
if (ret < 0) {
55+
goto unmarshal_err_out;
56+
}
57+
- ret = open(path.data, flags, mode);
58+
+ ret = open_regular(path.data, flags, mode);
59+
if (ret < 0) {
60+
ret = -errno;
61+
}
62+
@@ -707,7 +730,7 @@ static int do_open(struct iovec *iovec)
63+
if (ret < 0) {
64+
goto err_out;
65+
}
66+
- ret = open(path.data, flags);
67+
+ ret = open_regular(path.data, flags, 0);
68+
if (ret < 0) {
69+
ret = -errno;
70+
}
71+
diff --git a/hw/9pfs/9p-util.h b/hw/9pfs/9p-util.h
72+
index 546f46dc7..23000e917 100644
73+
--- a/hw/9pfs/9p-util.h
74+
+++ b/hw/9pfs/9p-util.h
75+
@@ -13,12 +13,16 @@
76+
#ifndef QEMU_9P_UTIL_H
77+
#define QEMU_9P_UTIL_H
78+
79+
+#include "qemu/error-report.h"
80+
+
81+
#ifdef O_PATH
82+
#define O_PATH_9P_UTIL O_PATH
83+
#else
84+
#define O_PATH_9P_UTIL 0
85+
#endif
86+
87+
+#define qemu_fstat fstat
88+
+
89+
static inline void close_preserve_errno(int fd)
90+
{
91+
int serrno = errno;
92+
@@ -26,6 +30,38 @@ static inline void close_preserve_errno(int fd)
93+
errno = serrno;
94+
}
95+
96+
+/**
97+
+ * close_if_special_file() - Close @fd if neither regular file nor directory.
98+
+ *
99+
+ * @fd: file descriptor of open file
100+
+ * Return: 0 on regular file or directory, -1 otherwise
101+
+ *
102+
+ * CVE-2023-2861: Prohibit opening any special file directly on host
103+
+ * (especially device files), as a compromised client could potentially gain
104+
+ * access outside exported tree under certain, unsafe setups. We expect
105+
+ * client to handle I/O on special files exclusively on guest side.
106+
+ */
107+
+static inline int close_if_special_file(int fd)
108+
+{
109+
+ struct stat stbuf;
110+
+
111+
+ if (qemu_fstat(fd, &stbuf) < 0) {
112+
+ close_preserve_errno(fd);
113+
+ return -1;
114+
+ }
115+
+ if (!S_ISREG(stbuf.st_mode) && !S_ISDIR(stbuf.st_mode)) {
116+
+ error_report_once(
117+
+ "9p: broken or compromised client detected; attempt to open "
118+
+ "special file (i.e. neither regular file, nor directory)"
119+
+ );
120+
+ close(fd);
121+
+ errno = ENXIO;
122+
+ return -1;
123+
+ }
124+
+
125+
+ return 0;
126+
+}
127+
+
128+
static inline int openat_dir(int dirfd, const char *name)
129+
{
130+
return openat(dirfd, name,
131+
@@ -56,6 +92,10 @@ again:
132+
return -1;
133+
}
134+
135+
+ if (close_if_special_file(fd) < 0) {
136+
+ return -1;
137+
+ }
138+
+
139+
serrno = errno;
140+
/* O_NONBLOCK was only needed to open the file. Let's drop it. We don't
141+
* do that with O_PATH since fcntl(F_SETFL) isn't supported, and openat()
142+
--
143+
2.34.1
144+

SPECS/qemu/qemu.spec

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -217,7 +217,7 @@ Obsoletes: %{name}-system-unicore32-core <= %{version}-%{release}
217217
Summary: QEMU is a FAST! processor emulator
218218
Name: qemu
219219
Version: 6.2.0
220-
Release: 21%{?dist}
220+
Release: 22%{?dist}
221221
License: BSD AND CC-BY AND GPLv2+ AND LGPLv2+ AND MIT
222222
Vendor: Microsoft Corporation
223223
Distribution: Mariner
@@ -279,6 +279,10 @@ Patch1017: CVE-2024-24474.patch
279279
Patch1018: CVE-2023-6683.patch
280280
Patch1019: CVE-2023-6693.patch
281281
Patch1020: CVE-2023-5088.patch
282+
# CVE-2023-2861 will be fixed in 8.1.0 by https://gitlab.com/qemu-project/qemu/-/commit/f6b0de53fb87ddefed348a39284c8e2f28dc4eda
283+
Patch1021: CVE-2023-2861.patch
284+
# CVE-2023-1544 will be fixed in 8.2.0 by https://gitlab.com/qemu-project/qemu/-/commit/85fc35afa93c7320d1641d344d0c5dfbe341d087
285+
Patch1022: CVE-2023-1544.patch
282286

283287
# alsa audio output
284288
BuildRequires: alsa-lib-devel
@@ -2313,6 +2317,10 @@ useradd -r -u 107 -g qemu -G kvm -d / -s %{_sbindir}/nologin \
23132317

23142318

23152319
%changelog
2320+
* Wed Apr 09 2025 Kevin Lockwood <v-klockwood@microsoft.com> - 6.2.0-22
2321+
- Add patch for CVE-2023-2861
2322+
- Add patch for CVE-2023-1544
2323+
23162324
* Wed Mar 19 2025 Kevin Lockwood <v-klockwood@microsoft.com> - 6.2.0-21
23172325
- Add patch for CVE-2023-6683
23182326
- Add patch for CVE-2023-6693

0 commit comments

Comments
 (0)