systemd: fix CVEs
cover systemd: fix CVEs
Apply CVE patches to systemd. Backport changes from thud when possible otherwise use patches from:
https://launchpad.net/ubuntu/+source/systemd/237-3ubuntu10.13
The following changes since commit 31f0c5e59c7fb0ae0915de584fbfcf3d95bbb061:
testsdk: Improvements to the json logging (2018-12-07 10:56:32 +0000)
are available in the git repository at:
git://github.com/gmccollister/openembedded-core sumo-cve-fixes
https://github.com/gmccollister/openembedded-core/tree/sumo-cve-fixes
Chen Qi (2):
systemd: fix CVE-2018-15686
systemd: fix CVE-2018-15688
George McCollister (5):
systemd: fix CVE-2018-15687
systemd: Security fix CVE-2018-16864
systemd: Security fix CVE-2018-16865
systemd: fix CVE-2018-6954
systemd: fix CVE-2019-6454
Marcus Cooper (1):
systemd: Security fix CVE-2018-16866
...sive-let-s-rework-the-recursive-logic-to-.patch | 252 +++ ...eserializing-state-always-use-read_line-L.patch | 250 +++ ...sure-we-have-enough-space-for-the-DHCP6-o.patch | 39 + ...n-t-resolve-pathnames-when-traversing-rec.patch | 643 +++++++ .../systemd/systemd/0002-Make-tmpfiles-safe.patch | 1828 ++++++++++++++++++++ ...-not-store-the-iovec-entry-for-process-co.patch | 193 +++ ...ld-set-a-limit-on-the-number-of-fields-1k.patch | 60 + ...ote-set-a-limit-on-the-number-of-fields-i.patch | 79 + ...nal-fix-out-of-bounds-read-CVE-2018-16866.patch | 49 + .../systemd/systemd/CVE-2019-6454.patch | 210 +++ ...e-receive-an-invalid-dbus-message-ignore-.patch | 61 + meta/recipes-core/systemd/systemd_237.bb | 11 + 12 files changed, 3675 insertions(+) create mode 100644 meta/recipes-core/systemd/systemd/0001-chown-recursive-let-s-rework-the-recursive-logic-to-.patch create mode 100644 meta/recipes-core/systemd/systemd/0001-core-when-deserializing-state-always-use-read_line-L.patch create mode 100644 meta/recipes-core/systemd/systemd/0001-dhcp6-make-sure-we-have-enough-space-for-the-DHCP6-o.patch create mode 100644 meta/recipes-core/systemd/systemd/0001-tmpfiles-don-t-resolve-pathnames-when-traversing-rec.patch create mode 100644 meta/recipes-core/systemd/systemd/0002-Make-tmpfiles-safe.patch create mode 100644 meta/recipes-core/systemd/systemd/0024-journald-do-not-store-the-iovec-entry-for-process-co.patch create mode 100644 meta/recipes-core/systemd/systemd/0025-journald-set-a-limit-on-the-number-of-fields-1k.patch create mode 100644 meta/recipes-core/systemd/systemd/0026-journal-remote-set-a-limit-on-the-number-of-fields-i.patch create mode 100644 meta/recipes-core/systemd/systemd/0027-journal-fix-out-of-bounds-read-CVE-2018-16866.patch create mode 100644 meta/recipes-core/systemd/systemd/CVE-2019-6454.patch create mode 100644 meta/recipes-core/systemd/systemd/sd-bus-if-we-receive-an-invalid-dbus-message-ignore-.patch
Signature · 1 line
2.11.0
PATCH 1/8 systemd: fix CVE-2018-15686
From: Chen Qi <[email protected]>
Backport patch to fix the following CVE.
CVE: CVE-2018-15686
Cherry-picked from thud 0ef70603bc983315eb0e8a97958d995a31198c35
--- ...eserializing-state-always-use-read_line-L.patch | 250 +++++++++++++++++++++ meta/recipes-core/systemd/systemd_237.bb | 1 + 2 files changed, 251 insertions(+) create mode 100644 meta/recipes-core/systemd/systemd/0001-core-when-deserializing-state-always-use-read_line-L.patch
meta/recipes-core/systemd/systemd/0001-core-when-deserializing-state-always-use-read_line-L.patch new file +250 -0
@@ -0,0 +1,250 @@ +From 56f77f7fcceea2fbb3b4efb8e307dd7784c63115 Mon Sep 17 00:00:00 2001 +From: Lennart Poettering <[email protected]> +Date: Wed, 17 Oct 2018 18:36:24 +0200 +Subject: [PATCH] =?UTF-8?q?=3D=3FUTF-8=3Fq=3Fcore:=3D20when=3D20deserializ?= + =?UTF-8?q?ing=3D20state=3D20always=3F=3D?= + + =?UTF-8?q?=20use=20read=5Fline(=E2=80=A6,=20LONG=5FLINE=5FMAX,=20?= + =?UTF-8?q?=E2=80=A6)?= +MIME-Version: 1.0 +Content-Type: text/plain; charset=UTF-8 +Content-Transfer-Encoding: 8bit + +This should be much better than fgets(), as we can read substantially +longer lines and overly long lines result in proper errors. + +Fixes a vulnerability discovered by Jann Horn at Google. + +CVE-2018-15686 +LP: #1796402 +https://bugzilla.redhat.com/show_bug.cgi?id=1639071 + +(cherry picked from commit 8948b3415d762245ebf5e19d80b97d4d8cc208c1) + +CVE: CVE-2018-15686 +Upstream-Status: Backport + +Signed-off-by: Chen Qi <[email protected]> + +--- + src/core/job.c | 19 +++++++++++-------- + src/core/manager.c | 44 ++++++++++++++++++++------------------------ + src/core/unit.c | 34 ++++++++++++++++++---------------- + src/core/unit.h | 2 +- + 4 files changed, 50 insertions(+), 49 deletions(-) + +diff --git a/src/core/job.c b/src/core/job.c +index c6de8d27e..e0f9cee2f 100644 +--- a/src/core/job.c ++++ b/src/core/job.c +@@ -28,6 +28,7 @@ + #include "dbus-job.h" + #include "dbus.h" + #include "escape.h" ++#include "fileio.h" + #include "job.h" + #include "log.h" + #include "macro.h" +@@ -1067,24 +1068,26 @@ int job_serialize(Job *j, FILE *f) { + } + + int job_deserialize(Job *j, FILE *f) { ++ int r; ++ + assert(j); + assert(f); + + for (;;) { +- char line[LINE_MAX], *l, *v; ++ _cleanup_free_ char *line = NULL; ++ char *l, *v; + size_t k; + +- if (!fgets(line, sizeof(line), f)) { +- if (feof(f)) +- return 0; +- return -errno; +- } ++ r = read_line(f, LONG_LINE_MAX, &line); ++ if (r < 0) ++ return log_error_errno(r, "Failed to read serialization line: %m"); ++ if (r == 0) ++ return 0; + +- char_array_0(line); + l = strstrip(line); + + /* End marker */ +- if (l[0] == 0) ++ if (isempty(l)) + return 0; + + k = strcspn(l, "="); +diff --git a/src/core/manager.c b/src/core/manager.c +index e837a46f5..423f82c94 100644 +--- a/src/core/manager.c ++++ b/src/core/manager.c +@@ -2841,22 +2841,19 @@ int manager_deserialize(Manager *m, FILE *f, FDSet *fds) { + m->n_reloading++; + + for (;;) { +- char line[LINE_MAX]; ++ _cleanup_free_ char *line = NULL; + const char *val, *l; + +- if (!fgets(line, sizeof(line), f)) { +- if (feof(f)) +- r = 0; +- else +- r = -errno; +- ++ r = read_line(f, LONG_LINE_MAX, &line); ++ if (r < 0) { ++ log_error_errno(r, "Failed to read serialization line: %m"); + goto finish; + } ++ if (r == 0) ++ break; + +- char_array_0(line); + l = strstrip(line); +- +- if (l[0] == 0) ++ if (isempty(l)) /* end marker */ + break; + + if ((val = startswith(l, "current-job-id="))) { +@@ -3003,29 +3000,31 @@ int manager_deserialize(Manager *m, FILE *f, FDSet *fds) { + } + + for (;;) { +- Unit *u; +- char name[UNIT_NAME_MAX+2]; ++ _cleanup_free_ char *line = NULL; + const char* unit_name; ++ Unit *u; + + /* Start marker */ +- if (!fgets(name, sizeof(name), f)) { +- if (feof(f)) +- r = 0; +- else +- r = -errno; +- ++ r = read_line(f, LONG_LINE_MAX, &line); ++ if (r < 0) { ++ log_error_errno(r, "Failed to read serialization line: %m"); + goto finish; + } ++ if (r == 0) ++ break; + +- char_array_0(name); +- unit_name = strstrip(name); ++ unit_name = strstrip(line); + + r = manager_load_unit(m, unit_name, NULL, NULL, &u); + if (r < 0) { + log_notice_errno(r, "Failed to load unit \"%s\", skipping deserialization: %m", unit_name); + if (r == -ENOMEM) + goto finish; +- unit_deserialize_skip(f); ++ ++ r = unit_deserialize_skip(f); ++ if (r < 0) ++ goto finish; ++ + continue; + } + +@@ -3038,9 +3037,6 @@ int manager_deserialize(Manager *m, FILE *f, FDSet *fds) { + } + + finish: +- if (ferror(f)) +- r = -EIO; +- + assert(m->n_reloading > 0); + m->n_reloading--; + +diff --git a/src/core/unit.c b/src/core/unit.c +index 932f05baa..4c3aa8e96 100644 +--- a/src/core/unit.c ++++ b/src/core/unit.c +@@ -3346,21 +3346,19 @@ int unit_deserialize(Unit *u, FILE *f, FDSet *fds) { + rt = (ExecRuntime**) ((uint8_t*) u + offset); + + for (;;) { +- char line[LINE_MAX], *l, *v; ++ _cleanup_free_ char *line = NULL; + CGroupIPAccountingMetric m; ++ char *l, *v; + size_t k; + +- if (!fgets(line, sizeof(line), f)) { +- if (feof(f)) +- return 0; +- return -errno; +- } ++ r = read_line(f, LONG_LINE_MAX, &line); ++ if (r < 0) ++ return log_error_errno(r, "Failed to read serialization line: %m"); ++ if (r == 0) /* eof */ ++ break; + +- char_array_0(line); + l = strstrip(line); +- +- /* End marker */ +- if (isempty(l)) ++ if (isempty(l)) /* End marker */ + break; + + k = strcspn(l, "="); +@@ -3637,23 +3635,27 @@ int unit_deserialize(Unit *u, FILE *f, FDSet *fds) { + return 0; + } + +-void unit_deserialize_skip(FILE *f) { ++int unit_deserialize_skip(FILE *f) { ++ int r; + assert(f); + + /* Skip serialized data for this unit. We don't know what it is. */ + + for (;;) { +- char line[LINE_MAX], *l; ++ _cleanup_free_ char *line = NULL; ++ char *l; + +- if (!fgets(line, sizeof line, f)) +- return; ++ r = read_line(f, LONG_LINE_MAX, &line); ++ if (r < 0) ++ return log_error_errno(r, "Failed to read serialization line: %m"); ++ if (r == 0) ++ return 0; + +- char_array_0(line); + l = strstrip(line); + + /* End marker */ + if (isempty(l)) +- return; ++ return 1; + } + } + +diff --git a/src/core/unit.h b/src/core/unit.h +index 8c79d4ed2..08ad1c652 100644 +--- a/src/core/unit.h ++++ b/src/core/unit.h +@@ -689,7 +689,7 @@ bool unit_can_serialize(Unit *u) _pure_; + + int unit_serialize(Unit *u, FILE *f, FDSet *fds, bool serialize_jobs); + int unit_deserialize(Unit *u, FILE *f, FDSet *fds); +-void unit_deserialize_skip(FILE *f); ++int unit_deserialize_skip(FILE *f); + + int unit_serialize_item(Unit *u, FILE *f, const char *key, const char *value); + int unit_serialize_item_escaped(Unit *u, FILE *f, const char *key, const char *value);
meta/recipes-core/systemd/systemd_237.bb +1 -0
@@ -54,6 +54,7 @@ SRC_URI += "file://touchscreen.rules \ file://libmount.patch \ file://0034-Fix-format-truncation-compile-failure-by-typecasting.patch \ file://0035-Define-glibc-compatible-basename-for-non-glibc-syste.patch \ + file://0001-core-when-deserializing-state-always-use-read_line-L.patch \ " SRC_URI_append_qemuall = " file://0001-core-device.c-Change-the-default-device-timeout-to-2.patch"
Signature · 1 line
2.11.0
PATCH 2/8 systemd: fix CVE-2018-15687
In reply to George McCollisterBackport patch to fix the following CVE.
CVE: CVE-2018-15687
Based on thud commit eeb621aa19f690971caf862290a172a115578ba1 The patch in the thud commit doesn't compile against 237. Use the version of this patch, CVE-2018-15687.patch from systemd_237-3ubuntu10.13.debian.
--- ...sive-let-s-rework-the-recursive-logic-to-.patch | 252 +++++++++++++++++++++ meta/recipes-core/systemd/systemd_237.bb | 1 + 2 files changed, 253 insertions(+) create mode 100644 meta/recipes-core/systemd/systemd/0001-chown-recursive-let-s-rework-the-recursive-logic-to-.patch
meta/recipes-core/systemd/systemd/0001-chown-recursive-let-s-rework-the-recursive-logic-to-.patch new file +252 -0
@@ -0,0 +1,252 @@ +From 2da8ba3f507345d0401ea9d7191fa16ffa560ebc Mon Sep 17 00:00:00 2001 +From: Lennart Poettering <[email protected]> +Date: Fri, 19 Oct 2018 11:26:59 +0200 +Subject: [PATCH] chown-recursive: let's rework the recursive logic to use + O_PATH + +That way we can pin a specific inode and analyze it and manipulate it +without it being swapped out beneath our hands. + +Fixes a vulnerability originally found by Jann Horn from Google. + +CVE-2018-15687 +LP: #1796692 +https://bugzilla.redhat.com/show_bug.cgi?id=1639076 + +Origin: upstream, https://github.com/poettering/systemd/commit/5de6cce58b3e8b79239b6e83653459d91af6e57c +Bug-Ubuntu: https://launchpad.net/bugs/1796692 + +Patch for 237 from: +systemd_237-3ubuntu10.13.debian CVE-2018-15687.patch + +CVE: CVE-2018-15687 +Upstream-Status: Backport + +--- + src/core/chown-recursive.c | 146 ++++++++++++++++++++++----------------------- + 1 file changed, 70 insertions(+), 76 deletions(-) + +diff --git a/src/core/chown-recursive.c b/src/core/chown-recursive.c +index c479450..27c6448 100644 +--- a/src/core/chown-recursive.c ++++ b/src/core/chown-recursive.c +@@ -18,18 +18,20 @@ + along with systemd; If not, see <http://www.gnu.org/licenses/>. + ***/ + +-#include <sys/types.h> +-#include <sys/stat.h> + #include <fcntl.h> ++#include <sys/stat.h> ++#include <sys/types.h> + +-#include "user-util.h" +-#include "macro.h" +-#include "fd-util.h" +-#include "dirent-util.h" + #include "chown-recursive.h" ++#include "dirent-util.h" ++#include "fd-util.h" ++#include "macro.h" ++#include "stdio-util.h" ++#include "strv.h" ++#include "user-util.h" + +-static int chown_one(int fd, const char *name, const struct stat *st, uid_t uid, gid_t gid) { +- int r; ++static int chown_one(int fd, const struct stat *st, uid_t uid, gid_t gid) { ++ char procfs_path[STRLEN("/proc/self/fd/") + DECIMAL_STR_MAX(int) + 1]; + + assert(fd >= 0); + assert(st); +@@ -38,90 +40,82 @@ + (!gid_is_valid(gid) || st->st_gid == gid)) + return 0; + +- if (name) +- r = fchownat(fd, name, uid, gid, AT_SYMLINK_NOFOLLOW); +- else +- r = fchown(fd, uid, gid); +- if (r < 0) +- return -errno; ++ /* We change ownership through the /proc/self/fd/%i path, so that we have a stable reference that works with ++ * O_PATH. (Note: fchown() and fchmod() do not work with O_PATH, the kernel refuses that. */ ++ xsprintf(procfs_path, "/proc/self/fd/%i", fd); + +- /* The linux kernel alters the mode in some cases of chown(). Let's undo this. */ +- if (name) { +- if (!S_ISLNK(st->st_mode)) +- r = fchmodat(fd, name, st->st_mode, 0); +- else /* There's currently no AT_SYMLINK_NOFOLLOW for fchmodat() */ +- r = 0; +- } else +- r = fchmod(fd, st->st_mode); +- if (r < 0) ++ if (chown(procfs_path, uid, gid) < 0) + return -errno; + ++ /* The linux kernel alters the mode in some cases of chown(). Let's undo this. We do this only for non-symlinks ++ * however. That's because for symlinks the access mode is ignored anyway and because on some kernels/file ++ * systems trying to change the access mode will succeed but has no effect while on others it actively ++ * fails. */ ++ if (!S_ISLNK(st->st_mode)) ++ if (chmod(procfs_path, st->st_mode & 07777) < 0) ++ return -errno; ++ + return 1; + } + + static int chown_recursive_internal(int fd, const struct stat *st, uid_t uid, gid_t gid) { ++ _cleanup_closedir_ DIR *d = NULL; + bool changed = false; ++ struct dirent *de; + int r; + + assert(fd >= 0); + assert(st); + +- if (S_ISDIR(st->st_mode)) { +- _cleanup_closedir_ DIR *d = NULL; +- struct dirent *de; +- +- d = fdopendir(fd); +- if (!d) { +- r = -errno; +- goto finish; +- } +- fd = -1; +- +- FOREACH_DIRENT_ALL(de, d, r = -errno; goto finish) { +- struct stat fst; +- +- if (dot_or_dot_dot(de->d_name)) +- continue; ++ d = fdopendir(fd); ++ if (!d) { ++ safe_close(fd); ++ return -errno; ++ } + +- if (fstatat(dirfd(d), de->d_name, &fst, AT_SYMLINK_NOFOLLOW) < 0) { +- r = -errno; +- goto finish; +- } +- +- if (S_ISDIR(fst.st_mode)) { +- int subdir_fd; +- +- subdir_fd = openat(dirfd(d), de->d_name, O_RDONLY|O_NONBLOCK|O_DIRECTORY|O_CLOEXEC|O_NOFOLLOW|O_NOATIME); +- if (subdir_fd < 0) { +- r = -errno; +- goto finish; +- } +- +- r = chown_recursive_internal(subdir_fd, &fst, uid, gid); +- if (r < 0) +- goto finish; +- if (r > 0) +- changed = true; +- } else { +- r = chown_one(dirfd(d), de->d_name, &fst, uid, gid); +- if (r < 0) +- goto finish; +- if (r > 0) +- changed = true; +- } ++ FOREACH_DIRENT_ALL(de, d, return -errno) { ++ _cleanup_close_ int path_fd = -1; ++ struct stat fst; ++ ++ if (dot_or_dot_dot(de->d_name)) ++ continue; ++ ++ /* Let's pin the child inode we want to fix now with an O_PATH fd, so that it cannot be swapped out ++ * while we manipulate it. */ ++ path_fd = openat(dirfd(d), de->d_name, O_PATH|O_CLOEXEC|O_NOFOLLOW); ++ if (path_fd < 0) ++ return -errno; ++ ++ if (fstat(path_fd, &fst) < 0) ++ return -errno; ++ ++ if (S_ISDIR(fst.st_mode)) { ++ int subdir_fd; ++ ++ /* Convert it to a "real" (i.e. non-O_PATH) fd now */ ++ subdir_fd = fd_reopen(path_fd, O_RDONLY|O_CLOEXEC|O_NOATIME); ++ if (subdir_fd < 0) ++ return subdir_fd; ++ ++ r = chown_recursive_internal(subdir_fd, &fst, uid, gid); /* takes possession of subdir_fd even on failure */ ++ if (r < 0) ++ return r; ++ if (r > 0) ++ changed = true; ++ } else { ++ r = chown_one(path_fd, &fst, uid, gid); ++ if (r < 0) ++ return r; ++ if (r > 0) ++ changed = true; + } ++ } + +- r = chown_one(dirfd(d), NULL, st, uid, gid); +- } else +- r = chown_one(fd, NULL, st, uid, gid); ++ r = chown_one(dirfd(d), st, uid, gid); + if (r < 0) +- goto finish; +- +- r = r > 0 || changed; ++ return r; + +-finish: +- safe_close(fd); +- return r; ++ return r > 0 || changed; + } + + int path_chown_recursive(const char *path, uid_t uid, gid_t gid) { +@@ -129,7 +123,7 @@ + struct stat st; + int r; + +- fd = open(path, O_RDONLY|O_NONBLOCK|O_DIRECTORY|O_CLOEXEC|O_NOFOLLOW|O_NOATIME); ++ fd = open(path, O_RDONLY|O_DIRECTORY|O_CLOEXEC|O_NOFOLLOW|O_NOATIME); + if (fd < 0) + return -errno; + +--- a/src/basic/fd-util.c ++++ b/src/basic/fd-util.c +@@ -578,3 +578,22 @@ + + return -EOPNOTSUPP; + } ++ ++int fd_reopen(int fd, int flags) { ++ char procfs_path[STRLEN("/proc/self/fd/") + DECIMAL_STR_MAX(int)]; ++ int new_fd; ++ ++ /* Reopens the specified fd with new flags. This is useful for convert an O_PATH fd into a regular one, or to ++ * turn O_RDWR fds into O_RDONLY fds. ++ * ++ * This doesn't work on sockets (since they cannot be open()ed, ever). ++ * ++ * This implicitly resets the file read index to 0. */ ++ ++ xsprintf(procfs_path, "/proc/self/fd/%i", fd); ++ new_fd = open(procfs_path, flags); ++ if (new_fd < 0) ++ return -errno; ++ ++ return new_fd; ++} +--- a/src/basic/fd-util.h ++++ b/src/basic/fd-util.h +@@ -91,3 +91,5 @@ + /* Hint: ENETUNREACH happens if we try to connect to "non-existing" special IP addresses, such as ::5 */ + #define ERRNO_IS_DISCONNECT(r) \ + IN_SET(r, ENOTCONN, ECONNRESET, ECONNREFUSED, ECONNABORTED, EPIPE, ENETUNREACH) ++ ++int fd_reopen(int fd, int flags);
meta/recipes-core/systemd/systemd_237.bb +1 -0
@@ -55,6 +55,7 @@ SRC_URI += "file://touchscreen.rules \ file://0034-Fix-format-truncation-compile-failure-by-typecasting.patch \ file://0035-Define-glibc-compatible-basename-for-non-glibc-syste.patch \ file://0001-core-when-deserializing-state-always-use-read_line-L.patch \ + file://0001-chown-recursive-let-s-rework-the-recursive-logic-to-.patch \ " SRC_URI_append_qemuall = " file://0001-core-device.c-Change-the-default-device-timeout-to-2.patch"
Signature · 1 line
2.11.0
PATCH 3/8 systemd: fix CVE-2018-15688
In reply to George McCollisterFrom: Chen Qi <[email protected]>
Backport patch to fix the following CVE.
CVE: CVE-2018-15688
Cherry-picked from thud 13591d7224393dc0ae529a03cdf74aceb3540ce9
--- ...sure-we-have-enough-space-for-the-DHCP6-o.patch | 39 ++++++++++++++++++++++ meta/recipes-core/systemd/systemd_237.bb | 1 + 2 files changed, 40 insertions(+) create mode 100644 meta/recipes-core/systemd/systemd/0001-dhcp6-make-sure-we-have-enough-space-for-the-DHCP6-o.patch
meta/recipes-core/systemd/systemd/0001-dhcp6-make-sure-we-have-enough-space-for-the-DHCP6-o.patch new file +39 -0
@@ -0,0 +1,39 @@ +From a2622b8398ba026faf481f5eddeb53231d9de4a7 Mon Sep 17 00:00:00 2001 +From: Lennart Poettering <[email protected]> +Date: Fri, 19 Oct 2018 12:12:33 +0200 +Subject: [PATCH] dhcp6: make sure we have enough space for the DHCP6 option + header + +Fixes a vulnerability originally discovered by Felix Wilhelm from +Google. + +CVE-2018-15688 +LP: #1795921 +https://bugzilla.redhat.com/show_bug.cgi?id=1639067 + +(cherry picked from commit 4dac5eaba4e419b29c97da38a8b1f82336c2c892) + +CVE: CVE-2018-15688 +Upstream-Status: Backport + +Signed-off-by: Chen Qi <[email protected]> +--- + src/libsystemd-network/dhcp6-option.c | 2 +- + 1 file changed, 1 insertion(+), 1 deletion(-) + +diff --git a/src/libsystemd-network/dhcp6-option.c b/src/libsystemd-network/dhcp6-option.c +index c4b402b..dcbaad0 100644 +--- a/src/libsystemd-network/dhcp6-option.c ++++ b/src/libsystemd-network/dhcp6-option.c +@@ -103,7 +103,7 @@ int dhcp6_option_append_ia(uint8_t **buf, size_t *buflen, DHCP6IA *ia) { + return -EINVAL; + } + +- if (*buflen < len) ++ if (*buflen < offsetof(DHCP6Option, data) + len) + return -ENOBUFS; + + ia_hdr = *buf; +-- +2.7.4 +
meta/recipes-core/systemd/systemd_237.bb +1 -0
@@ -56,6 +56,7 @@ SRC_URI += "file://touchscreen.rules \ file://0035-Define-glibc-compatible-basename-for-non-glibc-syste.patch \ file://0001-core-when-deserializing-state-always-use-read_line-L.patch \ file://0001-chown-recursive-let-s-rework-the-recursive-logic-to-.patch \ + file://0001-dhcp6-make-sure-we-have-enough-space-for-the-DHCP6-o.patch \ " SRC_URI_append_qemuall = " file://0001-core-device.c-Change-the-default-device-timeout-to-2.patch"
Signature · 1 line
2.11.0
PATCH 4/8 systemd: Security fix CVE-2018-16864
In reply to George McCollisterAffects < v240
Based on thud commit 403e74b07b6f3c4a2444e68c74a8434fb17aee49 The patch in the thud commit doesn't compile against 237. Use the version of this patch, CVE-2018-16864.patch from systemd_237-3ubuntu10.13.debian.
--- ...-not-store-the-iovec-entry-for-process-co.patch | 193 +++++++++++++++++++++ meta/recipes-core/systemd/systemd_237.bb | 1 + 2 files changed, 194 insertions(+) create mode 100644 meta/recipes-core/systemd/systemd/0024-journald-do-not-store-the-iovec-entry-for-process-co.patch
meta/recipes-core/systemd/systemd/0024-journald-do-not-store-the-iovec-entry-for-process-co.patch new file +193 -0
@@ -0,0 +1,193 @@ +From c29b44cb90e2cc521533e6169cf847553ebefd81 Mon Sep 17 00:00:00 2001 +From: =?UTF-8?q?Zbigniew=20J=C4=99drzejewski-Szmek?= <[email protected]> +Date: Wed, 5 Dec 2018 18:38:39 +0100 +Subject: [PATCH] journald: do not store the iovec entry for process + commandline on stack + +This fixes a crash where we would read the commandline, whose length is under +control of the sending program, and then crash when trying to create a stack +allocation for it. + +CVE-2018-16864 +https://bugzilla.redhat.com/show_bug.cgi?id=1653855 + +The message actually doesn't get written to disk, because +journal_file_append_entry() returns -E2BIG. + +Patch for 237 from: +systemd_237-3ubuntu10.13.debian CVE-2018-16864.patch + +CVE: CVE-2018-16864 +Upstream-Status: Backport + +--- + src/basic/io-util.c | 10 ++++++++++ + src/basic/io-util.h | 2 ++ + src/coredump/coredump.c | 31 +++++++++++-------------------- + src/journal/journald-server.c | 25 +++++++++++++++---------- + 4 files changed, 38 insertions(+), 30 deletions(-) + +--- a/src/basic/io-util.c ++++ b/src/basic/io-util.c +@@ -26,6 +26,7 @@ + #include <unistd.h> + + #include "io-util.h" ++#include "string-util.h" + #include "time-util.h" + + int flush_fd(int fd) { +@@ -270,3 +271,12 @@ + + return q - (const uint8_t*) p; + } ++ ++char* set_iovec_string_field(struct iovec *iovec, size_t *n_iovec, const char *field, const char *value) { ++ char *x; ++ ++ x = strappend(field, value); ++ if (x) ++ iovec[(*n_iovec)++] = IOVEC_MAKE_STRING(x); ++ return x; ++} +--- a/src/basic/io-util.h ++++ b/src/basic/io-util.h +@@ -91,3 +91,5 @@ + #define IOVEC_MAKE(base, len) (struct iovec) IOVEC_INIT(base, len) + #define IOVEC_INIT_STRING(string) IOVEC_INIT((char*) string, strlen(string)) + #define IOVEC_MAKE_STRING(string) (struct iovec) IOVEC_INIT_STRING(string) ++ ++char* set_iovec_string_field(struct iovec *iovec, size_t *n_iovec, const char *field, const char *value); +--- a/src/coredump/coredump.c ++++ b/src/coredump/coredump.c +@@ -1067,19 +1067,10 @@ + return 0; + } + +-static char* set_iovec_field(struct iovec iovec[27], size_t *n_iovec, const char *field, const char *value) { +- char *x; +- +- x = strappend(field, value); +- if (x) +- iovec[(*n_iovec)++] = IOVEC_MAKE_STRING(x); +- return x; +-} +- + static char* set_iovec_field_free(struct iovec iovec[27], size_t *n_iovec, const char *field, char *value) { + char *x; + +- x = set_iovec_field(iovec, n_iovec, field, value); ++ x = set_iovec_string_field(iovec, n_iovec, field, value); + free(value); + return x; + } +@@ -1129,33 +1120,33 @@ + disable_coredumps(); + } + +- set_iovec_field(iovec, n_iovec, "COREDUMP_UNIT=", context[CONTEXT_UNIT]); ++ set_iovec_string_field(iovec, n_iovec, "COREDUMP_UNIT=", context[CONTEXT_UNIT]); + } + + if (cg_pid_get_user_unit(pid, &t) >= 0) + set_iovec_field_free(iovec, n_iovec, "COREDUMP_USER_UNIT=", t); + + /* The next few are mandatory */ +- if (!set_iovec_field(iovec, n_iovec, "COREDUMP_PID=", context[CONTEXT_PID])) ++ if (!set_iovec_string_field(iovec, n_iovec, "COREDUMP_PID=", context[CONTEXT_PID])) + return log_oom(); + +- if (!set_iovec_field(iovec, n_iovec, "COREDUMP_UID=", context[CONTEXT_UID])) ++ if (!set_iovec_string_field(iovec, n_iovec, "COREDUMP_UID=", context[CONTEXT_UID])) + return log_oom(); + +- if (!set_iovec_field(iovec, n_iovec, "COREDUMP_GID=", context[CONTEXT_GID])) ++ if (!set_iovec_string_field(iovec, n_iovec, "COREDUMP_GID=", context[CONTEXT_GID])) + return log_oom(); + +- if (!set_iovec_field(iovec, n_iovec, "COREDUMP_SIGNAL=", context[CONTEXT_SIGNAL])) ++ if (!set_iovec_string_field(iovec, n_iovec, "COREDUMP_SIGNAL=", context[CONTEXT_SIGNAL])) + return log_oom(); + +- if (!set_iovec_field(iovec, n_iovec, "COREDUMP_RLIMIT=", context[CONTEXT_RLIMIT])) ++ if (!set_iovec_string_field(iovec, n_iovec, "COREDUMP_RLIMIT=", context[CONTEXT_RLIMIT])) + return log_oom(); + +- if (!set_iovec_field(iovec, n_iovec, "COREDUMP_COMM=", context[CONTEXT_COMM])) ++ if (!set_iovec_string_field(iovec, n_iovec, "COREDUMP_COMM=", context[CONTEXT_COMM])) + return log_oom(); + + if (context[CONTEXT_EXE] && +- !set_iovec_field(iovec, n_iovec, "COREDUMP_EXE=", context[CONTEXT_EXE])) ++ !set_iovec_string_field(iovec, n_iovec, "COREDUMP_EXE=", context[CONTEXT_EXE])) + return log_oom(); + + if (sd_pid_get_session(pid, &t) >= 0) +@@ -1223,7 +1214,7 @@ + iovec[(*n_iovec)++] = IOVEC_MAKE_STRING(t); + + if (safe_atoi(context[CONTEXT_SIGNAL], &signo) >= 0 && SIGNAL_VALID(signo)) +- set_iovec_field(iovec, n_iovec, "COREDUMP_SIGNAL_NAME=SIG", signal_to_string(signo)); ++ set_iovec_string_field(iovec, n_iovec, "COREDUMP_SIGNAL_NAME=SIG", signal_to_string(signo)); + + return 0; /* we successfully acquired all metadata */ + } +--- a/src/journal/journald-server.c ++++ b/src/journal/journald-server.c +@@ -769,6 +769,7 @@ + pid_t object_pid) { + + char source_time[sizeof("_SOURCE_REALTIME_TIMESTAMP=") + DECIMAL_STR_MAX(usec_t)]; ++ _cleanup_free_ char *cmdline1 = NULL, *cmdline2 = NULL; + uid_t journal_uid; + ClientContext *o; + +@@ -785,20 +786,23 @@ + IOVEC_ADD_NUMERIC_FIELD(iovec, n, c->uid, uid_t, uid_is_valid, UID_FMT, "_UID"); + IOVEC_ADD_NUMERIC_FIELD(iovec, n, c->gid, gid_t, gid_is_valid, GID_FMT, "_GID"); + +- IOVEC_ADD_STRING_FIELD(iovec, n, c->comm, "_COMM"); +- IOVEC_ADD_STRING_FIELD(iovec, n, c->exe, "_EXE"); +- IOVEC_ADD_STRING_FIELD(iovec, n, c->cmdline, "_CMDLINE"); +- IOVEC_ADD_STRING_FIELD(iovec, n, c->capeff, "_CAP_EFFECTIVE"); ++ IOVEC_ADD_STRING_FIELD(iovec, n, c->comm, "_COMM"); /* At most TASK_COMM_LENGTH (16 bytes) */ ++ IOVEC_ADD_STRING_FIELD(iovec, n, c->exe, "_EXE"); /* A path, so at most PATH_MAX (4096 bytes) */ + +- IOVEC_ADD_SIZED_FIELD(iovec, n, c->label, c->label_size, "_SELINUX_CONTEXT"); ++ if (c->cmdline) ++ /* At most _SC_ARG_MAX (2MB usually), which is too much to put on stack. ++ * Let's use a heap allocation for this one. */ ++ cmdline1 = set_iovec_string_field(iovec, &n, "_CMDLINE=", c->cmdline); + ++ IOVEC_ADD_STRING_FIELD(iovec, n, c->capeff, "_CAP_EFFECTIVE"); /* Read from /proc/.../status */ ++ IOVEC_ADD_SIZED_FIELD(iovec, n, c->label, c->label_size, "_SELINUX_CONTEXT"); + IOVEC_ADD_NUMERIC_FIELD(iovec, n, c->auditid, uint32_t, audit_session_is_valid, "%" PRIu32, "_AUDIT_SESSION"); + IOVEC_ADD_NUMERIC_FIELD(iovec, n, c->loginuid, uid_t, uid_is_valid, UID_FMT, "_AUDIT_LOGINUID"); + +- IOVEC_ADD_STRING_FIELD(iovec, n, c->cgroup, "_SYSTEMD_CGROUP"); ++ IOVEC_ADD_STRING_FIELD(iovec, n, c->cgroup, "_SYSTEMD_CGROUP"); /* A path */ + IOVEC_ADD_STRING_FIELD(iovec, n, c->session, "_SYSTEMD_SESSION"); + IOVEC_ADD_NUMERIC_FIELD(iovec, n, c->owner_uid, uid_t, uid_is_valid, UID_FMT, "_SYSTEMD_OWNER_UID"); +- IOVEC_ADD_STRING_FIELD(iovec, n, c->unit, "_SYSTEMD_UNIT"); ++ IOVEC_ADD_STRING_FIELD(iovec, n, c->unit, "_SYSTEMD_UNIT"); /* Unit names are bounded by UNIT_NAME_MAX */ + IOVEC_ADD_STRING_FIELD(iovec, n, c->user_unit, "_SYSTEMD_USER_UNIT"); + IOVEC_ADD_STRING_FIELD(iovec, n, c->slice, "_SYSTEMD_SLICE"); + IOVEC_ADD_STRING_FIELD(iovec, n, c->user_slice, "_SYSTEMD_USER_SLICE"); +@@ -819,13 +823,14 @@ + IOVEC_ADD_NUMERIC_FIELD(iovec, n, o->uid, uid_t, uid_is_valid, UID_FMT, "OBJECT_UID"); + IOVEC_ADD_NUMERIC_FIELD(iovec, n, o->gid, gid_t, gid_is_valid, GID_FMT, "OBJECT_GID"); + ++ /* See above for size limits, only ->cmdline may be large, so use a heap allocation for it. */ + IOVEC_ADD_STRING_FIELD(iovec, n, o->comm, "OBJECT_COMM"); + IOVEC_ADD_STRING_FIELD(iovec, n, o->exe, "OBJECT_EXE"); +- IOVEC_ADD_STRING_FIELD(iovec, n, o->cmdline, "OBJECT_CMDLINE"); +- IOVEC_ADD_STRING_FIELD(iovec, n, o->capeff, "OBJECT_CAP_EFFECTIVE"); ++ if (o->cmdline) ++ cmdline2 = set_iovec_string_field(iovec, &n, "OBJECT_CMDLINE=", o->cmdline); + ++ IOVEC_ADD_STRING_FIELD(iovec, n, o->capeff, "OBJECT_CAP_EFFECTIVE"); + IOVEC_ADD_SIZED_FIELD(iovec, n, o->label, o->label_size, "OBJECT_SELINUX_CONTEXT"); +- + IOVEC_ADD_NUMERIC_FIELD(iovec, n, o->auditid, uint32_t, audit_session_is_valid, "%" PRIu32, "OBJECT_AUDIT_SESSION"); + IOVEC_ADD_NUMERIC_FIELD(iovec, n, o->loginuid, uid_t, uid_is_valid, UID_FMT, "OBJECT_AUDIT_LOGINUID"); +
meta/recipes-core/systemd/systemd_237.bb +1 -0
@@ -57,6 +57,7 @@ SRC_URI += "file://touchscreen.rules \ file://0001-core-when-deserializing-state-always-use-read_line-L.patch \ file://0001-chown-recursive-let-s-rework-the-recursive-logic-to-.patch \ file://0001-dhcp6-make-sure-we-have-enough-space-for-the-DHCP6-o.patch \ + file://0024-journald-do-not-store-the-iovec-entry-for-process-co.patch \ " SRC_URI_append_qemuall = " file://0001-core-device.c-Change-the-default-device-timeout-to-2.patch"
Signature · 1 line
2.11.0
PATCH 5/8 systemd: Security fix CVE-2018-16865
In reply to George McCollisterAffects < v240
Based on thud commit d5d2b821fc85b8cf39f683061ac2a45bddd2139f The second patch in the thud commit doesn't apply against 237. Use the version of the second patch CVE-2018-16865_2.patch from systemd_237-3ubuntu10.13.debian.
--- ...ld-set-a-limit-on-the-number-of-fields-1k.patch | 60 ++++++++++++++++ ...ote-set-a-limit-on-the-number-of-fields-i.patch | 79 ++++++++++++++++++++++ meta/recipes-core/systemd/systemd_237.bb | 2 + 3 files changed, 141 insertions(+) create mode 100644 meta/recipes-core/systemd/systemd/0025-journald-set-a-limit-on-the-number-of-fields-1k.patch create mode 100644 meta/recipes-core/systemd/systemd/0026-journal-remote-set-a-limit-on-the-number-of-fields-i.patch
meta/recipes-core/systemd/systemd/0025-journald-set-a-limit-on-the-number-of-fields-1k.patch new file +60 -0
@@ -0,0 +1,60 @@ +From 4566aaf97f5b4143b930d75628f3abc905249dcd Mon Sep 17 00:00:00 2001 +From: =?UTF-8?q?Zbigniew=20J=C4=99drzejewski-Szmek?= <[email protected]> +Date: Wed, 5 Dec 2018 22:45:02 +0100 +Subject: [PATCH] journald: set a limit on the number of fields (1k) + +We allocate a iovec entry for each field, so with many short entries, +our memory usage and processing time can be large, even with a relatively +small message size. Let's refuse overly long entries. + +CVE-2018-16865 +https://bugzilla.redhat.com/show_bug.cgi?id=1653861 + +What from I can see, the problem is not from an alloca, despite what the CVE +description says, but from the attack multiplication that comes from creating +many very small iovecs: (void* + size_t) for each three bytes of input message. + +Patch backported from systemd master at +052c57f132f04a3cf4148f87561618da1a6908b4. + +CVE: CVE-2018-16865 +Upstream-Status: Backport + +--- + src/basic/journal-importer.h | 3 +++ + src/journal/journald-native.c | 5 +++++ + 2 files changed, 8 insertions(+) + +diff --git a/src/basic/journal-importer.h b/src/basic/journal-importer.h +index f49ce734a1..c4ae45d32d 100644 +--- a/src/basic/journal-importer.h ++++ b/src/basic/journal-importer.h +@@ -16,6 +16,9 @@ + #define DATA_SIZE_MAX (1024*1024*768u) + #define LINE_CHUNK 8*1024u + ++/* The maximum number of fields in an entry */ ++#define ENTRY_FIELD_COUNT_MAX 1024 ++ + struct iovec_wrapper { + struct iovec *iovec; + size_t size_bytes; +diff --git a/src/journal/journald-native.c b/src/journal/journald-native.c +index 5ff22a10af..951d092053 100644 +--- a/src/journal/journald-native.c ++++ b/src/journal/journald-native.c +@@ -140,6 +140,11 @@ static int server_process_entry( + } + + /* A property follows */ ++ if (n > ENTRY_FIELD_COUNT_MAX) { ++ log_debug("Received an entry that has more than " STRINGIFY(ENTRY_FIELD_COUNT_MAX) " fields, ignoring entry."); ++ r = 1; ++ goto finish; ++ } + + /* n existing properties, 1 new, +1 for _TRANSPORT */ + if (!GREEDY_REALLOC(iovec, m, +-- +2.11.0 +
meta/recipes-core/systemd/systemd/0026-journal-remote-set-a-limit-on-the-number-of-fields-i.patch new file +79 -0
79 lines not on this page · raw message
meta/recipes-core/systemd/systemd_237.bb +2 -0
@@ -58,6 +58,8 @@ SRC_URI += "file://touchscreen.rules \ file://0001-chown-recursive-let-s-rework-the-recursive-logic-to-.patch \ file://0001-dhcp6-make-sure-we-have-enough-space-for-the-DHCP6-o.patch \ file://0024-journald-do-not-store-the-iovec-entry-for-process-co.patch \ + file://0025-journald-set-a-limit-on-the-number-of-fields-1k.patch \ + file://0026-journal-remote-set-a-limit-on-the-number-of-fields-i.patch \ " SRC_URI_append_qemuall = " file://0001-core-device.c-Change-the-default-device-timeout-to-2.patch"
Signature · 1 line
2.11.0
PATCH 6/8 systemd: Security fix CVE-2018-16866
In reply to George McCollisterFrom: Marcus Cooper <[email protected]>
Affects < v240
From v2 patch on [email protected] Incresed file name number from 0026 to 0027.
--- ...nal-fix-out-of-bounds-read-CVE-2018-16866.patch | 49 ++++++++++++++++++++++ meta/recipes-core/systemd/systemd_237.bb | 1 + 2 files changed, 50 insertions(+) create mode 100644 meta/recipes-core/systemd/systemd/0027-journal-fix-out-of-bounds-read-CVE-2018-16866.patch
meta/recipes-core/systemd/systemd/0027-journal-fix-out-of-bounds-read-CVE-2018-16866.patch new file +49 -0
@@ -0,0 +1,49 @@ +From ebd06c37d4311db9851f4d3fdd023de3dd590de0 Mon Sep 17 00:00:00 2001 +From: Filipe Brandenburger <[email protected]> +Date: Thu, 10 Jan 2019 14:53:33 -0800 +Subject: [PATCH] journal: fix out-of-bounds read CVE-2018-16866 + +The original code didn't account for the fact that strchr() would match on the +'\0' character, making it read past the end of the buffer if no non-whitespace +character was present. + +This bug was introduced in commit ec5ff4445cca6a which was first released in +systemd v221 and later fixed in commit 8595102d3ddde6 which was released in +v240, so versions in the range [v221, v240) are affected. + +Patch backported from systemd-stable at f005e73d3723d62a39be661931fcb6347119b52b +also includes a change from systemd master which removes a heap buffer overflow +a6aadf4ae0bae185dc4c414d492a4a781c80ffe5. + +CVE: CVE-2018-16866 +Upstream-Status: Backport +Signed-off-by: Marcus Cooper <[email protected]> +--- + src/journal/journald-syslog.c | 4 ++-- + 1 file changed, 2 insertions(+), 2 deletions(-) + +diff --git a/src/journal/journald-syslog.c b/src/journal/journald-syslog.c +index 9dea116722..809b318c06 100644 +--- a/src/journal/journald-syslog.c ++++ b/src/journal/journald-syslog.c +@@ -194,7 +194,7 @@ size_t syslog_parse_identifier(const char **buf, char **identifier, char **pid) + e = l; + l--; + +- if (p[l-1] == ']') { ++ if (l > 0 && p[l-1] == ']') { + size_t k = l-1; + + for (;;) { +@@ -219,7 +219,7 @@ size_t syslog_parse_identifier(const char **buf, char **identifier, char **pid) + if (t) + *identifier = t; + +- if (strchr(WHITESPACE, p[e])) ++ if (p[e] != '\0' && strchr(WHITESPACE, p[e])) + e++; + *buf = p + e; + return e; +-- +2.11.0 +
meta/recipes-core/systemd/systemd_237.bb +1 -0
@@ -60,6 +60,7 @@ SRC_URI += "file://touchscreen.rules \ file://0024-journald-do-not-store-the-iovec-entry-for-process-co.patch \ file://0025-journald-set-a-limit-on-the-number-of-fields-1k.patch \ file://0026-journal-remote-set-a-limit-on-the-number-of-fields-i.patch \ + file://0027-journal-fix-out-of-bounds-read-CVE-2018-16866.patch \ " SRC_URI_append_qemuall = " file://0001-core-device.c-Change-the-default-device-timeout-to-2.patch"
Signature · 1 line
2.11.0
PATCH 7/8 systemd: fix CVE-2018-6954
In reply to George McCollisterApply patches to fix CVE-2018-6954
NVD description from https://nvd.nist.gov/vuln/detail/CVE-2018-6954
systemd-tmpfiles in systemd through 237 mishandles symlinks present in non-terminal path components, which allows local users to obtain ownership of arbitrary files via vectors involving creation of a directory and a file under that directory, and later replacing that directory with a symlink. This occurs even if the fs.protected_symlinks sysctl is turned on.
Patches from systemd_237-3ubuntu10.13.debian.
These patches shouldn't be required on newer OE releases since they use systemd v239 or higher.
--- ...n-t-resolve-pathnames-when-traversing-rec.patch | 643 +++++++ .../systemd/systemd/0002-Make-tmpfiles-safe.patch | 1828 ++++++++++++++++++++ meta/recipes-core/systemd/systemd_237.bb | 2 + 3 files changed, 2473 insertions(+) create mode 100644 meta/recipes-core/systemd/systemd/0001-tmpfiles-don-t-resolve-pathnames-when-traversing-rec.patch create mode 100644 meta/recipes-core/systemd/systemd/0002-Make-tmpfiles-safe.patch
meta/recipes-core/systemd/systemd/0001-tmpfiles-don-t-resolve-pathnames-when-traversing-rec.patch new file +643 -0
@@ -0,0 +1,643 @@ +From 33dc9a280f952f503e5493ee29f6815bef29d551 Mon Sep 17 00:00:00 2001 +From: Franck Bui <[email protected]> +Date: Fri, 2 Mar 2018 17:19:32 +0100 +Subject: [PATCH] tmpfiles: don't resolve pathnames when traversing recursively + through directory trees + +Otherwise we can be fooled if one path component is replaced underneath us. + +The patch achieves that by always operating at file descriptor level (by using +*at() helpers) and by making sure we do not any path resolution when traversing +direcotry trees. + +However this is not always possible, for instance when listing the content of a +directory or some operations don't provide the *at() helpers or others (such as +fchmodat()) don't have the AT_EMPTY_PATH flag. In such cases we operate on +/proc/self/fd/%i pseudo-symlink instead, which works the same for all kinds of +objects and requires no checking of type beforehand. + +Also O_PATH flag is used when opening file objects in order to prevent +undesired behaviors: device nodes from reacting, automounts from +triggering, etc... + +Fixes: CVE-2018-6954 + +Origin: upstream, https://github.com/systemd/systemd/commit/936f6bdb803c432578e2cdcc5f93f3bfff93aff0 +Bug: https://github.com/systemd/systemd/issues/7986 + +Patch from: +systemd_237-3ubuntu10.13.debian CVE-2018-6954.patch + +https://usn.ubuntu.com/3816-1/ states that CVE-2018-6954 doesn't +affect Ubuntu 18.10 which uses the same version of systemd as thud +(239). + +CVE: CVE-2018-6954 +Upstream-Status: Backport + +Signed-off-by: George McCollister <[email protected]> +--- + src/tmpfiles/tmpfiles.c | 363 +++++++++++++++++++++++++++++++----------------- + 1 file changed, 239 insertions(+), 124 deletions(-) + +diff --git a/src/tmpfiles/tmpfiles.c b/src/tmpfiles/tmpfiles.c +index 88cc543f09..613d418eb3 100644 +--- a/src/tmpfiles/tmpfiles.c ++++ b/src/tmpfiles/tmpfiles.c +@@ -792,94 +792,105 @@ static bool hardlink_vulnerable(struct stat *st) { + return !S_ISDIR(st->st_mode) && st->st_nlink > 1 && dangerous_hardlinks(); + } + +-static int path_set_perms(Item *i, const char *path) { +- char fn[STRLEN("/proc/self/fd/") + DECIMAL_STR_MAX(int)]; +- _cleanup_close_ int fd = -1; +- struct stat st; ++static int fd_set_perms(Item *i, int fd, const struct stat *st) { ++ _cleanup_free_ char *path = NULL; ++ int r; + + assert(i); +- assert(path); +- +- if (!i->mode_set && !i->uid_set && !i->gid_set) +- goto shortcut; +- +- /* We open the file with O_PATH here, to make the operation +- * somewhat atomic. Also there's unfortunately no fchmodat() +- * with AT_SYMLINK_NOFOLLOW, hence we emulate it here via +- * O_PATH. */ +- +- fd = open(path, O_NOFOLLOW|O_CLOEXEC|O_PATH); +- if (fd < 0) { +- int level = LOG_ERR, r = -errno; ++ assert(fd); + +- /* Option "e" operates only on existing objects. Do not +- * print errors about non-existent files or directories */ +- if (i->type == EMPTY_DIRECTORY && errno == ENOENT) { +- level = LOG_DEBUG; +- r = 0; +- } +- +- log_full_errno(level, errno, "Adjusting owner and mode for %s failed: %m", path); ++ r = fd_get_path(fd, &path); ++ if (r < 0) + return r; +- } + +- if (fstatat(fd, "", &st, AT_EMPTY_PATH) < 0) +- return log_error_errno(errno, "Failed to fstat() file %s: %m", path); ++ if (!i->mode_set && !i->uid_set && !i->gid_set) ++ goto shortcut; + +- if (hardlink_vulnerable(&st)) { ++ if (hardlink_vulnerable(st)) { + log_error("Refusing to set permissions on hardlinked file %s while the fs.protected_hardlinks sysctl is turned off.", path); + return -EPERM; + } + +- xsprintf(fn, "/proc/self/fd/%i", fd); +- + if (i->mode_set) { +- if (S_ISLNK(st.st_mode)) ++ if (S_ISLNK(st->st_mode)) + log_debug("Skipping mode fix for symlink %s.", path); + else { + mode_t m = i->mode; + + if (i->mask_perms) { +- if (!(st.st_mode & 0111)) ++ if (!(st->st_mode & 0111)) + m &= ~0111; +- if (!(st.st_mode & 0222)) ++ if (!(st->st_mode & 0222)) + m &= ~0222; +- if (!(st.st_mode & 0444)) ++ if (!(st->st_mode & 0444)) + m &= ~0444; +- if (!S_ISDIR(st.st_mode)) ++ if (!S_ISDIR(st->st_mode)) + m &= ~07000; /* remove sticky/sgid/suid bit, unless directory */ + } + +- if (m == (st.st_mode & 07777)) +- log_debug("\"%s\" has correct mode %o already.", path, st.st_mode); ++ if (m == (st->st_mode & 07777)) ++ log_debug("\"%s\" has correct mode %o already.", path, st->st_mode); + else { ++ char procfs_path[strlen("/proc/self/fd/") + DECIMAL_STR_MAX(int)]; ++ + log_debug("Changing \"%s\" to mode %o.", path, m); + +- if (chmod(fn, m) < 0) +- return log_error_errno(errno, "chmod() of %s via %s failed: %m", path, fn); ++ /* fchmodat() still doesn't have AT_EMPTY_PATH flag. */ ++ xsprintf(procfs_path, "/proc/self/fd/%i", fd); ++ ++ if (chmod(procfs_path, m) < 0) ++ return log_error_errno(errno, "chmod() of %s via %s failed: %m", path, procfs_path); + } + } + } + +- if ((i->uid_set && i->uid != st.st_uid) || +- (i->gid_set && i->gid != st.st_gid)) { ++ if ((i->uid_set && i->uid != st->st_uid) || ++ (i->gid_set && i->gid != st->st_gid)) { + log_debug("Changing \"%s\" to owner "UID_FMT":"GID_FMT, + path, + i->uid_set ? i->uid : UID_INVALID, + i->gid_set ? i->gid : GID_INVALID); + +- if (chown(fn, +- i->uid_set ? i->uid : UID_INVALID, +- i->gid_set ? i->gid : GID_INVALID) < 0) +- return log_error_errno(errno, "chown() of %s via %s failed: %m", path, fn); ++ if (fchownat(fd, ++ "", ++ i->uid_set ? i->uid : UID_INVALID, ++ i->gid_set ? i->gid : GID_INVALID, ++ AT_EMPTY_PATH) < 0) ++ return log_error_errno(errno, "fchownat() of %s failed: %m", path); + } + +- fd = safe_close(fd); +- + shortcut: + return label_fix(path, false, false); + } + ++static int path_set_perms(Item *i, const char *path) { ++ _cleanup_close_ int fd = -1; ++ struct stat st; ++ ++ assert(i); ++ assert(path); ++ ++ fd = open(path, O_NOFOLLOW|O_CLOEXEC|O_PATH); ++ if (fd < 0) { ++ int level = LOG_ERR, r = -errno; ++ ++ /* Option "e" operates only on existing objects. Do not ++ * print errors about non-existent files or directories */ ++ if (i->type == EMPTY_DIRECTORY && errno == ENOENT) { ++ level = LOG_DEBUG; ++ r = 0; ++ } ++ ++ log_full_errno(level, errno, "Adjusting owner and mode for %s failed: %m", path); ++ return r; ++ } ++ ++ if (fstat(fd, &st) < 0) ++ return log_error_errno(errno, "Failed to fstat() file %s: %m", path); ++ ++ return fd_set_perms(i, fd, &st); ++} ++ + static int parse_xattrs_from_arg(Item *i) { + const char *p; + int r; +@@ -918,21 +929,43 @@ static int parse_xattrs_from_arg(Item *i) { + return 0; + } + +-static int path_set_xattrs(Item *i, const char *path) { ++static int fd_set_xattrs(Item *i, int fd, const struct stat *st) { ++ char procfs_path[strlen("/proc/self/fd/") + DECIMAL_STR_MAX(int)]; ++ _cleanup_free_ char *path = NULL; + char **name, **value; ++ int r; + + assert(i); +- assert(path); ++ assert(fd); ++ ++ r = fd_get_path(fd, &path); ++ if (r < 0) ++ return r; ++ ++ xsprintf(procfs_path, "/proc/self/fd/%i", fd); + + STRV_FOREACH_PAIR(name, value, i->xattrs) { + log_debug("Setting extended attribute '%s=%s' on %s.", *name, *value, path); +- if (lsetxattr(path, *name, *value, strlen(*value), 0) < 0) ++ if (setxattr(procfs_path, *name, *value, strlen(*value), 0) < 0) + return log_error_errno(errno, "Setting extended attribute %s=%s on %s failed: %m", + *name, *value, path); + } + return 0; + } + ++static int path_set_xattrs(Item *i, const char *path) { ++ _cleanup_close_ int fd = -1; ++ ++ assert(i); ++ assert(path); ++ ++ fd = open(path, O_CLOEXEC|O_NOFOLLOW|O_PATH); ++ if (fd < 0) ++ return log_error_errno(errno, "Cannot open '%s': %m", path); ++ ++ return fd_set_xattrs(i, fd, NULL); ++} ++ + static int parse_acls_from_arg(Item *item) { + #if HAVE_ACL + int r; +@@ -998,52 +1031,71 @@ static int path_set_acl(const char *path, const char *pretty, acl_type_t type, a + } + #endif + +-static int path_set_acls(Item *item, const char *path) { ++static int fd_set_acls(Item *item, int fd, const struct stat *st) { + int r = 0; + #if HAVE_ACL +- char fn[STRLEN("/proc/self/fd/") + DECIMAL_STR_MAX(int)]; +- _cleanup_close_ int fd = -1; +- struct stat st; ++ char procfs_path[strlen("/proc/self/fd/") + DECIMAL_STR_MAX(int)]; ++ _cleanup_free_ char *path = NULL; + + assert(item); +- assert(path); +- +- fd = open(path, O_NOFOLLOW|O_CLOEXEC|O_PATH); +- if (fd < 0) +- return log_error_errno(errno, "Adjusting ACL of %s failed: %m", path); ++ assert(fd); ++ assert(st); + +- if (fstatat(fd, "", &st, AT_EMPTY_PATH) < 0) +- return log_error_errno(errno, "Failed to fstat() file %s: %m", path); ++ r = fd_get_path(fd, &path); ++ if (r < 0) ++ return r; + +- if (hardlink_vulnerable(&st)) { ++ if (hardlink_vulnerable(st)) { + log_error("Refusing to set ACLs on hardlinked file %s while the fs.protected_hardlinks sysctl is turned off.", path); + return -EPERM; + } + +- if (S_ISLNK(st.st_mode)) { ++ if (S_ISLNK(st->st_mode)) { + log_debug("Skipping ACL fix for symlink %s.", path); + return 0; + } + +- xsprintf(fn, "/proc/self/fd/%i", fd); ++ xsprintf(procfs_path, "/proc/self/fd/%i", fd); + + if (item->acl_access) +- r = path_set_acl(fn, path, ACL_TYPE_ACCESS, item->acl_access, item->force); ++ r = path_set_acl(procfs_path, path, ACL_TYPE_ACCESS, item->acl_access, item->force); + + if (r == 0 && item->acl_default) +- r = path_set_acl(fn, path, ACL_TYPE_DEFAULT, item->acl_default, item->force); ++ r = path_set_acl(procfs_path, path, ACL_TYPE_DEFAULT, item->acl_default, item->force); + + if (r > 0) + return -r; /* already warned */ +- else if (r == -EOPNOTSUPP) { ++ if (r == -EOPNOTSUPP) { + log_debug_errno(r, "ACLs not supported by file system at %s", path); + return 0; +- } else if (r < 0) +- log_error_errno(r, "ACL operation on \"%s\" failed: %m", path); ++ } ++ if (r < 0) ++ return log_error_errno(r, "ACL operation on \"%s\" failed: %m", path); + #endif + return r; + } + ++static int path_set_acls(Item *item, const char *path) { ++ int r = 0; ++#ifdef HAVE_ACL ++ _cleanup_close_ int fd = -1; ++ struct stat st; ++ ++ assert(item); ++ assert(path); ++ ++ fd = open(path, O_NOFOLLOW|O_CLOEXEC|O_PATH); ++ if (fd < 0) ++ return log_error_errno(errno, "Adjusting ACL of %s failed: %m", path); ++ ++ if (fstat(fd, &st) < 0) ++ return log_error_errno(errno, "Failed to fstat() file %s: %m", path); ++ ++ r = fd_set_acls(item, fd, &st); ++ #endif ++ return r; ++ } ++ + #define ATTRIBUTES_ALL \ + (FS_NOATIME_FL | \ + FS_SYNC_FL | \ +@@ -1143,30 +1195,24 @@ static int parse_attribute_from_arg(Item *item) { + return 0; + } + +-static int path_set_attribute(Item *item, const char *path) { +- _cleanup_close_ int fd = -1; +- struct stat st; ++static int fd_set_attribute(Item *item, int fd, const struct stat *st) { ++ char procfs_path[strlen("/proc/self/fd/") + DECIMAL_STR_MAX(int)]; ++ _cleanup_close_ int procfs_fd = -1; ++ _cleanup_free_ char *path = NULL; + unsigned f; + int r; + + if (!item->attribute_set || item->attribute_mask == 0) + return 0; + +- fd = open(path, O_RDONLY|O_NONBLOCK|O_CLOEXEC|O_NOATIME|O_NOFOLLOW); +- if (fd < 0) { +- if (errno == ELOOP) +- return log_error_errno(errno, "Skipping file attributes adjustment on symlink %s.", path); +- +- return log_error_errno(errno, "Cannot open '%s': %m", path); +- } +- +- if (fstat(fd, &st) < 0) +- return log_error_errno(errno, "Cannot stat '%s': %m", path); ++ r = fd_get_path(fd, &path); ++ if (r < 0) ++ return r; + + /* Issuing the file attribute ioctls on device nodes is not + * safe, as that will be delivered to the drivers, not the + * file system containing the device node. */ +- if (!S_ISREG(st.st_mode) && !S_ISDIR(st.st_mode)) { ++ if (!S_ISREG(st->st_mode) && !S_ISDIR(st->st_mode)) { + log_error("Setting file flags is only supported on regular files and directories, cannot set on '%s'.", path); + return -EINVAL; + } +@@ -1174,10 +1220,16 @@ static int path_set_attribute(Item *item, const char *path) { + f = item->attribute_value & item->attribute_mask; + + /* Mask away directory-specific flags */ +- if (!S_ISDIR(st.st_mode)) ++ if (!S_ISDIR(st->st_mode)) + f &= ~FS_DIRSYNC_FL; + +- r = chattr_fd(fd, f, item->attribute_mask); ++ xsprintf(procfs_path, "/proc/self/fd/%i", fd); ++ ++ procfs_fd = open(procfs_path, O_RDONLY|O_CLOEXEC|O_NOATIME); ++ if (procfs_fd < 0) ++ return -errno; ++ ++ r = chattr_fd(procfs_fd, f, item->attribute_mask); + if (r < 0) + log_full_errno(IN_SET(r, -ENOTTY, -EOPNOTSUPP) ? LOG_DEBUG : LOG_WARNING, + r, +@@ -1187,6 +1239,23 @@ static int path_set_attribute(Item *item, const char *path) { + return 0; + } + ++static int path_set_attribute(Item *item, const char *path) { ++ _cleanup_close_ int fd = -1; ++ struct stat st; ++ ++ if (!item->attribute_set || item->attribute_mask == 0) ++ return 0; ++ ++ fd = open(path, O_CLOEXEC|O_NOFOLLOW|O_PATH); ++ if (fd < 0) ++ return log_error_errno(errno, "Cannot open '%s': %m", path); ++ ++ if (fstat(fd, &st) < 0) ++ return log_error_errno(errno, "Cannot stat '%s': %m", path); ++ ++ return fd_set_attribute(item, fd, &st); ++} ++ + static int write_one_file(Item *i, const char *path) { + _cleanup_close_ int fd = -1; + int flags, r = 0; +@@ -1251,48 +1320,58 @@ done: + } + + typedef int (*action_t)(Item *, const char *); ++typedef int (*fdaction_t)(Item *, int fd, const struct stat *st); + +-static int item_do_children(Item *i, const char *path, action_t action) { +- _cleanup_closedir_ DIR *d; +- struct dirent *de; +- int r = 0; ++static int item_do(Item *i, int fd, const struct stat *st, fdaction_t action) { ++ int r = 0, q; + + assert(i); +- assert(path); ++ assert(fd >= 0); ++ assert(st); + + /* This returns the first error we run into, but nevertheless + * tries to go on */ ++ r = action(i, fd, st); + +- d = opendir_nomod(path); +- if (!d) +- return IN_SET(errno, ENOENT, ENOTDIR, ELOOP) ? 0 : -errno; ++ if (S_ISDIR(st->st_mode)) { ++ char procfs_path[strlen("/proc/self/fd/") + DECIMAL_STR_MAX(int)]; ++ _cleanup_closedir_ DIR *d = NULL; ++ struct dirent *de; + +- FOREACH_DIRENT_ALL(de, d, r = -errno) { +- _cleanup_free_ char *p = NULL; +- int q; ++ /* The passed 'fd' was opened with O_PATH. We need to convert ++ * it into a 'regular' fd before reading the directory content. */ ++ xsprintf(procfs_path, "/proc/self/fd/%i", fd); + +- if (dot_or_dot_dot(de->d_name)) +- continue; ++ d = opendir(procfs_path); ++ if (!d) { ++ r = r ?: -errno; ++ goto finish; ++ } + +- p = strjoin(path, "/", de->d_name); +- if (!p) +- return -ENOMEM; ++ FOREACH_DIRENT_ALL(de, d, q = -errno; goto finish) { ++ struct stat de_st; ++ int de_fd; ++ ++ if (dot_or_dot_dot(de->d_name)) ++ continue; + +- q = action(i, p); +- if (q < 0 && q != -ENOENT && r == 0) +- r = q; ++ de_fd = openat(fd, de->d_name, O_NOFOLLOW|O_CLOEXEC|O_PATH); ++ if (de_fd >= 0 && fstat(de_fd, &de_st) >= 0) ++ /* pass ownership of dirent fd over */ ++ q = item_do(i, de_fd, &de_st, action); ++ else ++ q = -errno; + +- if (IN_SET(de->d_type, DT_UNKNOWN, DT_DIR)) { +- q = item_do_children(i, p, action); + if (q < 0 && r == 0) + r = q; + } + } +- ++finish: ++ safe_close(fd); + return r; + } + +-static int glob_item(Item *i, action_t action, bool recursive) { ++static int glob_item(Item *i, action_t action) { + _cleanup_globfree_ glob_t g = { + #ifdef GLOB_ALTDIRFUNC + .gl_opendir = (void *(*)(const char *)) opendir_nomod, +@@ -1309,12 +1388,48 @@ static int glob_item(Item *i, action_t action, bool recursive) { + k = action(i, *fn); + if (k < 0 && r == 0) + r = k; ++ } + +- if (recursive) { +- k = item_do_children(i, *fn, action); +- if (k < 0 && r == 0) +- r = k; ++ return r; ++} ++ ++static int glob_item_recursively(Item *i, fdaction_t action) { ++ _cleanup_globfree_ glob_t g = { ++ .gl_opendir = (void *(*)(const char *)) opendir_nomod, ++ }; ++ int r = 0, k; ++ char **fn; ++ ++ k = safe_glob(i->path, GLOB_NOSORT|GLOB_BRACE, &g); ++ if (k < 0 && k != -ENOENT) ++ return log_error_errno(k, "glob(%s) failed: %m", i->path); ++ ++ STRV_FOREACH(fn, g.gl_pathv) { ++ _cleanup_close_ int fd = -1; ++ struct stat st; ++ ++ /* Make sure we won't trigger/follow file object (such as ++ * device nodes, automounts, ...) pointed out by 'fn' with ++ * O_PATH. Note, when O_PATH is used, flags other than ++ * O_CLOEXEC, O_DIRECTORY, and O_NOFOLLOW are ignored. */ ++ ++ fd = open(*fn, O_CLOEXEC|O_NOFOLLOW|O_PATH); ++ if (fd < 0) { ++ r = r ?: -errno; ++ continue; ++ } ++ ++ if (fstat(fd, &st) < 0) { ++ r = r ?: -errno; ++ continue; + } ++ ++ k = item_do(i, fd, &st, action); ++ if (k < 0 && r == 0) ++ r = k; ++ ++ /* we passed fd ownership to the previous call */ ++ fd = -1; + } + + return r; +@@ -1403,7 +1518,7 @@ static int create_item(Item *i) { + break; + + case WRITE_FILE: +- r = glob_item(i, write_one_file, false); ++ r = glob_item(i, write_one_file); + if (r < 0) + return r; + +@@ -1662,49 +1777,49 @@ static int create_item(Item *i) { + + case ADJUST_MODE: + case RELABEL_PATH: +- r = glob_item(i, path_set_perms, false); ++ r = glob_item(i, path_set_perms); + if (r < 0) + return r; + break; + + case RECURSIVE_RELABEL_PATH: +- r = glob_item(i, path_set_perms, true); ++ r = glob_item_recursively(i, fd_set_perms); + if (r < 0) + return r; + break; + + case SET_XATTR: +- r = glob_item(i, path_set_xattrs, false); ++ r = glob_item(i, path_set_xattrs); + if (r < 0) + return r; + break; + + case RECURSIVE_SET_XATTR: +- r = glob_item(i, path_set_xattrs, true); ++ r = glob_item_recursively(i, fd_set_xattrs); + if (r < 0) + return r; + break; + + case SET_ACL: +- r = glob_item(i, path_set_acls, false); ++ r = glob_item(i, path_set_acls); + if (r < 0) + return r; + break; + + case RECURSIVE_SET_ACL: +- r = glob_item(i, path_set_acls, true); ++ r = glob_item_recursively(i, fd_set_acls); + if (r < 0) + return r; + break; + + case SET_ATTRIBUTE: +- r = glob_item(i, path_set_attribute, false); ++ r = glob_item(i, path_set_attribute); + if (r < 0) + return r; + break; + + case RECURSIVE_SET_ATTRIBUTE: +- r = glob_item(i, path_set_attribute, true); ++ r = glob_item_recursively(i, fd_set_attribute); + if (r < 0) + return r; + break; +@@ -1754,7 +1869,7 @@ static int remove_item(Item *i) { + case REMOVE_PATH: + case TRUNCATE_DIRECTORY: + case RECURSIVE_REMOVE_PATH: +- return glob_item(i, remove_item_instance, false); ++ return glob_item(i, remove_item_instance); + + default: + return 0; +@@ -1828,7 +1943,7 @@ static int clean_item(Item *i) { + return 0; + case EMPTY_DIRECTORY: + case IGNORE_DIRECTORY_PATH: +- return glob_item(i, clean_item_instance, false); ++ return glob_item(i, clean_item_instance); + default: + return 0; + } +-- +2.11.0 +
meta/recipes-core/systemd/systemd/0002-Make-tmpfiles-safe.patch new file +1828 -0
1,828 lines not on this page · raw message
meta/recipes-core/systemd/systemd_237.bb +2 -0
@@ -61,6 +61,8 @@ SRC_URI += "file://touchscreen.rules \ file://0025-journald-set-a-limit-on-the-number-of-fields-1k.patch \ file://0026-journal-remote-set-a-limit-on-the-number-of-fields-i.patch \ file://0027-journal-fix-out-of-bounds-read-CVE-2018-16866.patch \ + file://0001-tmpfiles-don-t-resolve-pathnames-when-traversing-rec.patch \ + file://0002-Make-tmpfiles-safe.patch \ " SRC_URI_append_qemuall = " file://0001-core-device.c-Change-the-default-device-timeout-to-2.patch"
Signature · 1 line
2.11.0
PATCH 8/8 systemd: fix CVE-2019-6454
In reply to George McCollisterApply patches from systemd_237-3ubuntu10.13 to fix CVE-2019-6454. CVE-2019-6454 is an issue in which systemd (PID1) can be crashed with a specially formed D-Bus message.
For information see:
https://usn.ubuntu.com/3891-1/
https://git.launchpad.net/ubuntu/+source/systemd/commit/?h=applied/ubuntu/bionic-updates&id=d7584b894afcaa8a4a1abb69db2a9c81a6276e80
--- .../systemd/systemd/CVE-2019-6454.patch | 210 +++++++++++++++++++++ ...e-receive-an-invalid-dbus-message-ignore-.patch | 61 ++++++ meta/recipes-core/systemd/systemd_237.bb | 2 + 3 files changed, 273 insertions(+) create mode 100644 meta/recipes-core/systemd/systemd/CVE-2019-6454.patch create mode 100644 meta/recipes-core/systemd/systemd/sd-bus-if-we-receive-an-invalid-dbus-message-ignore-.patch
meta/recipes-core/systemd/systemd/CVE-2019-6454.patch new file +210 -0
@@ -0,0 +1,210 @@ +Description: sd-bus: enforce a size limit for dbus paths, and don't allocate + them on the stacka +Forwarded: no + +Patch from: systemd_237-3ubuntu10.13 + +For information see: +https://usn.ubuntu.com/3891-1/ +https://git.launchpad.net/ubuntu/+source/systemd/commit/?h=applied/ubuntu/bionic-updates&id=d7584b894afcaa8a4a1abb69db2a9c81a6276e80 + +CVE: CVE-2019-6454 +Upstream-Status: Backport + +Signed-off-by: George McCollister <[email protected]> + +--- a/src/libsystemd/sd-bus/bus-internal.c ++++ b/src/libsystemd/sd-bus/bus-internal.c +@@ -61,7 +61,7 @@ + if (slash) + return false; + +- return true; ++ return (q - p) <= BUS_PATH_SIZE_MAX; + } + + char* object_path_startswith(const char *a, const char *b) { +--- a/src/libsystemd/sd-bus/bus-internal.h ++++ b/src/libsystemd/sd-bus/bus-internal.h +@@ -339,6 +339,10 @@ + + #define BUS_MESSAGE_SIZE_MAX (64*1024*1024) + #define BUS_AUTH_SIZE_MAX (64*1024) ++/* Note that the D-Bus specification states that bus paths shall have no size limit. We enforce here one ++ * anyway, since truly unbounded strings are a security problem. The limit we pick is relatively large however, ++ * to not clash unnecessarily with real-life applications. */ ++#define BUS_PATH_SIZE_MAX (64*1024) + + #define BUS_CONTAINER_DEPTH 128 + +--- a/src/libsystemd/sd-bus/bus-objects.c ++++ b/src/libsystemd/sd-bus/bus-objects.c +@@ -1150,7 +1150,8 @@ + const char *path, + sd_bus_error *error) { + +- char *prefix; ++ _cleanup_free_ char *prefix = NULL; ++ size_t pl; + int r; + + assert(bus); +@@ -1166,7 +1167,12 @@ + return 0; + + /* Second, add fallback vtables registered for any of the prefixes */ +- prefix = alloca(strlen(path) + 1); ++ pl = strlen(path); ++ assert(pl <= BUS_PATH_SIZE_MAX); ++ prefix = new(char, pl + 1); ++ if (!prefix) ++ return -ENOMEM; ++ + OBJECT_PATH_FOREACH_PREFIX(prefix, path) { + r = object_manager_serialize_path(bus, reply, prefix, path, true, error); + if (r < 0) +@@ -1362,6 +1368,7 @@ + } + + int bus_process_object(sd_bus *bus, sd_bus_message *m) { ++ _cleanup_free_ char *prefix = NULL; + int r; + size_t pl; + bool found_object = false; +@@ -1386,9 +1393,12 @@ + assert(m->member); + + pl = strlen(m->path); +- do { +- char prefix[pl+1]; ++ assert(pl <= BUS_PATH_SIZE_MAX); ++ prefix = new(char, pl + 1); ++ if (!prefix) ++ return -ENOMEM; + ++ do { + bus->nodes_modified = false; + + r = object_find_and_run(bus, m, m->path, false, &found_object); +@@ -1516,9 +1526,15 @@ + + n = hashmap_get(bus->nodes, path); + if (!n) { +- char *prefix; ++ _cleanup_free_ char *prefix = NULL; ++ size_t pl; ++ ++ pl = strlen(path); ++ assert(pl <= BUS_PATH_SIZE_MAX); ++ prefix = new(char, pl + 1); ++ if (!prefix) ++ return -ENOMEM; + +- prefix = alloca(strlen(path) + 1); + OBJECT_PATH_FOREACH_PREFIX(prefix, path) { + n = hashmap_get(bus->nodes, prefix); + if (n) +@@ -2108,8 +2124,9 @@ + char **names) { + + BUS_DONT_DESTROY(bus); ++ _cleanup_free_ char *prefix = NULL; + bool found_interface = false; +- char *prefix; ++ size_t pl; + int r; + + assert_return(bus, -EINVAL); +@@ -2128,6 +2145,12 @@ + if (names && names[0] == NULL) + return 0; + ++ pl = strlen(path); ++ assert(pl <= BUS_PATH_SIZE_MAX); ++ prefix = new(char, pl + 1); ++ if (!prefix) ++ return -ENOMEM; ++ + do { + bus->nodes_modified = false; + +@@ -2137,7 +2160,6 @@ + if (bus->nodes_modified) + continue; + +- prefix = alloca(strlen(path) + 1); + OBJECT_PATH_FOREACH_PREFIX(prefix, path) { + r = emit_properties_changed_on_interface(bus, prefix, path, interface, true, &found_interface, names); + if (r != 0) +@@ -2269,7 +2291,8 @@ + + static int object_added_append_all(sd_bus *bus, sd_bus_message *m, const char *path) { + _cleanup_set_free_ Set *s = NULL; +- char *prefix; ++ _cleanup_free_ char *prefix = NULL; ++ size_t pl; + int r; + + assert(bus); +@@ -2314,7 +2337,12 @@ + if (bus->nodes_modified) + return 0; + +- prefix = alloca(strlen(path) + 1); ++ pl = strlen(path); ++ assert(pl <= BUS_PATH_SIZE_MAX); ++ prefix = new(char, pl + 1); ++ if (!prefix) ++ return -ENOMEM; ++ + OBJECT_PATH_FOREACH_PREFIX(prefix, path) { + r = object_added_append_all_prefix(bus, m, s, prefix, path, true); + if (r < 0) +@@ -2453,7 +2481,8 @@ + + static int object_removed_append_all(sd_bus *bus, sd_bus_message *m, const char *path) { + _cleanup_set_free_ Set *s = NULL; +- char *prefix; ++ _cleanup_free_ char *prefix = NULL; ++ size_t pl; + int r; + + assert(bus); +@@ -2485,7 +2514,12 @@ + if (bus->nodes_modified) + return 0; + +- prefix = alloca(strlen(path) + 1); ++ pl = strlen(path); ++ assert(pl <= BUS_PATH_SIZE_MAX); ++ prefix = new(char, pl + 1); ++ if (!prefix) ++ return -ENOMEM; ++ + OBJECT_PATH_FOREACH_PREFIX(prefix, path) { + r = object_removed_append_all_prefix(bus, m, s, prefix, path, true); + if (r < 0) +@@ -2635,7 +2669,8 @@ + const char *path, + const char *interface) { + +- char *prefix; ++ _cleanup_free_ char *prefix = NULL; ++ size_t pl; + int r; + + assert(bus); +@@ -2649,7 +2684,12 @@ + if (bus->nodes_modified) + return 0; + +- prefix = alloca(strlen(path) + 1); ++ pl = strlen(path); ++ assert(pl <= BUS_PATH_SIZE_MAX); ++ prefix = new(char, pl + 1); ++ if (!prefix) ++ return -ENOMEM; ++ + OBJECT_PATH_FOREACH_PREFIX(prefix, path) { + r = interfaces_added_append_one_prefix(bus, m, prefix, path, interface, true); + if (r != 0)
meta/recipes-core/systemd/systemd/sd-bus-if-we-receive-an-invalid-dbus-message-ignore-.patch new file +61 -0
61 lines not on this page · raw message
meta/recipes-core/systemd/systemd_237.bb +2 -0
@@ -63,6 +63,8 @@ SRC_URI += "file://touchscreen.rules \ file://0027-journal-fix-out-of-bounds-read-CVE-2018-16866.patch \ file://0001-tmpfiles-don-t-resolve-pathnames-when-traversing-rec.patch \ file://0002-Make-tmpfiles-safe.patch \ + file://CVE-2019-6454.patch \ + file://sd-bus-if-we-receive-an-invalid-dbus-message-ignore-.patch \ " SRC_URI_append_qemuall = " file://0001-core-device.c-Change-the-default-device-timeout-to-2.patch"
Signature · 1 line
2.11.0