Skip to content

Commit

Permalink
evm: prevent racing during tfm allocation
Browse files Browse the repository at this point in the history
There is a small chance of racing during tfm allocation.
This patch fixes it.

Signed-off-by: Dmitry Kasatkin <[email protected]>
Acked-by: Mimi Zohar <[email protected]>
Signed-off-by: James Morris <[email protected]>
  • Loading branch information
Dmitry Kasatkin committed Dec 20, 2011
1 parent d21b594 commit 97426f9
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions security/integrity/evm/evm_crypto.c
Original file line number Diff line number Diff line change
Expand Up @@ -27,26 +27,35 @@ static int evmkey_len = MAX_KEY_SIZE;

struct crypto_shash *hmac_tfm;

static DEFINE_MUTEX(mutex);

static struct shash_desc *init_desc(void)
{
int rc;
struct shash_desc *desc;

if (hmac_tfm == NULL) {
mutex_lock(&mutex);
if (hmac_tfm)
goto out;
hmac_tfm = crypto_alloc_shash(evm_hmac, 0, CRYPTO_ALG_ASYNC);
if (IS_ERR(hmac_tfm)) {
pr_err("Can not allocate %s (reason: %ld)\n",
evm_hmac, PTR_ERR(hmac_tfm));
rc = PTR_ERR(hmac_tfm);
hmac_tfm = NULL;
mutex_unlock(&mutex);
return ERR_PTR(rc);
}
rc = crypto_shash_setkey(hmac_tfm, evmkey, evmkey_len);
if (rc) {
crypto_free_shash(hmac_tfm);
hmac_tfm = NULL;
mutex_unlock(&mutex);
return ERR_PTR(rc);
}
out:
mutex_unlock(&mutex);
}

desc = kmalloc(sizeof(*desc) + crypto_shash_descsize(hmac_tfm),
Expand Down

0 comments on commit 97426f9

Please sign in to comment.