From 9f6235e1b4490ce7abbd125ed975343de6bcb9cd Mon Sep 17 00:00:00 2001 From: Frantisek Sumsal Date: Sat, 6 Mar 2021 22:22:32 +0100 Subject: [PATCH] test: fix TEST-50-DISSECT under sanitizers This test would normally get stuck when trying to mount the verity image due to: systemd-udevd[299]: dm-0: '/usr/sbin/dmsetup udevflags 6293812'(err) '==371==ASan runtime does not come first in initial library list; you should either link runtime to your application or manually preload it with LD_PRELOAD.' systemd-udevd[299]: dm-0: Process '/usr/sbin/dmsetup udevflags 6293812' failed with exit code 1 ... systemd-udevd[299]: dm-0: '/usr/sbin/dmsetup udevcomplete 6293812'(err) '==372==ASan runtime does not come first in initial library list; you should either link runtime to your application or manually preload it with LD_PRELOAD.' systemd-udevd[299]: dm-0: Process '/usr/sbin/dmsetup udevcomplete 6293812' failed with exit code 1. systemd-udevd[299]: dm-0: Command "/usr/sbin/dmsetup udevcomplete 6293812" returned 1 (error), ignoring. so let's add a simple udev rule which sets $LD_PRELOAD for the block subsystem. Also, install the ASan library along with necessary dependencies into the verity minimal image, to get rid of the annoying (yet harmless) errors about missing library from $LD_LIBRARY. --- test/test-functions | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/test/test-functions b/test/test-functions index 5796c6d9387..54f884cdec7 100644 --- a/test/test-functions +++ b/test/test-functions @@ -492,6 +492,13 @@ install_verity_minimal() { mkdir -p $initdir/usr/lib/systemd/system $initdir/usr/lib/extension-release.d $initdir/etc $initdir/var/tmp $initdir/opt setup_basic_dirs install_basic_tools + if [[ -v ASAN_RT_PATH ]]; then + # If we're compiled with ASan, install the ASan RT (and its dependencies) + # into the verity images to get rid of the annoying errors about + # missing $LD_PRELOAD libraries. + inst_libs "$ASAN_RT_PATH" + inst_library "$ASAN_RT_PATH" + fi cp $os_release $initdir/usr/lib/os-release ln -s ../usr/lib/os-release $initdir/etc/os-release touch $initdir/etc/machine-id $initdir/etc/resolv.conf @@ -730,6 +737,14 @@ printf "[Service]\nTimeoutSec=180s\n" >/etc/systemd/system/systemd-journal-flush mkdir -p /etc/systemd/system/dbus.service.d printf "[Service]\nEnvironment=ASAN_OPTIONS=leak_check_at_exit=false\n" >/etc/systemd/system/dbus.service.d/disable-lsan.conf +# Some utilities run via IMPORT/RUN/PROGRAM udev directives fail because +# they're uninstrumented (like dmsetup). Let's add a simple rule which sets +# LD_PRELOAD to the ASan RT library to fix this. +mkdir -p /etc/udev/rules.d +cat > /etc/udev/rules.d/00-set-LD_PRELOAD.rules << INNER_EOF +SUBSYSTEM=="block", ENV{LD_PRELOAD}="$ASAN_RT_PATH" +INNER_EOF + # The 'mount' utility doesn't behave well under libasan, causing unexpected # fails during boot and subsequent test results check: # bash-5.0# mount -o remount,rw -v /