Blame SOURCES/0668-journald-set-a-limit-on-the-number-of-fields-1k.patch

17b0f1
From 9dbac61cf123a57c1f39a2f134389f1a5877dc29 Mon Sep 17 00:00:00 2001
17b0f1
From: =?UTF-8?q?Zbigniew=20J=C4=99drzejewski-Szmek?= <zbyszek@in.waw.pl>
17b0f1
Date: Thu, 3 Jan 2019 16:09:05 +0100
17b0f1
Subject: [PATCH] journald: set a limit on the number of fields (1k)
17b0f1
17b0f1
We allocate a iovec entry for each field, so with many short entries,
17b0f1
our memory usage and processing time can be large, even with a relatively
17b0f1
small message size. Let's refuse overly long entries.
17b0f1
17b0f1
CVE-2018-16865
17b0f1
https://bugzilla.redhat.com/show_bug.cgi?id=1653861
17b0f1
17b0f1
What from I can see, the problem is not from an alloca, despite what the CVE
17b0f1
description says, but from the attack multiplication that comes from creating
17b0f1
many very small iovecs: (void* + size_t) for each three bytes of input
17b0f1
message.
17b0f1
17b0f1
Resolves: #1657792
17b0f1
---
17b0f1
 src/journal/journal-file.h    | 3 +++
17b0f1
 src/journal/journald-native.c | 4 ++++
17b0f1
 2 files changed, 7 insertions(+)
17b0f1
17b0f1
diff --git a/src/journal/journal-file.h b/src/journal/journal-file.h
17b0f1
index dd8ef52d2a..37749c4459 100644
17b0f1
--- a/src/journal/journal-file.h
17b0f1
+++ b/src/journal/journal-file.h
17b0f1
@@ -158,6 +158,9 @@ int journal_file_open_reliably(
17b0f1
  * files without adding too many zeros. */
17b0f1
 #define OFSfmt "%06"PRIx64
17b0f1
 
17b0f1
+/* The maximum number of fields in an entry */
17b0f1
+#define ENTRY_FIELD_COUNT_MAX 1024
17b0f1
+
17b0f1
 static inline bool VALID_REALTIME(uint64_t u) {
17b0f1
         /* This considers timestamps until the year 3112 valid. That should be plenty room... */
17b0f1
         return u > 0 && u < (1ULL << 55);
17b0f1
diff --git a/src/journal/journald-native.c b/src/journal/journald-native.c
17b0f1
index cf3349393f..0c451274f7 100644
17b0f1
--- a/src/journal/journald-native.c
17b0f1
+++ b/src/journal/journald-native.c
17b0f1
@@ -134,6 +134,10 @@ void server_process_native_message(
17b0f1
                 }
17b0f1
 
17b0f1
                 /* A property follows */
17b0f1
+                if (n > ENTRY_FIELD_COUNT_MAX) {
17b0f1
+                        log_debug("Received an entry that has more than " STRINGIFY(ENTRY_FIELD_COUNT_MAX) " fields, ignoring entry.");
17b0f1
+                        goto finish;
17b0f1
+                }
17b0f1
 
17b0f1
                 /* n existing properties, 1 new, +1 for _TRANSPORT */
17b0f1
                 if (!GREEDY_REALLOC(iovec, m, n + 2 + N_IOVEC_META_FIELDS + N_IOVEC_OBJECT_FIELDS)) {