From patchwork Mon Aug 17 15:09:36 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: 247875 Delivered-To: patch@linaro.org Received: by 2002:a54:3b12:0:0:0:0:0 with SMTP id j18csp2598815ect; Mon, 17 Aug 2020 12:48:01 -0700 (PDT) X-Google-Smtp-Source: ABdhPJw7chvnM9+sZTmZisz15zLf5wDLG5s5ZkpAgr5lL23UgBYQJ0nPtPHqohm7CApbqGLjGc5l X-Received: by 2002:a17:906:4dd4:: with SMTP id f20mr17674172ejw.170.1597693681623; Mon, 17 Aug 2020 12:48:01 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1597693681; cv=none; d=google.com; s=arc-20160816; b=yi8Tv3K7LE3GOh8R1tsbr+eARdbgoZdZQ8GDYE5t3Oa1f6f2yykhLfYous35AASHVj Iq7J0/z0c4FmRbFT3K51+C3Wn0WOvLyI4T1p5u6WSXN/sXeWwnGvQBNBIEO6gAqkbu3l YCuad7xdpqrRtfGoqYAhS5b02ZE9hLwUmCWr7P1nowJFjXuWKw9VrYfxz0KGksY1FAA/ u0Q8lq4hq7fGI3d/Kbvgp4IaCiKIrw25ukwsgNL3SqnP7oi9rn8GNpuwjBa3rDdl+zE9 TMybk/+TtN8L/Mg1oiShKKtmAkbzBp2eFTsCtd4+8ZkFUavobiif6oiCbg1DNaIj1IZ+ /AXA== 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=QmjHE0OAqqoEscM/WCwYP5YnY9PQv8PLFkOMEwx9hSM=; b=xR+i0FC7ccfNAZCyPPmjCe/BVfG/PCgY0YGRhbRmlNg25wGV9qufjulNmo9Uvws0q1 rw4ILuzB5cir9y+68AliVa0Vr/FNSVkDot98Lpj6ZkvVMsGmxADY2CJybt5dmeP+hqMJ 2/IxZfC1A0dSZDZ2ItPPRxGtNmq3UuKSya8dMpmQ/+T2bcRmpS34SVmjv+/NOGw1pAQz npaAk/4H2lTGVi0y0gs1SWZgbtZsMRjWKdSqCp7x80xzv74zFSlOlptG3+W9+0k/y8C7 SCmaqzJ70RBABy6OqIHpW6QCX2xmHyV8M7WMS9eDbPZzm3bwzi1nz0+YJMk1ev4ZIZfG YRTA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=qfXKtxzS; 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 c38si12608283edf.153.2020.08.17.12.48.01; Mon, 17 Aug 2020 12:48:01 -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=qfXKtxzS; 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 S1732684AbgHQTrc (ORCPT + 15 others); Mon, 17 Aug 2020 15:47:32 -0400 Received: from mail.kernel.org ([198.145.29.99]:42430 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729271AbgHQPUf (ORCPT ); Mon, 17 Aug 2020 11:20:35 -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 A62632075B; Mon, 17 Aug 2020 15:20:34 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1597677635; bh=+sEfMOMLHGs7h/0AYlLu4SUxfOejMe/f4lp3oYV0P3c=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=qfXKtxzSwwu9LkoM6AQAnRcsq95i3yEKJH3JqXT2KfXBzbVRUk8CKgaUX3EUyG87Q gwBdjRzxamjAlj4PAeqwdeBk2y2t1fkZ9EsEBLk+9yXLAJNWsEldO+HYLInfilthhb skP+iBSNElZ0LYjTM48m7Ya5TKiVTNqFani93Qhs= 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.8 023/464] crypto: ccree - fix resource leak on error path Date: Mon, 17 Aug 2020 17:09:36 +0200 Message-Id: <20200817143834.866725624@linuxfoundation.org> X-Mailer: git-send-email 2.28.0 In-Reply-To: <20200817143833.737102804@linuxfoundation.org> References: <20200817143833.737102804@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 872ea3ff1c6ba..f144fe04748b0 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)