Skip to content

Commit 167eded

Browse files
committed
Fix dangling pointer issue
This fixes an issue with the handling of the nonce field when opening authentication sessions. The ESYS layer expects either a pointer to a valid nonce of at least 16 bytes, or NULL if no nonce is provided. Our handling, however, passed down an invalid pointer that was referencing a now-defunct structure. What happened, both before #340 and after, was that the `Nonce` input was moved into a separate scope, either a `match` or a lambda function, then converted to `TPM2B_NONCE`. A reference to this `TPM2B_NONCE` was taken and converted to `*const TPM2B_NONCE`, which was passed outside of the scope. The pointer, therefore, ended up referencing a structure that was dropped at the end of that inner scope. To ensure memory safety, we need to keep ownership of the `TPM2B_NONCE` while the call is being made. Signed-off-by: Ionut Mihalcea <[email protected]>
1 parent 2ffedac commit 167eded

File tree

1 file changed

+2
-1
lines changed

1 file changed

+2
-1
lines changed

tss-esapi/src/context/tpm_commands/session_commands.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ impl Context {
5959
auth_hash: HashingAlgorithm,
6060
) -> Result<Option<AuthSession>> {
6161
let mut session_handle = ObjectHandle::None.into();
62+
let potential_tpm2b_nonce = nonce.map(|v| v.into());
6263
let ret = unsafe {
6364
Esys_StartAuthSession(
6465
self.mut_context(),
@@ -70,7 +71,7 @@ impl Context {
7071
self.optional_session_1(),
7172
self.optional_session_2(),
7273
self.optional_session_3(),
73-
nonce.map_or_else(null, |v| &v.into()),
74+
potential_tpm2b_nonce.as_ref().map_or_else(null, |v| v),
7475
session_type.into(),
7576
&symmetric.try_into()?,
7677
auth_hash.into(),

0 commit comments

Comments
 (0)