Blame SOURCES/0669-journal-remote-set-a-limit-on-the-number-of-fields-i.patch

17b0f1
From dec34b2c3b66f9ccf3977e3a45d3a8365ba92027 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:28:30 +0100
17b0f1
Subject: [PATCH] journal-remote: set a limit on the number of fields in a
17b0f1
 message
17b0f1
17b0f1
Existing use of E2BIG is replaced with ENOBUFS (entry too long), and E2BIG is
17b0f1
reused for the new error condition (too many fields).
17b0f1
17b0f1
This matches the change done for systemd-journald, hence forming the second
17b0f1
part of the fix for CVE-2018-16865
17b0f1
(https://bugzilla.redhat.com/show_bug.cgi?id=1653861).
17b0f1
17b0f1
Resolves: #1657792
17b0f1
---
17b0f1
 src/journal-remote/journal-remote-parse.c |  2 +-
17b0f1
 src/journal-remote/journal-remote-write.c |  3 +++
17b0f1
 src/journal-remote/journal-remote.c       | 14 ++++++++++++--
17b0f1
 3 files changed, 16 insertions(+), 3 deletions(-)
17b0f1
17b0f1
diff --git a/src/journal-remote/journal-remote-parse.c b/src/journal-remote/journal-remote-parse.c
17b0f1
index 64089da19b..53f4e36123 100644
17b0f1
--- a/src/journal-remote/journal-remote-parse.c
17b0f1
+++ b/src/journal-remote/journal-remote-parse.c
17b0f1
@@ -107,7 +107,7 @@ static int get_line(RemoteSource *source, char **line, size_t *size) {
17b0f1
                 source->scanned = source->filled;
17b0f1
                 if (source->scanned >= DATA_SIZE_MAX) {
17b0f1
                         log_error("Entry is bigger than %u bytes.", DATA_SIZE_MAX);
17b0f1
-                        return -E2BIG;
17b0f1
+                        return -ENOBUFS;
17b0f1
                 }
17b0f1
 
17b0f1
                 if (source->passive_fd)
17b0f1
diff --git a/src/journal-remote/journal-remote-write.c b/src/journal-remote/journal-remote-write.c
17b0f1
index 99820fa7b8..99920e62c5 100644
17b0f1
--- a/src/journal-remote/journal-remote-write.c
17b0f1
+++ b/src/journal-remote/journal-remote-write.c
17b0f1
@@ -22,6 +22,9 @@
17b0f1
 #include "journal-remote.h"
17b0f1
 
17b0f1
 int iovw_put(struct iovec_wrapper *iovw, void* data, size_t len) {
17b0f1
+        if (iovw->count >= ENTRY_FIELD_COUNT_MAX)
17b0f1
+                return -E2BIG;
17b0f1
+
17b0f1
         if (!GREEDY_REALLOC(iovw->iovec, iovw->size_bytes, iovw->count + 1))
17b0f1
                 return log_oom();
17b0f1
 
17b0f1
diff --git a/src/journal-remote/journal-remote.c b/src/journal-remote/journal-remote.c
17b0f1
index a455fb6bd8..e65daf6a0b 100644
17b0f1
--- a/src/journal-remote/journal-remote.c
17b0f1
+++ b/src/journal-remote/journal-remote.c
17b0f1
@@ -524,11 +524,18 @@ static int process_http_upload(
17b0f1
                         break;
17b0f1
                 else if (r < 0) {
17b0f1
                         log_warning("Failed to process data for connection %p", connection);
17b0f1
-                        if (r == -E2BIG)
17b0f1
+                        if (r == -ENOBUFS)
17b0f1
                                 return mhd_respondf(connection,
17b0f1
                                                     MHD_HTTP_REQUEST_ENTITY_TOO_LARGE,
17b0f1
                                                     "Entry is too large, maximum is %u bytes.\n",
17b0f1
                                                     DATA_SIZE_MAX);
17b0f1
+
17b0f1
+                        else if (r == -E2BIG)
17b0f1
+                                return mhd_respondf(connection,
17b0f1
+                                                    MHD_HTTP_REQUEST_ENTITY_TOO_LARGE,
17b0f1
+                                                    "Entry with more fields than the maximum of %u\n",
17b0f1
+                                                    ENTRY_FIELD_COUNT_MAX);
17b0f1
+
17b0f1
                         else
17b0f1
                                 return mhd_respondf(connection,
17b0f1
                                                     MHD_HTTP_UNPROCESSABLE_ENTITY,
17b0f1
@@ -1043,7 +1050,10 @@ static int handle_raw_source(sd_event_source *event,
17b0f1
                 log_debug("%zu active sources remaining", s->active);
17b0f1
                 return 0;
17b0f1
         } else if (r == -E2BIG) {
17b0f1
-                log_notice_errno(E2BIG, "Entry too big, skipped");
17b0f1
+                log_notice_errno(E2BIG, "Entry with too many fields, skipped");
17b0f1
+                return 1;
17b0f1
+        } else if (r == -ENOBUFS) {
17b0f1
+                log_notice_errno(ENOBUFS, "Entry too big, skipped");
17b0f1
                 return 1;
17b0f1
         } else if (r == -EAGAIN) {
17b0f1
                 return 0;