8d419f
From 137a22e0192941fa275b70665af7a0d54f6ad614 Mon Sep 17 00:00:00 2001
8d419f
From: Frantisek Sumsal <frantisek@sumsal.cz>
8d419f
Date: Wed, 15 Jun 2022 12:32:51 +0200
8d419f
Subject: [PATCH] test: drop all LD_PRELOAD-related ASan workarounds
8d419f
8d419f
since they shouldn't be necessary anymore, as we tweak the "problematic"
8d419f
binaries on per-binary basis.
8d419f
8d419f
(cherry picked from commit fa65ba6baac8c9241cf30802bb5fd3698d1f3189)
8d419f
8d419f
Related: #2087652
8d419f
---
8d419f
 test/test-functions | 54 +--------------------------------------------
8d419f
 1 file changed, 1 insertion(+), 53 deletions(-)
8d419f
8d419f
diff --git a/test/test-functions b/test/test-functions
8d419f
index a9ff561083..f55e64493d 100644
8d419f
--- a/test/test-functions
8d419f
+++ b/test/test-functions
8d419f
@@ -593,10 +593,6 @@ install_verity_minimal() {
8d419f
             # missing $LD_PRELOAD libraries.
8d419f
             inst_libs "$ASAN_RT_PATH"
8d419f
             inst_library "$ASAN_RT_PATH"
8d419f
-            # Create a dummy LSan suppression file otherwise gcc's ASan
8d419f
-            # complains as it doesn't exist in the minimal image
8d419f
-            # (i.e. when running TEST-29 or TEST-50 under sanitizers)
8d419f
-            touch "$initdir/systemd-lsan.supp"
8d419f
         fi
8d419f
         cp "$os_release" "$initdir/usr/lib/os-release"
8d419f
         ln -s ../usr/lib/os-release "$initdir/etc/os-release"
8d419f
@@ -792,20 +788,6 @@ if [[ ! -e "$ASAN_RT_PATH" ]]; then
8d419f
     exit 1
8d419f
 fi
8d419f
 
8d419f
-# Suppress certain leaks reported by LSan (either in external tools or bogus
8d419f
-# ones)
8d419f
-# Docs: # https://github.com/google/sanitizers/wiki/AddressSanitizerLeakSanitizer#suppressions
8d419f
-#
8d419f
-# - fsck is called by systemd-homed and is reporting a leak we're not interested
8d419f
-#   in
8d419f
-# - libLLVM is a "side effect" caused by the previous fsck leak
8d419f
-cat >/systemd-lsan.supp <
8d419f
-leak:/bin/fsck$
8d419f
-leak:/sbin/fsck$
8d419f
-leak:/lib/libLLVM
8d419f
-INNER_EOF
8d419f
-
8d419f
-DEFAULT_LSAN_OPTIONS=${LSAN_OPTIONS:-}:suppressions=/systemd-lsan.supp
8d419f
 DEFAULT_ASAN_OPTIONS=${ASAN_OPTIONS:-strict_string_checks=1:detect_stack_use_after_return=1:check_initialization_order=1:strict_init_order=1}
8d419f
 DEFAULT_UBSAN_OPTIONS=${UBSAN_OPTIONS:-print_stacktrace=1:print_summary=1:halt_on_error=1}
8d419f
 DEFAULT_ENVIRONMENT="ASAN_OPTIONS=\$DEFAULT_ASAN_OPTIONS UBSAN_OPTIONS=\$DEFAULT_UBSAN_OPTIONS LSAN_OPTIONS=\$DEFAULT_LSAN_OPTIONS"
8d419f
@@ -818,9 +800,7 @@ mount -t proc proc /proc
8d419f
 mount -t sysfs sysfs /sys
8d419f
 mount -o remount,rw /
8d419f
 
8d419f
-# A lot of services (most notably dbus) won't start without preloading libasan
8d419f
-# See https://github.com/systemd/systemd/issues/5004
8d419f
-DEFAULT_ENVIRONMENT="\$DEFAULT_ENVIRONMENT LD_PRELOAD=$ASAN_RT_PATH ASAN_RT_PATH=$ASAN_RT_PATH"
8d419f
+DEFAULT_ENVIRONMENT="\$DEFAULT_ENVIRONMENT ASAN_RT_PATH=$ASAN_RT_PATH"
8d419f
 
8d419f
 if [[ "$ASAN_COMPILER" == "clang" ]]; then
8d419f
   # Let's add the ASan DSO's path to the dynamic linker's cache. This is pretty
8d419f
@@ -857,38 +837,6 @@ printf "[Unit]\nConditionVirtualization=container\n\n[Service]\nTimeoutSec=240s\
8d419f
 mkdir -p /etc/systemd/system/systemd-journal-flush.service.d
8d419f
 printf "[Service]\nTimeoutSec=180s\n" >/etc/systemd/system/systemd-journal-flush.service.d/timeout.conf
8d419f
 
8d419f
-# D-Bus has troubles during system shutdown causing it to fail. Although it's
8d419f
-# harmless, it causes unnecessary noise in the logs, so let's disable LSan's
8d419f
-# at_exit check just for the dbus.service
8d419f
-mkdir -p /etc/systemd/system/dbus.service.d
8d419f
-printf "[Service]\nEnvironment=ASAN_OPTIONS=leak_check_at_exit=false\n" >/etc/systemd/system/dbus.service.d/disable-lsan.conf
8d419f
-
8d419f
-# Some utilities run via IMPORT/RUN/PROGRAM udev directives fail because
8d419f
-# they're uninstrumented (like dmsetup). Let's add a simple rule which sets
8d419f
-# LD_PRELOAD to the ASan RT library to fix this.
8d419f
-mkdir -p /etc/udev/rules.d
8d419f
-cat >/etc/udev/rules.d/00-set-LD_PRELOAD.rules <
8d419f
-SUBSYSTEM=="block", ENV{LD_PRELOAD}="$ASAN_RT_PATH"
8d419f
-INNER_EOF
8d419f
-chmod 0644 /etc/udev/rules.d/00-set-LD_PRELOAD.rules
8d419f
-
8d419f
-# The 'mount' utility doesn't behave well under libasan, causing unexpected
8d419f
-# fails during boot and subsequent test results check:
8d419f
-# bash-5.0# mount -o remount,rw -v /
8d419f
-# mount: /dev/sda1 mounted on /.
8d419f
-# bash-5.0# echo \$?
8d419f
-# 1
8d419f
-# Let's workaround this by clearing the previously set LD_PRELOAD env variable,
8d419f
-# so the libasan library is not loaded for this particular service
8d419f
-unset_ld_preload() {
8d419f
-    local _dropin_dir="/etc/systemd/system/\$1.service.d"
8d419f
-    mkdir -p "\$_dropin_dir"
8d419f
-    printf "[Service]\nUnsetEnvironment=LD_PRELOAD\n" >"\$_dropin_dir/unset_ld_preload.conf"
8d419f
-}
8d419f
-
8d419f
-unset_ld_preload systemd-remount-fs
8d419f
-unset_ld_preload testsuite-
8d419f
-
8d419f
 export ASAN_OPTIONS=\$DEFAULT_ASAN_OPTIONS:log_path=/systemd.asan.log UBSAN_OPTIONS=\$DEFAULT_UBSAN_OPTIONS
8d419f
 exec "$ROOTLIBDIR/systemd" "\$@"
8d419f
 EOF