From 92ee875a31adcfc940bb5cb8d076bd1374fe2625 Mon Sep 17 00:00:00 2001 From: Frantisek Sumsal Date: Tue, 19 Dec 2023 15:05:23 +0100 Subject: [PATCH] test: trigger /boot mount if it's an automount If the target mount point is an automount, checking it for writeability without triggering it first is iffy and yields different results based on kernel version: ~# systemd-run --wait --pipe -p ProtectSystem=yes bash -xec 'uname -r; mount -l | grep boot; test ! -w /boot' Running as unit: run-u36.service; invocation ID: f948ff4f3c8e4bcfba364ead94bd0ad9 + uname -r 4.18.0-529.el8.x86_64 + mount -l + grep boot systemd-1 on /boot type autofs (rw,relatime,fd=43,pgrp=1,timeout=120,minproto=5,maxproto=5,direct,pipe_ino=356096) + test '!' -w /boot Finished with result: exit-code Main processes terminated with: code=exited/status=1 ~# systemd-run --wait --pipe -p ProtectSystem=yes bash -xec 'uname -r; mount -l | grep boot; test ! -w /boot' Running as unit: run-u274.service; invocation ID: ccc53ed63c3249348cf714f97a3a7026 + uname -r 6.6.7-arch1-1 + mount -l + grep boot systemd-1 on /boot type autofs (rw,relatime,fd=95,pgrp=1,timeout=120,minproto=5,maxproto=5,direct,pipe_ino=730583) + test '!' -w /boot Finished with result: success Main processes terminated with: code=exited/status=0 One solution would be to use /boot/ instead of just /boot, which triggers the automount during the check, but in that case the mount would happen _after_ we apply the ProtectSystem= stuff, so the mount point would be unexpectedly writable: ~# systemd-run --wait --pipe -p ProtectSystem=yes bash -xec 'uname -r; mount -l | grep boot; test ! -w /boot/ || mount -l | grep boot' Running as unit: run-u282.service; invocation ID: 2154f6b4cbd34ddeb3e246cb7c991918 + uname -r 6.6.7-arch1-1 + mount -l + grep boot systemd-1 on /boot type autofs (rw,relatime,fd=95,pgrp=1,timeout=120,minproto=5,maxproto=5,direct,pipe_ino=730583) + test '!' -w /boot/ + mount -l + grep boot systemd-1 on /boot type autofs (rw,relatime,fd=95,pgrp=1,timeout=120,minproto=5,maxproto=5,direct,pipe_ino=730583) /dev/vda2 on /boot type vfat (rw,nosuid,nodev,noexec,relatime,nosymfollow,fmask=0077,dmask=0077,codepage=437,iocharset=ascii,shortname=mixed,utf8,errors=remount-ro) Let's just trigger the (possible) automounts explicitly before we do any checks to avoid all this stuff. Also, when at it, check that ProtectSystem=yes|full correctly protects the ESP mount as well. Follow-up for 97bbb9cfbd. --- test/units/testsuite-07.exec-context.sh | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/test/units/testsuite-07.exec-context.sh b/test/units/testsuite-07.exec-context.sh index 5fb7dddf89..c84974f1de 100755 --- a/test/units/testsuite-07.exec-context.sh +++ b/test/units/testsuite-07.exec-context.sh @@ -32,10 +32,19 @@ proc_supports_option() { # the transient stuff from systemd-run. Let's just skip the following tests # in that case instead of complicating the test setup even more */ if [[ -z "${COVERAGE_BUILD_DIR:-}" ]]; then + if ! systemd-detect-virt -cq && command -v bootctl >/dev/null; then + boot_path="$(bootctl --print-boot-path)" + esp_path="$(bootctl --print-esp-path)" + + # If the mount points are handled by automount units, make sure we trigger + # them before proceeding further + ls -l "$boot_path" "$esp_path" + fi + systemd-run --wait --pipe -p ProtectSystem=yes \ - bash -xec "test ! -w /usr; test ! -w /boot; test -w /etc; test -w /var" + bash -xec "test ! -w /usr; ${boot_path:+"test ! -w $boot_path; test ! -w $esp_path;"} test -w /etc; test -w /var" systemd-run --wait --pipe -p ProtectSystem=full \ - bash -xec "test ! -w /usr; test ! -w /boot; test ! -w /etc; test -w /var" + bash -xec "test ! -w /usr; ${boot_path:+"test ! -w $boot_path; test ! -w $esp_path;"} test ! -w /etc; test -w /var" systemd-run --wait --pipe -p ProtectSystem=strict \ bash -xec "test ! -w /; test ! -w /etc; test ! -w /var; test -w /dev; test -w /proc" systemd-run --wait --pipe -p ProtectSystem=no \