Skip to content

Commit d5af351

Browse files
ESYS: StartAuthSession bind auth trailing zeroes
When StartAuthSession is called with a bind entity with a auth value containing trailing zeroes, the HMAC or policy session computation of ESYS does not match the computation on the TPM2. The fix is to remove trailing zeroes from the auth value according to the specification (TPM2 Architecture, 19.6.5, Note 2) before computation of the session key. The fixed bug is especially tricky as a randomly generated auth value of the bind object can cause HMAC or policy session to fail occassionally. Signed-off-by: Stefan Thöni <stefan.thoeni@gapfruit.com>
1 parent a19ac4c commit d5af351

File tree

1 file changed

+16
-5
lines changed

1 file changed

+16
-5
lines changed

src/tss2-esys/api/Esys_StartAuthSession.c

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -458,8 +458,19 @@ Esys_StartAuthSession_Finish(
458458
size_t secret_size = 0;
459459
if (tpmKey != ESYS_TR_NONE)
460460
secret_size += keyHash_size;
461-
if (bind != ESYS_TR_NONE && bindNode != NULL)
462-
secret_size += bindNode->auth.size;
461+
size_t bind_auth_size = 0;
462+
if (bind != ESYS_TR_NONE && bindNode != NULL) {
463+
/*
464+
* TPM2.0 Architecture 19.6.5 Note 2
465+
*
466+
* Remove tailing zeroes from the auth value
467+
*/
468+
bind_auth_size = bindNode->auth.size;
469+
while ((bind_auth_size > 0) &&
470+
(bindNode->auth.buffer[bind_auth_size - 1] == 0x00))
471+
bind_auth_size--;
472+
secret_size += bind_auth_size;
473+
}
463474
/*
464475
* A non null pointer for secret is required by the subsequent functions,
465476
* hence a malloc is called with size 1 if secret_size is zero.
@@ -470,11 +481,11 @@ Esys_StartAuthSession_Finish(
470481
return TSS2_ESYS_RC_MEMORY;
471482
}
472483
if (bind != ESYS_TR_NONE && bindNode != NULL
473-
&& bindNode->auth.size > 0)
474-
memcpy(&secret[0], &bindNode->auth.buffer[0], bindNode->auth.size);
484+
&& bind_auth_size > 0)
485+
memcpy(&secret[0], &bindNode->auth.buffer[0], bind_auth_size);
475486
if (tpmKey != ESYS_TR_NONE)
476487
memcpy(&secret[(bind == ESYS_TR_NONE || bindNode == NULL) ? 0
477-
: bindNode->auth.size],
488+
: bind_auth_size],
478489
&esysContext->salt.buffer[0], keyHash_size);
479490
if (bind != ESYS_TR_NONE && bindNode != NULL)
480491
iesys_compute_bound_entity(&bindNode->rsrc.name,

0 commit comments

Comments
 (0)