crypto: inside-secure - fix the invalidation step during cra_exit
authorAntoine Tenart <antoine.tenart@bootlin.com>
Tue, 13 Feb 2018 08:26:55 +0000 (09:26 +0100)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Fri, 25 May 2018 14:17:46 +0000 (16:17 +0200)
[ Upstream commit b7007dbccd92f7b8c00e590020bee542a48c6a2c ]

When exiting a transformation, the cra_exit() helper is called in each
driver providing one. The Inside Secure SafeXcel driver has one, which
is responsible of freeing some areas and of sending one invalidation
request to the crypto engine, to invalidate the context that was used
during the transformation.

We could see in some setups (when lots of transformations were being
used with a short lifetime, and hence lots of cra_exit() calls) NULL
pointer dereferences and other weird issues. All these issues were
coming from accessing the tfm context.

The issue is the invalidation request completion is checked using a
wait_for_completion_interruptible() call in both the cipher and hash
cra_exit() helpers. In some cases this was interrupted while the
invalidation request wasn't processed yet. And then cra_exit() returned,
and its caller was freeing the tfm instance. Only then the request was
being handled by the SafeXcel driver, which lead to the said issues.

This patch fixes this by using wait_for_completion() calls in these
specific cases.

Fixes: 1b44c5a60c13 ("crypto: inside-secure - add SafeXcel EIP197 crypto engine driver")
Signed-off-by: Antoine Tenart <antoine.tenart@bootlin.com>
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
Signed-off-by: Sasha Levin <alexander.levin@microsoft.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
drivers/crypto/inside-secure/safexcel_cipher.c
drivers/crypto/inside-secure/safexcel_hash.c

index fcc0a606d74839bb46f2af6d0ac66bdb12b3d511..29cf7e00b574378e6cbbc7aa0357a4b9180f3a20 100644 (file)
@@ -446,7 +446,7 @@ static int safexcel_cipher_exit_inv(struct crypto_tfm *tfm)
        if (!priv->ring[ring].need_dequeue)
                safexcel_dequeue(priv, ring);
 
-       wait_for_completion_interruptible(&result.completion);
+       wait_for_completion(&result.completion);
 
        if (result.error) {
                dev_warn(priv->dev,
index ca84d82dcc0254a3d6748a6de4c60aec284af83f..69f29776591a40b97d26b4ea8ab224aa88ecd684 100644 (file)
@@ -494,7 +494,7 @@ static int safexcel_ahash_exit_inv(struct crypto_tfm *tfm)
        if (!priv->ring[ring].need_dequeue)
                safexcel_dequeue(priv, ring);
 
-       wait_for_completion_interruptible(&result.completion);
+       wait_for_completion(&result.completion);
 
        if (result.error) {
                dev_warn(priv->dev, "hash: completion error (%d)\n",