naccyde / rpms / systemd

Forked from rpms/systemd a year ago
Clone
ff6046
From 3d0342f0c47c293f10d417ba429ff50436d30ddb Mon Sep 17 00:00:00 2001
ff6046
From: Evgeny Vereshchagin <evvers@ya.ru>
ff6046
Date: Tue, 3 Jul 2018 03:25:53 +0000
ff6046
Subject: [PATCH] tests: add a wrapper for when systemd is built with ASAN
ff6046
ff6046
(cherry picked from commit 1786fae3668fa94359ee58a8c11031dc46459255)
ff6046
---
ff6046
 test/test-functions | 35 ++++++++++++++++++++++++++++++++++-
ff6046
 1 file changed, 34 insertions(+), 1 deletion(-)
ff6046
ff6046
diff --git a/test/test-functions b/test/test-functions
ff6046
index 4417301be9..a6f88e4545 100644
ff6046
--- a/test/test-functions
ff6046
+++ b/test/test-functions
ff6046
@@ -21,7 +21,7 @@ if ! ROOTLIBDIR=$(pkg-config --variable=systemdutildir systemd); then
ff6046
     ROOTLIBDIR=/usr/lib/systemd
ff6046
 fi
ff6046
 
ff6046
-BASICTOOLS="test sh bash setsid loadkeys setfont login sulogin gzip sleep echo mount umount cryptsetup date dmsetup modprobe sed cmp tee rm true false chmod chown ln"
ff6046
+BASICTOOLS="test sh bash setsid loadkeys setfont login sulogin gzip sleep echo mount umount cryptsetup date dmsetup modprobe sed cmp tee rm true false chmod chown ln xargs"
ff6046
 DEBUGTOOLS="df free ls stty cat ps ln ip route dmesg dhclient mkdir cp ping dhclient strace less grep id tty touch du sort hostname find"
ff6046
 
ff6046
 STATEDIR="${BUILD_DIR:-.}/test/$(basename $(dirname $(realpath $0)))"
ff6046
@@ -317,6 +317,39 @@ EOF
ff6046
     chmod 0755 $_valgrind_wrapper
ff6046
 }
ff6046
 
ff6046
+create_asan_wrapper() {
ff6046
+    local _asan_wrapper=$initdir/$ROOTLIBDIR/systemd-under-asan
ff6046
+    ddebug "Create $_asan_wrapper"
ff6046
+    cat >$_asan_wrapper <
ff6046
+#!/bin/bash
ff6046
+
ff6046
+set -x
ff6046
+
ff6046
+DEFAULT_ASAN_OPTIONS=strict_string_checks=1:detect_stack_use_after_return=1:check_initialization_order=1:strict_init_order=1
ff6046
+DEFAULT_ENVIRONMENT=ASAN_OPTIONS=\$DEFAULT_ASAN_OPTIONS
ff6046
+
ff6046
+mount -t proc proc /proc
ff6046
+mount -t sysfs sysfs /sys
ff6046
+mount -o remount,rw /
ff6046
+
ff6046
+PATH_TO_ASAN=\$(find / -name '*libasan*' | sed 1q)
ff6046
+if [[ "\$PATH_TO_ASAN" ]]; then
ff6046
+  # A lot of services (most notably dbus) won't start without preloading libasan
ff6046
+  # See https://github.com/systemd/systemd/issues/5004
ff6046
+  DEFAULT_ENVIRONMENT="\$DEFAULT_ENVIRONMENT LD_PRELOAD=\$PATH_TO_ASAN"
ff6046
+fi
ff6046
+echo DefaultEnvironment=\$DEFAULT_ENVIRONMENT >>/etc/systemd/system.conf
ff6046
+
ff6046
+# ASAN and syscall filters aren't compatible with each other.
ff6046
+find / -name '*.service' -type f | xargs sed -i 's/^\\(MemoryDeny\\|SystemCall\\)/#\\1/'
ff6046
+
ff6046
+export ASAN_OPTIONS=\$DEFAULT_ASAN_OPTIONS:log_path=/systemd.asan.log
ff6046
+exec  $ROOTLIBDIR/systemd "\$@"
ff6046
+EOF
ff6046
+
ff6046
+    chmod 0755 $_asan_wrapper
ff6046
+}
ff6046
+
ff6046
 create_strace_wrapper() {
ff6046
     local _strace_wrapper=$initdir/$ROOTLIBDIR/systemd-under-strace
ff6046
     ddebug "Create $_strace_wrapper"