From c113eec07fd51e1ade89f8c4b5348e31aa827a07 Mon Sep 17 00:00:00 2001 From: Yu'an Wang Date: Tue, 8 Jun 2021 21:22:48 +0800 Subject: [PATCH] crypto: hisilicon-hpre add req check when callback hulk inclusion category: Bugfix bugzilla: NA CVE: NA When running the hpre kernel state task, a ras error occurred. After the driver actively called back the incomplete task to recycle the sqe resources, the hardware wrote back the sqe and caused the kernel calltrace. Signed-off-by: Yu'an Wang Signed-off-by: Hui Tang Reviewed-by: Zibo Xu Signed-off-by: Yang Yingliang --- drivers/crypto/hisilicon/hpre/hpre.h | 1 + drivers/crypto/hisilicon/hpre/hpre_crypto.c | 10 +++++++++- drivers/crypto/hisilicon/hpre/hpre_main.c | 3 ++- 3 files changed, 12 insertions(+), 2 deletions(-) diff --git a/drivers/crypto/hisilicon/hpre/hpre.h b/drivers/crypto/hisilicon/hpre/hpre.h index 203eb2ac1e67..14d60b48afc1 100644 --- a/drivers/crypto/hisilicon/hpre/hpre.h +++ b/drivers/crypto/hisilicon/hpre/hpre.h @@ -32,6 +32,7 @@ enum hpre_dfx_dbgfs_file { HPRE_SEND_BUSY_CNT, HPRE_OVER_THRHLD_CNT, HPRE_OVERTIME_THRHLD, + HPRE_INVALID_REQ_CNT, HPRE_DFX_FILE_NUM }; diff --git a/drivers/crypto/hisilicon/hpre/hpre_crypto.c b/drivers/crypto/hisilicon/hpre/hpre_crypto.c index b68b30c886ad..5031d64789e6 100644 --- a/drivers/crypto/hisilicon/hpre/hpre_crypto.c +++ b/drivers/crypto/hisilicon/hpre/hpre_crypto.c @@ -414,9 +414,17 @@ static void hpre_rsa_cb(struct hpre_ctx *ctx, void *resp) static void hpre_alg_cb(struct hisi_qp *qp, void *resp) { struct hpre_ctx *ctx = qp->qp_ctx; + struct hpre_dfx *dfx = ctx->hpre->debug.dfx; struct hpre_sqe *sqe = resp; + struct hpre_asym_request *req = ctx->req_list[le16_to_cpu(sqe->tag)]; + + + if (unlikely(!req)) { + atomic64_inc(&dfx[HPRE_INVALID_REQ_CNT].value); + return; + } - ctx->req_list[le16_to_cpu(sqe->tag)]->cb(ctx, resp); + req->cb(ctx, resp); } static int hpre_ctx_init(struct hpre_ctx *ctx) diff --git a/drivers/crypto/hisilicon/hpre/hpre_main.c b/drivers/crypto/hisilicon/hpre/hpre_main.c index 22f623945b0b..6c5dc53c92fa 100644 --- a/drivers/crypto/hisilicon/hpre/hpre_main.c +++ b/drivers/crypto/hisilicon/hpre/hpre_main.c @@ -178,7 +178,8 @@ static const char *hpre_dfx_files[HPRE_DFX_FILE_NUM] = { "send_fail_cnt", "send_busy_cnt", "over_thrhld_cnt", - "overtime_thrhld" + "overtime_thrhld", + "invalid_req_cnt" }; #ifdef CONFIG_CRYPTO_QM_UACCE -- GitLab