summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorVijay Anusuri <vanusuri@mvista.com>2024-01-16 07:35:36 +0530
committerSteve Sakoman <steve@sakoman.com>2024-01-21 08:33:19 -1000
commit854aafaea449e5808c0cc2ddf02088511cd3defb (patch)
treef9952e297ac8dc6edfbdbf8788f81396de962c20
parent7e3b27865d62ecf75ec3b374888d9bafd7e7f5fc (diff)
downloadpoky-854aafaea449e5808c0cc2ddf02088511cd3defb.tar.gz
qemu: Backport fix for CVE-2023-2861
Updated 0012-fix-libcap-header-issue-on-some-distro.patch to resolve patch fuzz caused by the CVE-2023-2861 patch Upstream-Status: Backport [https://gitlab.com/qemu-project/qemu/-/commit/a5804fcf7b22fc7d1f9ec794dd284c7d504bd16b & https://gitlab.com/qemu-project/qemu/-/commit/f6b0de53fb87ddefed348a39284c8e2f28dc4eda] (From OE-Core rev: cede843cdd1d1a83b2d616086aa69a2b584f9442) Signed-off-by: Vijay Anusuri <vanusuri@mvista.com> Signed-off-by: Steve Sakoman <steve@sakoman.com>
-rw-r--r--meta/recipes-devtools/qemu/qemu.inc2
-rw-r--r--meta/recipes-devtools/qemu/qemu/0012-fix-libcap-header-issue-on-some-distro.patch9
-rw-r--r--meta/recipes-devtools/qemu/qemu/9pfs-local-ignore-O_NOATIME-if-we-don-t-have-permiss.patch63
-rw-r--r--meta/recipes-devtools/qemu/qemu/CVE-2023-2861.patch178
4 files changed, 249 insertions, 3 deletions
diff --git a/meta/recipes-devtools/qemu/qemu.inc b/meta/recipes-devtools/qemu/qemu.inc
index 4f856c749e..59ff69d51d 100644
--- a/meta/recipes-devtools/qemu/qemu.inc
+++ b/meta/recipes-devtools/qemu/qemu.inc
@@ -142,6 +142,8 @@ SRC_URI = "https://download.qemu.org/${BPN}-${PV}.tar.xz \
142 file://CVE-2023-3180.patch \ 142 file://CVE-2023-3180.patch \
143 file://CVE-2020-24165.patch \ 143 file://CVE-2020-24165.patch \
144 file://CVE-2023-5088.patch \ 144 file://CVE-2023-5088.patch \
145 file://9pfs-local-ignore-O_NOATIME-if-we-don-t-have-permiss.patch \
146 file://CVE-2023-2861.patch \
145 " 147 "
146UPSTREAM_CHECK_REGEX = "qemu-(?P<pver>\d+(\.\d+)+)\.tar" 148UPSTREAM_CHECK_REGEX = "qemu-(?P<pver>\d+(\.\d+)+)\.tar"
147 149
diff --git a/meta/recipes-devtools/qemu/qemu/0012-fix-libcap-header-issue-on-some-distro.patch b/meta/recipes-devtools/qemu/qemu/0012-fix-libcap-header-issue-on-some-distro.patch
index 3a7d7bbd33..3789f1edea 100644
--- a/meta/recipes-devtools/qemu/qemu/0012-fix-libcap-header-issue-on-some-distro.patch
+++ b/meta/recipes-devtools/qemu/qemu/0012-fix-libcap-header-issue-on-some-distro.patch
@@ -60,7 +60,7 @@ Signed-off-by: Hongxu Jia <hongxu.jia@windriver.com>
60 1 file changed, 5 insertions(+), 2 deletions(-) 60 1 file changed, 5 insertions(+), 2 deletions(-)
61 61
62diff --git a/fsdev/virtfs-proxy-helper.c b/fsdev/virtfs-proxy-helper.c 62diff --git a/fsdev/virtfs-proxy-helper.c b/fsdev/virtfs-proxy-helper.c
63index 6f132c5f..8329950c 100644 63index 300c9765..2823db7d 100644
64--- a/fsdev/virtfs-proxy-helper.c 64--- a/fsdev/virtfs-proxy-helper.c
65+++ b/fsdev/virtfs-proxy-helper.c 65+++ b/fsdev/virtfs-proxy-helper.c
66@@ -13,7 +13,6 @@ 66@@ -13,7 +13,6 @@
@@ -71,9 +71,9 @@ index 6f132c5f..8329950c 100644
71 #include <sys/fsuid.h> 71 #include <sys/fsuid.h>
72 #include <sys/vfs.h> 72 #include <sys/vfs.h>
73 #include <sys/ioctl.h> 73 #include <sys/ioctl.h>
74@@ -27,7 +26,11 @@ 74@@ -28,7 +27,11 @@
75 #include "9p-iov-marshal.h"
76 #include "hw/9pfs/9p-proxy.h" 75 #include "hw/9pfs/9p-proxy.h"
76 #include "hw/9pfs/9p-util.h"
77 #include "fsdev/9p-iov-marshal.h" 77 #include "fsdev/9p-iov-marshal.h"
78- 78-
79+/* 79+/*
@@ -84,3 +84,6 @@ index 6f132c5f..8329950c 100644
84 #define PROGNAME "virtfs-proxy-helper" 84 #define PROGNAME "virtfs-proxy-helper"
85 85
86 #ifndef XFS_SUPER_MAGIC 86 #ifndef XFS_SUPER_MAGIC
87--
882.25.1
89
diff --git a/meta/recipes-devtools/qemu/qemu/9pfs-local-ignore-O_NOATIME-if-we-don-t-have-permiss.patch b/meta/recipes-devtools/qemu/qemu/9pfs-local-ignore-O_NOATIME-if-we-don-t-have-permiss.patch
new file mode 100644
index 0000000000..72d9c47bde
--- /dev/null
+++ b/meta/recipes-devtools/qemu/qemu/9pfs-local-ignore-O_NOATIME-if-we-don-t-have-permiss.patch
@@ -0,0 +1,63 @@
1From a5804fcf7b22fc7d1f9ec794dd284c7d504bd16b Mon Sep 17 00:00:00 2001
2From: Omar Sandoval <osandov@fb.com>
3Date: Thu, 14 May 2020 08:06:43 +0200
4Subject: [PATCH] 9pfs: local: ignore O_NOATIME if we don't have permissions
5
6QEMU's local 9pfs server passes through O_NOATIME from the client. If
7the QEMU process doesn't have permissions to use O_NOATIME (namely, it
8does not own the file nor have the CAP_FOWNER capability), the open will
9fail. This causes issues when from the client's point of view, it
10believes it has permissions to use O_NOATIME (e.g., a process running as
11root in the virtual machine). Additionally, overlayfs on Linux opens
12files on the lower layer using O_NOATIME, so in this case a 9pfs mount
13can't be used as a lower layer for overlayfs (cf.
14https://github.com/osandov/drgn/blob/dabfe1971951701da13863dbe6d8a1d172ad9650/vmtest/onoatimehack.c
15and https://github.com/NixOS/nixpkgs/issues/54509).
16
17Luckily, O_NOATIME is effectively a hint, and is often ignored by, e.g.,
18network filesystems. open(2) notes that O_NOATIME "may not be effective
19on all filesystems. One example is NFS, where the server maintains the
20access time." This means that we can honor it when possible but fall
21back to ignoring it.
22
23Acked-by: Christian Schoenebeck <qemu_oss@crudebyte.com>
24Signed-off-by: Omar Sandoval <osandov@fb.com>
25Message-Id: <e9bee604e8df528584693a4ec474ded6295ce8ad.1587149256.git.osandov@fb.com>
26Signed-off-by: Greg Kurz <groug@kaod.org>
27
28Upstream-Status: Backport [https://gitlab.com/qemu-project/qemu/-/commit/a5804fcf7b22fc7d1f9ec794dd284c7d504bd16b]
29Signed-off-by: Vijay Anusuri <vanusuri@mvista.com>
30---
31 hw/9pfs/9p-util.h | 13 +++++++++++++
32 1 file changed, 13 insertions(+)
33
34diff --git a/hw/9pfs/9p-util.h b/hw/9pfs/9p-util.h
35index 79ed6b233e5..546f46dc7dc 100644
36--- a/hw/9pfs/9p-util.h
37+++ b/hw/9pfs/9p-util.h
38@@ -37,9 +37,22 @@ static inline int openat_file(int dirfd, const char *name, int flags,
39 {
40 int fd, serrno, ret;
41
42+again:
43 fd = openat(dirfd, name, flags | O_NOFOLLOW | O_NOCTTY | O_NONBLOCK,
44 mode);
45 if (fd == -1) {
46+ if (errno == EPERM && (flags & O_NOATIME)) {
47+ /*
48+ * The client passed O_NOATIME but we lack permissions to honor it.
49+ * Rather than failing the open, fall back without O_NOATIME. This
50+ * doesn't break the semantics on the client side, as the Linux
51+ * open(2) man page notes that O_NOATIME "may not be effective on
52+ * all filesystems". In particular, NFS and other network
53+ * filesystems ignore it entirely.
54+ */
55+ flags &= ~O_NOATIME;
56+ goto again;
57+ }
58 return -1;
59 }
60
61--
62GitLab
63
diff --git a/meta/recipes-devtools/qemu/qemu/CVE-2023-2861.patch b/meta/recipes-devtools/qemu/qemu/CVE-2023-2861.patch
new file mode 100644
index 0000000000..70b7d6c562
--- /dev/null
+++ b/meta/recipes-devtools/qemu/qemu/CVE-2023-2861.patch
@@ -0,0 +1,178 @@
1From f6b0de53fb87ddefed348a39284c8e2f28dc4eda Mon Sep 17 00:00:00 2001
2From: Christian Schoenebeck <qemu_oss@crudebyte.com>
3Date: Wed, 7 Jun 2023 18:29:33 +0200
4Subject: [PATCH] 9pfs: prevent opening special files (CVE-2023-2861)
5
6The 9p protocol does not specifically define how server shall behave when
7client tries to open a special file, however from security POV it does
8make sense for 9p server to prohibit opening any special file on host side
9in general. A sane Linux 9p client for instance would never attempt to
10open a special file on host side, it would always handle those exclusively
11on its guest side. A malicious client however could potentially escape
12from the exported 9p tree by creating and opening a device file on host
13side.
14
15With QEMU this could only be exploited in the following unsafe setups:
16
17 - Running QEMU binary as root AND 9p 'local' fs driver AND 'passthrough'
18 security model.
19
20or
21
22 - Using 9p 'proxy' fs driver (which is running its helper daemon as
23 root).
24
25These setups were already discouraged for safety reasons before,
26however for obvious reasons we are now tightening behaviour on this.
27
28Fixes: CVE-2023-2861
29Reported-by: Yanwu Shen <ywsPlz@gmail.com>
30Reported-by: Jietao Xiao <shawtao1125@gmail.com>
31Reported-by: Jinku Li <jkli@xidian.edu.cn>
32Reported-by: Wenbo Shen <shenwenbo@zju.edu.cn>
33Signed-off-by: Christian Schoenebeck <qemu_oss@crudebyte.com>
34Reviewed-by: Greg Kurz <groug@kaod.org>
35Reviewed-by: Michael Tokarev <mjt@tls.msk.ru>
36Message-Id: <E1q6w7r-0000Q0-NM@lizzy.crudebyte.com>
37
38Upstream-Status: Backport [https://gitlab.com/qemu-project/qemu/-/commit/f6b0de53fb87ddefed348a39284c8e2f28dc4eda]
39CVE: CVE-2023-2861
40Signed-off-by: Vijay Anusuri <vanusuri@mvista.com>
41---
42 fsdev/virtfs-proxy-helper.c | 27 +++++++++++++++++++++++--
43 hw/9pfs/9p-util.h | 40 +++++++++++++++++++++++++++++++++++++
44 2 files changed, 65 insertions(+), 2 deletions(-)
45
46diff --git a/fsdev/virtfs-proxy-helper.c b/fsdev/virtfs-proxy-helper.c
47index 6f132c5f..300c9765 100644
48--- a/fsdev/virtfs-proxy-helper.c
49+++ b/fsdev/virtfs-proxy-helper.c
50@@ -26,6 +26,7 @@
51 #include "qemu/xattr.h"
52 #include "9p-iov-marshal.h"
53 #include "hw/9pfs/9p-proxy.h"
54+#include "hw/9pfs/9p-util.h"
55 #include "fsdev/9p-iov-marshal.h"
56
57 #define PROGNAME "virtfs-proxy-helper"
58@@ -350,6 +351,28 @@ static void resetugid(int suid, int sgid)
59 }
60 }
61
62+/*
63+ * Open regular file or directory. Attempts to open any special file are
64+ * rejected.
65+ *
66+ * returns file descriptor or -1 on error
67+ */
68+static int open_regular(const char *pathname, int flags, mode_t mode)
69+{
70+ int fd;
71+
72+ fd = open(pathname, flags, mode);
73+ if (fd < 0) {
74+ return fd;
75+ }
76+
77+ if (close_if_special_file(fd) < 0) {
78+ return -1;
79+ }
80+
81+ return fd;
82+}
83+
84 /*
85 * send response in two parts
86 * 1) ProxyHeader
87@@ -694,7 +717,7 @@ static int do_create(struct iovec *iovec)
88 if (ret < 0) {
89 goto unmarshal_err_out;
90 }
91- ret = open(path.data, flags, mode);
92+ ret = open_regular(path.data, flags, mode);
93 if (ret < 0) {
94 ret = -errno;
95 }
96@@ -719,7 +742,7 @@ static int do_open(struct iovec *iovec)
97 if (ret < 0) {
98 goto err_out;
99 }
100- ret = open(path.data, flags);
101+ ret = open_regular(path.data, flags, 0);
102 if (ret < 0) {
103 ret = -errno;
104 }
105diff --git a/hw/9pfs/9p-util.h b/hw/9pfs/9p-util.h
106index 546f46dc..79fdd2a3 100644
107--- a/hw/9pfs/9p-util.h
108+++ b/hw/9pfs/9p-util.h
109@@ -13,12 +13,16 @@
110 #ifndef QEMU_9P_UTIL_H
111 #define QEMU_9P_UTIL_H
112
113+#include "qemu/error-report.h"
114+
115 #ifdef O_PATH
116 #define O_PATH_9P_UTIL O_PATH
117 #else
118 #define O_PATH_9P_UTIL 0
119 #endif
120
121+#define qemu_fstat fstat
122+
123 static inline void close_preserve_errno(int fd)
124 {
125 int serrno = errno;
126@@ -26,6 +30,38 @@ static inline void close_preserve_errno(int fd)
127 errno = serrno;
128 }
129
130+/**
131+ * close_if_special_file() - Close @fd if neither regular file nor directory.
132+ *
133+ * @fd: file descriptor of open file
134+ * Return: 0 on regular file or directory, -1 otherwise
135+ *
136+ * CVE-2023-2861: Prohibit opening any special file directly on host
137+ * (especially device files), as a compromised client could potentially gain
138+ * access outside exported tree under certain, unsafe setups. We expect
139+ * client to handle I/O on special files exclusively on guest side.
140+ */
141+static inline int close_if_special_file(int fd)
142+{
143+ struct stat stbuf;
144+
145+ if (qemu_fstat(fd, &stbuf) < 0) {
146+ close_preserve_errno(fd);
147+ return -1;
148+ }
149+ if (!S_ISREG(stbuf.st_mode) && !S_ISDIR(stbuf.st_mode)) {
150+ error_report_once(
151+ "9p: broken or compromised client detected; attempt to open "
152+ "special file (i.e. neither regular file, nor directory)"
153+ );
154+ close(fd);
155+ errno = ENXIO;
156+ return -1;
157+ }
158+
159+ return 0;
160+}
161+
162 static inline int openat_dir(int dirfd, const char *name)
163 {
164 return openat(dirfd, name,
165@@ -56,6 +92,10 @@ again:
166 return -1;
167 }
168
169+ if (close_if_special_file(fd) < 0) {
170+ return -1;
171+ }
172+
173 serrno = errno;
174 /* O_NONBLOCK was only needed to open the file. Let's drop it. We don't
175 * do that with O_PATH since fcntl(F_SETFL) isn't supported, and openat()
176--
1772.25.1
178