aboutsummaryrefslogtreecommitdiff
path: root/ks.c
diff options
context:
space:
mode:
authorRob Austein <sra@hactrn.net>2017-05-30 19:52:32 -0400
committerRob Austein <sra@hactrn.net>2017-05-30 19:52:32 -0400
commit6b881dfa81a0d51d4897c62de5abdb94c1aba0b7 (patch)
tree379f49ff56a47011efff9e154e2a11216a4a2b3c /ks.c
parentb9188794e2634aa4918ba46298b88f03f2454dd4 (diff)
Hold keystore lock before calling keystore driver methods.
Most keystore methods already followed this rule, but hal_ks_*_init() and hal_ks_*_logout() were confused, in different ways.
Diffstat (limited to 'ks.c')
-rw-r--r--ks.c34
1 files changed, 26 insertions, 8 deletions
diff --git a/ks.c b/ks.c
index 92dc303..665a2fd 100644
--- a/ks.c
+++ b/ks.c
@@ -205,10 +205,19 @@ hal_error_t hal_ks_block_update(hal_ks_t *ks,
hal_error_t hal_ks_init(hal_ks_t *ks, const int alloc)
{
- return
- ks == NULL || ks->driver == NULL ? HAL_ERROR_BAD_ARGUMENTS :
- ks->driver->init == NULL ? HAL_ERROR_NOT_IMPLEMENTED :
- ks->driver->init(ks, alloc);
+ if (ks == NULL || ks->driver == NULL)
+ return HAL_ERROR_BAD_ARGUMENTS;
+
+ if (ks->driver->init == NULL)
+ return HAL_ERROR_NOT_IMPLEMENTED;
+
+ hal_ks_lock();
+
+ const hal_error_t err = ks->driver->init(ks, alloc);
+
+ hal_ks_unlock();
+
+ return err;
}
static inline void *gnaw(uint8_t **mem, size_t *len, const size_t size)
@@ -466,10 +475,19 @@ hal_error_t hal_ks_init_common(hal_ks_t *ks)
hal_error_t hal_ks_logout(hal_ks_t *ks, const hal_client_handle_t client)
{
- return
- ks == NULL || ks->driver == NULL ? HAL_ERROR_BAD_ARGUMENTS :
- ks->driver->logout == NULL ? HAL_ERROR_NOT_IMPLEMENTED :
- ks->driver->logout(ks, client);
+ if (ks == NULL || ks->driver == NULL)
+ return HAL_ERROR_BAD_ARGUMENTS;
+
+ if (ks->driver->logout == NULL)
+ return HAL_ERROR_NOT_IMPLEMENTED;
+
+ hal_ks_lock();
+
+ const hal_error_t err = ks->driver->logout(ks, client);
+
+ hal_ks_unlock();
+
+ return err;
}
/*