Azure / azure-utpm-c

TPM C library for use with Azure IoT SDKs
MIT License
12 stars 14 forks source link

tpm_comm_linux.c bypasses tpm2-abrmd on some Linux installations #53

Closed alexeyzolotarev closed 1 year ago

alexeyzolotarev commented 4 years ago

Hello there,

We've seen issues where certain applications, such as iotedge daemon, or tpm_device_provision tool from azure-iot-sdk-c that rely on azure-utpm-c library start to work unstable when tpm2-abrmd running, giving out various errors originating from the azure-utpm-c library.

When attempting to run tpm_device_provision tool from azure-iot-sdk-c that uses utpm as a dependency, we saw the following behavior:

This is caused by the load_abrmd function from the tpm_comm_linux.c that attempts to dlopen the shared library defined in the TPM_TABRMD_USERMODE_RESOURCE_MGR variable as libtss2-tcti-tabrmd.so, (but not as libtss2.tcti-tabrmd.so.0 as it is done for other defines in the same source file).

In our system the tpm2-abrmd installs that file with .so.0 and .so.0.0.0 but not as *.so file, so this causes the failure of dlopen to find the file and as a result the load_abrmd function in azure-utpm-c library falls back to the direct access to /dev/tpm0. The in-kernel resource manager might not be available in kernels earlier than 4.12, so for those systems no TPM resource manager is used at all and the tools fail because of non synchronized shared access to the /dev/tpm0. This conflicts with tpm2-abrmd daemon that shoudl be exclusively accessing the device.

While a workaround was found to create a libtss2-tcti-tabrmd.so symlink which fixed the dlopen issue and thus used the tpm2-tabrmd resource manager, the generic behavior on some systems where those symlinks are missing or could not be created and that tpm2-tabrmd resource manager not being used at all, causing issues of shared access to /dev/tpm0, as the tpm2-abrmd daemon already using the device.

So possible fix in this library could be to also check the name libtss2-tcti-tabrmd.so.0 along with the libtss2-tcti-tabrmd.so so that not to miss the installed and running tpm2-tabrmd resource manager.

applications affected:

condition of failure

CIPop commented 1 year ago

libtss2-tcti-tabrmd.so missing (installed as libtss2-tcti-tabrmd.so.0 or with .so.0.0.0 extension)

This might be the issue.

We recommend the following setup: https://github.com/Azure/azure-iot-sdk-c/blob/main/provisioning_client/devdoc/using_provisioning_client.md#tpm-resource-manager