From patchwork Mon Aug 17 15:13:37 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: 247848 Delivered-To: patch@linaro.org Received: by 2002:a92:cc90:0:0:0:0:0 with SMTP id x16csp2868096ilo; Mon, 17 Aug 2020 11:34:52 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzmwVWt/1oc15ku6g7n3VVkFupIYSwbg1FjE5GW5lf7ZQ/mtVpsrYl9LhJlqYAKxdyHoFoV X-Received: by 2002:a50:e611:: with SMTP id y17mr15699381edm.376.1597689292021; Mon, 17 Aug 2020 11:34:52 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1597689292; cv=none; d=google.com; s=arc-20160816; b=BYBbGJaHu3vrepRQMOEkc3+Oq931tyXsHISzpS0MS9VS7fXxXZcU3pQa12QxRlMYAU s8F5wgE6Q5EV/At6PVkeEFbCjPQE2jWujXtWqEzuxmpHkkf5dQgN+EwM7sxKLdpMBLd9 CwTFiVGAip+wjOr0+jmuvZurz1Om3IsJdWKVozflhAvxDdNJbmyhbWkPgPLZtwegJbU6 UB6Q4Ba5CgEQiSmgEkx+PR/e424zQnKmYLj/xAFU0AePVjKTEuOn7rJfkcGRgMfAetjP 7GbJDQ8yBQHHksz1jnoeF3m5egvUv3kz9xTQNGigR2O6d6wqDt9t898RA4ychuea1gJK tDMQ== 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=r8kWEGSBMSnHclqcTY7PT36Yqcrj4idkVSJbXR/sn1A=; b=eYD+VKzGU8gv11mrsXvM+P7KwAyQZy6BvvzIilH2fb2jvHB51Pq3r3nRgL3mDIYslV m8mbGwVttjNT1Xn2ZNIHikEL1e8A8EI7UO220bQtGZNyLZvqbw+gXaI5I2gMltllP00b QVynyUGvsM/uZ+nEclZpTi4No3yz/7V6M8qaGrtnACytQbbeXmkUHxBJc5l/RYO0lVdh oj948Wb5AduJWkVuUrHpLRBM1LxR8b8vWgViUSNFxkBlO9epWjOkDvaU8oSDoAHXX085 eAwkyfCI+sQfTtHB/1CuTuufMFnJjzjvGV8jgwHctS+cJ0OQh+w0Y+vpO9+KvnFeAgTA XMPQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=R9MpmUQ6; 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 bm20si10904118edb.583.2020.08.17.11.34.51; Mon, 17 Aug 2020 11:34:52 -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=R9MpmUQ6; 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 S2391089AbgHQSeX (ORCPT + 15 others); Mon, 17 Aug 2020 14:34:23 -0400 Received: from mail.kernel.org ([198.145.29.99]:47142 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730997AbgHQQAE (ORCPT ); Mon, 17 Aug 2020 12:00:04 -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 80793206FA; Mon, 17 Aug 2020 16:00:03 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1597680004; bh=NoKBmNF1CPMXkPxFxDReFjhMpjaSUi0JQfGvv1WQiBM=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=R9MpmUQ6exvtoWD4BpwAfKta/wrxYZ18MAcr5GJdcJFq+I76sVDsKUN6J4TMidDSk qITz62IL21NG4M09YcrmwuC0AEXeuhkQbgNiEcYblZ+24SZxx+IOPGmxHRx4QQpF/a 3SzWteDv4ywg2wy0nOxrVlpExt3BE2tSEmP+tfhA= 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.4 016/270] crypto: ccree - fix resource leak on error path Date: Mon, 17 Aug 2020 17:13:37 +0200 Message-Id: <20200817143756.602395827@linuxfoundation.org> X-Mailer: git-send-email 2.28.0 In-Reply-To: <20200817143755.807583758@linuxfoundation.org> References: <20200817143755.807583758@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 cd9c60268bf8d..9bf0cce578f02 100644 --- a/drivers/crypto/ccree/cc_cipher.c +++ b/drivers/crypto/ccree/cc_cipher.c @@ -163,7 +163,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)); @@ -175,10 +174,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); @@ -190,21 +198,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)