From 6258394c1e32e2e730c7e406578b22df25f0588a Mon Sep 17 00:00:00 2001 From: Frantisek Sumsal Date: Wed, 28 Sep 2022 17:01:55 +0200 Subject: [PATCH] test: wrap `ls` and `stat` to make it work w/ sanitizers in specific cases When `/etc/nsswitch.conf` uses `systemd` together with `[SUCCESS=merge]`, `ls -l` will pull in `libnss_systemd` causing `SIGABRT`, as `ls` is not instrumented (by default): ``` -bash-5.1# strace -f -e %file ls -l /dev execve("/usr/bin/ls", ["ls", "-l", "/dev"], 0x7ffc3bb211c8 /* 24 vars*/) = 0 ... openat(AT_FDCWD, "/etc/passwd", O_RDONLY|O_CLOEXEC) = 3 newfstatat(3, "", {st_mode=S_IFREG|0644, st_size=1896, ...}, AT_EMPTY_PATH) = 0 newfstatat(AT_FDCWD, "/etc/nsswitch.conf", {st_mode=S_IFREG|0644, st_size=359, ...}, 0) = 0 openat(AT_FDCWD, "/etc/group", O_RDONLY|O_CLOEXEC) = 3 newfstatat(3, "", {st_mode=S_IFREG|0644, st_size=965, ...}, AT_EMPTY_PATH) = 0 openat(AT_FDCWD, "/etc/ld.so.cache", O_RDONLY|O_CLOEXEC) = 3 newfstatat(3, "", {st_mode=S_IFREG|0644, st_size=10779, ...}, AT_EMPTY_PATH) = 0 openat(AT_FDCWD, "/usr/lib/libnss_systemd.so.2", O_RDONLY|O_CLOEXEC) = 3 newfstatat(3, "", {st_mode=S_IFREG|0755, st_size=16195176, ...}, AT_EMPTY_PATH) = 0 openat(AT_FDCWD, "/usr/lib/libasan.so.8", O_RDONLY|O_CLOEXEC) = 3 ... readlink("/proc/self/exe", "/usr/bin/ls", 4096) = 11 open("/proc/self/cmdline", O_RDONLY) = 3 open("/proc/self/environ", O_RDONLY) = 3 ==620==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. --- SIGABRT {si_signo=SIGABRT, si_code=SI_TKILL, si_pid=620, si_uid=0} --- +++ killed by SIGABRT (core dumped) +++ Aborted (core dumped) ``` This also happens with `stat`. Let's add both `ls` and `stat` to the "wrap list" to work around this. Spotted on Arch Linux. (cherry picked from commit 5ad15138458b4f2957bd9d2bc2c8e3c9afe99337) --- test/test-functions | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/test/test-functions b/test/test-functions index 4fe416be88..0b8d41b48d 100644 --- a/test/test-functions +++ b/test/test-functions @@ -2467,8 +2467,10 @@ inst_binary() { # Same as above, but we need to wrap certain libraries unconditionally # # getent, login, su, useradd, userdel - dlopen()s (not only) systemd's PAM modules + # ls, stat - pulls in nss_systemd with certain options (like ls -l) when + # nsswitch.conf uses [SUCCESS=merge] (like on Arch Linux) # tar - called by machinectl in TEST-25 - if get_bool "$IS_BUILT_WITH_ASAN" && [[ "$bin" =~ /(getent|login|su|tar|useradd|userdel)$ ]]; then + if get_bool "$IS_BUILT_WITH_ASAN" && [[ "$bin" =~ /(getent|login|ls|stat|su|tar|useradd|userdel)$ ]]; then wrap_binary=1 fi