systemd-tests-249.17-alt2.x86_64 unsafe-tmp-usage-in-scripts fail The test discovered scripts with errors which may be used by a user for damaging important system files. For example if a script uses in its work a temp file which is created in /tmp directory, then every user can create symlinks with the same name (pattern) in this directory in order to destroy or rewrite some system or another user's files. Scripts _must_ _use_ mktemp/tempfile or must use $TMPDIR. mktemp/tempfile is safest. $TMPDIR is safer than /tmp/ because libpam-tmpdir creates a subdirectory of /tmp that is only accessible by that user, and then sets TMPDIR and other variables to that. Hence, it doesn't matter nearly as much if you create a non-random filename, because nobody but you can access it. Found error in /usr/lib/systemd/tests/testdata/units/testsuite-58.sh: $ grep -A5 -B5 /tmp/ /usr/lib/systemd/tests/testdata/units/testsuite-58.sh fi export SYSTEMD_LOG_LEVEL=debug export PAGER=cat rm -f /var/tmp/testsuite-58.img /var/tmp/testsuite-58.2.img /tmp/testsuite-58.dump mkdir -p /tmp/testsuite-58-defs/ # First part: create a disk image and verify its in order cat >/tmp/testsuite-58-defs/esp.conf </tmp/testsuite-58-defs/usr.conf </tmp/testsuite-58-defs/root.conf </tmp/testsuite-58-defs/esp.conf </tmp/testsuite-58-defs/usr.conf </tmp/testsuite-58-defs/root.conf </testok exit 0 Found error in /usr/lib/systemd/tests/testdata/units/testsuite-57-short-lived.sh: $ grep -A5 -B5 /tmp/ /usr/lib/systemd/tests/testdata/units/testsuite-57-short-lived.sh #!/usr/bin/env bash set -ex if [ -f /tmp/testsuite-57.counter ] ; then read -r counter < /tmp/testsuite-57.counter counter=$(("$counter" + 1)) else counter=0 fi echo "$counter" > /tmp/testsuite-57.counter if [ "$counter" -eq 5 ] ; then systemctl kill --kill-who=main -sUSR1 testsuite-57.service fi Found error in /usr/lib/systemd/tests/testdata/units/testsuite-54.sh: $ grep -A5 -B5 /tmp/ /usr/lib/systemd/tests/testdata/units/testsuite-54.sh -p LoadCredential=shadow:/etc/shadow \ -p SetCredential=dog:wuff \ -p DynamicUser=1 \ --wait \ --pipe \ cat '${CREDENTIALS_DIRECTORY}/passwd' '${CREDENTIALS_DIRECTORY}/shadow' '${CREDENTIALS_DIRECTORY}/dog' >/tmp/ts54-concat ( cat /etc/passwd /etc/shadow && echo -n wuff ) | cmp /tmp/ts54-concat rm /tmp/ts54-concat # Verify that the creds are immutable systemd-run -p LoadCredential=passwd:/etc/passwd \ -p DynamicUser=1 \ --wait \ Found error in /usr/lib/systemd/tests/testdata/units/testsuite-46.sh: $ grep -A5 -B5 /tmp/ /usr/lib/systemd/tests/testdata/units/testsuite-46.sh # filesystems, let's drop these fields before comparing the outputs to # avoid unexpected fails. To see the full outputs of both homectl & # userdbctl (for debugging purposes) drop the fields just before the # comparison. local USERNAME="${1:?missing argument}" homectl inspect "$USERNAME" | tee /tmp/a userdbctl user "$USERNAME" | tee /tmp/b diff -I '/^\s*Disk (Size|Free|Floor|Ceiling):/' /tmp/{a,b} rm /tmp/{a,b} } systemd-analyze log-level debug systemd-analyze log-target console Found error in /usr/lib/systemd/tests/testdata/units/testsuite-44.sh: $ grep -A5 -B5 /tmp/ /usr/lib/systemd/tests/testdata/units/testsuite-44.sh systemd-analyze log-level debug systemd-run --wait -p LogNamespace=foobar echo "hello world" journalctl --namespace=foobar --sync journalctl -o cat --namespace=foobar >/tmp/hello-world journalctl -o cat >/tmp/no-hello-world grep "^hello world$" /tmp/hello-world grep "^hello world$" /tmp/no-hello-world && { echo 'unexpected success'; exit 1; } systemd-analyze log-level info echo OK >/testok Found error in /usr/lib/systemd/tests/testdata/units/testsuite-42.sh: $ grep -A5 -B5 /tmp/ /usr/lib/systemd/tests/testdata/units/testsuite-42.sh systemd-run --unit=exec2.service --wait -p StandardOutput=tty -p StandardError=tty -p Type=exec -p ExecStopPost='/bin/touch /run/exec2' sh -c 'sleep 1; false' \ && { echo 'unexpected success'; exit 1; } test -f /run/exec2 cat >/tmp/forking1.sh </tmp/forking2.sh </tmp/notify1.sh </tmp/F/truncated echo "This should be truncated" >/tmp/F/truncated-with-content systemd-tmpfiles --create - </tmp/F/rw-fs/foo systemd-tmpfiles --create - </tmp/F/rw-fs/foo systemd-tmpfiles --create - < fails. systemd-tmpfiles --create - </tmp/test20-mainpid.sh </run/mainpidsh/pid EOF chmod +x /tmp/test20-mainpid.sh systemd-run --unit=test20-mainpidsh.service -p StandardOutput=tty -p StandardError=tty -p Type=forking -p RuntimeDirectory=mainpidsh -p PIDFile=/run/mainpidsh/pid /tmp/test20-mainpid.sh test "$(systemctl show -P MainPID test20-mainpidsh.service)" -eq "$(cat /run/mainpidsh/pid)" cat >/tmp/test20-mainpid2.sh </run/mainpidsh2/pid chown 1001:1001 /run/mainpidsh2/pid EOF chmod +x /tmp/test20-mainpid2.sh systemd-run --unit=test20-mainpidsh2.service -p StandardOutput=tty -p StandardError=tty -p Type=forking -p RuntimeDirectory=mainpidsh2 -p PIDFile=/run/mainpidsh2/pid /tmp/test20-mainpid2.sh test "$(systemctl show -P MainPID test20-mainpidsh2.service)" -eq "$(cat /run/mainpidsh2/pid)" cat >/dev/shm/test20-mainpid3.sh </tmp/bind systemd-nspawn "${SUSE_OPTS[@]}" --register=no -D "$_root" --bind=/tmp/bind /bin/sh -c 'test -e /tmp/bind' } function check_norbind { # https://github.com/systemd/systemd/issues/13170 local _root="/var/lib/machines/testsuite-13.norbind-path" rm -rf "$_root" mkdir -p /tmp/binddir/subdir echo -n "outer" >/tmp/binddir/subdir/file mount -t tmpfs tmpfs /tmp/binddir/subdir echo -n "inner" >/tmp/binddir/subdir/file /usr/lib/systemd/tests/testdata/create-busybox-container "$_root" systemd-nspawn "${SUSE_OPTS[@]}" --register=no -D "$_root" --bind=/tmp/binddir:/mnt:norbind /bin/sh -c 'CONTENT=$(cat /mnt/subdir/file); if [[ $CONTENT != "outer" ]]; then echo "*** unexpected content: $CONTENT"; return 1; fi' } function check_notification_socket { # https://github.com/systemd/systemd/issues/4944 local _cmd='echo a | $(busybox which nc) -U -u -w 1 /run/host/notify' -- systemd-nspawn "${SUSE_OPTS[@]}" --register=no -D /testsuite-13.nc-container /bin/sh -x -c "$_cmd" systemd-nspawn "${SUSE_OPTS[@]}" --register=no -D /testsuite-13.nc-container -U /bin/sh -x -c "$_cmd" } function check_os_release { local _cmd='. /tmp/os-release if [ -n "${ID:+set}" ] && [ "${ID}" != "${container_host_id}" ]; then exit 1; fi if [ -n "${VERSION_ID:+set}" ] && [ "${VERSION_ID}" != "${container_host_version_id}" ]; then exit 1; fi if [ -n "${BUILD_ID:+set}" ] && [ "${BUILD_ID}" != "${container_host_build_id}" ]; then exit 1; fi if [ -n "${VARIANT_ID:+set}" ] && [ "${VARIANT_ID}" != "${container_host_variant_id}" ]; then exit 1; fi cd /tmp; (cd /run/host; md5sum os-release) | md5sum -c -- # Ensure that /etc always wins if available cp /usr/lib/os-release /etc echo MARKER=1 >>/etc/os-release fi systemd-nspawn "${SUSE_OPTS[@]}" --register=no -D /testsuite-13.nc-container --bind="${_os_release_source}":/tmp/os-release /bin/sh -x -e -c "$_cmd" if grep -q MARKER /etc/os-release; then rm /etc/os-release ln -s ../usr/lib/os-release /etc/os-release fi } function check_machinectl_bind { local _cmd='for i in $(seq 1 20); do if test -f /tmp/marker; then exit 0; fi; sleep 0.5; done; exit 1;' cat >/run/systemd/system/nspawn_machinectl_bind.service </run/systemd/nspawn/testsuite-13.nc-container.nspawn <