From patchwork Mon Aug 17 15:11:10 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Greg Kroah-Hartman X-Patchwork-Id: 247805 Delivered-To: patch@linaro.org Received: by 2002:a92:cc90:0:0:0:0:0 with SMTP id x16csp2740219ilo; Mon, 17 Aug 2020 08:41:22 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwZahsnXmSR83Oo0layCOH0FQ41Km/gYKuoYX0neWEhfNinS56MHGpwrPW6LOVdb2DdWnmM X-Received: by 2002:a50:e809:: with SMTP id e9mr15766002edn.133.1597678882571; Mon, 17 Aug 2020 08:41:22 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1597678882; cv=none; d=google.com; s=arc-20160816; b=n/z7R2wvI9ZT0fjH/CCHjWplWI+YZaBzcrLA8o/DzAkzlE0Ms9CJTyMI7Ceo+7khQn 7B0D0Q/GBmnQ7jHVe5leOhzlfeu312URpesQdAvmun4N0lk8JpBJQudwpH5m3jKawPsQ U6e6+/Q8sm0v5PwtmlMnBD9HL6jyBLomScPZ/BEAmP5/TtPA9QDOf0LyQWcngKK46Giz OARkbh7VvACKqHOFPUx7ICaHdzU2UBc71PPLuJaJQPm0PMK3RG6cgzu0c8RLBUYQmg4h JI5wMDBD/X8xzicOjbF9wBDwSc85samSFgfCPPrDQ4UWhLtOCBhbIRBE/lfD6zsWRVCT etEw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=jy+47KWWs0+9Id4/04PhMTHEMW5Enxs6tHVSBhPU4ow=; b=YPCXoCY1NH2+dT0LY3X+RVUv4Hy6NVyZHqnSgqLwhG0vuqsWZ4wROMSSTr4fkpcyan djuB/K/fDbw/yszFRfNNpOJB8TyZT108geEyDLbjRo84iJRJRVXBU/MfOTD9jY1/Z/xA tqMLJp/XhDxHR2HxxZizNl8NmCx7rB03PCTkSdCMOJ8+BUj1GHoatliPmJJVZUIdJA7J cVoEq2uAksp00DyjIiv7ywN1EfugfPTIrtISMf6ZlnZeVau5flCOvaTm9ocaBSxd8fsc +DcBsN6pnQL5mkmDUkDP9IDjJ3/ccPWjiEogMAW8DjY8ZEQAb6opCM/dMExFM8JaQsWq cyiw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b="liFAG/f3"; spf=pass (google.com: domain of stable-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=stable-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id fx20si11090060ejb.581.2020.08.17.08.41.22; Mon, 17 Aug 2020 08:41:22 -0700 (PDT) Received-SPF: pass (google.com: domain of stable-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b="liFAG/f3"; spf=pass (google.com: domain of stable-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=stable-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730389AbgHQPlT (ORCPT + 15 others); Mon, 17 Aug 2020 11:41:19 -0400 Received: from mail.kernel.org ([198.145.29.99]:50488 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730721AbgHQPlS (ORCPT ); Mon, 17 Aug 2020 11:41:18 -0400 Received: from localhost (83-86-89-107.cable.dynamic.v4.ziggo.nl [83.86.89.107]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id A95E822CAE; Mon, 17 Aug 2020 15:41:16 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1597678877; bh=pwd8sTXOmkL22U64OXCCpqiQ23X2e4TzpaRY8PfRy+M=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=liFAG/f3U44UnHHGH4OWGb3awcO7PkHHvnENR0H+jsg755VHh+8gLFFEnMsQQyM4i wGY5Pct4fKX3hse0YjvbaTHlAXkSba7t0NorGWBpMUn/ttwpbQhGKXc0dUws+JMVqt 38Hvba2kqApZZf1calDY9eXQ4pqTd/ybUYwZSXpw= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Gilad Ben-Yossef , Markus Elfring , Herbert Xu , Sasha Levin Subject: [PATCH 5.7 020/393] crypto: ccree - fix resource leak on error path Date: Mon, 17 Aug 2020 17:11:10 +0200 Message-Id: <20200817143820.573802137@linuxfoundation.org> X-Mailer: git-send-email 2.28.0 In-Reply-To: <20200817143819.579311991@linuxfoundation.org> References: <20200817143819.579311991@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Sender: stable-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: stable@vger.kernel.org From: Gilad Ben-Yossef [ Upstream commit 9bc6165d608d676f05d8bf156a2c9923ee38d05b ] Fix a small resource leak on the error path of cipher processing. Signed-off-by: Gilad Ben-Yossef Fixes: 63ee04c8b491e ("crypto: ccree - add skcipher support") Cc: Markus Elfring Signed-off-by: Herbert Xu Signed-off-by: Sasha Levin --- drivers/crypto/ccree/cc_cipher.c | 30 ++++++++++++++++++------------ 1 file changed, 18 insertions(+), 12 deletions(-) -- 2.25.1 diff --git a/drivers/crypto/ccree/cc_cipher.c b/drivers/crypto/ccree/cc_cipher.c index a84335328f371..89f7661f0dce8 100644 --- a/drivers/crypto/ccree/cc_cipher.c +++ b/drivers/crypto/ccree/cc_cipher.c @@ -159,7 +159,6 @@ static int cc_cipher_init(struct crypto_tfm *tfm) skcipher_alg.base); struct device *dev = drvdata_to_dev(cc_alg->drvdata); unsigned int max_key_buf_size = cc_alg->skcipher_alg.max_keysize; - int rc = 0; dev_dbg(dev, "Initializing context @%p for %s\n", ctx_p, crypto_tfm_alg_name(tfm)); @@ -171,10 +170,19 @@ static int cc_cipher_init(struct crypto_tfm *tfm) ctx_p->flow_mode = cc_alg->flow_mode; ctx_p->drvdata = cc_alg->drvdata; + if (ctx_p->cipher_mode == DRV_CIPHER_ESSIV) { + /* Alloc hash tfm for essiv */ + ctx_p->shash_tfm = crypto_alloc_shash("sha256-generic", 0, 0); + if (IS_ERR(ctx_p->shash_tfm)) { + dev_err(dev, "Error allocating hash tfm for ESSIV.\n"); + return PTR_ERR(ctx_p->shash_tfm); + } + } + /* Allocate key buffer, cache line aligned */ ctx_p->user.key = kmalloc(max_key_buf_size, GFP_KERNEL); if (!ctx_p->user.key) - return -ENOMEM; + goto free_shash; dev_dbg(dev, "Allocated key buffer in context. key=@%p\n", ctx_p->user.key); @@ -186,21 +194,19 @@ static int cc_cipher_init(struct crypto_tfm *tfm) if (dma_mapping_error(dev, ctx_p->user.key_dma_addr)) { dev_err(dev, "Mapping Key %u B at va=%pK for DMA failed\n", max_key_buf_size, ctx_p->user.key); - return -ENOMEM; + goto free_key; } dev_dbg(dev, "Mapped key %u B at va=%pK to dma=%pad\n", max_key_buf_size, ctx_p->user.key, &ctx_p->user.key_dma_addr); - if (ctx_p->cipher_mode == DRV_CIPHER_ESSIV) { - /* Alloc hash tfm for essiv */ - ctx_p->shash_tfm = crypto_alloc_shash("sha256-generic", 0, 0); - if (IS_ERR(ctx_p->shash_tfm)) { - dev_err(dev, "Error allocating hash tfm for ESSIV.\n"); - return PTR_ERR(ctx_p->shash_tfm); - } - } + return 0; - return rc; +free_key: + kfree(ctx_p->user.key); +free_shash: + crypto_free_shash(ctx_p->shash_tfm); + + return -ENOMEM; } static void cc_cipher_exit(struct crypto_tfm *tfm)