-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA512

fetchmail-SA-2021-01: DoS or information disclosure logging long messages

Topics:		fetchmail denial of service or information disclosure when logging long messages

Author:		Matthias Andree
Version:	1.3
Announced:	2021-07-28 (original), 2021-08-09 (last update)
Type:		missing variable initialization can cause read from bad memory
		locations
Impact:		fetchmail logs random information, or segfaults and aborts,
		stalling inbound mail
Danger:		low
Acknowledgment:	Christian Herdtweck, Intra2net AG, Tübingen, Germany
		for analysis and report and a patch suggestion

CVE Name:	CVE-2021-36386 and CVE-2008-2711
URL:		https://www.fetchmail.info/fetchmail-SA-2021-01.txt
URL:		https://www.fetchmail.info/fetchmail-SA-2008-01.txt
Project URL:	https://www.fetchmail.info/

Affects:	- fetchmail releases up to and including 6.3.8
		- fetchmail releases 6.3.17 up to incl. 6.4.19
		  (but note 6.4.20 regresses for buffered output,
		   f.i. with --logfile)

Not affected:	- fetchmail releases 6.4.21 and newer
		  (fetchmail 6.4.20 fixes the immediate bug but regresses
		   and causes message truncation on buffered output)
		- fetchmail releases 6.3.9 to 6.3.16

Corrected in:	c546c829 + d3db2da1 Git commit hash (both needed)
		2021-08-09 fetchmail 6.4.21 release tarball
		2021-08-03 7.0.0-alpha9/6.5.0-beta4 snapshots

0. Release history
==================

2021-07-07	initial report to maintainer
2021-07-28 1.0	release
2021-07-28 1.1	update Git commit hash with correction
2021-08-03 1.2  add references to CVE-2008-2711/fetchmail-SA-2008-01
2021-08-09 1.3  mention buffered logging regression (--logfile)


1. Background
=============

fetchmail is a software package to retrieve mail from remote POP3, IMAP,
ETRN or ODMR servers and forward it to local SMTP, LMTP servers or
message delivery agents. fetchmail supports SSL and TLS security layers
through the OpenSSL library, if enabled at compile time and if also
enabled at run time, in both SSL/TLS-wrapped mode on dedicated ports as
well as in-band-negotiated "STARTTLS" and "STLS" modes through the
regular protocol ports.


2. Problem description and Impact
=================================

Fetchmail has long had support to assemble log/error messages that are
generated piecemeal, and takes care to reallocate the output buffer as needed.
In the reallocation case, i. e. when long log messages are assembled that can
stem from very long headers, and on systems that have a varargs.h/stdarg.h
interface (all modern systems), fetchmail's code would fail to reinitialize
the va_list argument to vsnprintf.

The exact effects depend on the verbose mode (how many -v are given) of
fetchmail, computer architecture, compiler, operating system and
configuration.  On some systems, the code just works without ill effects, some
systems log a garbage message (potentially disclosing sensitive information),
some systems log literally "(null)", some systems trigger SIGSEGV (signal
#11), which crashes fetchmail, causing a denial of service on fetchmail's end.

The same bug then named CVE-2008-2711 had already been fixed in fetchmail 6.3.9,
but a code refactoring in fetchmail 6.3.17 (commit 414a3809 in 2010)
reintroduced the bug.
Fetchmail versions 6.4.19 and older are no longer supported, however.

The bugfix used in 6.4.20 uses a different, more thorough, approach.


3. Solution
===========

Install fetchmail 6.4.21 or newer.

The fetchmail source code is available from
<https://sourceforge.net/projects/fetchmail/files/>.

Distributors are encouraged to review the NEWS file and move forward to
6.4.21, rather than backport individual security fixes, because doing so
routinely misses other fixes crucial to fetchmail's proper operation,
for which no security announcements are issued, or documentation,
or translation updates.

The regression fix for the new non-security bug in 6.4.20 that causes
log message truncation simply consists of editing report.c to rotate lines 289 
through 291, such that the /corrected/ report.c then looks like this:

   286	    n = snprintf (partial_message + partial_message_size_used,
   287			    partial_message_size - partial_message_size_used,
   288			    message, a1, a2, a3, a4, a5, a6, a7, a8);
   289
   290	    if (n > 0) partial_message_size_used += n;
   291	#endif
   292
   293	    if (unbuffered && partial_message_size_used != 0)


Fetchmail 6.4.X releases have been made with a focus on unchanged user and
program interfaces so as to avoid disruptions when upgrading from 6.3.Z or
6.4.X to 6.4.Y with Y > X.  Care was taken to not change the interface
incompatibly.


A. Copyright, License and Non-Warranty
======================================

(C) Copyright 2021 by Matthias Andree, <matthias.andree@gmx.de>.
Some rights reserved.

fetchmail-SA-2021-01 © 2021 by Matthias Andree is licensed under CC
BY-ND 4.0. To view a copy of this license, visit
http://creativecommons.org/licenses/by-nd/4.0/

THIS WORK IS PROVIDED FREE OF CHARGE AND WITHOUT ANY WARRANTIES.
Use the information herein at your own risk.

END of fetchmail-SA-2021-01
-----BEGIN PGP SIGNATURE-----

iQIzBAEBCgAdFiEE3EplW9mTzUhx+oIQ5BKxVu/zhVoFAmERUo4ACgkQ5BKxVu/z
hVrq4RAAnvtDbwEvjSEWFVvmZTG7qcrOxAs1SCb+dp33PKy8EPfzE3vjCHEsrwRv
XjX6dKWK61wG7+7kGUyeNlBXASWso2BSR9TypRVi2PXK5aKUgSi0qs0eGpR11jnx
QN9b96rklFb6odJVua/PwWKUG6vBILX1o8DgvoMX4B5S7LipgD/gecuqQyD0t0l5
TSyJZRaU763B7c4sZjuEwXtfqA49AbBSICq7qAbOa5R695ZelDvFgV3HHCoJIZqN
W2gMtsfCDboyViDf5jHllnbUmAl4bPCHOOcC53zfsESL37/pNYxgAsY2RHyWyhbU
yqVNH/0XTA5UxjN3i81mPbIo0oPI1Yejsbk+V73bI8hBaDtwqZ3BtU/gRYN5ODQi
w2DokSJ5cju7mDX4Ua05ee5n7U3291SJIc/XiMRDh2FauRM1JF2TeLwtgN0iwLM/
OxZZSjtLrb/X2noBa3jRbJ5sho94mw/suW5jyuVAxKZzJCzgp45f7AeuqtvzYi1X
0TWLwQCEjoPBAySpdi36AZmJfiY2gfFgVSXlE5Piekg4n/QRRn+Qt9227WKJKkH2
IwTqDIBkvjHXMnmNZTHLf28kKesF0BfYMpo9kDn+Cg4Gln4r0T4zRBB8HwljWfnx
j/4EAI+Nl9NpZ+xZFJe3YBJeOsXpSc+MAqK6tNWK4sKDCzHtnVU=
=NnPX
-----END PGP SIGNATURE-----
