Blame SOURCES/rsyslog-7.4.7-bz1142373-cve-2014-3634.patch

1c0eb9
From 0d7a31540b25b2942ae35dd3c62d9ee33020a157 Mon Sep 17 00:00:00 2001
1c0eb9
From: Tomas Heinrich <theinric@redhat.com>
1c0eb9
Date: Tue, 7 Oct 2014 10:24:06 +0200
1c0eb9
Subject: [PATCH] fix CVE-2014-3634
1c0eb9
1c0eb9
See the following links for details:
1c0eb9
https://access.redhat.com/security/cve/CVE-2014-3634
1c0eb9
http://www.rsyslog.com/remote-syslog-pri-vulnerability/
1c0eb9
---
1c0eb9
 grammar/rainerscript.h  |  4 +--
1c0eb9
 runtime/msg.c           | 33 ++++++++++++++++---------
1c0eb9
 runtime/parser.c        | 13 ++++++----
1c0eb9
 runtime/rsyslog.h       | 66 ++++++++++++++++++++++++++++++++++++++++---------
1c0eb9
 runtime/srutils.c       |  1 +
1c0eb9
 runtime/syslogd-types.h |  3 ---
1c0eb9
 6 files changed, 88 insertions(+), 32 deletions(-)
1c0eb9
1c0eb9
diff --git a/grammar/rainerscript.h b/grammar/rainerscript.h
1c0eb9
index 0657330..52050e4 100644
1c0eb9
--- a/grammar/rainerscript.h
1c0eb9
+++ b/grammar/rainerscript.h
1c0eb9
@@ -7,8 +7,8 @@
1c0eb9
 #include <regex.h>
1c0eb9
 #include "typedefs.h"
1c0eb9
 
1c0eb9
-
1c0eb9
-#define	LOG_NFACILITIES	24	/* current number of syslog facilities */
1c0eb9
+#define	LOG_NFACILITIES	24+1	/* This is a dupe from rsyslog.h, but we can't include it as
1c0eb9
+				   I don't know how to get hold of that damn off64_t data type... */
1c0eb9
 #define CNFFUNC_MAX_ARGS 32
1c0eb9
 	/**< maximum number of arguments that any function can have (among
1c0eb9
 	 *   others, this is used to size data structures).
1c0eb9
diff --git a/runtime/msg.c b/runtime/msg.c
1c0eb9
index 10ecf48..abb58c9 100644
1c0eb9
--- a/runtime/msg.c
1c0eb9
+++ b/runtime/msg.c
1c0eb9
@@ -90,7 +90,7 @@ static char *two_digits[100] = {
1c0eb9
 static struct {
1c0eb9
 	uchar *pszName;
1c0eb9
 	short lenName;
1c0eb9
-} syslog_pri_names[192] = {
1c0eb9
+} syslog_pri_names[200] = {
1c0eb9
 	{ UCHAR_CONSTANT("0"), 3},
1c0eb9
 	{ UCHAR_CONSTANT("1"), 3},
1c0eb9
 	{ UCHAR_CONSTANT("2"), 3},
1c0eb9
@@ -282,22 +282,30 @@ static struct {
1c0eb9
 	{ UCHAR_CONSTANT("188"), 5},
1c0eb9
 	{ UCHAR_CONSTANT("189"), 5},
1c0eb9
 	{ UCHAR_CONSTANT("190"), 5},
1c0eb9
-	{ UCHAR_CONSTANT("191"), 5}
1c0eb9
+	{ UCHAR_CONSTANT("191"), 5},
1c0eb9
+	{ UCHAR_CONSTANT("192"), 5},
1c0eb9
+	{ UCHAR_CONSTANT("193"), 5},
1c0eb9
+	{ UCHAR_CONSTANT("194"), 5},
1c0eb9
+	{ UCHAR_CONSTANT("195"), 5},
1c0eb9
+	{ UCHAR_CONSTANT("196"), 5},
1c0eb9
+	{ UCHAR_CONSTANT("197"), 5},
1c0eb9
+	{ UCHAR_CONSTANT("198"), 5},
1c0eb9
+	{ UCHAR_CONSTANT("199"), 5},
1c0eb9
 	};
1c0eb9
 static char hexdigit[16] =
1c0eb9
 	{'0', '1', '2', '3', '4', '5', '6', '7', '8',
1c0eb9
 	 '9', 'A', 'B', 'C', 'D', 'E', 'F' };
1c0eb9
 
1c0eb9
 /*syslog facility names (as of RFC5424) */
1c0eb9
-static char *syslog_fac_names[24] = { "kern", "user", "mail", "daemon", "auth", "syslog", "lpr",
1c0eb9
+static char *syslog_fac_names[LOG_NFACILITIES] = { "kern", "user", "mail", "daemon", "auth", "syslog", "lpr",
1c0eb9
 			    	      "news", "uucp", "cron", "authpriv", "ftp", "ntp", "audit",
1c0eb9
 			    	      "alert", "clock", "local0", "local1", "local2", "local3",
1c0eb9
-			    	      "local4", "local5", "local6", "local7" };
1c0eb9
+			    	      "local4", "local5", "local6", "local7", "invld" };
1c0eb9
 /* length of the facility names string (for optimizatiions) */
1c0eb9
-static short len_syslog_fac_names[24] = { 4, 4, 4, 6, 4, 6, 3,
1c0eb9
+static short len_syslog_fac_names[LOG_NFACILITIES] = { 4, 4, 4, 6, 4, 6, 3,
1c0eb9
 			    	          4, 4, 4, 8, 3, 3, 5,
1c0eb9
 			    	          5, 5, 6, 6, 6, 6,
1c0eb9
-			    	          6, 6, 6, 6 };
1c0eb9
+			    	          6, 6, 6, 6, 5 };
1c0eb9
 
1c0eb9
 /* table of severity names (in numerical order)*/
1c0eb9
 static char *syslog_severity_names[8] = { "emerg", "alert", "crit", "err", "warning", "notice", "info", "debug" };
1c0eb9
@@ -307,8 +315,8 @@ static short len_syslog_severity_names[8] = { 5, 5, 4, 3, 7, 6, 4, 5 };
1c0eb9
  * and facility values to a numerical string... -- rgerhars, 2009-06-17
1c0eb9
  */
1c0eb9
 
1c0eb9
-static char *syslog_number_names[24] = { "0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "11", "12", "13", "14",
1c0eb9
-					 "15", "16", "17", "18", "19", "20", "21", "22", "23" };
1c0eb9
+static char *syslog_number_names[LOG_NFACILITIES] = { "0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "11", "12", "13", "14",
1c0eb9
+					 "15", "16", "17", "18", "19", "20", "21", "22", "23", "24" };
1c0eb9
 
1c0eb9
 /* global variables */
1c0eb9
 #if defined(HAVE_MALLOC_TRIM) && !defined(HAVE_ATOMIC_BUILTINS)
1c0eb9
@@ -678,8 +686,8 @@ static inline rsRetVal msgBaseConstruct(msg_t **ppThis)
1c0eb9
 	pM->flowCtlType = 0;
1c0eb9
 	pM->bParseSuccess = 0;
1c0eb9
 	pM->iRefCount = 1;
1c0eb9
-	pM->iSeverity = -1;
1c0eb9
-	pM->iFacility = -1;
1c0eb9
+	pM->iSeverity = LOG_DEBUG;
1c0eb9
+	pM->iFacility = LOG_INVLD;
1c0eb9
 	pM->iLenPROGNAME = -1;
1c0eb9
 	pM->offAfterPRI = 0;
1c0eb9
 	pM->offMSG = -1;
1c0eb9
@@ -1499,7 +1507,10 @@ uchar *getMSG(msg_t *pM)
1c0eb9
 /* Get PRI value as integer */
1c0eb9
 static int getPRIi(msg_t *pM)
1c0eb9
 {
1c0eb9
-	return (pM->iFacility << 3) + (pM->iSeverity);
1c0eb9
+	unsigned pri = (pM->iFacility << 3) + (pM->iSeverity);
1c0eb9
+	if(pri > LOG_MAXPRI)
1c0eb9
+		pri = LOG_PRI_INVLD;
1c0eb9
+	return pri;
1c0eb9
 }
1c0eb9
 
1c0eb9
 
1c0eb9
diff --git a/runtime/parser.c b/runtime/parser.c
1c0eb9
index 74b28f4..e708b33 100644
1c0eb9
--- a/runtime/parser.c
1c0eb9
+++ b/runtime/parser.c
1c0eb9
@@ -444,7 +444,7 @@ finalize_it:
1c0eb9
 static inline rsRetVal
1c0eb9
 ParsePRI(msg_t *pMsg)
1c0eb9
 {
1c0eb9
-	int pri;
1c0eb9
+	unsigned pri;
1c0eb9
 	uchar *msg;
1c0eb9
 	int lenMsg;
1c0eb9
 	DEFiRet;
1c0eb9
@@ -463,13 +463,16 @@ ParsePRI(msg_t *pMsg)
1c0eb9
 			 * but it offers us performance...
1c0eb9
 			 */
1c0eb9
 			pri = 0;
1c0eb9
-			while(--lenMsg > 0 && isdigit((int) *++msg)) {
1c0eb9
+			while(--lenMsg > 0 && isdigit((int) *++msg) && pri <= LOG_MAXPRI) {
1c0eb9
 				pri = 10 * pri + (*msg - '0');
1c0eb9
 			}
1c0eb9
-			if(*msg == '>')
1c0eb9
+			if(*msg == '>') {
1c0eb9
 				++msg;
1c0eb9
-			if(pri & ~(LOG_FACMASK|LOG_PRIMASK))
1c0eb9
-				pri = DEFUPRI;
1c0eb9
+			} else {
1c0eb9
+				pri = LOG_PRI_INVLD;
1c0eb9
+			}
1c0eb9
+			if(pri > LOG_MAXPRI)
1c0eb9
+				pri = LOG_PRI_INVLD;
1c0eb9
 		}
1c0eb9
 		pMsg->iFacility = LOG_FAC(pri);
1c0eb9
 		pMsg->iSeverity = LOG_PRI(pri);
1c0eb9
diff --git a/runtime/rsyslog.h b/runtime/rsyslog.h
1c0eb9
index e62ba86..37c4b1b 100644
1c0eb9
--- a/runtime/rsyslog.h
1c0eb9
+++ b/runtime/rsyslog.h
1c0eb9
@@ -76,19 +76,63 @@
1c0eb9
  * #                  End Config Settings                      # *
1c0eb9
  * ############################################################# */
1c0eb9
 
1c0eb9
-/* portability: not all platforms have these defines, so we
1c0eb9
- * define them here if they are missing. -- rgerhards, 2008-03-04
1c0eb9
+/* make sure we uses consistent macros, no matter what the
1c0eb9
+ * platform gives us.
1c0eb9
  */
1c0eb9
-#ifndef LOG_MAKEPRI
1c0eb9
-#	define	LOG_MAKEPRI(fac, pri)	(((fac) << 3) | (pri))
1c0eb9
-#endif
1c0eb9
-#ifndef LOG_PRI
1c0eb9
-#	define	LOG_PRI(p)	((p) & LOG_PRIMASK)
1c0eb9
-#endif
1c0eb9
-#ifndef LOG_FAC
1c0eb9
-#	define	LOG_FAC(p)	(((p) & LOG_FACMASK) >> 3)
1c0eb9
-#endif
1c0eb9
+#define LOG_NFACILITIES 24+1 /* plus one for our special "invld" facility! */
1c0eb9
+#define LOG_MAXPRI 191	/* highest supported valid PRI value --> RFC3164, RFC5424 */
1c0eb9
+#undef LOG_MAKEPRI
1c0eb9
+#define LOG_PRI_INVLD	(LOG_INVLD|LOG_DEBUG)	/* PRI is invalid --> special "invld.=debug" PRI code (rsyslog-specific) */
1c0eb9
+
1c0eb9
+#define	LOG_EMERG	0	/* system is unusable */
1c0eb9
+#define	LOG_ALERT	1	/* action must be taken immediately */
1c0eb9
+#define	LOG_CRIT	2	/* critical conditions */
1c0eb9
+#define	LOG_ERR		3	/* error conditions */
1c0eb9
+#define	LOG_WARNING	4	/* warning conditions */
1c0eb9
+#define	LOG_NOTICE	5	/* normal but significant condition */
1c0eb9
+#define	LOG_INFO	6	/* informational */
1c0eb9
+#define	LOG_DEBUG	7	/* debug-level messages */
1c0eb9
+
1c0eb9
+#define	LOG_KERN	(0<<3)	/* kernel messages */
1c0eb9
+#define	LOG_USER	(1<<3)	/* random user-level messages */
1c0eb9
+#define	LOG_MAIL	(2<<3)	/* mail system */
1c0eb9
+#define	LOG_DAEMON	(3<<3)	/* system daemons */
1c0eb9
+#define	LOG_AUTH	(4<<3)	/* security/authorization messages */
1c0eb9
+#define	LOG_SYSLOG	(5<<3)	/* messages generated internally by syslogd */
1c0eb9
+#define	LOG_LPR		(6<<3)	/* line printer subsystem */
1c0eb9
+#define	LOG_NEWS	(7<<3)	/* network news subsystem */
1c0eb9
+#define	LOG_UUCP	(8<<3)	/* UUCP subsystem */
1c0eb9
+#define	LOG_CRON	(9<<3)	/* clock daemon */
1c0eb9
+#define	LOG_AUTHPRIV	(10<<3)	/* security/authorization messages (private) */
1c0eb9
+#define	LOG_FTP		(11<<3)	/* ftp daemon */
1c0eb9
+#define	LOG_LOCAL0	(16<<3)	/* reserved for local use */
1c0eb9
+#define	LOG_LOCAL1	(17<<3)	/* reserved for local use */
1c0eb9
+#define	LOG_LOCAL2	(18<<3)	/* reserved for local use */
1c0eb9
+#define	LOG_LOCAL3	(19<<3)	/* reserved for local use */
1c0eb9
+#define	LOG_LOCAL4	(20<<3)	/* reserved for local use */
1c0eb9
+#define	LOG_LOCAL5	(21<<3)	/* reserved for local use */
1c0eb9
+#define	LOG_LOCAL6	(22<<3)	/* reserved for local use */
1c0eb9
+#define	LOG_LOCAL7	(23<<3)	/* reserved for local use */
1c0eb9
+#define LOG_FAC_INVLD   24
1c0eb9
+#define	LOG_INVLD	(LOG_FAC_INVLD<<3)	/* invalid facility/PRI code */
1c0eb9
+
1c0eb9
+/* we need to use a function to avoid side-effects. This MUST guard
1c0eb9
+ * against invalid facility values. rgerhards, 2014-09-16
1c0eb9
+ */
1c0eb9
+static inline int pri2fac(const int pri)
1c0eb9
+{
1c0eb9
+	unsigned fac = pri >> 3;
1c0eb9
+	return (fac > 23) ? LOG_FAC_INVLD : fac;
1c0eb9
+}
1c0eb9
+
1c0eb9
+#define LOG_FAC(x) pri2fac(x)
1c0eb9
+
1c0eb9
+static inline int pri2sev(const int pri)
1c0eb9
+{
1c0eb9
+	return pri & 0x07;
1c0eb9
+}
1c0eb9
 
1c0eb9
+#define LOG_PRI(x) pri2sev(x)
1c0eb9
 
1c0eb9
 /* the rsyslog core provides information about present feature to plugins
1c0eb9
  * asking it. Below are feature-test macros which must be used to query
1c0eb9
diff --git a/runtime/srutils.c b/runtime/srutils.c
1c0eb9
index 6a509b4..4f9f6c1 100644
1c0eb9
--- a/runtime/srutils.c
1c0eb9
+++ b/runtime/srutils.c
1c0eb9
@@ -103,6 +103,7 @@ syslogName_t	syslogFacNames[] = {
1c0eb9
 	{"local5",       LOG_LOCAL5},
1c0eb9
 	{"local6",       LOG_LOCAL6},
1c0eb9
 	{"local7",       LOG_LOCAL7},
1c0eb9
+	{"invld",        LOG_INVLD},
1c0eb9
 	{NULL,           -1},
1c0eb9
 };
1c0eb9
 
1c0eb9
diff --git a/runtime/syslogd-types.h b/runtime/syslogd-types.h
1c0eb9
index 6947a11..8aee425 100644
1c0eb9
--- a/runtime/syslogd-types.h
1c0eb9
+++ b/runtime/syslogd-types.h
1c0eb9
@@ -27,9 +27,6 @@
1c0eb9
 
1c0eb9
 #include "stringbuf.h"
1c0eb9
 #include <sys/param.h>
1c0eb9
-#if HAVE_SYSLOG_H
1c0eb9
-#include <syslog.h>
1c0eb9
-#endif
1c0eb9
 
1c0eb9
 /* we use RSTRUE/FALSE to prevent name claches with other packages */
1c0eb9
 #define RSFALSE 0
1c0eb9
-- 
1c0eb9
1.9.3
1c0eb9