teknoraver / rpms / systemd

Forked from rpms/systemd 3 months ago
Clone

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

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