Merge pull request #11252 from evverx/use-asan-wrapper-on-travis-ci
travis: run PID1, journald and everything else under ASan+UBsan
This commit is contained in:
@@ -3,7 +3,7 @@
|
||||
# ex: ts=8 sw=4 sts=4 et filetype=sh
|
||||
set -e
|
||||
TEST_DESCRIPTION="Basic systemd setup"
|
||||
RUN_IN_UNPRIVILEGED_CONTAINER=yes
|
||||
RUN_IN_UNPRIVILEGED_CONTAINER=${RUN_IN_UNPRIVILEGED_CONTAINER:-yes}
|
||||
|
||||
. $TEST_BASE_DIR/test-functions
|
||||
|
||||
@@ -26,7 +26,7 @@ Description=Testsuite service
|
||||
After=multi-user.target
|
||||
|
||||
[Service]
|
||||
ExecStart=/bin/sh -x -c 'systemctl --state=failed --no-legend --no-pager > /failed ; echo OK > /testok'
|
||||
ExecStart=/bin/sh -x -c 'systemctl --state=failed --no-legend --no-pager > /failed ; systemctl daemon-reload ; echo OK > /testok'
|
||||
Type=oneshot
|
||||
EOF
|
||||
|
||||
|
||||
+40
-1
@@ -37,7 +37,7 @@ is_built_with_asan() {
|
||||
fi
|
||||
|
||||
# Borrowed from https://github.com/google/oss-fuzz/blob/cd9acd02f9d3f6e80011cc1e9549be526ce5f270/infra/base-images/base-runner/bad_build_check#L182
|
||||
local _asan_calls=$(objdump -dC $BUILD_DIR/systemd | egrep "callq\s+[0-9a-f]+\s+<__asan" -c)
|
||||
local _asan_calls=$(objdump -dC $BUILD_DIR/systemd-journald | egrep "callq\s+[0-9a-f]+\s+<__asan" -c)
|
||||
if (( $_asan_calls < 1000 )); then
|
||||
return 1
|
||||
else
|
||||
@@ -344,6 +344,7 @@ if [[ "\$PATH_TO_ASAN" ]]; then
|
||||
DEFAULT_ENVIRONMENT="\$DEFAULT_ENVIRONMENT LD_PRELOAD=\$PATH_TO_ASAN"
|
||||
fi
|
||||
echo DefaultEnvironment=\$DEFAULT_ENVIRONMENT >>/etc/systemd/system.conf
|
||||
echo DefaultTimeoutStartSec=180s >>/etc/systemd/system.conf
|
||||
|
||||
# ASAN and syscall filters aren't compatible with each other.
|
||||
find / -name '*.service' -type f | xargs sed -i 's/^\\(MemoryDeny\\|SystemCall\\)/#\\1/'
|
||||
@@ -354,6 +355,11 @@ JOURNALD_CONF_DIR=/etc/systemd/system/systemd-journald.service.d
|
||||
mkdir -p "\$JOURNALD_CONF_DIR"
|
||||
printf "[Service]\nEnvironment=ASAN_OPTIONS=\$DEFAULT_ASAN_OPTIONS:log_path=/systemd-journald.asan.log\n" >"\$JOURNALD_CONF_DIR/env.conf"
|
||||
|
||||
# 90s isn't enough for some services to finish when literally everything is run
|
||||
# under ASan+UBSan in containers, which, in turn, are run in VMs.
|
||||
mkdir -p /etc/systemd/system/systemd-hwdb-update.service.d
|
||||
printf "[Service]\nTimeoutSec=180s\n" >/etc/systemd/system/systemd-hwdb-update.service.d/timeout.conf
|
||||
|
||||
export ASAN_OPTIONS=\$DEFAULT_ASAN_OPTIONS:log_path=/systemd.asan.log UBSAN_OPTIONS=\$DEFAULT_UBSAN_OPTIONS
|
||||
exec $ROOTLIBDIR/systemd "\$@"
|
||||
EOF
|
||||
@@ -453,8 +459,39 @@ EOF
|
||||
fi
|
||||
}
|
||||
|
||||
check_asan_reports() {
|
||||
local ret=0
|
||||
local root="$1"
|
||||
|
||||
if [[ "$IS_BUILT_WITH_ASAN" = "yes" ]]; then
|
||||
ls -l "$root"
|
||||
if [[ -e "$root/systemd.asan.log.1" ]]; then
|
||||
cat "$root/systemd.asan.log.1"
|
||||
ret=$(($ret+1))
|
||||
fi
|
||||
|
||||
journald_report=$(find "$root" -name "systemd-journald.asan.log*" -exec cat {} \;)
|
||||
if [[ ! -z "$journald_report" ]]; then
|
||||
printf "%s" "$journald_report"
|
||||
ret=$(($ret+1))
|
||||
fi
|
||||
|
||||
pids=$("$BUILD_DIR/journalctl" -D "$root/var/log/journal" | perl -alne 'print $1 if /\[(\d+)\]:\s*SUMMARY:\s+\w+Sanitizer/')
|
||||
if [[ ! -z "$pids" ]]; then
|
||||
ret=$(($ret+1))
|
||||
for pid in $pids; do
|
||||
"$BUILD_DIR/journalctl" -D "$root/var/log/journal" _PID=$pid --no-pager
|
||||
done
|
||||
fi
|
||||
fi
|
||||
|
||||
return $ret
|
||||
}
|
||||
|
||||
check_result_nspawn() {
|
||||
local ret=1
|
||||
local journald_report=""
|
||||
local pids=""
|
||||
[[ -e $TESTDIR/$1/testok ]] && ret=0
|
||||
[[ -f $TESTDIR/$1/failed ]] && cp -a $TESTDIR/$1/failed $TESTDIR
|
||||
cp -a $TESTDIR/$1/var/log/journal $TESTDIR
|
||||
@@ -462,6 +499,7 @@ check_result_nspawn() {
|
||||
ls -l $TESTDIR/journal/*/*.journal
|
||||
test -s $TESTDIR/failed && ret=$(($ret+1))
|
||||
[ -n "$TIMED_OUT" ] && ret=$(($ret+1))
|
||||
check_asan_reports "$TESTDIR/$1" || ret=$(($ret+1))
|
||||
return $ret
|
||||
}
|
||||
|
||||
@@ -473,6 +511,7 @@ check_result_qemu() {
|
||||
[[ -e $TESTDIR/root/testok ]] && ret=0
|
||||
[[ -f $TESTDIR/root/failed ]] && cp -a $TESTDIR/root/failed $TESTDIR
|
||||
cp -a $TESTDIR/root/var/log/journal $TESTDIR
|
||||
check_asan_reports "$TESTDIR/root" || ret=$(($ret+1))
|
||||
umount $TESTDIR/root
|
||||
[[ -f $TESTDIR/failed ]] && cat $TESTDIR/failed
|
||||
ls -l $TESTDIR/journal/*/*.journal
|
||||
|
||||
Reference in New Issue
Block a user