diff mbox series

[meta-security,2/2] swtpm: backport sysusers and tmpfiles support

Message ID 20261124033342.3126460-3-nirameka@qti.qualcomm.com
State New
Headers show
Series swtpm: upgrade to 0.10.2 and backport sysusers/tmpfiles support | expand

Commit Message

Niranjan Reddy Mekala Nov. 24, 2026, 3:33 a.m. UTC
Backport the upstream sysusers.d and tmpfiles.d integration to
provision the tss user and /var/lib/swtpm-localca declaratively.

Also backport the follow-up change that aligns the tss sysusers
definition with tpm2-tss to avoid conflicting definitions.

Package the generated sysusers.d and tmpfiles.d configuration files.

Signed-off-by: Niranjan Reddy Mekala <nirameka@qti.qualcomm.com>
---
 ...ll-sysusers.d-and-tmpfiles.d-configs.patch | 86 +++++++++++++++++++
 ...2-swtpm-sync-sysuser.d-with-tpm2-tss.patch | 29 +++++++
 meta-tpm/recipes-tpm/swtpm/swtpm_0.10.2.bb    |  9 +-
 3 files changed, 123 insertions(+), 1 deletion(-)
 create mode 100644 meta-tpm/recipes-tpm/swtpm/swtpm/0001-swtpm-install-sysusers.d-and-tmpfiles.d-configs.patch
 create mode 100644 meta-tpm/recipes-tpm/swtpm/swtpm/0002-swtpm-sync-sysuser.d-with-tpm2-tss.patch
diff mbox series

Patch

diff --git a/meta-tpm/recipes-tpm/swtpm/swtpm/0001-swtpm-install-sysusers.d-and-tmpfiles.d-configs.patch b/meta-tpm/recipes-tpm/swtpm/swtpm/0001-swtpm-install-sysusers.d-and-tmpfiles.d-configs.patch
new file mode 100644
index 0000000..3fc414d
--- /dev/null
+++ b/meta-tpm/recipes-tpm/swtpm/swtpm/0001-swtpm-install-sysusers.d-and-tmpfiles.d-configs.patch
@@ -0,0 +1,86 @@ 
+From d318d40469474eb8f3ccc4a6e9fe0ba100814e20 Mon Sep 17 00:00:00 2001
+From: Luca Boccassi <luca.boccassi@gmail.com>
+Date: Mon, 22 Sep 2025 17:56:24 +0100
+Subject: [PATCH] swtpm: install sysusers.d and tmpfiles.d configs
+
+These configuration files will create the required user, group and
+data directory on first boot/factory reset/package installation,
+without requiring manual scripts or actions. This is very important
+for image-based OSes, but it is useful in other cases to, to allow
+using declarative configuration instead of scripts.
+
+RPM now has built-in support for sysusers.d too.
+
+https://www.freedesktop.org/software/systemd/man/latest/tmpfiles.d.html
+https://www.freedesktop.org/software/systemd/man/latest/sysusers.d.html
+
+Signed-off-by: Luca Boccassi <luca.boccassi@gmail.com>
+Upstream-Status: Backport [https://github.com/stefanberger/swtpm/commit/d318d40469474eb8f3ccc4a6e9fe0ba100814e20]
+---
+ .gitignore                 |  2 ++
+ configure.ac               |  2 ++
+ src/Makefile.am            | 10 ++++++++++
+ src/swtpm-sysusers.conf.in |  1 +
+ src/swtpm-tmpfiles.conf.in |  1 +
+ 5 files changed, 16 insertions(+)
+ create mode 100644 src/swtpm-sysusers.conf.in
+ create mode 100644 src/swtpm-tmpfiles.conf.in
+
+diff --git a/.gitignore b/.gitignore
+index 579d0be..012ef88 100644
+--- a/.gitignore
++++ b/.gitignore
+@@ -63,6 +63,8 @@ Makefile
+ /src/swtpm_ioctl/swtpm_ioctl
+ /src/swtpm_localca/swtpm_localca
+ /src/swtpm_setup/swtpm_setup
++/src/swtpm-sysusers.conf
++/src/swtpm-tmpfiles.conf
+ /src/utils/swtpm_conf.h
+ /test-driver
+ tests/*.log
+diff --git a/configure.ac b/configure.ac
+index afcd18a..4eab9f4 100644
+--- a/configure.ac
++++ b/configure.ac
+@@ -502,6 +502,8 @@ AC_CONFIG_FILES([Makefile                   \
+ 		src/swtpm_ioctl/Makefile    \
+ 		src/swtpm_localca/Makefile  \
+ 		src/swtpm_setup/Makefile    \
++		src/swtpm-sysusers.conf     \
++		src/swtpm-tmpfiles.conf     \
+ 		src/utils/Makefile          \
+ 		src/utils/swtpm_conf.h      \
+ 		man/Makefile                \
+diff --git a/src/Makefile.am b/src/Makefile.am
+index 9e03c78..c36d5cc 100644
+--- a/src/Makefile.am
++++ b/src/Makefile.am
+@@ -17,3 +17,13 @@ if WITH_SELINUX
+ SUBDIRS += \
+ 	selinux
+ endif
++
++sysusersdir = $(prefix)/lib/sysusers.d
++sysusers_DATA = swtpm-sysusers.conf
++
++tmpfilesdir = $(prefix)/lib/tmpfiles.d
++tmpfiles_DATA = swtpm-tmpfiles.conf
++
++EXTRA_DIST = \
++	swtpm-sysusers.conf \
++	swtpm-tmpfiles.conf
+diff --git a/src/swtpm-sysusers.conf.in b/src/swtpm-sysusers.conf.in
+new file mode 100644
+index 0000000..0b02ca4
+--- /dev/null
++++ b/src/swtpm-sysusers.conf.in
+@@ -0,0 +1 @@
++u! @TSS_USER@ - "TPM software stack" @LOCALSTATEDIR@/lib/swtpm-localca
+diff --git a/src/swtpm-tmpfiles.conf.in b/src/swtpm-tmpfiles.conf.in
+new file mode 100644
+index 0000000..afe2d13
+--- /dev/null
++++ b/src/swtpm-tmpfiles.conf.in
+@@ -0,0 +1 @@
++d @LOCALSTATEDIR@/lib/swtpm-localca 0750 @TSS_USER@ root
diff --git a/meta-tpm/recipes-tpm/swtpm/swtpm/0002-swtpm-sync-sysuser.d-with-tpm2-tss.patch b/meta-tpm/recipes-tpm/swtpm/swtpm/0002-swtpm-sync-sysuser.d-with-tpm2-tss.patch
new file mode 100644
index 0000000..edc0402
--- /dev/null
+++ b/meta-tpm/recipes-tpm/swtpm/swtpm/0002-swtpm-sync-sysuser.d-with-tpm2-tss.patch
@@ -0,0 +1,29 @@ 
+From b64b114c9c6941d9729fcc2ad511f108a3affaef Mon Sep 17 00:00:00 2001
+From: Luca Boccassi <luca.boccassi@gmail.com>
+Date: Wed, 7 Oct 2026 08:29:09 +0200
+Subject: [PATCH] swtpm: sync sysuser.d with tpm2-tss
+
+tpm2-tss has shipped a sysusers.d file since 2019 for the tss user:
+
+https://github.com/tpm2-software/tpm2-tss/commit/c43f3c2190eb06e731c5bf7c2849d07f5f8503a5
+
+When two sysusers.d configs have a conflict, the tool raises a warning,
+and the result depends on alphabetic sorting of the config names which
+isn't great. Sync the content: drop the '!', drop the homedir (not used
+anyway) and modify the GECOS string.
+
+Fixes: d318d4046947 ("swtpm: install sysusers.d and tmpfiles.d configs")
+
+Signed-off-by: Luca Boccassi <luca.boccassi@gmail.com>
+Upstream-Status: Backport [https://github.com/stefanberger/swtpm/commit/b64b114c9c6941d9729fcc2ad511f108a3affaef]
+---
+ src/swtpm-sysusers.conf.in | 2 +-
+ 1 file changed, 1 insertion(+), 1 deletion(-)
+
+diff --git a/src/swtpm-sysusers.conf.in b/src/swtpm-sysusers.conf.in
+index 0b02ca4..a9a1779 100644
+--- a/src/swtpm-sysusers.conf.in
++++ b/src/swtpm-sysusers.conf.in
+@@ -1 +1 @@
+-u! @TSS_USER@ - "TPM software stack" @LOCALSTATEDIR@/lib/swtpm-localca
++u @TSS_USER@ - "tss user for tpm2"
diff --git a/meta-tpm/recipes-tpm/swtpm/swtpm_0.10.2.bb b/meta-tpm/recipes-tpm/swtpm/swtpm_0.10.2.bb
index 1e91a91..50d2cfc 100644
--- a/meta-tpm/recipes-tpm/swtpm/swtpm_0.10.2.bb
+++ b/meta-tpm/recipes-tpm/swtpm/swtpm_0.10.2.bb
@@ -8,7 +8,10 @@  SECTION = "apps"
 DEPENDS = "libtasn1 coreutils-native expect-native socat-native glib-2.0 net-tools-native libtpms json-glib"
 
 SRCREV = "32b5a0575991a73398de9749d63cafd847008af2"
-SRC_URI = "git://github.com/stefanberger/swtpm.git;branch=stable-0.10;protocol=https"
+SRC_URI = "git://github.com/stefanberger/swtpm.git;branch=stable-0.10;protocol=https \
+           file://0001-swtpm-install-sysusers.d-and-tmpfiles.d-configs.patch \
+           file://0002-swtpm-sync-sysuser.d-with-tpm2-tss.patch \
+          "
 PE = "2"
 
 PARALLEL_MAKE = ""
@@ -40,6 +43,10 @@  USERADD_PARAM:${PN} = "--system -g ${TSS_GROUP} --home-dir / \
 
 PACKAGE_BEFORE_PN = "${PN}-cuse"
 FILES:${PN}-cuse = "${bindir}/swtpm_cuse"
+FILES:${PN} += " \
+    ${libdir}/sysusers.d/swtpm-sysusers.conf \
+    ${libdir}/tmpfiles.d/swtpm-tmpfiles.conf \
+"
 
 INSANE_SKIP:${PN}   += "dev-so"