From: Ruibin Deng <dengruibin@h-partners.com> This patch series includes 8 bugfix and cleanup patches. Bugfixes address input validation, argument order, scheduling while atomic, memory leak, a nd GFP flag issues. Cleanups remove misleading logs and unused dead code. Chenghai Huang (2): crypto: hisilicon/zip - reject multi-entrant src in fallback and oversized lz4 input crypto: hisilicon/qm - remove misleading log in hisi_qm_alloc_qps_node Wenkai Lin (5): crypto: hisilicon/qm - fix devm_kcalloc argument order crypto: hisilicon/sec2 - fix scheduling while atomic in aead soft fallback crypto: hisilicon/qm - fix memory leak in hisi_qm_sort_devices crypto: hisilicon/qm - fix GFP flag inconsistency in hisi_qm_memory_init crypto: hisilicon/zip - fix scheduling while atomic in backlog soft fallback lizhi (1): crypto: hisilicon/sec2 - remove unused req_list dead code in BD_TYPE2 path drivers/crypto/hisilicon/qm.c | 12 +++--- drivers/crypto/hisilicon/sec2/sec.h | 2 - drivers/crypto/hisilicon/sec2/sec_crypto.c | 19 +--------- drivers/crypto/hisilicon/zip/zip_crypto.c | 43 +++++++++++++++++----- 4 files changed, 41 insertions(+), 35 deletions(-) -- 2.43.0
From: Chenghai Huang <huangchenghai2@huawei.com> driver inclusion category: bugfix bugzilla: https://atomgit.com/openeuler/kernel/issues/10368 CVE: NA ---------------------------------------------------------------------- Add two input guards to the zip acomp path: 1. In hisi_zip_fallback_do_work, reject requests whose src scatterlist has more than one entry, mirroring iaa_comp_acompress which only handles a single contiguous src buffer. The software fallback via ACOMP_FBREQ_ON_STACK hands the original src/dst sg list to the sync tfm, so a multi-entry src is not supported there. 2. In hisi_zip_acompress, reject lz4 (hisi-lz4-acomp) requests whose input exceeds 1 MiB (HZIP_MAX_INPUT_LEN). hisi_zip_acompress is shared by the deflate and lz4 acomp algorithms, so the limit is applied only when the tfm algorithm name is "lz4". Both paths return -EINVAL on rejection. Fixes: 276305d6332a ("crypto: hisilicon/zip - add backlog support for zip") Signed-off-by: Chenghai Huang <huangchenghai2@huawei.com> Signed-off-by: Ruibin Deng <dengruibin@h-partners.com> --- drivers/crypto/hisilicon/zip/zip_crypto.c | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/drivers/crypto/hisilicon/zip/zip_crypto.c b/drivers/crypto/hisilicon/zip/zip_crypto.c index 7603a07d7e55..745d6785ccdc 100644 --- a/drivers/crypto/hisilicon/zip/zip_crypto.c +++ b/drivers/crypto/hisilicon/zip/zip_crypto.c @@ -26,6 +26,7 @@ #define HZIP_ALG_PRIORITY 80 #define HZIP_SGL_SGE_NR 10 +#define HZIP_MAX_INPUT_LEN ((u32)0x100000) #define HZIP_ALG_DEFLATE GENMASK(5, 4) #define HZIP_ALG_LZ4 BIT(8) @@ -130,6 +131,12 @@ static int hisi_zip_fallback_do_work(struct crypto_comp *tfm, struct acomp_req * if (!tfm) return -EINVAL; + /* The software fallback expects single contiguous src/dst buffers */ + if (sg_nents(acomp_req->src) > 1 || sg_nents(acomp_req->dst) > 1) { + pr_err("failed to do fallback work, scatter src/dst nents > 1\n"); + return -EINVAL; + } + input = kmap_local_page(sg_page(acomp_req->src)) + acomp_req->src->offset; output = kmap_local_page(sg_page(acomp_req->dst)) + acomp_req->dst->offset; @@ -443,6 +450,7 @@ static int hisi_zip_do_comp(struct hisi_zip_req *req, bool is_decompress) struct acomp_req *acomp_req = req->req; struct hisi_zip_ctx *ctx = crypto_tfm_ctx(acomp_req->base.tfm); struct hisi_qp *qp = req->qp_ctx->qp; + struct device *dev; int ret; if (unlikely(!acomp_req->src || !acomp_req->slen || @@ -453,6 +461,15 @@ static int hisi_zip_do_comp(struct hisi_zip_req *req, bool is_decompress) return hisi_zip_fallback_do_work(ctx->soft_tfm, acomp_req, is_decompress); + dev = &qp->qm->pdev->dev; + + if (req->qp_ctx->req_type == HZIP_ALG_TYPE_LZ4 && + acomp_req->slen > HZIP_MAX_INPUT_LEN) { + dev_info_ratelimited(dev, "input len %u exceeds the limit %u\n", + acomp_req->slen, HZIP_MAX_INPUT_LEN); + return -EINVAL; + } + /* Check whether any request is being queued */ if ((acomp_req->base.flags & CRYPTO_TFM_REQ_MAY_BACKLOG) && !list_empty(&qp->backlog.list)) { @@ -480,8 +497,7 @@ static int hisi_zip_do_comp(struct hisi_zip_req *req, bool is_decompress) /* hardwre busy add to backlog list */ hisi_zip_enqueue_backlog(req); } else if (unlikely(ret != -EINPROGRESS)) { - dev_info_ratelimited(&qp->qm->pdev->dev, - "failed to do %scompress (%d)!\n", + dev_info_ratelimited(dev, "failed to do %scompress (%d)!\n", qp->alg_type ? "de" : "", ret); ret = -ENOSPC; goto unmap_req; -- 2.43.0
From: Chenghai Huang <huangchenghai2@huawei.com> driver inclusion category: cleanup bugzilla: https://atomgit.com/openeuler/kernel/issues/10368 CVE: NA ---------------------------------------------------------------------- crypto testmgr runs algorithm tests concurrently. When pf_q_num is configured small, hardware queue allocation may transiently fail and print "Failed to create qps", which users misread as a self-test failure. Remove the misleading log; the error code stays for real callers. Signed-off-by: Chenghai Huang <huangchenghai2@huawei.com> Signed-off-by: Ruibin Deng <dengruibin@h-partners.com> --- drivers/crypto/hisilicon/qm.c | 3 --- 1 file changed, 3 deletions(-) diff --git a/drivers/crypto/hisilicon/qm.c b/drivers/crypto/hisilicon/qm.c index 67201faf3cbc..636f1886aa8f 100644 --- a/drivers/crypto/hisilicon/qm.c +++ b/drivers/crypto/hisilicon/qm.c @@ -3978,9 +3978,6 @@ int hisi_qm_alloc_qps_node(struct hisi_qm_list *qm_list, int qp_num, } mutex_unlock(&qm_list->lock); - if (ret) - pr_info("Failed to create qps, node[%d], qp[%d]!\n", - node, qp_num); err: free_list(&head); -- 2.43.0
From: lizhi <lizhi206@huawei.com> driver inclusion category: cleanup bugzilla: https://atomgit.com/openeuler/kernel/issues/10368 CVE: NA ---------------------------------------------------------------------- Remove dead code from the SEC2 BD_TYPE2 submission path. The req_list pointer array, send_head ring cursor and the sec_sqe.type2.tag write were populated on send but never read back on completion. The BD_TYPE2 completion callback sec_req_cb recovers the request via container_of on qp->msg[cq_head] and does not consume the tag or req_list, so these writes and the per-queue kcalloc(q_depth, sizeof(struct sec_req *)) allocation were pure overhead. Drop the unused fields and their write sites to save memory per queue and avoid future maintenance confusion. Signed-off-by: lizhi <lizhi206@huawei.com> Signed-off-by: Ruibin Deng <dengruibin@h-partners.com> --- drivers/crypto/hisilicon/sec2/sec.h | 2 -- drivers/crypto/hisilicon/sec2/sec_crypto.c | 17 +---------------- 2 files changed, 1 insertion(+), 18 deletions(-) diff --git a/drivers/crypto/hisilicon/sec2/sec.h b/drivers/crypto/hisilicon/sec2/sec.h index c12a39a8a9d4..9e33dbf371ef 100644 --- a/drivers/crypto/hisilicon/sec2/sec.h +++ b/drivers/crypto/hisilicon/sec2/sec.h @@ -158,7 +158,6 @@ struct sec_cipher_ctx { /* SEC queue context which defines queue's relatives */ struct sec_qp_ctx { struct hisi_qp *qp; - struct sec_req **req_list; struct idr req_idr; struct sec_alg_res *res; struct sec_ctx *ctx; @@ -166,7 +165,6 @@ struct sec_qp_ctx { spinlock_t id_lock; struct hisi_acc_sgl_pool *c_in_pool; struct hisi_acc_sgl_pool *c_out_pool; - u16 send_head; }; enum sec_alg_type { diff --git a/drivers/crypto/hisilicon/sec2/sec_crypto.c b/drivers/crypto/hisilicon/sec2/sec_crypto.c index 2d22860c030a..cf3e76b10eeb 100644 --- a/drivers/crypto/hisilicon/sec2/sec_crypto.c +++ b/drivers/crypto/hisilicon/sec2/sec_crypto.c @@ -214,18 +214,11 @@ static int qp_send_message(struct sec_req *req) return -EBUSY; } - if (qp_ctx->ctx->type_supported == SEC_BD_TYPE2) { - req->sec_sqe.type2.tag = cpu_to_le16((u16)qp_ctx->send_head); - qp_ctx->req_list[qp_ctx->send_head] = req; - } - ret = hisi_qp_send(qp_ctx->qp, &req->sec_sqe); if (ret) { spin_unlock_bh(&qp_ctx->req_lock); return ret; } - if (qp_ctx->ctx->type_supported == SEC_BD_TYPE2) - qp_ctx->send_head = (qp_ctx->send_head + 1) % qp_ctx->qp->sq_depth; spin_unlock_bh(&qp_ctx->req_lock); @@ -574,13 +567,9 @@ static int sec_alloc_qp_ctx_resource(struct sec_ctx *ctx, struct sec_qp_ctx *qp_ struct device *dev = ctx->dev; int ret = -ENOMEM; - qp_ctx->req_list = kcalloc(q_depth, sizeof(struct sec_req *), GFP_KERNEL); - if (!qp_ctx->req_list) - return ret; - qp_ctx->res = kcalloc(q_depth, sizeof(struct sec_alg_res), GFP_KERNEL); if (!qp_ctx->res) - goto err_free_req_list; + return ret; qp_ctx->res->depth = q_depth; qp_ctx->c_in_pool = hisi_acc_create_sgl_pool(dev, q_depth, SEC_SGL_SGE_NR); @@ -607,8 +596,6 @@ static int sec_alloc_qp_ctx_resource(struct sec_ctx *ctx, struct sec_qp_ctx *qp_ hisi_acc_free_sgl_pool(dev, qp_ctx->c_in_pool); err_free_res: kfree(qp_ctx->res); -err_free_req_list: - kfree(qp_ctx->req_list); return ret; } @@ -620,7 +607,6 @@ static void sec_free_qp_ctx_resource(struct sec_ctx *ctx, struct sec_qp_ctx *qp_ hisi_acc_free_sgl_pool(dev, qp_ctx->c_out_pool); hisi_acc_free_sgl_pool(dev, qp_ctx->c_in_pool); kfree(qp_ctx->res); - kfree(qp_ctx->req_list); } static int sec_create_qp_ctx(struct sec_ctx *ctx, int qp_ctx_id) @@ -642,7 +628,6 @@ static int sec_create_qp_ctx(struct sec_ctx *ctx, int qp_ctx_id) spin_lock_init(&qp_ctx->req_lock); idr_init(&qp_ctx->req_idr); spin_lock_init(&qp_ctx->id_lock); - qp_ctx->send_head = 0; ret = sec_alloc_qp_ctx_resource(ctx, qp_ctx); if (ret) -- 2.43.0
From: Wenkai Lin <linwenkai6@hisilicon.com> driver inclusion category: bugfix bugzilla: https://atomgit.com/openeuler/kernel/issues/10368 CVE: NA ---------------------------------------------------------------------- The n and size arguments of devm_kcalloc in qm_pre_store_caps() are swapped. Fix the order to match the kcalloc(n, size, flags) convention. Fixes: 5a981b9ed12b ("crypto: hisilicon/qm - replace devm_kzalloc with devm_kcalloc") Signed-off-by: Wenkai Lin <linwenkai6@hisilicon.com> Signed-off-by: Ruibin Deng <dengruibin@h-partners.com> --- drivers/crypto/hisilicon/qm.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/crypto/hisilicon/qm.c b/drivers/crypto/hisilicon/qm.c index 636f1886aa8f..be8234664def 100644 --- a/drivers/crypto/hisilicon/qm.c +++ b/drivers/crypto/hisilicon/qm.c @@ -5909,7 +5909,7 @@ static int qm_pre_store_caps(struct hisi_qm *qm) size_t i, size; size = ARRAY_SIZE(qm_cap_query_info); - qm_cap = devm_kcalloc(&pdev->dev, sizeof(*qm_cap), size, GFP_KERNEL); + qm_cap = devm_kcalloc(&pdev->dev, size, sizeof(*qm_cap), GFP_KERNEL); if (!qm_cap) return -ENOMEM; -- 2.43.0
From: Wenkai Lin <linwenkai6@hisilicon.com> driver inclusion category: bugfix bugzilla: https://atomgit.com/openeuler/kernel/issues/10368 CVE: NA ---------------------------------------------------------------------- sec_aead_soft_crypto() allocates the sub-request with GFP_KERNEL, which may sleep. This is safe when called directly from sec_aead_crypto() (process context), but the function is also reachable through the backlog drain path. When an AEAD request sits in the backlog queue and qp_send_message() returns a non-EBUSY error, the backlog is drained in software while the backlog spinlock is still held. The GFP_KERNEL allocation inside aead_request_alloc() can then schedule out, triggering scheduling while atomic. Fix it by switching the allocation to GFP_ATOMIC so it is safe in both the process-context path and the spinlock-held backlog drain path. Fixes: 0a2a464f8631 ("crypto: hisilicon/sec - fix the aead software fallback for engine") Signed-off-by: Wenkai Lin <linwenkai6@hisilicon.com> Signed-off-by: Ruibin Deng <dengruibin@h-partners.com> --- drivers/crypto/hisilicon/sec2/sec_crypto.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/crypto/hisilicon/sec2/sec_crypto.c b/drivers/crypto/hisilicon/sec2/sec_crypto.c index cf3e76b10eeb..86aa3b5b69e8 100644 --- a/drivers/crypto/hisilicon/sec2/sec_crypto.c +++ b/drivers/crypto/hisilicon/sec2/sec_crypto.c @@ -2515,7 +2515,7 @@ static int sec_aead_soft_crypto(struct sec_ctx *ctx, struct aead_request *subreq; int ret; - subreq = aead_request_alloc(a_ctx->fallback_aead_tfm, GFP_KERNEL); + subreq = aead_request_alloc(a_ctx->fallback_aead_tfm, GFP_ATOMIC); if (!subreq) return -ENOMEM; -- 2.43.0
From: Wenkai Lin <linwenkai6@hisilicon.com> driver inclusion category: bugfix bugzilla: https://atomgit.com/openeuler/kernel/issues/10368 CVE: NA ---------------------------------------------------------------------- hisi_qm_sort_devices() allocates a struct hisi_qm_resource for each QM device and inserts it into one of two local lists (non_full_list or full_list). If kzalloc() fails mid-loop, the function returns -ENOMEM immediately without freeing the resources already inserted into the local lists. Because the splice into the caller's @head list happens only after the loop completes, the caller's free_list(&head) cannot reclaim them — the already-allocated res entries are lost. Fix by freeing both local lists before returning -ENOMEM. Fixes: 3f1ec97aacf1 ("crypto: hisilicon/qm - Put device finding logic into QM") Signed-off-by: Wenkai Lin <linwenkai6@hisilicon.com> Signed-off-by: Ruibin Deng <dengruibin@h-partners.com> --- drivers/crypto/hisilicon/qm.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/drivers/crypto/hisilicon/qm.c b/drivers/crypto/hisilicon/qm.c index be8234664def..6fa8c08e9e7e 100644 --- a/drivers/crypto/hisilicon/qm.c +++ b/drivers/crypto/hisilicon/qm.c @@ -3925,8 +3925,11 @@ static int hisi_qm_sort_devices(int node, struct list_head *head, dev_node = 0; res = kzalloc(sizeof(*res), GFP_KERNEL); - if (!res) + if (!res) { + free_list(&non_full_list); + free_list(&full_list); return -ENOMEM; + } res->qm = qm; res->distance = node_distance(dev_node, node); -- 2.43.0
From: Wenkai Lin <linwenkai6@hisilicon.com> driver inclusion category: bugfix bugzilla: https://atomgit.com/openeuler/kernel/issues/10368 CVE: NA ---------------------------------------------------------------------- hisi_qm_memory_init() is called from hisi_qm_init() (process context) but uses GFP_ATOMIC for dma_alloc_coherent(). The equivalent allocation in qm_alloc_xqc_dma() uses GFP_KERNEL. Switch to GFP_KERNEL for consistency. Fixes: 5308f6600a39 ("crypto: hisilicon - QM memory management optimization") Signed-off-by: Wenkai Lin <linwenkai6@hisilicon.com> Signed-off-by: Ruibin Deng <dengruibin@h-partners.com> --- drivers/crypto/hisilicon/qm.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/crypto/hisilicon/qm.c b/drivers/crypto/hisilicon/qm.c index 6fa8c08e9e7e..1028d8f44dd8 100644 --- a/drivers/crypto/hisilicon/qm.c +++ b/drivers/crypto/hisilicon/qm.c @@ -6221,7 +6221,7 @@ static int hisi_qm_memory_init(struct hisi_qm *qm) QMC_ALIGN(sizeof(struct qm_sqc) * qm->qp_num) + QMC_ALIGN(sizeof(struct qm_cqc) * qm->qp_num); qm->qdma.va = dma_alloc_coherent(dev, qm->qdma.size, &qm->qdma.dma, - GFP_ATOMIC); + GFP_KERNEL); dev_dbg(dev, "allocate qm dma buf size=%zx)\n", qm->qdma.size); if (!qm->qdma.va) { ret = -ENOMEM; -- 2.43.0
From: Wenkai Lin <linwenkai6@hisilicon.com> driver inclusion category: bugfix bugzilla: https://atomgit.com/openeuler/kernel/issues/10368 CVE: NA ---------------------------------------------------------------------- hisi_zip_send_backlog() calls hisi_zip_send_backlog_soft() while holding qp->backlog.lock (spinlock_bh). The soft fallback path runs crypto_comp_compress/decompress which may sleep internally, causing scheduling while atomic. Splice the remaining backlog list into a local list under the lock, unlock, then run the soft fallback on the local list without holding the spinlock. Fixes: 276305d6332a ("crypto: hisilicon/zip - add backlog support for zip") Signed-off-by: Wenkai Lin <linwenkai6@hisilicon.com> Signed-off-by: Ruibin Deng <dengruibin@h-partners.com> --- drivers/crypto/hisilicon/zip/zip_crypto.c | 23 +++++++++++++++-------- 1 file changed, 15 insertions(+), 8 deletions(-) diff --git a/drivers/crypto/hisilicon/zip/zip_crypto.c b/drivers/crypto/hisilicon/zip/zip_crypto.c index 745d6785ccdc..03473a3aea13 100644 --- a/drivers/crypto/hisilicon/zip/zip_crypto.c +++ b/drivers/crypto/hisilicon/zip/zip_crypto.c @@ -335,14 +335,15 @@ static int hisi_zip_do_work(struct hisi_zip_req *req) return ret; } -static void hisi_zip_send_backlog_soft(struct hisi_zip_qp_ctx *qp_ctx) +static void hisi_zip_send_backlog_soft(struct hisi_zip_qp_ctx *qp_ctx, + struct list_head *head) { struct hisi_zip_ctx *ctx = qp_ctx->ctx; bool is_decomp = qp_ctx->qp->alg_type; struct hisi_zip_req *req, *tmp; int ret; - list_for_each_entry_safe(req, tmp, &qp_ctx->qp->backlog.list, list) { + list_for_each_entry_safe(req, tmp, head, list) { list_del(&req->list); if (req->req_id != HZIP_INVAL_REQ_ID) { @@ -364,12 +365,12 @@ static void hisi_zip_send_backlog_soft(struct hisi_zip_qp_ctx *qp_ctx) static void hisi_zip_send_backlog(struct hisi_qp *qp) { struct hisi_zip_req *req, *tmp; - struct hisi_zip_req_q *req_q; + struct hisi_zip_qp_ctx *qp_ctx = NULL; + LIST_HEAD(soft_list); int ret; spin_lock_bh(&qp->backlog.lock); list_for_each_entry_safe(req, tmp, &qp->backlog.list, list) { - req_q = &req->qp_ctx->req_q; if (req->req_id == HZIP_INVAL_REQ_ID) { ret = hisi_zip_create_req(req); if (ret) @@ -378,8 +379,11 @@ static void hisi_zip_send_backlog(struct hisi_qp *qp) ret = hisi_zip_map_req_buffers(req); if (unlikely(ret)) { hisi_zip_remove_req(req); - hisi_zip_send_backlog_soft(req->qp_ctx); - goto unlock; + qp_ctx = req->qp_ctx; + list_splice_init(&qp->backlog.list, &soft_list); + spin_unlock_bh(&qp->backlog.lock); + hisi_zip_send_backlog_soft(qp_ctx, &soft_list); + return; } } @@ -393,8 +397,11 @@ static void hisi_zip_send_backlog(struct hisi_qp *qp) case -EBUSY: goto unlock; default: - hisi_zip_send_backlog_soft(req->qp_ctx); - goto unlock; + qp_ctx = req->qp_ctx; + list_splice_init(&qp->backlog.list, &soft_list); + spin_unlock_bh(&qp->backlog.lock); + hisi_zip_send_backlog_soft(qp_ctx, &soft_list); + return; } } -- 2.43.0
反馈: 您发送到kernel@openeuler.org的补丁/补丁集,已成功转换为PR! PR链接地址: https://atomgit.com/openeuler/kernel/merge_requests/31234 邮件列表地址:https://mailweb.openeuler.org/archives/list/kernel@openeuler.org/message/CNF... FeedBack: The patch(es) which you have sent to kernel@openeuler.org mailing list has been converted to a pull request successfully! Pull request link: https://atomgit.com/openeuler/kernel/merge_requests/31234 Mailing list address: https://mailweb.openeuler.org/archives/list/kernel@openeuler.org/message/CNF...
participants (2)
-
patchwork bot -
Weili Qian