Skip to content

Commit 80a52e1

Browse files
gcabidduherbertx
authored andcommitted
crypto: qat - fix memory leak in RSA
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>
1 parent 3868238 commit 80a52e1

1 file changed

Lines changed: 1 addition & 11 deletions

File tree

drivers/crypto/qat/qat_common/qat_asym_algs.c

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1257,18 +1257,8 @@ static void qat_rsa_exit_tfm(struct crypto_akcipher *tfm)
12571257
struct qat_rsa_ctx *ctx = akcipher_tfm_ctx(tfm);
12581258
struct device *dev = &GET_DEV(ctx->inst->accel_dev);
12591259

1260-
if (ctx->n)
1261-
dma_free_coherent(dev, ctx->key_sz, ctx->n, ctx->dma_n);
1262-
if (ctx->e)
1263-
dma_free_coherent(dev, ctx->key_sz, ctx->e, ctx->dma_e);
1264-
if (ctx->d) {
1265-
memset(ctx->d, '\0', ctx->key_sz);
1266-
dma_free_coherent(dev, ctx->key_sz, ctx->d, ctx->dma_d);
1267-
}
1260+
qat_rsa_clear_ctx(dev, ctx);
12681261
qat_crypto_put_instance(ctx->inst);
1269-
ctx->n = NULL;
1270-
ctx->e = NULL;
1271-
ctx->d = NULL;
12721262
}
12731263

12741264
static struct akcipher_alg rsa = {

0 commit comments

Comments
 (0)