Browse code

Systemd : Fix CVE-2017-18078.

Change-Id: I1e5e3450b387f0d903ee52a77a56a77e0df22055
Reviewed-on: http://photon-jenkins.eng.vmware.com:8082/4882
Tested-by: gerrit-photon <photon-checkins@vmware.com>
Reviewed-by: Anish Swaminathan <anishs@vmware.com>

Xiaolin Li authored on 2018/03/16 05:12:32
Showing 2 changed files
1 1
new file mode 100644
... ...
@@ -0,0 +1,82 @@
0
+From 5579f85663d10269e7ac7464be6548c99cea4ada Mon Sep 17 00:00:00 2001
1
+From: Lennart Poettering <lennart@poettering.net>
2
+Date: Tue, 23 Jan 2018 14:03:34 +0100
3
+Subject: [PATCH] tmpfiles: refuse to chown()/chmod() files which are
4
+ hardlinked, unless protected_hardlinks sysctl is on
5
+
6
+Let's add some extra safety.
7
+
8
+Fixes: #7736
9
+---
10
+ src/tmpfiles/tmpfiles.c | 43 +++++++++++++++++++++++++++++++++++++++++++
11
+ 1 file changed, 43 insertions(+)
12
+
13
+diff --git a/src/tmpfiles/tmpfiles.c b/src/tmpfiles/tmpfiles.c
14
+index d733768f277..5b56e7dcdd2 100644
15
+--- a/src/tmpfiles/tmpfiles.c
16
+@@ -604,6 +604,39 @@ finish:
17
+         return r;
18
+ }
19
+ 
20
++static bool dangerous_hardlinks(void) {
21
++        _cleanup_free_ char *value = NULL;
22
++        static int cached = -1;
23
++        int r;
24
++
25
++        /* Check whether the fs.protected_hardlinks sysctl is on. If we can't determine it we assume its off, as that's
26
++         * what the upstream default is. */
27
++
28
++        if (cached >= 0)
29
++                return cached;
30
++
31
++        r = read_one_line_file("/proc/sys/fs/protected_hardlinks", &value);
32
++        if (r < 0) {
33
++                log_debug_errno(r, "Failed to read fs.protected_hardlinks sysctl: %m");
34
++                return true;
35
++        }
36
++
37
++        r = parse_boolean(value);
38
++        if (r < 0) {
39
++                log_debug_errno(r, "Failed to parse fs.protected_hardlinks sysctl: %m");
40
++                return true;
41
++        }
42
++
43
++        cached = r == 0;
44
++        return cached;
45
++}
46
++
47
++static bool hardlink_vulnerable(struct stat *st) {
48
++        assert(st);
49
++
50
++        return !S_ISDIR(st->st_mode) && st->st_nlink > 1 && dangerous_hardlinks();
51
++}
52
++
53
+ static int path_set_perms(Item *i, const char *path) {
54
+         _cleanup_close_ int fd = -1;
55
+         struct stat st;
56
+@@ -623,6 +623,11 @@ static int path_set_perms(Item *i, const char *path) {
57
+         if (fstatat(fd, "", &st, AT_EMPTY_PATH) < 0)
58
+                 return log_error_errno(errno, "Failed to fstat() file %s: %m", path);
59
+ 
60
++        if (hardlink_vulnerable(&st)) {
61
++                log_error("Refusing to set permissions on hardlinked file %s while the fs.protected_hardlinks sysctl is turned off.", path);
62
++                return -EPERM;
63
++        }
64
++
65
+         if (S_ISLNK(st.st_mode))
66
+                 log_debug("Skipping mode an owner fix for symlink %s.", path);
67
+         else {
68
+
69
+@@ -971,6 +1009,11 @@ static int path_set_acls(Item *item, const char *path) {
70
+         if (fstatat(fd, "", &st, AT_EMPTY_PATH) < 0)
71
+                 return log_error_errno(errno, "Failed to fstat() file %s: %m", path);
72
+ 
73
++        if (hardlink_vulnerable(&st)) {
74
++                log_error("Refusing to set ACLs on hardlinked file %s while the fs.protected_hardlinks sysctl is turned off.", path);
75
++                return -EPERM;
76
++        }
77
++
78
+         if (S_ISLNK(st.st_mode)) {
79
+                 log_debug("Skipping ACL fix for symlink %s.", path);
80
+                 return 0;
... ...
@@ -1,7 +1,7 @@
1 1
 Summary:          Systemd-228
2 2
 Name:             systemd
3 3
 Version:          228
4
-Release:          44%{?dist}
4
+Release:          45%{?dist}
5 5
 License:          LGPLv2+ and GPLv2+ and MIT
6 6
 URL:              http://www.freedesktop.org/wiki/Software/systemd/
7 7
 Group:            System Environment/Security
... ...
@@ -43,6 +43,7 @@ Patch26:          systemd-228-CVE-2015-7510-long-machinename.patch
43 43
 Patch27:          systemd-228-resolved-null-deferencing-fix.patch
44 44
 Patch28:          systemd-228-link-disabled-nullptr-fix.patch
45 45
 Patch29:          systemd-228-CVE-2017-15908-dns-pkt-loop-fix.patch
46
+Patch30:          systemd-228-CVE-2017-18078.patch
46 47
 Requires:         Linux-PAM
47 48
 Requires:         libcap
48 49
 Requires:         xz
... ...
@@ -106,6 +107,7 @@ sed -i "s:blkid/::" $(grep -rl "blkid/blkid.h")
106 106
 %patch27 -p1
107 107
 %patch28 -p1
108 108
 %patch29 -p1
109
+%patch30 -p1
109 110
 sed -i "s#\#DefaultTasksMax=512#DefaultTasksMax=infinity#g" src/core/system.conf
110 111
 
111 112
 %build
... ...
@@ -244,6 +246,9 @@ rm -rf %{buildroot}/*
244 244
 
245 245
 
246 246
 %changelog
247
+%changelog
248
+*    Thu Mar 15 2018 Xiaolin Li <xiaolinl@vmware.com>  228-45
249
+-    Fix CVE-2017-18078.
247 250
 *    Wed Nov 29 2017 Anish Swaminathan <anishs@vmware.com> 228-44
248 251
 -    Remove the sed replace to autovt (autovt is a symlink to getty service)
249 252
 *    Thu Nov 09 2017 Vinay Kulkarni <kulkarniv@vmware.com>  228-43