tpm2-util: also load libtss2-tcti-device.so.0 in dlopen_tpm2()

This TCTI module is the one we need to actually access a Linux TPM
device, we'll hence pretty much always need it if we do TPM at all.
Given that we nowadays turn off dlopen() after fork() in the child,
let's explicitly load it as part of dlopen_tpm2() so that it is
available whenever TPM2 is used.
This commit is contained in:
Lennart Poettering
2026-03-04 08:28:29 +01:00
parent 96a8bfcd7a
commit 5f85409f93
3 changed files with 39 additions and 1 deletions
+19 -1
View File
@@ -47,9 +47,11 @@ int dlsym_many_or_warn_sentinel(void *dl, int log_level, ...) {
return r;
}
int dlopen_many_sym_or_warn_sentinel(void **dlp, const char *filename, int log_level, ...) {
int dlopen_verbose(void **dlp, const char *filename) {
int r;
assert(dlp);
if (*dlp)
return 0; /* Already loaded */
@@ -62,6 +64,22 @@ int dlopen_many_sym_or_warn_sentinel(void **dlp, const char *filename, int log_l
}
log_debug("Loaded shared library '%s' via dlopen().", filename);
*dlp = TAKE_PTR(dl);
return 1;
}
int dlopen_many_sym_or_warn_sentinel(void **dlp, const char *filename, int log_level, ...) {
int r;
assert(dlp);
if (*dlp)
return 0; /* Already loaded */
_cleanup_(dlclosep) void *dl = NULL;
r = dlopen_verbose(&dl, filename);
if (r < 0)
return r;
va_list ap;
va_start(ap, log_level);
+1
View File
@@ -11,6 +11,7 @@ static inline void dlclosep(void **dlp) {
safe_dlclose(*dlp);
}
int dlopen_verbose(void **dlp, const char *filename);
int dlsym_many_or_warn_sentinel(void *dl, int log_level, ...) _sentinel_;
int dlopen_many_sym_or_warn_sentinel(void **dlp, const char *filename, int log_level, ...) _sentinel_;
+19
View File
@@ -53,6 +53,7 @@
static void *libtss2_esys_dl = NULL;
static void *libtss2_rc_dl = NULL;
static void *libtss2_mu_dl = NULL;
static void *libtss2_tcti_device_dl = NULL;
static DLSYM_PROTOTYPE(Esys_Create) = NULL;
static DLSYM_PROTOTYPE(Esys_CreateLoaded) = NULL;
@@ -226,6 +227,20 @@ static int dlopen_tpm2_mu(void) {
DLSYM_ARG(Tss2_MU_UINT32_Marshal));
}
static int dlopen_tpm2_tcti_device(void) {
/* The "device" TCTI is the most relevant one, let's also load it explicitly on dlopen_tpm2(), even
* if we don't resolve any symbols here. */
ELF_NOTE_DLOPEN("tpm",
"Support for TPM",
ELF_NOTE_DLOPEN_PRIORITY_SUGGESTED,
"libtss2-tcti-device.so.0");
return dlopen_verbose(
&libtss2_tcti_device_dl,
"libtss2-tcti-device.so.0");
}
#endif
int dlopen_tpm2(void) {
@@ -244,6 +259,10 @@ int dlopen_tpm2(void) {
if (r < 0)
return r;
r = dlopen_tpm2_tcti_device();
if (r < 0)
return r;
return 0;
#else
return -EOPNOTSUPP;