File 0002-tssProperties-add-TPM_USE_RESOURCE_MANAGER.patch of Package tss2
From f2ce523f2f0509a4d443bc586d7d4b6fe25f9c15 Mon Sep 17 00:00:00 2001
From: James Bottomley <James.Bottomley@HansenPartnership.com>
Date: Fri, 30 Dec 2016 15:57:25 -0800
Subject: [PATCH 2/2] tssProperties: add TPM_USE_RESOURCE_MANAGER
The resource manager in Linux must be activated by an ioctl before it
can be used. Since the use of a resource manager makes all transient
objects volatile, the user has to be aware of using one, so make this
a settable property. The expectation is that code which should use a
resource manager should have this in it
TSS_SetProperty(tssContext, TPM_USE_RESOURCE_MANAGER, "1");
Signed-off-by: James Bottomley <James.Bottomley@HansenPartnership.com>
---
utils/tss2/tss.h | 1 +
utils/tssdev.c | 12 ++++++++++++
utils/tssproperties.c | 36 ++++++++++++++++++++++++++++++++++++
utils/tssproperties.h | 3 +++
4 files changed, 52 insertions(+)
diff --git a/utils/tss2/tss.h b/utils/tss2/tss.h
index a8c4636..605908e 100644
--- a/utils/tss2/tss.h
+++ b/utils/tss2/tss.h
@@ -91,6 +91,7 @@ extern "C" {
#define TPM_DEVICE 7
#define TPM_ENCRYPT_SESSIONS 8
#define TPM_SERVER_TYPE 9
+#define TPM_USE_RESOURCE_MANAGER 10
LIB_EXPORT
TPM_RC TSS_SetProperty(TSS_CONTEXT *tssContext,
diff --git a/utils/tssdev.c b/utils/tssdev.c
index c407cb9..7c3d467 100644
--- a/utils/tssdev.c
+++ b/utils/tssdev.c
@@ -49,8 +49,13 @@
#include <unistd.h>
#include <arpa/inet.h>
#include <sys/types.h>
+#include <sys/ioctl.h>
#include <fcntl.h>
+/* FIXME: Linux definition of TPM_IOC_NEW_SPACE eventually needs
+ * to come from linux/tpm.h */
+#define TPM_IOC_NEW_SPACE _IO(0xa2, 0x00)
+
#include <tss2/tssresponsecode.h>
#include <tss2/tsserror.h>
#include <tss2/tssprint.h>
@@ -115,6 +120,13 @@ static uint32_t TSS_Dev_Open(TSS_CONTEXT *tssContext)
if (tssVerbose) printf("TSS_Dev_Open: Error opening %s\n", tssContext->tssDevice);
rc = TSS_RC_NO_CONNECTION;
}
+ if (rc == 0 && tssContext->tssUseResourceManager) {
+ if (tssVerbose) printf("TSS_Dev_Open, Using a Resource Manager\n");
+ if (ioctl(tssContext->dev_fd, TPM_IOC_NEW_SPACE)) {
+ if (tssVerbose) printf("TSS_Dev_Open: ioctl to set Resource Manager failed");
+ rc = TSS_RC_NO_CONNECTION;
+ }
+ }
}
if (rc == 0) {
fcntl(tssContext->dev_fd, O_RDONLY | O_NONBLOCK);
diff --git a/utils/tssproperties.c b/utils/tssproperties.c
index 6a7f7fe..462a55d 100644
--- a/utils/tssproperties.c
+++ b/utils/tssproperties.c
@@ -63,6 +63,7 @@ static TPM_RC TSS_SetServerType(TSS_CONTEXT *tssContext, const char *value);
static TPM_RC TSS_SetInterfaceType(TSS_CONTEXT *tssContext, const char *value);
static TPM_RC TSS_SetDevice(TSS_CONTEXT *tssContext, const char *value);
static TPM_RC TSS_SetEncryptSessions(TSS_CONTEXT *tssContext, const char *value);
+static TPM_RC TSS_SetUseResourceManager(TSS_CONTEXT *tssContext, const char *value);
/* globals for the library */
@@ -118,6 +119,10 @@ int tssFirstCall = TRUE;
#define TPM_ENCRYPT_SESSIONS_DEFAULT "1"
#endif
+#ifndef TPM_USE_RESOURCE_MANAGER_DEFAULT
+#define TPM_USE_RESOURCE_MANAGER_DEFAULT "0"
+#endif
+
/* TSS_GlobalProperties_Init() sets the global verbose trace flags at the first entry points to the
TSS */
@@ -187,6 +192,10 @@ TPM_RC TSS_Properties_Init(TSS_CONTEXT *tssContext)
value = getenv("TPM_ENCRYPT_SESSIONS");
rc = TSS_SetEncryptSessions(tssContext, value);
}
+ if (rc == 0) {
+ value = getenv("TPM_USE_RESOURCE_MANAGER");
+ rc = TSS_SetUseResourceManager(tssContext, value);
+ }
/* TPM socket command port */
if (rc == 0) {
value = getenv("TPM_COMMAND_PORT");
@@ -275,6 +284,9 @@ TPM_RC TSS_SetProperty(TSS_CONTEXT *tssContext,
case TPM_ENCRYPT_SESSIONS:
rc = TSS_SetEncryptSessions(tssContext, value);
break;
+ case TPM_USE_RESOURCE_MANAGER:
+ rc = TSS_SetUseResourceManager(tssContext, value);
+ break;
default:
rc = TSS_RC_BAD_PROPERTY;
}
@@ -485,3 +497,27 @@ static TPM_RC TSS_SetEncryptSessions(TSS_CONTEXT *tssContext, const char *value)
}
return rc;
}
+
+static TPM_RC TSS_SetUseResourceManager(TSS_CONTEXT *tssContext, const char *value)
+{
+ TPM_RC rc = 0;
+ int irc;
+
+ /* close an open connection before changing property */
+ if (rc == 0) {
+ rc = TSS_Close(tssContext);
+ }
+ if (rc == 0) {
+ if (value == NULL) {
+ value = TPM_USE_RESOURCE_MANAGER_DEFAULT;
+ }
+ }
+ if (rc == 0) {
+ irc = sscanf(value, "%u", &tssContext->tssUseResourceManager);
+ if (irc != 1) {
+ if (tssVerbose) printf("TSS_SetUseResourceManager: error, value invalid\n");
+ rc = TSS_RC_BAD_PROPERTY_VALUE;
+ }
+ }
+ return rc;
+}
diff --git a/utils/tssproperties.h b/utils/tssproperties.h
index 9c285dd..79d2479 100644
--- a/utils/tssproperties.h
+++ b/utils/tssproperties.h
@@ -124,6 +124,9 @@ extern "C" {
/* device driver interface */
const char *tssDevice;
+ /* whether to activate resource manager (tss device only) */
+ int tssUseResourceManager;
+
/* TRUE for the first time through, indicates that interface open must occur */
int tssFirstTransmit;
--
2.6.6