From 9220ceb6c562b92f6303bce8db318a607f60cfe0 Mon Sep 17 00:00:00 2001 From: jinlun <108639392+15058718379@users.noreply.github.com> Date: Tue, 5 Sep 2023 17:22:08 +0800 Subject: [PATCH] Initialize tcti in advance init_thread_func creates a thread and then initializes the tcti. When /dev/tpm0 does not exist, the thread is created. If other processes communicate with abrmd, the connection may be established. However, /dev/tpm0 does not exist, and init_thread_func releases resources. After the resources are released randomly, the resources may still be used by id_pid_mix_from_incall to randomly obtain the kernel dump in uint64. The patch initializes the tcti in advance to avoid concurrency. https://github.com/tpm2-software/tpm2-abrmd/issues/838 --- src/tabrmd-init.c | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/src/tabrmd-init.c b/src/tabrmd-init.c index ea711559..e5b7f6ff 100644 --- a/src/tabrmd-init.c +++ b/src/tabrmd-init.c @@ -137,6 +137,15 @@ init_thread_func (gpointer user_data) g_info ("init_thread_func start"); g_mutex_lock (&data->init_mutex); + + rc = Tss2_TctiLdr_Initialize (data->options.tcti_conf, &tcti_ctx); + if (rc != TSS2_RC_SUCCESS || tcti_ctx == NULL) { + g_critical ("%s: failed to create TCTI with conf \"%s\", got RC: 0x%x", + __func__, data->options.tcti_conf, rc); + ret = EX_IOERR; + goto err_out; + } + /* Setup program signals */ if (g_unix_signal_add(SIGINT, signal_handler, data->loop) <= 0 || g_unix_signal_add(SIGTERM, signal_handler, data->loop) <= 0) @@ -170,13 +179,6 @@ init_thread_func (gpointer user_data) ipc_frontend_connect (data->ipc_frontend, &data->init_mutex); - rc = Tss2_TctiLdr_Initialize (data->options.tcti_conf, &tcti_ctx); - if (rc != TSS2_RC_SUCCESS || tcti_ctx == NULL) { - g_critical ("%s: failed to create TCTI with conf \"%s\", got RC: 0x%x", - __func__, data->options.tcti_conf, rc); - ret = EX_IOERR; - goto err_out; - } tcti = tcti_new (tcti_ctx); data->tpm2 = tpm2_new (tcti); g_clear_object (&tcti);