From patchwork Tue Jul 17 08:08:32 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Amit Pundir X-Patchwork-Id: 142114 Delivered-To: patch@linaro.org Received: by 2002:a2e:9754:0:0:0:0:0 with SMTP id f20-v6csp3359833ljj; Tue, 17 Jul 2018 01:08:51 -0700 (PDT) X-Google-Smtp-Source: AAOMgpenNcBzKFKkwakLjYz/RTkqgaHlvu/5W+GkPb61GD04ztGizaNx/LpKgKuPfSI0196GxKIR X-Received: by 2002:a62:8b0f:: with SMTP id j15-v6mr656705pfe.33.1531814931233; Tue, 17 Jul 2018 01:08:51 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1531814931; cv=none; d=google.com; s=arc-20160816; b=N9WgZBEX9n1V1grs4NfGukZLXSyGA1MSVjkEoGsgXC97PXs4UYusyGzOhNFez+gMZ1 TS/IgmxpzivE5xaJex4bjLL8hjc+H7qtXGF9SVjZQYdxtx3a0g+Zk7bbjbwFel6+jfeR FqWyXd6Tu/ajNf7p0t+Fa4WW2WLhMM9MjF9LZ7qM16YSmcorul+Yh+Q21PJYE1zERAPy shyg1hcU8osXINt3YpSrNiOnYDuvFfSfar66aF2mtnWPeF7KbC8nU7DAmQxCvOa5WWfd U5WmXweIotSz3dR2yQXvMjXHosjN+qfmcdW/gL/CM59S3L7FbAxv/fDh3r2priqqHr8Q qyxw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:dkim-signature:arc-authentication-results; bh=XMQRq9D5op91GTLZsCfXJahcD4VKogpoOB1GVcvoyoc=; b=N8di43ReSmp64HTPA7BMLaZzZNjVyeoV7YFMZzs9zUE78sw3UL7XcgciclTUGrbg3y V3xsK6qWD4qhIrAaP2JciFJ2+EkThWEUkTzUHFRH7defMEUNk0EUptbsx5R5QRCla7pT HQiFsGkCfFvj8DgHGAZTMK3fiVdHmDSm3zaGw+YRP1XUROamMVT5POu39jn++lwQ/jH7 pbqTkn0XYuP4lSKoxkbMfQCcOXfFzi/1fjNXquhVxrYbW+GsYiPdJFsRaiXKq3SITMv/ k0HNGP11/chKPhVVhfXTA6nXiQpe/A6Xl8Sd8UA/EBDX67EJZeWoY4Yt/psEbOWwXHO9 A2Kw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=I5jIJYp8; spf=pass (google.com: best guess record for domain of stable-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=stable-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id j1-v6si309442pll.493.2018.07.17.01.08.51; Tue, 17 Jul 2018 01:08:51 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of stable-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=I5jIJYp8; spf=pass (google.com: best guess record for domain of stable-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=stable-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729701AbeGQIkM (ORCPT + 13 others); Tue, 17 Jul 2018 04:40:12 -0400 Received: from mail-pl0-f68.google.com ([209.85.160.68]:35291 "EHLO mail-pl0-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726819AbeGQIkM (ORCPT ); Tue, 17 Jul 2018 04:40:12 -0400 Received: by mail-pl0-f68.google.com with SMTP id w3-v6so126476plq.2 for ; Tue, 17 Jul 2018 01:08:50 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=XMQRq9D5op91GTLZsCfXJahcD4VKogpoOB1GVcvoyoc=; b=I5jIJYp8aCExZdFDldIpo2Q9WGRbHjDlwVliyFV8Vt9ljMsvnH4YwniMXilLFbyPUi rBtrHGdwLjsudiNfidvJiu0TLuz/4eN7/3cfSROwZo/TQiocOwyayo+QXXxTksAlgznO HST2ejAOkxUOAlYmU0lCIjwnfRRue9VUhM8ic= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=XMQRq9D5op91GTLZsCfXJahcD4VKogpoOB1GVcvoyoc=; b=NRIN3ImGW751C1zAKZhtHHLiTpZe67V62wonXf2ENAlyuvMHIH8ym83U9jaLAtgoGS uMhsrSi5SWjWbL24W2ll60l7urt+vYQ+IHOhuzJgj4WNTSX5qRKFjOSJDmoxXMofcDod zvGmN3CoCWfKrXgeYWoaf1CKfGaSXSIC917igO7/MpRMDC7YbhJT7UOV1+/EnUIoJe5Z z0zQc3R+4wGSzpn8I1DYGhrxukdli3JrvqSmi4nNh3fRg05kmMtKUuSB/ZXFntjU9KE1 42SSj+gnR+FkbO3nAArq9yhOJIH59NZCQt+NOjkgJn3VjeUNBTq9xUvjWfZgEINPFuLL avlA== X-Gm-Message-State: AOUpUlHfT5GLVuwOc7yphSBC2jcSN0zK2ATwb1o+rI6WBvgEkwDqE71q RYCOfzpXS8Q2B/YhNm0u4CDs//NWn+U= X-Received: by 2002:a17:902:bc85:: with SMTP id bb5-v6mr614898plb.229.1531814929642; Tue, 17 Jul 2018 01:08:49 -0700 (PDT) Received: from localhost.localdomain ([106.51.22.240]) by smtp.gmail.com with ESMTPSA id c85-v6sm2205083pfd.110.2018.07.17.01.08.47 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Tue, 17 Jul 2018 01:08:48 -0700 (PDT) From: Amit Pundir To: Greg KH , Stable Cc: Christian Lamparter , Herbert Xu Subject: [PATCH for-4.14.y 3/5] crypto: crypto4xx - fix crypto4xx_build_pdr, crypto4xx_build_sdr leak Date: Tue, 17 Jul 2018 13:38:32 +0530 Message-Id: <1531814914-19191-4-git-send-email-amit.pundir@linaro.org> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1531814914-19191-1-git-send-email-amit.pundir@linaro.org> References: <1531814914-19191-1-git-send-email-amit.pundir@linaro.org> Sender: stable-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: stable@vger.kernel.org From: Christian Lamparter commit 5d59ad6eea82ef8df92b4109615a0dde9d8093e9 upstream. If one of the later memory allocations in rypto4xx_build_pdr() fails: dev->pdr (and/or) dev->pdr_uinfo wouldn't be freed. crypto4xx_build_sdr() has the same issue with dev->sdr. Signed-off-by: Christian Lamparter Signed-off-by: Herbert Xu Signed-off-by: Amit Pundir --- Cherry-picked from lede tree https://git.lede-project.org/?p=source.git drivers/crypto/amcc/crypto4xx_core.c | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) -- 2.7.4 diff --git a/drivers/crypto/amcc/crypto4xx_core.c b/drivers/crypto/amcc/crypto4xx_core.c index 3118cec0d81e..3f9eee7e555f 100644 --- a/drivers/crypto/amcc/crypto4xx_core.c +++ b/drivers/crypto/amcc/crypto4xx_core.c @@ -207,7 +207,7 @@ static u32 crypto4xx_build_pdr(struct crypto4xx_device *dev) dev->pdr_pa); return -ENOMEM; } - memset(dev->pdr, 0, sizeof(struct ce_pd) * PPC4XX_NUM_PD); + memset(dev->pdr, 0, sizeof(struct ce_pd) * PPC4XX_NUM_PD); dev->shadow_sa_pool = dma_alloc_coherent(dev->core_dev->device, 256 * PPC4XX_NUM_PD, &dev->shadow_sa_pool_pa, @@ -240,13 +240,15 @@ static u32 crypto4xx_build_pdr(struct crypto4xx_device *dev) static void crypto4xx_destroy_pdr(struct crypto4xx_device *dev) { - if (dev->pdr != NULL) + if (dev->pdr) dma_free_coherent(dev->core_dev->device, sizeof(struct ce_pd) * PPC4XX_NUM_PD, dev->pdr, dev->pdr_pa); + if (dev->shadow_sa_pool) dma_free_coherent(dev->core_dev->device, 256 * PPC4XX_NUM_PD, dev->shadow_sa_pool, dev->shadow_sa_pool_pa); + if (dev->shadow_sr_pool) dma_free_coherent(dev->core_dev->device, sizeof(struct sa_state_record) * PPC4XX_NUM_PD, @@ -416,12 +418,12 @@ static u32 crypto4xx_build_sdr(struct crypto4xx_device *dev) static void crypto4xx_destroy_sdr(struct crypto4xx_device *dev) { - if (dev->sdr != NULL) + if (dev->sdr) dma_free_coherent(dev->core_dev->device, sizeof(struct ce_sd) * PPC4XX_NUM_SD, dev->sdr, dev->sdr_pa); - if (dev->scatter_buffer_va != NULL) + if (dev->scatter_buffer_va) dma_free_coherent(dev->core_dev->device, dev->scatter_buffer_size * PPC4XX_NUM_SD, dev->scatter_buffer_va, @@ -1191,7 +1193,7 @@ static int crypto4xx_probe(struct platform_device *ofdev) rc = crypto4xx_build_gdr(core_dev->dev); if (rc) - goto err_build_gdr; + goto err_build_pdr; rc = crypto4xx_build_sdr(core_dev->dev); if (rc) @@ -1234,12 +1236,11 @@ static int crypto4xx_probe(struct platform_device *ofdev) err_request_irq: irq_dispose_mapping(core_dev->irq); tasklet_kill(&core_dev->tasklet); - crypto4xx_destroy_sdr(core_dev->dev); err_build_sdr: + crypto4xx_destroy_sdr(core_dev->dev); crypto4xx_destroy_gdr(core_dev->dev); -err_build_gdr: - crypto4xx_destroy_pdr(core_dev->dev); err_build_pdr: + crypto4xx_destroy_pdr(core_dev->dev); kfree(core_dev->dev); err_alloc_dev: kfree(core_dev);