From 93e9a18fbf09deb59bd133986f4c89aeb2d2d86a Mon Sep 17 00:00:00 2001
From: Qualys Security Advisory <email address hidden>
Date: Tue, 23 Feb 2021 08:33:03 -0800
Subject: [PATCH 51/57] CVE-2020-28007: Link attack in Exim's log directory
We patch this vulnerability by opening (instead of just creating) the
log file in an unprivileged (exim) child process, and by passing this
file descriptor back to the privileged (root) parent process. The two
functions log_send_fd() and log_recv_fd() are inspired by OpenSSH's
functions mm_send_fd() and mm_receive_fd(); thanks!
This patch also fixes:
- a NULL-pointer dereference in usr1_handler() (this signal handler is
installed before process_log_path is initialized);
- a file-descriptor leak in dmarc_write_history_file() (two return paths
did not close history_file_fd).
Note: the use of log_open_as_exim() in dmarc_write_history_file() should
be fine because the documentation explicitly states "Make sure the
directory of this file is writable by the user exim runs as."
and also:
apt install libopendmarc-dev libspf2-dev
Custom builds are actually supposed to be supported by editing special files,
README.Debian.html says:
"Additionally, the source package offers infrastructure to build your own custom-tailored exim4-daemon-custom which exactly fits your special local needs. The infrastructure to do so is already in place, see debian/rules for instructions. "
Unfortunately, anyone doing that to enable dmarc will have a failing build.
Trisquel enables dmarc in its build, and also failed its build when pulling the update.
Here is the end of the build output which shows the failure:
gcc dmarc.c
gcc -c -g -O2 -D_LARGEFILE_SOURCE -fno-strict-aliasing -Wall -I/usr/local/include -I/usr/local/include -fvisibility=hidden -I. dmarc.c
dmarc.c: In function 'dmarc_send_forensic_report':
dmarc.c:166:47: warning: suggest parentheses around '&&' within '||' [-Wparentheses]
if ( dmarc_policy == DMARC_POLICY_REJECT && action == DMARC_RESULT_REJECT
dmarc.c:168:47: warning: suggest parentheses around '&&' within '||' [-Wparentheses]
|| dmarc_policy == DMARC_POLICY_NONE && action == DMARC_RESULT_REJECT
dmarc.c:169:47: warning: suggest parentheses around '&&' within '||' [-Wparentheses]
|| dmarc_policy == DMARC_POLICY_NONE && action == DMARC_RESULT_QUARANTINE
dmarc.c: At top level:
dmarc.c:211:1: error: static declaration of 'dmarc_write_history_file' follows non-static declaration
dmarc_write_history_file()
^~~~~~~~~~~~~~~~~~~~~~~~
In file included from dmarc.c:22:0:
dmarc.h:26:5: note: previous declaration of 'dmarc_write_history_file' was here
int dmarc_write_history_file();
^~~~~~~~~~~~~~~~~~~~~~~~
dmarc.c: In function 'dmarc_write_history_file':
dmarc.c:265:25: error: 'f' undeclared (first use in this function) (host_checking || f.running_in_test_harness) ? " (not really)" : ""); ^
dmarc.c:265:25: note: each undeclared identifier is reported only once for each function it appears in
Makefile:811: recipe for target 'dmarc.o' failed
make[3]: *** [dmarc.o] Error 1
make[3]: Leaving directory '/nocow/t/bionic-exim/exim4-4.90.1/b-exim4-daemon-heavy/build-Linux-x86_64'
Makefile:35: recipe for target 'all' failed
make[2]: *** [all] Error 2
make[2]: Leaving directory '/nocow/t/bionic-exim/exim4-4.90.1/b-exim4-daemon-heavy'
debian/rules:111: recipe for target 'override_dh_auto_build' failed
make[1]: *** [override_dh_auto_build] Error 2
make[1]: Leaving directory '/nocow/t/bionic-exim/exim4-4.90.1'
debian/rules:293: recipe for target 'build' failed
make: *** [build] Error 2
dpkg-buildpackage: error: debian/rules build subprocess returned exit status 2
debuild: fatal error at line 1152:
dpkg-buildpackage -rfakeroot -us -uc -ui -b failed
./debian/ patches/ sec-202105/ 0051-CVE- 2020-28007- Link-attack- in-Exim- s-log-directory .patch
Backport of:
From 93e9a18fbf09deb 59bd133986f4c89 aeb2d2d86a Mon Sep 17 00:00:00 2001
From: Qualys Security Advisory <email address hidden>
Date: Tue, 23 Feb 2021 08:33:03 -0800
Subject: [PATCH 51/57] CVE-2020-28007: Link attack in Exim's log directory
We patch this vulnerability by opening (instead of just creating) the
log file in an unprivileged (exim) child process, and by passing this
file descriptor back to the privileged (root) parent process. The two
functions log_send_fd() and log_recv_fd() are inspired by OpenSSH's
functions mm_send_fd() and mm_receive_fd(); thanks!
This patch also fixes:
- a NULL-pointer dereference in usr1_handler() (this signal handler is
installed before process_log_path is initialized);
- a file-descriptor leak in dmarc_write_ history_ file() (two return paths
did not close history_file_fd).
Note: the use of log_open_as_exim() in dmarc_write_ history_ file() should
be fine because the documentation explicitly states "Make sure the
directory of this file is writable by the user exim runs as."
(cherry picked from commit 2502cc41d1d92c1 413eca6a4ba035c 21162662bd) +++++++ ++++--- ------- ------- - functions. h | 3 +- +++++++ +++++++ +++++++ ------- ------- --
---
src/src/dmarc.c | 179 +++++++
src/src/exim.c | 14 +--
src/src/
src/src/log.c | 214 +++++++
test/stderr/0397 | 6 +-
5 files changed, 234 insertions(+), 182 deletions(-)
dmarc.c is not used in the default build configuration, but the patch
is broken and causes a failed build when it is enabled.
An easy way to test this is to download the source package, edit
the source file src/EDITME:
-# EXPERIMENTAL_ SPF=yes local/include SPF=yes local/include
-# CFLAGS += -I/usr/
-# LDFLAGS += -lspf2
+EXPERIMENTAL_
+CFLAGS += -I/usr/
+LDFLAGS += -lspf2
-# EXPERIMENTAL_ DMARC=yes opendmarc. tlds local/include DMARC=yes opendmarc. tlds local/include
-# DMARC_TLD_FILE= /etc/exim/
-# CFLAGS += -I/usr/
-# LDFLAGS += -lopendmarc
+EXPERIMENTAL_
+DMARC_TLD_FILE= /etc/exim4/
+CFLAGS += -I/usr/
+LDFLAGS += -lopendmarc
and also:
apt install libopendmarc-dev libspf2-dev
Custom builds are actually supposed to be supported by editing special files,
README.Debian.html says:
"Additionally, the source package offers infrastructure to build your own custom-tailored exim4-daemon-custom which exactly fits your special local needs. The infrastructure to do so is already in place, see debian/rules for instructions. "
Unfortunately, anyone doing that to enable dmarc will have a failing build.
Trisquel enables dmarc in its build, and also failed its build when pulling the update.
Here is the end of the build output which shows the failure:
gcc dmarc.c aliasing -Wall -I/usr/ local/include -I/usr/ local/include -fvisibility=hidden -I. dmarc.c send_forensic_ report' : QUARANTINE write_history_ file' follows non-static declaration write_history_ file() ~~~~~~~ ~~~~~~~ ~~~~ write_history_ file' was here history_ file(); ~~~~~~~ ~~~~~~~ ~~~~~~~ ~ write_history_ file':
(host_checking || f.running_ in_test_ harness) ? " (not really)" : "");
^ t/bionic- exim/exim4- 4.90.1/ b-exim4- daemon- heavy/build- Linux-x86_ 64' t/bionic- exim/exim4- 4.90.1/ b-exim4- daemon- heavy' dh_auto_ build' failed dh_auto_ build] Error 2 t/bionic- exim/exim4- 4.90.1'
gcc -c -g -O2 -D_LARGEFILE_SOURCE -fno-strict-
dmarc.c: In function 'dmarc_
dmarc.c:166:47: warning: suggest parentheses around '&&' within '||' [-Wparentheses]
if ( dmarc_policy == DMARC_POLICY_REJECT && action == DMARC_RESULT_REJECT
dmarc.c:168:47: warning: suggest parentheses around '&&' within '||' [-Wparentheses]
|| dmarc_policy == DMARC_POLICY_NONE && action == DMARC_RESULT_REJECT
dmarc.c:169:47: warning: suggest parentheses around '&&' within '||' [-Wparentheses]
|| dmarc_policy == DMARC_POLICY_NONE && action == DMARC_RESULT_
dmarc.c: At top level:
dmarc.c:211:1: error: static declaration of 'dmarc_
dmarc_
^~~~~~
In file included from dmarc.c:22:0:
dmarc.h:26:5: note: previous declaration of 'dmarc_
int dmarc_write_
^~
dmarc.c: In function 'dmarc_
dmarc.c:265:25: error: 'f' undeclared (first use in this function)
dmarc.c:265:25: note: each undeclared identifier is reported only once for each function it appears in
Makefile:811: recipe for target 'dmarc.o' failed
make[3]: *** [dmarc.o] Error 1
make[3]: Leaving directory '/nocow/
Makefile:35: recipe for target 'all' failed
make[2]: *** [all] Error 2
make[2]: Leaving directory '/nocow/
debian/rules:111: recipe for target 'override_
make[1]: *** [override_
make[1]: Leaving directory '/nocow/
debian/rules:293: recipe for target 'build' failed
make: *** [build] Error 2
dpkg-buildpackage: error: debian/rules build subprocess returned exit status 2
debuild: fatal error at line 1152:
dpkg-buildpackage -rfakeroot -us -uc -ui -b failed