Received: by 2002:a05:6a10:a0d1:0:0:0:0 with SMTP id j17csp2635868pxa; Mon, 17 Aug 2020 15:04:52 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwXAc1k0a5obMwtnbF+52/zhJL0lRXZvnuSyaAmkoaLSa1K7Y+uyJ6LvHIacm6wuZu0hoHy X-Received: by 2002:aa7:c889:: with SMTP id p9mr17201179eds.105.1597701892041; Mon, 17 Aug 2020 15:04:52 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1597701892; cv=none; d=google.com; s=arc-20160816; b=sgALxHepsxfAYHyBG0/pV/xQIBI7yWrxWyqBx2zwR5aGvBlgJkg8NvJspP18Ws7wRa lhlz1TRGWuMpKHvtdGi0Ly1u6v69IzbfTwa3JR0KMeN4aiEvqWstq/Twx7gnjdEhDZU6 FFwxMoj3QZ0FNkpKXGpn8gD++lL8z9aqNqgOvTVeBkCqS1aA9Ws4kYhN7FeJ+WrD0RUh M/UyhwnNiGJX0OeF3xQKvPMLr3QSTbChy6XoJYTh6qxPrtsH+oWYUlc+LUh/pszEyubP PzUUOJBLyHOG1E0Ii1k5fqpnNEV+8g/8uZFgbu8Znja01ojBtTLq9aLGWukm1/Cp3Y47 w5nQ== 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=EUaMpUtGGfL6ZBDfDuqmjsgVrZzISs1eWPfvzSjKEdrDFUzBKriKLXjdblHjnurUuO XzVXMVQPoZzhGNsz+RY8Edfy25IDSWWP7FufUdhVZOn0gEiaSt+ELoFCf25rt16j1I0I k6+53MWgHP9TiJ6KBEjc+kWEDpRAsiKFiKVomUBrst7hGWexKkpCtui01iipZXrXsiCN wfkhRGoW/x2QMEoNVP7Wza9DXkDYhpF/nUjnqOrcidqZm7ncev1wsSjBYkr7xJeyf3If LM9hV2u6hn/J44iZgDmvzklA6OpzLWtS5XYfzOWIEKKUzUWbPbfQRQu7JB9clCOQ55mS 9+VA== 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 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 i28si14838848edj.373.2020.08.17.15.04.28; Mon, 17 Aug 2020 15:04:52 -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="liFAG/f3"; 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 S2387966AbgHQPyF (ORCPT + 99 others); Mon, 17 Aug 2020 11:54:05 -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 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 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) -- 2.25.1