Blame SOURCES/0062-core-enforce-a-limit-on-STATUS-texts-recvd-from-serv.patch

a3e2b5
From 6abfec31acae53943896b309db4a09a1cecac9a3 Mon Sep 17 00:00:00 2001
a3e2b5
From: Lennart Poettering <lennart@poettering.net>
a3e2b5
Date: Wed, 17 Oct 2018 18:37:48 +0200
a3e2b5
Subject: [PATCH] core: enforce a limit on STATUS= texts recvd from services
a3e2b5
a3e2b5
Let's better be safe than sorry, and put a limit on what we receive.
a3e2b5
a3e2b5
(cherry picked from commit 3eac1bcae9284fb8b18f4b82156c0e85ddb004e5)
a3e2b5
a3e2b5
Related: CVE-2018-15686
a3e2b5
---
a3e2b5
 src/core/service.c | 8 ++++++--
a3e2b5
 src/core/service.h | 2 ++
a3e2b5
 2 files changed, 8 insertions(+), 2 deletions(-)
a3e2b5
a3e2b5
diff --git a/src/core/service.c b/src/core/service.c
a3e2b5
index db1356c417..db17221888 100644
a3e2b5
--- a/src/core/service.c
a3e2b5
+++ b/src/core/service.c
a3e2b5
@@ -3549,8 +3549,12 @@ static void service_notify_message(
a3e2b5
                 _cleanup_free_ char *t = NULL;
a3e2b5
 
a3e2b5
                 if (!isempty(e)) {
a3e2b5
-                        if (!utf8_is_valid(e))
a3e2b5
-                                log_unit_warning(u, "Status message in notification message is not UTF-8 clean.");
a3e2b5
+                        /* Note that this size limit check is mostly paranoia: since the datagram size we are willing
a3e2b5
+                         * to process is already limited to NOTIFY_BUFFER_MAX, this limit here should never be hit. */
a3e2b5
+                        if (strlen(e) > STATUS_TEXT_MAX)
a3e2b5
+                                log_unit_warning(u, "Status message overly long (%zu > %u), ignoring.", strlen(e), STATUS_TEXT_MAX);
a3e2b5
+                        else if (!utf8_is_valid(e))
a3e2b5
+                                log_unit_warning(u, "Status message in notification message is not UTF-8 clean, ignoring.");
a3e2b5
                         else {
a3e2b5
                                 t = strdup(e);
a3e2b5
                                 if (!t)
a3e2b5
diff --git a/src/core/service.h b/src/core/service.h
a3e2b5
index 9c06e91883..a142b09f0d 100644
a3e2b5
--- a/src/core/service.h
a3e2b5
+++ b/src/core/service.h
a3e2b5
@@ -202,3 +202,5 @@ const char* service_result_to_string(ServiceResult i) _const_;
a3e2b5
 ServiceResult service_result_from_string(const char *s) _pure_;
a3e2b5
 
a3e2b5
 DEFINE_CAST(SERVICE, Service);
a3e2b5
+
a3e2b5
+#define STATUS_TEXT_MAX (16U*1024U)