Skip to content

Commit 88c98cb

Browse files
committed
test: make sure we get PID1's stack trace on ASan/UBSan errors
As hitting an ASan/UBSan error in PID1 results in a crash (and a kernel panic when running under qemu), we usually lose the stack trace which makes debugging quite painful. Let's mitigate this by forwarding the stack trace to multiple places - namely to a file and the syslog.
1 parent da3cd87 commit 88c98cb

File tree

1 file changed

+18
-9
lines changed

1 file changed

+18
-9
lines changed

test/test-functions

+18-9
Original file line numberDiff line numberDiff line change
@@ -914,7 +914,7 @@ EOF
914914
}
915915

916916
create_asan_wrapper() {
917-
local asan_wrapper default_asan_options default_ubsan_options default_environment
917+
local asan_wrapper default_asan_options default_ubsan_options default_environment manager_environment
918918

919919
[[ -z "$ASAN_RT_PATH" ]] && dfatal "ASAN_RT_PATH is empty, but it shouldn't be"
920920

@@ -948,12 +948,17 @@ EOF
948948
"UBSAN_OPTIONS='$default_ubsan_options'"
949949
"ASAN_RT_PATH='$ASAN_RT_PATH'"
950950
)
951+
manager_environment=(
952+
"ASAN_OPTIONS='$default_asan_options:log_path=/systemd-pid1.asan.log:log_to_syslog=1'"
953+
"UBSAN_OPTIONS='$default_ubsan_options:log_path=/systemd-pid1.ubsan.log:log_to_syslog=1'"
954+
"ASAN_RT_PATH='$ASAN_RT_PATH'"
955+
)
951956

952957
mkdir -p "${initdir:?}/etc/systemd/system.conf.d/"
953958
cat >"${initdir:?}/etc/systemd/system.conf.d/asan.conf" <<EOF
954959
[Manager]
955960
DefaultEnvironment=${default_environment[*]}
956-
ManagerEnvironment=${default_environment[*]}
961+
ManagerEnvironment=${manager_environment[*]}
957962
DefaultTimeoutStartSec=180s
958963
DefaultStandardOutput=journal+console
959964
EOF
@@ -1002,7 +1007,7 @@ EOF
10021007
set -eux
10031008
10041009
export PATH="/sbin:/bin:/usr/sbin:/usr/bin"
1005-
export ${default_environment[@]}
1010+
export ${manager_environment[@]}
10061011
[[ -n "\$ASAN_OPTIONS" && -n "\$UBSAN_OPTIONS" ]]
10071012
10081013
exec "$ROOTLIBDIR/systemd" "\$@"
@@ -1534,6 +1539,7 @@ create_empty_image_rootdir() {
15341539
check_asan_reports() {
15351540
local ret=0
15361541
local root="${1:?}"
1542+
local log report
15371543

15381544
if get_bool "$IS_BUILT_WITH_ASAN"; then
15391545
ls -l "$root"
@@ -1542,12 +1548,15 @@ check_asan_reports() {
15421548
ret=$((ret+1))
15431549
fi
15441550

1545-
journald_report="$(find "$root" -name "systemd-journald.*san.log*" -exec cat {} \;)"
1546-
if [[ -n "$journald_report" ]]; then
1547-
printf "%s\n" "$journald_report"
1548-
cat "$root/systemd-journald.out" || :
1549-
ret=$((ret+1))
1550-
fi
1551+
for log in pid1 journald; do
1552+
report="$(find "$root" -name "systemd-$log.*san.log*" -exec cat {} \;)"
1553+
if [[ -n "$report" ]]; then
1554+
printf "%s\n" "$report"
1555+
# shellcheck disable=SC2015
1556+
[[ "$log" == journald ]] && cat "$root/systemd-journald.out" || :
1557+
ret=$((ret+1))
1558+
fi
1559+
done
15511560

15521561
# May 08 13:23:31 H testleak[2907148]: SUMMARY: AddressSanitizer: 4 byte(s) leaked in 1 allocation(s).
15531562
pids="$(

0 commit comments

Comments
 (0)