Paul Traina
2017-Apr-10 20:59 UTC
[Logcheck-devel] Bug#860052: can generate illegal and thus lost e-mail messages due to long lines
Package: logcheck Version: 1.3.18 Severity: important Tags: security [Note: I've tagged this with security because of the DoS potential, where admins relying on logcheck can have their logs "lost" if someone generates a long log message. Your choice whether you think it's legitimate or not, but I am obligated to point it out.] If a log line is generated that is >998 characters, logcheck will generate an illegal (MUST in SMTP RFC is violated) e-mail message that exim (and possibly other mailers) will choke on. This was caused because we force mime-encode to use an encoding of 7bit on the resultant logfiles. That's fundamentally a mistake, as mime-encode is smart enough to recognize that the encoding needs to be changed in cases where lines have non-ascii characters or are too long, and will re-encode as quoted-printable. I can imagine, in days past, that this was a deliberate choice because so many sysadmin types were using non-mime-compliant MUAs and wanted to be able to simply cut and paste out of /bin/mailx output, but we don't live in that universe and haven't for a couple of decades. Dropping all log messages because of one overly-long-line is highly problematic. Fix: Any place in `/usr/sbin/logcheck` where there is --enconding "7bit" can simply be removed. Let mime-encode do its job, it knows better than logcheck what to do with the input data. -- System Information: Debian Release: 9.0 APT prefers testing APT policy: (500, 'testing') Architecture: amd64 (x86_64) Kernel: Linux 2.6.32-042stab120.16 (SMP w/4 CPU cores) Locale: LANG=en_US.UTF-8, LC_CTYPE=en_US.UTF-8 (charmap=UTF-8) Shell: /bin/sh linked to /bin/dash Init: systemd (via /run/systemd/system) Versions of packages logcheck depends on: ii adduser 3.115 ii cron [cron-daemon] 3.0pl1-128+b1 ii exim4-daemon-light [mail-transport-agent] 4.88-5 ii lockfile-progs 0.1.17+b1 ii logtail 1.3.18 ii mime-construct 1.11+nmu2 ii rsyslog [system-log-daemon] 8.24.0-1 Versions of packages logcheck recommends: ii logcheck-database 1.3.18 Versions of packages logcheck suggests: pn syslog-summary <none> -- Configuration Files: /etc/logcheck/logcheck.conf [Errno 13] Permission denied: '/etc/logcheck/logcheck.conf' /etc/logcheck/logcheck.logfiles [Errno 13] Permission denied: '/etc/logcheck/logcheck.logfiles' -- no debconf information
Anthony DeRobertis
2017-Nov-17 19:00 UTC
[Logcheck-devel] Bug#860052: [PATCH] Let mime-construct pick an encoding (closes: #860052)
tags 860052 + patch thanks Note that this uses arrays, which are of course a bashism, but the top of the script explicitly calls for bash, so I presume bashisms are OK. Unfortunately, because of the "eval", it doesn't fully protect from weirdness in the config file. Of course, it looks like that eval could fairly easily be removed... From 86c8dc10a6452c011b993569ea0994bf280fb40f Mon Sep 17 00:00:00 2001 From: Anthony DeRobertis Date: Fri, 17 Nov 2017 12:43:01 -0500 Subject: [PATCH] Let mime-construct pick an encoding (closes: #860052) Forcing 7bit is nice for MUAs and other tools that don't fully support MIME encoding messages, but has the downside of sometimes generating non-compliant messages. In particular, overly long lines get the logcheck message rejected by Debian's default Exim configuration. Add a configuration option to allow this to be overridden if required to work with some MIME-unaware tool. --- etc/logcheck.conf | 11 +++++++++++ src/logcheck | 16 ++++++++++++---- 2 files changed, 23 insertions(+), 4 deletions(-) diff --git a/etc/logcheck.conf b/etc/logcheck.conf index 4653c11..1699fae 100644 --- a/etc/logcheck.conf +++ b/etc/logcheck.conf @@ -71,6 +71,17 @@ FQDN=1 #ADDTAG="no" +# Previous versions of logcheck always sent messages in 7bit encoding, +# even if that resulted in RFC-violating messages. For example, really +# long syslog lines would generate too-long SMTP lines, which are +# rejected at least by Debian's default exim configuration. The new +# default is to let mime-construct pick an appropriate encoding, but you +# can override it by setting the below (to any of the encodings +# supported by mime-construct). You may need to do this if you have +# tools handling logcheck emails that don't understand MIME encoding. + +#MIMEENCODING="7bit" + # Set a different location for temporary files than /tmp # this is useful if your /tmp is small and you are getting # errors such as: diff --git a/src/logcheck b/src/logcheck index a8c58ea..48082f3 100755 --- a/src/logcheck +++ b/src/logcheck @@ -84,6 +84,7 @@ INTRO=1 LOGCHECKDEBUG=0 MAILOUT=0 MAILASATTACH=0 +MIMEENCODING NOCLEANUP=0 REBOOT=0 FQDN=0 @@ -176,7 +177,7 @@ Also verify that the logcheck user can read all files referenced in $(export) EOF } | eval mime-construct $MIMECONSTRUCTARGS \ - --subject "'Logcheck: $HOSTNAME $DATE exiting due to errors'" --encoding "7bit" \ + --subject "'Logcheck: $HOSTNAME $DATE exiting due to errors'" "${ENCODING[@]}" \ --file - --to "$SENDMAILTO" elif [ "$MAILOUT" -eq 1 ]; then @@ -306,14 +307,14 @@ sendreport() { debug "Sending report: '$subject' to $SENDMAILTO" if [ "$MAILASATTACH" -eq 1 ]; then debug "Sending report as attachment" - eval mime-construct $MIMECONSTRUCTARGS --subject "'$subject'" --encoding "7bit" --string "'Report attached'" --to "$SENDMAILTO" --attachment "logcheck_report" --encoding "7bit" --file "$TMPDIR/report" + eval mime-construct $MIMECONSTRUCTARGS --subject "'$subject'" "${ENCODING[@]}" --string "'Report attached'" --to "$SENDMAILTO" --attachment "logcheck_report" "${ENCODING[@]}" --file "$TMPDIR/report" return $? elif [ "$MAILASATTACH" -eq 2 ]; then debug "Sending report as gzip attachment" - eval mime-construct $MIMECONSTRUCTARGS --subject "'$subject'" --encoding "7bit" --string "'Report attached'" --to "$SENDMAILTO" --type "application/x-gzip" --attachment "logcheck_report.gz" --file "'gzip -c $TMPDIR/report |'" + eval mime-construct $MIMECONSTRUCTARGS --subject "'$subject'" "${ENCODING[@]}" --string "'Report attached'" --to "$SENDMAILTO" --type "application/x-gzip" --attachment "logcheck_report.gz" --file "'gzip -c $TMPDIR/report |'" return $? fi - eval mime-construct $MIMECONSTRUCTARGS --subject "'$subject'" --to "$SENDMAILTO" --encoding "7bit" --file "$TMPDIR/report" + eval mime-construct $MIMECONSTRUCTARGS --subject "'$subject'" --to "$SENDMAILTO" "${ENCODING[@]}" --file "$TMPDIR/report" fi } @@ -536,6 +537,13 @@ else SORT="sort -k 1,3 -s" fi +# Set the forced mime encoding if not left blank (auto) +if [ -n "$MIMEENCODING" ]; then + ENCODING=(--encoding "$MIMEENCODING") +else + ENCODING=() +fi + # Hostname either fully qualified or not. if [ "$FQDN" -eq 1 ]; then HOSTNAME="$(hostname --fqdn 2>/dev/null)" -- 2.15.0