anolis: crypto: iax: Fix deflate crash caused by global shared tfm
commit openanolis. ANBZ: #2423 When iax deflate calls fallback to generic deflate, they use the same global shared tfm: deflate_generic_tfm. This shared tfm makes a deflate fallback call crash. So fix it. Signed-off-by: Kun(llfl) <llfl@linux.alibaba.com> Link: https://gitee.com/anolis/cloud-kernel/pulls/774 Reviewed-by: Xiaochen Shen <xiaochen.shen@intel.com> Reviewed-by: Zelin Deng <zelin.deng@linux.alibaba.com> Signed-off-by: Xinghui Li <korantli@tencent.com>
This commit is contained in:
parent
97eaa88495
commit
6a87cc2e7b
|
@ -37,7 +37,33 @@ MODULE_PARM_DESC(iax_verify_compress,
|
|||
static LIST_HEAD(iax_devices);
|
||||
static DEFINE_SPINLOCK(iax_devices_lock);
|
||||
|
||||
static struct crypto_comp *deflate_generic_tfm;
|
||||
struct deflate_generic_ctx {
|
||||
struct crypto_comp *deflate_generic_tfm;
|
||||
};
|
||||
|
||||
static int iax_deflate_generic_init(struct crypto_tfm *tfm)
|
||||
{
|
||||
struct deflate_generic_ctx *ctx = crypto_tfm_ctx(tfm);
|
||||
struct crypto_comp *deflate_tfm;
|
||||
|
||||
if (crypto_has_comp("deflate-generic", 0, 0))
|
||||
deflate_tfm = crypto_alloc_comp("deflate-generic", 0, 0);
|
||||
|
||||
if (IS_ERR_OR_NULL(deflate_tfm)) {
|
||||
pr_err("IAX could not alloc %s tfm: errcode = %ld\n",
|
||||
"deflate-generic", PTR_ERR(deflate_tfm));
|
||||
return -ENOMEM;
|
||||
}
|
||||
ctx->deflate_generic_tfm = deflate_tfm;
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void iax_deflate_generic_exit(struct crypto_tfm *tfm)
|
||||
{
|
||||
struct deflate_generic_ctx *ctx = crypto_tfm_ctx(tfm);
|
||||
|
||||
crypto_free_comp(ctx->deflate_generic_tfm);
|
||||
}
|
||||
|
||||
static int iax_wqs_get(struct iax_device *iax_device)
|
||||
{
|
||||
|
@ -874,12 +900,13 @@ static int iax_comp_compress(struct crypto_tfm *tfm,
|
|||
const u8 *src, unsigned int slen,
|
||||
u8 *dst, unsigned int *dlen)
|
||||
{
|
||||
struct deflate_generic_ctx *ctx = crypto_tfm_ctx(tfm);
|
||||
u64 start_time_ns;
|
||||
int ret = 0;
|
||||
|
||||
if (!iax_crypto_enabled) {
|
||||
pr_debug("%s: iax_crypto disabled, using deflate-generic compression\n", __func__);
|
||||
ret = crypto_comp_compress(deflate_generic_tfm,
|
||||
ret = crypto_comp_compress(ctx->deflate_generic_tfm,
|
||||
src, slen, dst, dlen);
|
||||
return ret;
|
||||
}
|
||||
|
@ -900,12 +927,13 @@ static int iax_comp_decompress(struct crypto_tfm *tfm,
|
|||
const u8 *src, unsigned int slen,
|
||||
u8 *dst, unsigned int *dlen)
|
||||
{
|
||||
struct deflate_generic_ctx *ctx = crypto_tfm_ctx(tfm);
|
||||
u64 start_time_ns;
|
||||
int ret = 0;
|
||||
|
||||
if (!iax_crypto_enabled) {
|
||||
pr_debug("%s: iax_crypto disabled, using deflate-generic decompression\n", __func__);
|
||||
ret = crypto_comp_decompress(deflate_generic_tfm,
|
||||
ret = crypto_comp_decompress(ctx->deflate_generic_tfm,
|
||||
src, slen, dst, dlen);
|
||||
return ret;
|
||||
}
|
||||
|
@ -928,6 +956,9 @@ static struct crypto_alg iax_comp_deflate = {
|
|||
.cra_flags = CRYPTO_ALG_TYPE_COMPRESS,
|
||||
.cra_priority = IAX_ALG_PRIORITY,
|
||||
.cra_module = THIS_MODULE,
|
||||
.cra_ctxsize = sizeof(struct deflate_generic_ctx),
|
||||
.cra_init = iax_deflate_generic_init,
|
||||
.cra_exit = iax_deflate_generic_exit,
|
||||
.cra_u = {
|
||||
.compress = {
|
||||
.coa_compress = iax_comp_compress,
|
||||
|
@ -939,6 +970,7 @@ static struct crypto_alg iax_comp_deflate = {
|
|||
static int iax_comp_acompress(struct acomp_req *req)
|
||||
{
|
||||
struct crypto_tfm *tfm = req->base.tfm;
|
||||
struct deflate_generic_ctx *ctx = crypto_tfm_ctx(tfm);
|
||||
u64 start_time_ns;
|
||||
void *src, *dst;
|
||||
int ret = 0;
|
||||
|
@ -948,7 +980,7 @@ static int iax_comp_acompress(struct acomp_req *req)
|
|||
|
||||
if (!iax_crypto_enabled) {
|
||||
pr_debug("%s: iax_crypto disabled, using deflate-generic compression\n", __func__);
|
||||
ret = crypto_comp_compress(deflate_generic_tfm,
|
||||
ret = crypto_comp_compress(ctx->deflate_generic_tfm,
|
||||
src, req->slen, dst, &req->dlen);
|
||||
kunmap_atomic(src);
|
||||
kunmap_atomic(dst);
|
||||
|
@ -976,6 +1008,7 @@ static int iax_comp_acompress(struct acomp_req *req)
|
|||
static int iax_comp_adecompress(struct acomp_req *req)
|
||||
{
|
||||
struct crypto_tfm *tfm = req->base.tfm;
|
||||
struct deflate_generic_ctx *ctx = crypto_tfm_ctx(tfm);
|
||||
u64 start_time_ns;
|
||||
void *src, *dst;
|
||||
int ret;
|
||||
|
@ -985,7 +1018,7 @@ static int iax_comp_adecompress(struct acomp_req *req)
|
|||
|
||||
if (!iax_crypto_enabled) {
|
||||
pr_debug("%s: iax_crypto disabled, using deflate-generic decompression\n", __func__);
|
||||
ret = crypto_comp_decompress(deflate_generic_tfm,
|
||||
ret = crypto_comp_decompress(ctx->deflate_generic_tfm,
|
||||
src, req->slen, dst, &req->dlen);
|
||||
kunmap_atomic(src);
|
||||
kunmap_atomic(dst);
|
||||
|
@ -1016,6 +1049,9 @@ static struct acomp_alg iax_acomp_deflate = {
|
|||
.cra_name = "deflate",
|
||||
.cra_driver_name = "iax_crypto",
|
||||
.cra_module = THIS_MODULE,
|
||||
.cra_ctxsize = sizeof(struct deflate_generic_ctx),
|
||||
.cra_init = iax_deflate_generic_init,
|
||||
.cra_exit = iax_deflate_generic_exit,
|
||||
.cra_priority = IAX_ALG_PRIORITY,
|
||||
}
|
||||
};
|
||||
|
@ -1175,15 +1211,6 @@ static int __init iax_crypto_init_module(void)
|
|||
nr_cpus = num_online_cpus();
|
||||
nr_nodes = num_online_nodes();
|
||||
|
||||
if (crypto_has_comp("deflate-generic", 0, 0))
|
||||
deflate_generic_tfm = crypto_alloc_comp("deflate-generic", 0, 0);
|
||||
|
||||
if (IS_ERR_OR_NULL(deflate_generic_tfm)) {
|
||||
pr_err("IAX could not alloc %s tfm: errcode = %ld\n",
|
||||
"deflate-generic", PTR_ERR(deflate_generic_tfm));
|
||||
return -ENOMEM;
|
||||
}
|
||||
|
||||
wq_table = alloc_percpu(struct idxd_wq *);
|
||||
if (!wq_table)
|
||||
return -ENOMEM;
|
||||
|
@ -1211,7 +1238,6 @@ out:
|
|||
err_crypto_register:
|
||||
idxd_driver_unregister(&iax_crypto_driver);
|
||||
err_driver_register:
|
||||
crypto_free_comp(deflate_generic_tfm);
|
||||
free_percpu(wq_table);
|
||||
|
||||
goto out;
|
||||
|
@ -1224,7 +1250,6 @@ static void __exit iax_crypto_cleanup_module(void)
|
|||
iax_unregister_compression_device();
|
||||
free_percpu(wq_table);
|
||||
free_iax_devices();
|
||||
crypto_free_comp(deflate_generic_tfm);
|
||||
pr_info("%s: cleaned up\n", __func__);
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue