daandemeyer / rpms / systemd

Forked from rpms/systemd 2 years ago
Clone
4bff0a
From 3d0342f0c47c293f10d417ba429ff50436d30ddb Mon Sep 17 00:00:00 2001
4bff0a
From: Evgeny Vereshchagin <evvers@ya.ru>
4bff0a
Date: Tue, 3 Jul 2018 03:25:53 +0000
4bff0a
Subject: [PATCH] tests: add a wrapper for when systemd is built with ASAN
4bff0a
4bff0a
(cherry picked from commit 1786fae3668fa94359ee58a8c11031dc46459255)
4bff0a
---
4bff0a
 test/test-functions | 35 ++++++++++++++++++++++++++++++++++-
4bff0a
 1 file changed, 34 insertions(+), 1 deletion(-)
4bff0a
4bff0a
diff --git a/test/test-functions b/test/test-functions
4bff0a
index 4417301be9..a6f88e4545 100644
4bff0a
--- a/test/test-functions
4bff0a
+++ b/test/test-functions
4bff0a
@@ -21,7 +21,7 @@ if ! ROOTLIBDIR=$(pkg-config --variable=systemdutildir systemd); then
4bff0a
     ROOTLIBDIR=/usr/lib/systemd
4bff0a
 fi
4bff0a
 
4bff0a
-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"
4bff0a
+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"
4bff0a
 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"
4bff0a
 
4bff0a
 STATEDIR="${BUILD_DIR:-.}/test/$(basename $(dirname $(realpath $0)))"
4bff0a
@@ -317,6 +317,39 @@ EOF
4bff0a
     chmod 0755 $_valgrind_wrapper
4bff0a
 }
4bff0a
 
4bff0a
+create_asan_wrapper() {
4bff0a
+    local _asan_wrapper=$initdir/$ROOTLIBDIR/systemd-under-asan
4bff0a
+    ddebug "Create $_asan_wrapper"
4bff0a
+    cat >$_asan_wrapper <
4bff0a
+#!/bin/bash
4bff0a
+
4bff0a
+set -x
4bff0a
+
4bff0a
+DEFAULT_ASAN_OPTIONS=strict_string_checks=1:detect_stack_use_after_return=1:check_initialization_order=1:strict_init_order=1
4bff0a
+DEFAULT_ENVIRONMENT=ASAN_OPTIONS=\$DEFAULT_ASAN_OPTIONS
4bff0a
+
4bff0a
+mount -t proc proc /proc
4bff0a
+mount -t sysfs sysfs /sys
4bff0a
+mount -o remount,rw /
4bff0a
+
4bff0a
+PATH_TO_ASAN=\$(find / -name '*libasan*' | sed 1q)
4bff0a
+if [[ "\$PATH_TO_ASAN" ]]; then
4bff0a
+  # A lot of services (most notably dbus) won't start without preloading libasan
4bff0a
+  # See https://github.com/systemd/systemd/issues/5004
4bff0a
+  DEFAULT_ENVIRONMENT="\$DEFAULT_ENVIRONMENT LD_PRELOAD=\$PATH_TO_ASAN"
4bff0a
+fi
4bff0a
+echo DefaultEnvironment=\$DEFAULT_ENVIRONMENT >>/etc/systemd/system.conf
4bff0a
+
4bff0a
+# ASAN and syscall filters aren't compatible with each other.
4bff0a
+find / -name '*.service' -type f | xargs sed -i 's/^\\(MemoryDeny\\|SystemCall\\)/#\\1/'
4bff0a
+
4bff0a
+export ASAN_OPTIONS=\$DEFAULT_ASAN_OPTIONS:log_path=/systemd.asan.log
4bff0a
+exec  $ROOTLIBDIR/systemd "\$@"
4bff0a
+EOF
4bff0a
+
4bff0a
+    chmod 0755 $_asan_wrapper
4bff0a
+}
4bff0a
+
4bff0a
 create_strace_wrapper() {
4bff0a
     local _strace_wrapper=$initdir/$ROOTLIBDIR/systemd-under-strace
4bff0a
     ddebug "Create $_strace_wrapper"