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