core: add LUOSession= unit setting

Acquiring a LUO session from /dev/liveupdate requires privileges,
and also the device is a single-owner driver so only a single
process can open it at any given time.

Add a LUOSession= service settings that allows units running
without privileges to get a session assigned to them.

The kernel imposes a 64 chars limit on session names, which is
too short to avoid clashes, so derive a hash from joining the
unit name with the parameter name, that way two units using
the same setting don't clash.
This commit is contained in:
Luca Boccassi
2026-06-17 13:11:15 +01:00
parent 9404fa70df
commit 82b8615463
13 changed files with 344 additions and 3 deletions
+27
View File
@@ -60,6 +60,17 @@ RemainAfterExit=yes
FileDescriptorStoreMax=${maxfd}
FileDescriptorStorePreserve=yes
ExecStart=${cmd}
EOF
# Create a unit with LUOSession= to test server-managed session lifecycle
cat >"/run/systemd/system/TEST-91-LIVEUPDATE-session.service" <<EOF
[Service]
Type=oneshot
RemainAfterExit=yes
FileDescriptorStoreMax=10
FileDescriptorStorePreserve=yes
LUOSession=test-session-1 test-session-2
ExecStart=/usr/lib/systemd/tests/unit-tests/manual/test-luo check-sessions test-session-1 test-session-2
EOF
}
@@ -226,6 +237,16 @@ EOF
/run/TEST-91-LIVEUPDATE-failure.attempt \
/run/TEST-91-LIVEUPDATE-failure.preserve-broken
systemctl daemon-reload
# Verify the LUOSession= sessions was restored. Starting the unit again must
# reuse the restored sessions rather than handing out fresh ones (the names are
# already present in the fd store), and the payload verifies they are valid.
n_fds=$(systemctl show -P NFileDescriptorStore TEST-91-LIVEUPDATE-session.service)
echo "Session unit fd store count after kexec: $n_fds"
test "$n_fds" -eq 2
systemctl start TEST-91-LIVEUPDATE-session.service
n_fds=$(systemctl show -P NFileDescriptorStore TEST-91-LIVEUPDATE-session.service)
test "$n_fds" -eq 2
else
# Create memfds with known content and push them to our fd store.
# Also request a LUO session, store a memfd in it, and push the session fd to the fd store.
@@ -285,6 +306,12 @@ EOF
test "$n_fds" -eq 3
done
# Test LUOSession= setting: start the unit and verify sessions are in its fd store
systemctl start TEST-91-LIVEUPDATE-session.service
n_fds=$(systemctl show -P NFileDescriptorStore TEST-91-LIVEUPDATE-session.service)
echo "Session unit fd store count: $n_fds"
test "$n_fds" -eq 2 # test-session-1 and test-session-2
# 'systemctl kexec' auto-loads the default boot entry (i.e. the booted UKI,
# via EFI LoaderEntrySelected/LoaderEntryDefault). Append a marker to the
# kernel command line so we can tell the two boots apart, and also the current