Skip to content

Commit

Permalink
crypto: qat - fix memory leak in RSA
Browse files Browse the repository at this point in the history
[ Upstream commit 80a52e1 ]

When an RSA key represented in form 2 (as defined in PKCS #1 V2.1) is
used, some components of the private key persist even after the TFM is
released.
Replace the explicit calls to free the buffers in qat_rsa_exit_tfm()
with a call to qat_rsa_clear_ctx() which frees all buffers referenced in
the TFM context.

Cc: stable@vger.kernel.org
Fixes: 879f77e ("crypto: qat - Add RSA CRT mode")
Signed-off-by: Giovanni Cabiddu <giovanni.cabiddu@intel.com>
Reviewed-by: Adam Guerin <adam.guerin@intel.com>
Reviewed-by: Wojciech Ziemba <wojciech.ziemba@intel.com>
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
Signed-off-by: Sasha Levin <sashal@kernel.org>
  • Loading branch information
gcabiddu authored and gregkh committed Jul 29, 2022
1 parent 2cb73f4 commit 0f967fd
Showing 1 changed file with 1 addition and 11 deletions.
12 changes: 1 addition & 11 deletions drivers/crypto/qat/qat_common/qat_asym_algs.c
Original file line number Diff line number Diff line change
Expand Up @@ -1257,18 +1257,8 @@ static void qat_rsa_exit_tfm(struct crypto_akcipher *tfm)
struct qat_rsa_ctx *ctx = akcipher_tfm_ctx(tfm);
struct device *dev = &GET_DEV(ctx->inst->accel_dev);

if (ctx->n)
dma_free_coherent(dev, ctx->key_sz, ctx->n, ctx->dma_n);
if (ctx->e)
dma_free_coherent(dev, ctx->key_sz, ctx->e, ctx->dma_e);
if (ctx->d) {
memset(ctx->d, '\0', ctx->key_sz);
dma_free_coherent(dev, ctx->key_sz, ctx->d, ctx->dma_d);
}
qat_rsa_clear_ctx(dev, ctx);
qat_crypto_put_instance(ctx->inst);
ctx->n = NULL;
ctx->e = NULL;
ctx->d = NULL;
}

static struct akcipher_alg rsa = {
Expand Down

0 comments on commit 0f967fd

Please sign in to comment.