anitazha / rpms / systemd

Forked from rpms/systemd 3 years ago
Clone
923a60
From 93c5087eed9abf8012dc5b0ccd2dd7ead1323899 Mon Sep 17 00:00:00 2001
923a60
From: Franck Bui <fbui@suse.com>
923a60
Date: Thu, 29 Sep 2016 19:44:34 +0200
923a60
Subject: [PATCH] pid1: don't return any error in manager_dispatch_notify_fd()
923a60
 (#4240)
923a60
923a60
If manager_dispatch_notify_fd() fails and returns an error then the handling of
923a60
service notifications will be disabled entirely leading to a compromised system.
923a60
923a60
For example pid1 won't be able to receive the WATCHDOG messages anymore and
923a60
will kill all services supposed to send such messages.
923a60
Cherry-picked from: 9987750e7a4c62e0eb8473603150596ba7c3a015
923a60
Resolves: #1380259
923a60
---
923a60
 src/core/manager.c | 13 +++++++++----
923a60
 1 file changed, 9 insertions(+), 4 deletions(-)
923a60
923a60
diff --git a/src/core/manager.c b/src/core/manager.c
923a60
index 689b266158..ed81059554 100644
923a60
--- a/src/core/manager.c
923a60
+++ b/src/core/manager.c
923a60
@@ -1673,10 +1673,14 @@ static int manager_dispatch_notify_fd(sd_event_source *source, int fd, uint32_t
923a60
 
923a60
         n = recvmsg(m->notify_fd, &msghdr, MSG_DONTWAIT|MSG_CMSG_CLOEXEC);
923a60
         if (n < 0) {
923a60
-                if (errno == EAGAIN || errno == EINTR)
923a60
-                        return 0;
923a60
+                if (!IN_SET(errno, EAGAIN, EINTR))
923a60
+                        log_error("Failed to receive notification message: %m");
923a60
 
923a60
-                return -errno;
923a60
+                /* It's not an option to return an error here since it
923a60
+                 * would disable the notification handler entirely. Services
923a60
+                 * wouldn't be able to send the WATCHDOG message for
923a60
+                 * example... */
923a60
+                return 0;
923a60
         }
923a60
         if (n == 0) {
923a60
                 log_debug("Got zero-length notification message. Ignoring.");
923a60
@@ -1703,7 +1707,8 @@ static int manager_dispatch_notify_fd(sd_event_source *source, int fd, uint32_t
923a60
                 r = fdset_new_array(&fds, fd_array, n_fds);
923a60
                 if (r < 0) {
923a60
                         close_many(fd_array, n_fds);
923a60
-                        return log_oom();
923a60
+                        log_oom();
923a60
+                        return 0;
923a60
                 }
923a60
         }
923a60