Received: by 2002:a05:6a10:a0d1:0:0:0:0 with SMTP id j17csp2653403pxa; Mon, 17 Aug 2020 15:35:59 -0700 (PDT) X-Google-Smtp-Source: ABdhPJz2HmkgHGO+eCfu47tfofnKDdUCB/REK2OeT8FivmgQPLHunBjSwAIs0/OMAer87w9fWD8h X-Received: by 2002:a17:906:73d9:: with SMTP id n25mr17902928ejl.412.1597703759279; Mon, 17 Aug 2020 15:35:59 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1597703759; cv=none; d=google.com; s=arc-20160816; b=mop2eNKVT3PP0C6SzdI/2qHfunIdyLr7Oi/IIVPY2TTv/5evzgod63V3Wq73kVkXH1 urIDgSoVTsOszoO+BHZ8rEYkPG8XweJP0qGAchbQQtWTWoHMakFzlOxJMRG6CfP4OW48 8p8TyKVmbIzM6wM2aX8t8FBsnJFNGz/wIjFy9W+532+Iydt5grSosA/GVhU48vDXacQZ hDqAXA36h87guLa4qzMVDmpbZrnINCeeBrON6oY2FkfCapJwbBsxlvGt7sPo0pGH9A/D ciNieuczrsNudsAc5ZhC7Csg+If3jpXDsNBugDCdUE+GI24C8h0asR6XLAsAPgxFKVYd XpMw== 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=8aS6GesVfLNExRkLMrzd3vMQLWsObJrC29iEA+pmuuI=; b=qxliWkkgkJCbyHFww3DaDdc3+USo3nq3pJNTPzdyIejJc8zgVHojGO4hWljA1wAfto M7o2BNmEIOz9HdIrHg2/a6rJVcWJfdKQ7+w7kymy+RMNEmYRt2XU1gLWkvt4b6kfYIG9 aV27wXxNECF2qaK1xEPusgr7bcbG7Hr6mfFCdC3bTCd6JSZymE27gd4htOCzaoz3U/Xn LvZv97nBr+7UnVpYDqMjNdU934n88QerzpX/nEJ+9Ei5PwLXR3u8sp2q9NdnoQRPYPba TfhRPc3ALT/nWPGH9AeW+3MB5NxiuovKKTZGmoGWUpjR9wvIJWgAq39on9Y4k/KvZiAm eJIg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=Fk86VXhB; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-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 a18si10336150ejr.184.2020.08.17.15.35.36; Mon, 17 Aug 2020 15:35:59 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-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=Fk86VXhB; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-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 S2389404AbgHQRKh (ORCPT + 99 others); Mon, 17 Aug 2020 13:10:37 -0400 Received: from mail.kernel.org ([198.145.29.99]:39652 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2388606AbgHQQLR (ORCPT ); Mon, 17 Aug 2020 12:11:17 -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 916C022BF5; Mon, 17 Aug 2020 16:11:15 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1597680676; bh=5umpobZfU532MNHExFEMg4AwPASjY4mr8L46crhIfWk=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Fk86VXhBa4tBbGHDJxjIr3BWLnMCtm5NvY4KH2BvwV0GeQxkqmEr2iCPLAT8g6naT IailWnlTPxWuy038uF3UTU/n3WbWnBasI5TTPl6U1iiO+MahDp2x5lz6NU7XTSj1t6 rRqW0IaD1bReqwiDjsZ9DCzlvy2A5q43VecVJ9Wo= 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 4.19 012/168] crypto: ccree - fix resource leak on error path Date: Mon, 17 Aug 2020 17:15:43 +0200 Message-Id: <20200817143734.336080170@linuxfoundation.org> X-Mailer: git-send-email 2.28.0 In-Reply-To: <20200817143733.692105228@linuxfoundation.org> References: <20200817143733.692105228@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@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(-) diff --git a/drivers/crypto/ccree/cc_cipher.c b/drivers/crypto/ccree/cc_cipher.c index 28a5b8b38fa2f..1bcb6f0157b07 100644 --- a/drivers/crypto/ccree/cc_cipher.c +++ b/drivers/crypto/ccree/cc_cipher.c @@ -137,7 +137,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)); @@ -149,10 +148,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); @@ -164,21 +172,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) -- 2.25.1