Merge pull request #9280 from valeriosetti/psasim-reset-slots-on-disconnection

psasim-server: add function to reset operations slots
This commit is contained in:
Tom Cosgrove 2024-06-19 11:10:52 +01:00 committed by GitHub
commit 150b88c9d2
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
6 changed files with 65 additions and 0 deletions

View File

@ -2314,3 +2314,8 @@ psa_status_t psa_crypto_call(psa_msg_t msg)
return ok ? PSA_SUCCESS : PSA_ERROR_GENERIC_ERROR;
}
void psa_crypto_close(void)
{
psa_sim_serialize_reset();
}

View File

@ -242,6 +242,16 @@ EOF
return ok ? PSA_SUCCESS : PSA_ERROR_GENERIC_ERROR;
}
EOF
# Finally, add psa_crypto_close()
print $fh <<EOF;
void psa_crypto_close(void)
{
psa_sim_serialize_reset();
}
EOF
close($fh);

View File

@ -713,3 +713,11 @@ int psasim_deserialise_mbedtls_svc_key_id_t(uint8_t **pos,
return 1;
}
void psa_sim_serialize_reset(void)
{
memset(hash_operation_handles, 0, sizeof(hash_operation_handles));
memset(hash_operations, 0, sizeof(hash_operations));
memset(aead_operation_handles, 0, sizeof(aead_operation_handles));
memset(aead_operations, 0, sizeof(aead_operations));
}

View File

@ -54,6 +54,12 @@
* don't contain pointers.
*/
/** Reset all operation slots.
*
* Should be called when all clients have disconnected.
*/
void psa_sim_serialize_reset(void);
/** Return how much buffer space is needed by \c psasim_serialise_begin().
*
* \return The number of bytes needed in the buffer for

View File

@ -105,6 +105,7 @@ if ($which eq "h") {
}
}
print define_server_serialize_reset(@types);
} else {
die("internal error - shouldn't happen");
}
@ -329,6 +330,12 @@ sub h_header
* don't contain pointers.
*/
/** Reset all operation slots.
*
* Should be called when all clients have disconnected.
*/
void psa_sim_serialize_reset(void);
/** Return how much buffer space is needed by \c psasim_serialise_begin().
*
* \return The number of bytes needed in the buffer for
@ -913,6 +920,33 @@ int psasim_deserialise_begin(uint8_t **pos, size_t *remaining)
EOF
}
# Return the code for psa_sim_serialize_reset()
sub define_server_serialize_reset
{
my @types = @_;
my $code = <<EOF;
void psa_sim_serialize_reset(void)
{
EOF
for my $type (@types) {
next unless $type =~ /^psa_(\w+_operation)_t$/;
my $what = $1; # e.g. "hash_operation"
$code .= <<EOF;
memset(${what}_handles, 0, sizeof(${what}_handles));
memset(${what}s, 0, sizeof(${what}s));
EOF
}
$code .= <<EOF;
}
EOF
}
# Horrible way to align first, second and third lines of function signature to
# appease uncrustify (these are the 2nd-4th lines of code, indices 1, 2 and 3)
#

View File

@ -54,6 +54,7 @@ int psa_server_main(int argc, char *argv[])
int client_disconnected = 0;
char mbedtls_version[18];
extern psa_status_t psa_crypto_call(psa_msg_t msg);
extern psa_status_t psa_crypto_close(void);
mbedtls_version_get_string_full(mbedtls_version);
SERVER_PRINT("%s", mbedtls_version);
@ -81,6 +82,7 @@ int psa_server_main(int argc, char *argv[])
SERVER_PRINT("Got a disconnection message");
ret = PSA_SUCCESS;
client_disconnected = 1;
psa_crypto_close();
break;
default:
SERVER_PRINT("Got an IPC call of type %d", msg.type);