Skip to content

Commit 684bd54

Browse files
gcabiddugregkh
authored andcommitted
crypto: qat - fix compression instance leak
[ Upstream commit 795c24c ] qat_comp_alg_init_tfm() acquires a compression instance via qat_compression_get_instance_node() before calling qat_comp_build_ctx() to initialize the compression context. If qat_comp_build_ctx() fails, the function returns an error without releasing the compression instance, causing a resource leak. When qat_comp_build_ctx() fails, release the compression instance with qat_compression_put_instance() and clear the context to avoid leaving a stale reference to the released instance. The issue was introduced when build_deflate_ctx() (which always returned void) was replaced by qat_comp_build_ctx() (which can return an error) without adding error handling for the failure path. Fixes: cd0e716 ("crypto: qat - refactor compression template logic") Signed-off-by: Giovanni Cabiddu <giovanni.cabiddu@intel.com> Reviewed-by: Laurent M Coquerel <laurent.m.coquerel@intel.com> Reviewed-by: Ahsan Atta <ahsan.atta@intel.com> Reviewed-by: Wojciech Drewek <wojciech.drewek@linux.intel.com> Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au> Signed-off-by: Sasha Levin <sashal@kernel.org>
1 parent 06b30be commit 684bd54

1 file changed

Lines changed: 8 additions & 2 deletions

File tree

drivers/crypto/intel/qat/qat_common/qat_comp_algs.c

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ static int qat_comp_alg_init_tfm(struct crypto_acomp *acomp_tfm)
133133
struct crypto_tfm *tfm = crypto_acomp_tfm(acomp_tfm);
134134
struct qat_compression_ctx *ctx = crypto_tfm_ctx(tfm);
135135
struct qat_compression_instance *inst;
136-
int node;
136+
int node, ret;
137137

138138
if (tfm->node == NUMA_NO_NODE)
139139
node = numa_node_id();
@@ -146,7 +146,13 @@ static int qat_comp_alg_init_tfm(struct crypto_acomp *acomp_tfm)
146146
return -EINVAL;
147147
ctx->inst = inst;
148148

149-
return qat_comp_build_ctx(inst->accel_dev, ctx->comp_ctx, QAT_DEFLATE);
149+
ret = qat_comp_build_ctx(inst->accel_dev, ctx->comp_ctx, QAT_DEFLATE);
150+
if (ret) {
151+
qat_compression_put_instance(inst);
152+
memset(ctx, 0, sizeof(*ctx));
153+
}
154+
155+
return ret;
150156
}
151157

152158
static void qat_comp_alg_exit_tfm(struct crypto_acomp *acomp_tfm)

0 commit comments

Comments
 (0)