923a60
From b71d112385937fdffac8bb78df279b23bc9441c4 Mon Sep 17 00:00:00 2001
923a60
From: Jan Synacek <jsynacek@redhat.com>
923a60
Date: Tue, 4 Dec 2018 10:01:35 +0100
923a60
Subject: [PATCH] core: enforce a limit on STATUS= texts recvd from services
923a60
923a60
Let's better be safe than sorry, and put a limit on what we receive.
923a60
923a60
(cherry picked from commit 3eac1bcae9284fb8b18f4b82156c0e85ddb004e5)
923a60
923a60
Related: CVE-2018-15686
923a60
---
923a60
 src/core/service.c | 8 ++++++--
923a60
 src/core/service.h | 2 ++
923a60
 2 files changed, 8 insertions(+), 2 deletions(-)
923a60
923a60
diff --git a/src/core/service.c b/src/core/service.c
923a60
index 4d542ad947..fe6e2ff17c 100644
923a60
--- a/src/core/service.c
923a60
+++ b/src/core/service.c
923a60
@@ -3045,8 +3045,12 @@ static void service_notify_message(Unit *u, pid_t pid, char **tags, FDSet *fds)
923a60
                 _cleanup_free_ char *t = NULL;
923a60
 
923a60
                 if (!isempty(e)) {
923a60
-                        if (!utf8_is_valid(e))
923a60
-                                log_unit_warning(u->id, "Status message in notification is not UTF-8 clean.");
923a60
+                        /* Note that this size limit check is mostly paranoia: since the datagram size we are willing
923a60
+                         * to process is already limited to NOTIFY_BUFFER_MAX, this limit here should never be hit. */
923a60
+                        if (strlen(e) > STATUS_TEXT_MAX)
923a60
+                                log_unit_warning(u->id, "Status message overly long (%zu > %u), ignoring.", strlen(e), STATUS_TEXT_MAX);
923a60
+                        else if (!utf8_is_valid(e))
923a60
+                                log_unit_warning(u->id, "Status message in notification message is not UTF-8 clean, ignoring.");
923a60
                         else {
923a60
                                 log_unit_debug(u->id, "%s: got STATUS=%s", u->id, e);
923a60
 
923a60
diff --git a/src/core/service.h b/src/core/service.h
923a60
index 1f937dfe57..e0547a464e 100644
923a60
--- a/src/core/service.h
923a60
+++ b/src/core/service.h
923a60
@@ -31,6 +31,8 @@ typedef struct ServiceFDStore ServiceFDStore;
923a60
 #include "exit-status.h"
923a60
 #include "emergency-action.h"
923a60
 
923a60
+#define STATUS_TEXT_MAX (16U*1024U)
923a60
+
923a60
 typedef enum ServiceState {
923a60
         SERVICE_DEAD,
923a60
         SERVICE_START_PRE,