summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTomasz Bursztyka <tomasz.bursztyka@linux.intel.com>2017-04-26 11:27:31 +0200
committerAnas Nashif <nashif@linux.intel.com>2017-04-27 13:06:34 +0000
commitdc646b5f2e18275850bc8d9fa05452509dac45cb (patch)
treed117d04db6504032f8c802002dbc5628adefd26b
parentaec8a03877230d5f870c24c38bda296c6faaad0f (diff)
drivers/crypto: Fix a memory leak in tc shim driver
If setting up crypto context fails enough times, the sessions will all end up "in use" though they will not. This will lock tc shim driver altogether and no crypto context will be possible to run on it. Change-Id: I72346854e52294f96afc32f30ac5bfd0c368812b Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
-rw-r--r--drivers/crypto/crypto_tc_shim.c22
1 files changed, 12 insertions, 10 deletions
diff --git a/drivers/crypto/crypto_tc_shim.c b/drivers/crypto/crypto_tc_shim.c
index 2eb953c31..7ef3522f9 100644
--- a/drivers/crypto/crypto_tc_shim.c
+++ b/drivers/crypto/crypto_tc_shim.c
@@ -180,16 +180,6 @@ int tc_session_setup(struct device *dev, struct cipher_ctx *ctx,
ARG_UNUSED(dev);
- idx = get_unused_session();
-
- if (idx == CRYPTO_MAX_SESSION) {
- SYS_LOG_ERR("Max sessions in progress");
- return -ENOSPC;
- }
-
- ctx->drv_sessn_state = &tc_driver_state[idx];
- data = &tc_driver_state[idx];
-
/* The shim currently supports only CBC or CTR mode for AES */
if (algo != CRYPTO_CIPHER_ALGO_AES) {
SYS_LOG_ERR("TC Shim Unsupported algo");
@@ -256,12 +246,24 @@ int tc_session_setup(struct device *dev, struct cipher_ctx *ctx,
ctx->ops.cipher_mode = mode;
+ idx = get_unused_session();
+ if (idx == CRYPTO_MAX_SESSION) {
+ SYS_LOG_ERR("Max sessions in progress");
+ return -ENOSPC;
+ }
+
+ data = &tc_driver_state[idx];
+
if (tc_aes128_set_encrypt_key(&data->session_key, ctx->key.bit_stream)
== TC_CRYPTO_FAIL) {
SYS_LOG_ERR("TC internal error in setting key");
+ tc_driver_state[idx].in_use = 0;
+
return -EIO;
}
+ ctx->drv_sessn_state = data;
+
return 0;
}