Received: by 2002:a05:6a10:a0d1:0:0:0:0 with SMTP id j17csp2517455pxa; Mon, 17 Aug 2020 11:36:31 -0700 (PDT) X-Google-Smtp-Source: ABdhPJx5j0GMygJndl7ng9rOLYRVG6abcyv/3fG3Wc7r/KTyRZZwZ0Tu/z3xz9nc7CZNgLl3s3Oy X-Received: by 2002:a50:fb10:: with SMTP id d16mr16401006edq.134.1597689390805; Mon, 17 Aug 2020 11:36:30 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1597689390; cv=none; d=google.com; s=arc-20160816; b=RaHUIO9UvFMLWabvLTBq1oR0Y44Walp7I9hogJEUN2WIG/KXwD31AywuGtYBWJPJlw jP0NqYqgt6f6gyuTO19bocbwR60CWmPNbcApTrqWtH6BSwbXXfFubZNuKBBrB9Rx8i1Q 8fIwugwWfF2C/dAYcUHynQi7gk6dv+iE2kuRETmCG+q05Ow370W3yg+iZIvj77fjEszO qZ7/txPnyKUM2yuT6oME9E/Idhpf4eIoIs256Cjb+5R/7yefcr3v+05anC9y5QQSZD7k a7nbuavi2nmq6+66Qos7gJ6WJ60NNwjQ5tkv0hOZAgezRCnKw+igZieyyBCB53DuHvPk 12nA== 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=DG0sE90GKZgIBzd41JfGbmtin3l/MP+gbatwuOBdGo7YxUtT7PwI9eCM0WUE8gTJbL +tjIf0VBdW0cH1xM8KrtcW7OacpxlG9q9UQO8bOZP5s7EtUqMGYEl20X7eewaSOzvF7x iMJHGc5lVRr7I7PGdjtYxIVJOSZ/9lotmlQSDGC46ejUZiLwGE1YwLIFC9j/84Ghaq6r HdiVs8orSqnjKLOwRdSWAhnwWFATy7ht5cLIzzyHSjaczEDajw4yGdEMgyX0qjNXzEJx qX77wdUip/2YdlvQcgRG4hTHKVY/Vw3B8QNjGw+Gc/8hpXLAKFoNFIMHxtDaKuu8/+8i hmHQ== 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 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 c5si12019704edq.89.2020.08.17.11.36.08; Mon, 17 Aug 2020 11:36:30 -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=R9MpmUQ6; 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 S2391258AbgHQSeh (ORCPT + 99 others); Mon, 17 Aug 2020 14:34:37 -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 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 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) -- 2.25.1