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

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