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