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