Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1379)

Unified Diff: src/tcs/tcs_auth_mgr.c

Issue 3581012: Upgrade from trousers 0.3.3 to 0.3.6 and from testsuite 0.2 to 0.3. (Closed) Base URL: ssh://git@gitrw.chromium.org:9222/trousers.git
Patch Set: git cl push Created 10 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « src/tcs/rpc/tcstp/rpc_transport.c ('k') | src/tcs/tcs_evlog_biosem.c » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/tcs/tcs_auth_mgr.c
diff --git a/src/tcs/tcs_auth_mgr.c b/src/tcs/tcs_auth_mgr.c
index 577eaad556e6abee500d138326110745fc36af24..5d07832c0b534646b57371e473e2de8a22a2d520 100644
--- a/src/tcs/tcs_auth_mgr.c
+++ b/src/tcs/tcs_auth_mgr.c
@@ -28,7 +28,6 @@
MUTEX_DECLARE_EXTERN(tcsp_lock);
-
/* Note: The after taking the auth_mgr_lock in any of the functions below, the
* mem_cache_lock cannot be taken without risking a deadlock. So, the auth_mgr
* functions must be "self-contained" wrt locking */
@@ -80,14 +79,13 @@ auth_mgr_final()
TSS_RESULT
auth_mgr_save_ctx(TCS_CONTEXT_HANDLE hContext)
{
- TSS_RESULT result;
+ TSS_RESULT result = TSS_SUCCESS;
UINT32 i;
for (i = 0; i < auth_mgr.auth_mapper_size; i++) {
if (auth_mgr.auth_mapper[i].full == TRUE &&
auth_mgr.auth_mapper[i].swap == NULL &&
auth_mgr.auth_mapper[i].tcs_ctx != hContext) {
-
LogDebug("Calling TPM_SaveAuthContext for TCS CTX %x. Swapping out: TCS %x "
"TPM %x", hContext, auth_mgr.auth_mapper[i].tcs_ctx,
auth_mgr.auth_mapper[i].tpm_handle);
@@ -98,12 +96,11 @@ auth_mgr_save_ctx(TCS_CONTEXT_HANDLE hContext)
LogDebug("TPM_SaveAuthContext failed: 0x%x", result);
return result;
}
-
- /* XXX should there be a break here? */
+ break;
}
}
- return TSS_SUCCESS;
+ return result;
}
/* if there's a TCS context waiting to get auth, wake it up or swap it in */
@@ -111,7 +108,7 @@ void
auth_mgr_swap_in()
{
if (auth_mgr.overflow[auth_mgr.of_tail] != NULL) {
- LogDebug("waking up thread %zd, auth slot has opened", THREAD_ID);
+ LogDebug("waking up thread %lddd, auth slot has opened", THREAD_ID);
/* wake up the next sleeping thread in order and increment tail */
COND_SIGNAL(auth_mgr.overflow[auth_mgr.of_tail]);
auth_mgr.overflow[auth_mgr.of_tail] = NULL;
@@ -152,7 +149,7 @@ auth_mgr_swap_out(TCS_CONTEXT_HANDLE hContext)
auth_mgr.overflow[auth_mgr.of_head] = cond;
auth_mgr.of_head = (auth_mgr.of_head + 1) % auth_mgr.overflow_size;
/* go to sleep */
- LogDebug("thread %zd going to sleep until auth slot opens", THREAD_ID);
+ LogDebug("thread %lddd going to sleep until auth slot opens", THREAD_ID);
auth_mgr.sleeping_threads++;
COND_WAIT(cond, &tcsp_lock);
auth_mgr.sleeping_threads--;
@@ -183,7 +180,7 @@ auth_mgr_swap_out(TCS_CONTEXT_HANDLE hContext)
auth_mgr.of_tail = 0;
auth_mgr.overflow[auth_mgr.of_head] = cond;
auth_mgr.of_head = (auth_mgr.of_head + 1) % auth_mgr.overflow_size;
- LogDebug("thread %zd going to sleep until auth slot opens", THREAD_ID);
+ LogDebug("thread %lddd going to sleep until auth slot opens", THREAD_ID);
auth_mgr.sleeping_threads++;
COND_WAIT(cond, &tcsp_lock);
auth_mgr.sleeping_threads--;
@@ -218,8 +215,8 @@ auth_mgr_close_context(TCS_CONTEXT_HANDLE tcs_handle)
/* Ok, probably dealing with a 1.1 TPM */
if (result == TPM_E_BAD_ORDINAL)
- result = internal_TerminateHandle(
- auth_mgr.auth_mapper[i].tpm_handle);
+ result = internal_TerminateHandle(
+ auth_mgr.auth_mapper[i].tpm_handle);
if (result == TCPA_E_INVALID_AUTHHANDLE) {
LogDebug("Tried to close an invalid auth handle: %x",
@@ -228,10 +225,14 @@ auth_mgr_close_context(TCS_CONTEXT_HANDLE tcs_handle)
LogDebug("TPM_TerminateHandle returned %d", result);
}
}
+ /* clear the slot */
auth_mgr.open_auth_sessions--;
auth_mgr.auth_mapper[i].full = FALSE;
+ auth_mgr.auth_mapper[i].tpm_handle = 0;
+ auth_mgr.auth_mapper[i].tcs_ctx = 0;
LogDebug("released auth for TCS %x TPM %x", tcs_handle,
- auth_mgr.auth_mapper[i].tpm_handle);
+ auth_mgr.auth_mapper[i].tpm_handle);
+
auth_mgr_swap_in();
}
}
@@ -264,14 +265,22 @@ auth_mgr_release_auth_handle(TCS_AUTHHANDLE tpm_auth_handle, TCS_CONTEXT_HANDLE
auth_mgr.auth_mapper[i].tpm_handle == tpm_auth_handle &&
auth_mgr.auth_mapper[i].tcs_ctx == tcs_handle) {
if (!cont) {
- /* Only termininate when not in use anymore */
- result = TCSP_FlushSpecific_Common(auth_mgr.auth_mapper[i].tpm_handle,
- TPM_RT_AUTH);
+ /*
+ * This function should not be necessary, but
+ * if the main operation resulted in an error,
+ * the TPM may still hold the auth handle
+ * and it must be freed. Most of the time
+ * this call will result in TPM_E_INVALID_AUTHHANDLE
+ * error which can be ignored.
+ */
+ result = TCSP_FlushSpecific_Common(
+ auth_mgr.auth_mapper[i].tpm_handle,
+ TPM_RT_AUTH);
/* Ok, probably dealing with a 1.1 TPM */
if (result == TPM_E_BAD_ORDINAL)
- result = internal_TerminateHandle(
- auth_mgr.auth_mapper[i].tpm_handle);
+ result = internal_TerminateHandle(
+ auth_mgr.auth_mapper[i].tpm_handle);
if (result == TCPA_E_INVALID_AUTHHANDLE) {
LogDebug("Tried to close an invalid auth handle: %x",
@@ -279,12 +288,22 @@ auth_mgr_release_auth_handle(TCS_AUTHHANDLE tpm_auth_handle, TCS_CONTEXT_HANDLE
} else if (result != TCPA_SUCCESS) {
LogDebug("TPM_TerminateHandle returned %d", result);
}
+
+ if (result == TPM_SUCCESS) {
+ LogDebug("released auth for TCS %x TPM %x",
+ auth_mgr.auth_mapper[i].tcs_ctx, tpm_auth_handle);
+ }
+ /*
+ * Mark it as released, the "cont" flag indicates
+ * that it is no longer needed.
+ */
+ auth_mgr.open_auth_sessions--;
+ auth_mgr.auth_mapper[i].full = FALSE;
+ auth_mgr.auth_mapper[i].tpm_handle = 0;
+ auth_mgr.auth_mapper[i].tcs_ctx = 0;
+ auth_mgr_swap_in();
}
- auth_mgr.open_auth_sessions--;
- auth_mgr.auth_mapper[i].full = FALSE;
- LogDebug("released auth for TCS %x TPM %x",
- auth_mgr.auth_mapper[i].tcs_ctx, tpm_auth_handle);
- auth_mgr_swap_in();
+ /* If the cont flag is TRUE, we have to keep the handle */
}
}
@@ -368,7 +387,7 @@ auth_mgr_add(TCS_CONTEXT_HANDLE tcsContext, TCS_AUTHHANDLE tpm_auth_handle)
}
- LogDebugFn("Thread %zd growing the auth table to %u entries", THREAD_ID,
+ LogDebugFn("Thread %ld growing the auth table to %u entries", THREAD_ID,
auth_mgr.auth_mapper_size + TSS_DEFAULT_AUTH_TABLE_SIZE);
auth_mgr.auth_mapper = calloc(auth_mgr.auth_mapper_size +
@@ -563,4 +582,3 @@ TPM_LoadAuthContext(UINT32 size, BYTE *blob, TPM_AUTHHANDLE *handle)
return result;
}
-
« no previous file with comments | « src/tcs/rpc/tcstp/rpc_transport.c ('k') | src/tcs/tcs_evlog_biosem.c » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698