Control: tags -1 + patch

Hi,

The unit also races the optee module: on an Orange Pi 5 (RK3588S, OP-TEE
4.11, fTPM) tee-supplicant started before /dev/teepriv0 existed in 1 of 3
boots, exited, and /dev/tpm0 never appeared.

The attached patch uses upstream's [email protected], started by a
udev rule on teepriv*, run as root as today, waiting for the REE FS
directory, without upstream's "modprobe -r tpm_ftpm_tee" ExecStop.
postinst drops the old unit's enablement; a running supplicant keeps
running until the next boot.

Tested on that board: 5/5 boots with /dev/tpmrm0, fTPM seal/unseal, NV,
LUKS unlock after reboot, and the upgrade from 4.10.0-1.

Developed with Claude (Anthropic); I reviewed and tested it.

Arun
From 54a313a490837bf638c18a877d9ab21083205d5c Mon Sep 17 00:00:00 2001
From: Arun Iyengar <[email protected]>
Date: Fri, 13 Nov 2026 13:39:16 +0000
Subject: [PATCH] Start tee-supplicant from udev with [email protected]

The multi-user unit races the optee module: if /dev/teepriv0 is not there
yet, tee-supplicant exits and the fTPM never probes. Use upstream's
template unit and a udev rule (the systemd part of upstream's; no
tee/teepriv groups, since the supplicant stays root). On upgrade, leave
a running supplicant alone: stopping it under live fTPM I/O breaks the
fTPM. The new unit takes over at the next boot.

Closes: #1149302
---
 debian/changelog               |  7 +++++++
 debian/tee-supplicant.postinst | 25 +++++++++++++++++++++++++
 debian/tee-supplicant.service  |  9 ---------
 debian/tee-supplicant.udev     |  3 +++
 debian/[email protected] | 13 +++++++++++++
 5 files changed, 48 insertions(+), 9 deletions(-)
 create mode 100644 debian/tee-supplicant.postinst
 delete mode 100644 debian/tee-supplicant.service
 create mode 100644 debian/tee-supplicant.udev
 create mode 100644 debian/[email protected]

diff --git a/debian/changelog b/debian/changelog
index de27ba1..82ee411 100644
--- a/debian/changelog
+++ b/debian/changelog
@@ -1,3 +1,10 @@
+optee-client (4.11.0-2) UNRELEASED; urgency=medium
+
+  * Start tee-supplicant from udev with [email protected], so it no
+    longer races the optee module. (Closes: #1149302)
+
+ -- Arun Iyengar <[email protected]>  Fri, 13 Nov 2026 12:00:00 +0000
+
 optee-client (4.11.0-1) unstable; urgency=low
 
   * New upstream version 4.11.0
diff --git a/debian/tee-supplicant.postinst b/debian/tee-supplicant.postinst
new file mode 100644
index 0000000..67f40bf
--- /dev/null
+++ b/debian/tee-supplicant.postinst
@@ -0,0 +1,25 @@
+#!/bin/sh
+set -e
+
+# tee-supplicant.service was replaced by [email protected], started
+# by udev. A running supplicant is left alone: stopping it breaks TEE
+# clients that use secure storage, such as the fTPM. The new unit takes
+# over at the next boot.
+if [ "$1" = "configure" ]; then
+	if dpkg --compare-versions "$2" lt-nl "4.11.0-1.1~" &&
+	   command -v deb-systemd-helper >/dev/null; then
+		deb-systemd-helper purge 'tee-supplicant.service' >/dev/null || true
+		deb-systemd-helper unmask 'tee-supplicant.service' >/dev/null || true
+	fi
+	if [ -d /run/systemd/system ]; then
+		systemctl --system daemon-reload >/dev/null || true
+		if ! systemctl -q is-active tee-supplicant.service; then
+			for d in /dev/teepriv*; do
+				[ -c "$d" ] || continue
+				deb-systemd-invoke start "tee-supplicant@${d#/dev/}.service" >/dev/null || true
+			done
+		fi
+	fi
+fi
+
+#DEBHELPER#
diff --git a/debian/tee-supplicant.service b/debian/tee-supplicant.service
deleted file mode 100644
index 7148515..0000000
--- a/debian/tee-supplicant.service
+++ /dev/null
@@ -1,9 +0,0 @@
-[Unit]
-Description=TEE Supplicant
-
-[Service]
-Type=simple
-ExecStart=/usr/sbin/tee-supplicant
-
-[Install]
-WantedBy=multi-user.target
diff --git a/debian/tee-supplicant.udev b/debian/tee-supplicant.udev
new file mode 100644
index 0000000..62b82bd
--- /dev/null
+++ b/debian/tee-supplicant.udev
@@ -0,0 +1,3 @@
+# Start tee-supplicant@<dev>.service when the OP-TEE supplicant device appears
+# (upstream tee-supplicant/optee-udev.rules.in, systemd part).
+KERNEL=="teepriv[0-9]*", TAG+="systemd", ENV{SYSTEMD_WANTS}+="tee-supplicant@%k.service"
diff --git a/debian/[email protected] b/debian/[email protected]
new file mode 100644
index 0000000..e710161
--- /dev/null
+++ b/debian/[email protected]
@@ -0,0 +1,13 @@
+[Unit]
+Description=TEE Supplicant on %i
+DefaultDependencies=no
+After=dev-%i.device systemd-remount-fs.service
+Wants=dev-%i.device
+RequiresMountsFor=/var/lib/optee-client/data/tee
+Conflicts=shutdown.target
+Before=tpm2.target sysinit.target shutdown.target
+
+[Service]
+Type=notify
+EnvironmentFile=-/etc/default/tee-supplicant
+ExecStart=/usr/sbin/tee-supplicant $OPTARGS /dev/%I
-- 
2.55.0

Reply via email to