summaryrefslogtreecommitdiffstats
path: root/meta
diff options
context:
space:
mode:
authorMarcus Cooper <marcus.cooper@axis.com>2019-01-24 13:43:39 +0100
committerRichard Purdie <richard.purdie@linuxfoundation.org>2019-01-24 17:45:25 +0000
commitdee2bf9c3f893474dcc650042cb04a25789ae7c4 (patch)
tree7c9708e61a4d6ff0731b09ec1515b55d55738bb2 /meta
parente157997dfcb1c1508e23e3c41b43e581bddf0d83 (diff)
downloadpoky-dee2bf9c3f893474dcc650042cb04a25789ae7c4.tar.gz
systemd: Security fix CVE-2018-16864
Affects < v240 (From OE-Core rev: 6900b9cc2cd3e66469a9561bb478b87c0903b0ea) Signed-off-by: Marcus Cooper <marcusc@axis.com> Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
Diffstat (limited to 'meta')
-rw-r--r--meta/recipes-core/systemd/systemd/0024-journald-do-not-store-the-iovec-entry-for-process-co.patch204
-rw-r--r--meta/recipes-core/systemd/systemd_239.bb1
2 files changed, 205 insertions, 0 deletions
diff --git a/meta/recipes-core/systemd/systemd/0024-journald-do-not-store-the-iovec-entry-for-process-co.patch b/meta/recipes-core/systemd/systemd/0024-journald-do-not-store-the-iovec-entry-for-process-co.patch
new file mode 100644
index 0000000000..c3009545b1
--- /dev/null
+++ b/meta/recipes-core/systemd/systemd/0024-journald-do-not-store-the-iovec-entry-for-process-co.patch
@@ -0,0 +1,204 @@
1From fe19f5a9d0d8b9977e9507a9b66c3cc66744cd38 Mon Sep 17 00:00:00 2001
2From: =?UTF-8?q?Zbigniew=20J=C4=99drzejewski-Szmek?= <zbyszek@in.waw.pl>
3Date: Wed, 5 Dec 2018 18:38:39 +0100
4Subject: [PATCH] journald: do not store the iovec entry for process
5 commandline on stack
6
7This fixes a crash where we would read the commandline, whose length is under
8control of the sending program, and then crash when trying to create a stack
9allocation for it.
10
11CVE-2018-16864
12https://bugzilla.redhat.com/show_bug.cgi?id=1653855
13
14The message actually doesn't get written to disk, because
15journal_file_append_entry() returns -E2BIG.
16
17Patch backported from systemd master at
18084eeb865ca63887098e0945fb4e93c852b91b0f.
19---
20 src/basic/io-util.c | 10 ++++++++++
21 src/basic/io-util.h | 2 ++
22 src/coredump/coredump.c | 31 +++++++++++--------------------
23 src/journal/journald-server.c | 25 +++++++++++++++----------
24 4 files changed, 38 insertions(+), 30 deletions(-)
25
26diff --git a/src/basic/io-util.c b/src/basic/io-util.c
27index 1f64cc933b..575398fbe6 100644
28--- a/src/basic/io-util.c
29+++ b/src/basic/io-util.c
30@@ -8,6 +8,7 @@
31 #include <unistd.h>
32
33 #include "io-util.h"
34+#include "string-util.h"
35 #include "time-util.h"
36
37 int flush_fd(int fd) {
38@@ -252,3 +253,12 @@ ssize_t sparse_write(int fd, const void *p, size_t sz, size_t run_length) {
39
40 return q - (const uint8_t*) p;
41 }
42+
43+char* set_iovec_string_field(struct iovec *iovec, size_t *n_iovec, const char *field, const char *value) {
44+ char *x;
45+
46+ x = strappend(field, value);
47+ if (x)
48+ iovec[(*n_iovec)++] = IOVEC_MAKE_STRING(x);
49+ return x;
50+}
51diff --git a/src/basic/io-util.h b/src/basic/io-util.h
52index ed189b5820..792a64ad5e 100644
53--- a/src/basic/io-util.h
54+++ b/src/basic/io-util.h
55@@ -71,3 +71,5 @@ static inline bool FILE_SIZE_VALID_OR_INFINITY(uint64_t l) {
56 #define IOVEC_MAKE(base, len) (struct iovec) IOVEC_INIT(base, len)
57 #define IOVEC_INIT_STRING(string) IOVEC_INIT((char*) string, strlen(string))
58 #define IOVEC_MAKE_STRING(string) (struct iovec) IOVEC_INIT_STRING(string)
59+
60+char* set_iovec_string_field(struct iovec *iovec, size_t *n_iovec, const char *field, const char *value);
61diff --git a/src/coredump/coredump.c b/src/coredump/coredump.c
62index 20a1cbdd45..18e4f61d72 100644
63--- a/src/coredump/coredump.c
64+++ b/src/coredump/coredump.c
65@@ -1053,19 +1053,10 @@ static int send_iovec(const struct iovec iovec[], size_t n_iovec, int input_fd)
66 return 0;
67 }
68
69-static char* set_iovec_field(struct iovec *iovec, size_t *n_iovec, const char *field, const char *value) {
70- char *x;
71-
72- x = strappend(field, value);
73- if (x)
74- iovec[(*n_iovec)++] = IOVEC_MAKE_STRING(x);
75- return x;
76-}
77-
78 static char* set_iovec_field_free(struct iovec *iovec, size_t *n_iovec, const char *field, char *value) {
79 char *x;
80
81- x = set_iovec_field(iovec, n_iovec, field, value);
82+ x = set_iovec_string_field(iovec, n_iovec, field, value);
83 free(value);
84 return x;
85 }
86@@ -1115,36 +1106,36 @@ static int gather_pid_metadata(
87 disable_coredumps();
88 }
89
90- set_iovec_field(iovec, n_iovec, "COREDUMP_UNIT=", context[CONTEXT_UNIT]);
91+ set_iovec_string_field(iovec, n_iovec, "COREDUMP_UNIT=", context[CONTEXT_UNIT]);
92 }
93
94 if (cg_pid_get_user_unit(pid, &t) >= 0)
95 set_iovec_field_free(iovec, n_iovec, "COREDUMP_USER_UNIT=", t);
96
97 /* The next few are mandatory */
98- if (!set_iovec_field(iovec, n_iovec, "COREDUMP_PID=", context[CONTEXT_PID]))
99+ if (!set_iovec_string_field(iovec, n_iovec, "COREDUMP_PID=", context[CONTEXT_PID]))
100 return log_oom();
101
102- if (!set_iovec_field(iovec, n_iovec, "COREDUMP_UID=", context[CONTEXT_UID]))
103+ if (!set_iovec_string_field(iovec, n_iovec, "COREDUMP_UID=", context[CONTEXT_UID]))
104 return log_oom();
105
106- if (!set_iovec_field(iovec, n_iovec, "COREDUMP_GID=", context[CONTEXT_GID]))
107+ if (!set_iovec_string_field(iovec, n_iovec, "COREDUMP_GID=", context[CONTEXT_GID]))
108 return log_oom();
109
110- if (!set_iovec_field(iovec, n_iovec, "COREDUMP_SIGNAL=", context[CONTEXT_SIGNAL]))
111+ if (!set_iovec_string_field(iovec, n_iovec, "COREDUMP_SIGNAL=", context[CONTEXT_SIGNAL]))
112 return log_oom();
113
114- if (!set_iovec_field(iovec, n_iovec, "COREDUMP_RLIMIT=", context[CONTEXT_RLIMIT]))
115+ if (!set_iovec_string_field(iovec, n_iovec, "COREDUMP_RLIMIT=", context[CONTEXT_RLIMIT]))
116 return log_oom();
117
118- if (!set_iovec_field(iovec, n_iovec, "COREDUMP_HOSTNAME=", context[CONTEXT_HOSTNAME]))
119+ if (!set_iovec_string_field(iovec, n_iovec, "COREDUMP_HOSTNAME=", context[CONTEXT_HOSTNAME]))
120 return log_oom();
121
122- if (!set_iovec_field(iovec, n_iovec, "COREDUMP_COMM=", context[CONTEXT_COMM]))
123+ if (!set_iovec_string_field(iovec, n_iovec, "COREDUMP_COMM=", context[CONTEXT_COMM]))
124 return log_oom();
125
126 if (context[CONTEXT_EXE] &&
127- !set_iovec_field(iovec, n_iovec, "COREDUMP_EXE=", context[CONTEXT_EXE]))
128+ !set_iovec_string_field(iovec, n_iovec, "COREDUMP_EXE=", context[CONTEXT_EXE]))
129 return log_oom();
130
131 if (sd_pid_get_session(pid, &t) >= 0)
132@@ -1212,7 +1203,7 @@ static int gather_pid_metadata(
133 iovec[(*n_iovec)++] = IOVEC_MAKE_STRING(t);
134
135 if (safe_atoi(context[CONTEXT_SIGNAL], &signo) >= 0 && SIGNAL_VALID(signo))
136- set_iovec_field(iovec, n_iovec, "COREDUMP_SIGNAL_NAME=SIG", signal_to_string(signo));
137+ set_iovec_string_field(iovec, n_iovec, "COREDUMP_SIGNAL_NAME=SIG", signal_to_string(signo));
138
139 return 0; /* we successfully acquired all metadata */
140 }
141diff --git a/src/journal/journald-server.c b/src/journal/journald-server.c
142index 4f1550ec5b..31be085c6b 100644
143--- a/src/journal/journald-server.c
144+++ b/src/journal/journald-server.c
145@@ -753,6 +753,7 @@ static void dispatch_message_real(
146 pid_t object_pid) {
147
148 char source_time[sizeof("_SOURCE_REALTIME_TIMESTAMP=") + DECIMAL_STR_MAX(usec_t)];
149+ _cleanup_free_ char *cmdline1 = NULL, *cmdline2 = NULL;
150 uid_t journal_uid;
151 ClientContext *o;
152
153@@ -769,20 +770,23 @@ static void dispatch_message_real(
154 IOVEC_ADD_NUMERIC_FIELD(iovec, n, c->uid, uid_t, uid_is_valid, UID_FMT, "_UID");
155 IOVEC_ADD_NUMERIC_FIELD(iovec, n, c->gid, gid_t, gid_is_valid, GID_FMT, "_GID");
156
157- IOVEC_ADD_STRING_FIELD(iovec, n, c->comm, "_COMM");
158- IOVEC_ADD_STRING_FIELD(iovec, n, c->exe, "_EXE");
159- IOVEC_ADD_STRING_FIELD(iovec, n, c->cmdline, "_CMDLINE");
160- IOVEC_ADD_STRING_FIELD(iovec, n, c->capeff, "_CAP_EFFECTIVE");
161+ IOVEC_ADD_STRING_FIELD(iovec, n, c->comm, "_COMM"); /* At most TASK_COMM_LENGTH (16 bytes) */
162+ IOVEC_ADD_STRING_FIELD(iovec, n, c->exe, "_EXE"); /* A path, so at most PATH_MAX (4096 bytes) */
163
164- IOVEC_ADD_SIZED_FIELD(iovec, n, c->label, c->label_size, "_SELINUX_CONTEXT");
165+ if (c->cmdline)
166+ /* At most _SC_ARG_MAX (2MB usually), which is too much to put on stack.
167+ * Let's use a heap allocation for this one. */
168+ cmdline1 = set_iovec_string_field(iovec, &n, "_CMDLINE=", c->cmdline);
169
170+ IOVEC_ADD_STRING_FIELD(iovec, n, c->capeff, "_CAP_EFFECTIVE"); /* Read from /proc/.../status */
171+ IOVEC_ADD_SIZED_FIELD(iovec, n, c->label, c->label_size, "_SELINUX_CONTEXT");
172 IOVEC_ADD_NUMERIC_FIELD(iovec, n, c->auditid, uint32_t, audit_session_is_valid, "%" PRIu32, "_AUDIT_SESSION");
173 IOVEC_ADD_NUMERIC_FIELD(iovec, n, c->loginuid, uid_t, uid_is_valid, UID_FMT, "_AUDIT_LOGINUID");
174
175- IOVEC_ADD_STRING_FIELD(iovec, n, c->cgroup, "_SYSTEMD_CGROUP");
176+ IOVEC_ADD_STRING_FIELD(iovec, n, c->cgroup, "_SYSTEMD_CGROUP"); /* A path */
177 IOVEC_ADD_STRING_FIELD(iovec, n, c->session, "_SYSTEMD_SESSION");
178 IOVEC_ADD_NUMERIC_FIELD(iovec, n, c->owner_uid, uid_t, uid_is_valid, UID_FMT, "_SYSTEMD_OWNER_UID");
179- IOVEC_ADD_STRING_FIELD(iovec, n, c->unit, "_SYSTEMD_UNIT");
180+ IOVEC_ADD_STRING_FIELD(iovec, n, c->unit, "_SYSTEMD_UNIT"); /* Unit names are bounded by UNIT_NAME_MAX */
181 IOVEC_ADD_STRING_FIELD(iovec, n, c->user_unit, "_SYSTEMD_USER_UNIT");
182 IOVEC_ADD_STRING_FIELD(iovec, n, c->slice, "_SYSTEMD_SLICE");
183 IOVEC_ADD_STRING_FIELD(iovec, n, c->user_slice, "_SYSTEMD_USER_SLICE");
184@@ -803,13 +807,14 @@ static void dispatch_message_real(
185 IOVEC_ADD_NUMERIC_FIELD(iovec, n, o->uid, uid_t, uid_is_valid, UID_FMT, "OBJECT_UID");
186 IOVEC_ADD_NUMERIC_FIELD(iovec, n, o->gid, gid_t, gid_is_valid, GID_FMT, "OBJECT_GID");
187
188+ /* See above for size limits, only ->cmdline may be large, so use a heap allocation for it. */
189 IOVEC_ADD_STRING_FIELD(iovec, n, o->comm, "OBJECT_COMM");
190 IOVEC_ADD_STRING_FIELD(iovec, n, o->exe, "OBJECT_EXE");
191- IOVEC_ADD_STRING_FIELD(iovec, n, o->cmdline, "OBJECT_CMDLINE");
192- IOVEC_ADD_STRING_FIELD(iovec, n, o->capeff, "OBJECT_CAP_EFFECTIVE");
193+ if (o->cmdline)
194+ cmdline2 = set_iovec_string_field(iovec, &n, "OBJECT_CMDLINE=", o->cmdline);
195
196+ IOVEC_ADD_STRING_FIELD(iovec, n, o->capeff, "OBJECT_CAP_EFFECTIVE");
197 IOVEC_ADD_SIZED_FIELD(iovec, n, o->label, o->label_size, "OBJECT_SELINUX_CONTEXT");
198-
199 IOVEC_ADD_NUMERIC_FIELD(iovec, n, o->auditid, uint32_t, audit_session_is_valid, "%" PRIu32, "OBJECT_AUDIT_SESSION");
200 IOVEC_ADD_NUMERIC_FIELD(iovec, n, o->loginuid, uid_t, uid_is_valid, UID_FMT, "OBJECT_AUDIT_LOGINUID");
201
202--
2032.11.0
204
diff --git a/meta/recipes-core/systemd/systemd_239.bb b/meta/recipes-core/systemd/systemd_239.bb
index c146897508..94729a6a39 100644
--- a/meta/recipes-core/systemd/systemd_239.bb
+++ b/meta/recipes-core/systemd/systemd_239.bb
@@ -38,6 +38,7 @@ SRC_URI += "file://touchscreen.rules \
38 file://0001-sysctl-Don-t-pass-null-directive-argument-to-s.patch \ 38 file://0001-sysctl-Don-t-pass-null-directive-argument-to-s.patch \
39 file://0002-core-Fix-use-after-free-case-in-load_from_path.patch \ 39 file://0002-core-Fix-use-after-free-case-in-load_from_path.patch \
40 file://0001-meson-rename-Ddebug-to-Ddebug-extra.patch \ 40 file://0001-meson-rename-Ddebug-to-Ddebug-extra.patch \
41 file://0024-journald-do-not-store-the-iovec-entry-for-process-co.patch \
41 " 42 "
42 43
43# patches made for musl are only applied on TCLIBC is musl 44# patches made for musl are only applied on TCLIBC is musl