From patchwork Mon Sep 28 17:59:45 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Gustavo A. R. Silva" X-Patchwork-Id: 11804437 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 139D7618 for ; Mon, 28 Sep 2020 17:54:29 +0000 (UTC) Received: from merlin.infradead.org (merlin.infradead.org [205.233.59.134]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id C696F208D5 for ; Mon, 28 Sep 2020 17:54:28 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="JmaXvjIR"; dkim=fail reason="signature verification failed" (1024-bit key) header.d=kernel.org header.i=@kernel.org header.b="0dLGNWA5" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org C696F208D5 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=kernel.org Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=merlin.20170209; h=Sender:Content-Transfer-Encoding: Content-Type:Cc:List-Subscribe:List-Help:List-Post:List-Archive: List-Unsubscribe:List-Id:MIME-Version:Message-ID:Subject:To:From:Date: Reply-To:Content-ID:Content-Description:Resent-Date:Resent-From:Resent-Sender :Resent-To:Resent-Cc:Resent-Message-ID:In-Reply-To:References:List-Owner; bh=fBdDkVtoK70M4mmB+UyMkYx6t6tMZScv/rXYO+i3IVc=; b=JmaXvjIR0VknU/6oLavFHnKVpS rO85PqCKsaq67IPBRe3bvcpRvKD1c+ovdpkY6rkutBVJMro6D6uuOGl/MWrb+9BiQRgHTJAZeyBTb ZhzItMF8JbZiO8fgOL+CVuYkS0dLWP/2Ap+lztcgONJkzNtUkdOAYpX3fqlSnv/RaGxOnnzNOzqmV wOb6kT0skLxnrtvU4J++Ygb4PcXH0WFGieBTpq++qsfBE5BjzQs0yIOEjAy2DdHykVFHR2M/sYSak l19Xpbr/cWejB/7NSylW2LSQ5YLFI50zOlIUt7v3vtIsOP5bsZ4GWMsfz32ldQbRl8SrNdBVByGmy xd9YpFsw==; Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1kMxLn-0001rA-Ax; Mon, 28 Sep 2020 17:54:11 +0000 Received: from mail.kernel.org ([198.145.29.99]) by merlin.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1kMxLk-0001q8-G0 for linux-arm-kernel@lists.infradead.org; Mon, 28 Sep 2020 17:54:09 +0000 Received: from embeddedor (187-162-31-110.static.axtel.net [187.162.31.110]) (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 E980920739; Mon, 28 Sep 2020 17:54:05 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1601315646; bh=eRK9s/qdp7HfBAgb/9dXe02+7LZBsL6ffyU2erZwEFM=; h=Date:From:To:Cc:Subject:From; b=0dLGNWA5IX9gZnjYZAzBKptuiEXVyZdwEyKIeEyvpzCYz9dSe+7O9FbXIwADMA+PU /tTbj3P+yG+3V0zYKqLB1/FHjW+NId+zvcnAkAab12fRCEBLKwcWynNGQXYpR2gsj2 MHFIhbhI2ew71U2OAButRmh8e2575TGGd9LIKqlM= Date: Mon, 28 Sep 2020 12:59:45 -0500 From: "Gustavo A. R. Silva" To: Corentin Labbe , Herbert Xu , "David S. Miller" , Maxime Ripard , Chen-Yu Tsai Subject: [PATCH][next] crypto: sun8i-ss - Fix memory leak in sun8i_ss_prng_generate() Message-ID: <20200928175945.GA11320@embeddedor> MIME-Version: 1.0 Content-Disposition: inline User-Agent: Mutt/1.9.4 (2018-02-28) X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20200928_135408_602803_224BD1B7 X-CRM114-Status: GOOD ( 14.24 ) X-Spam-Score: -5.9 (-----) X-Spam-Report: SpamAssassin version 3.4.4 on merlin.infradead.org summary: Content analysis details: (-5.9 points) pts rule name description ---- ---------------------- -------------------------------------------------- -5.0 RCVD_IN_DNSWL_HI RBL: Sender listed at https://www.dnswl.org/, high trust [198.145.29.99 listed in list.dnswl.org] -0.0 SPF_PASS SPF: sender matches SPF record 0.0 SPF_HELO_NONE SPF: HELO does not publish an SPF Record -0.1 DKIM_VALID_EF Message has a valid DKIM or DK signature from envelope-from domain -0.1 DKIM_VALID_AU Message has a valid DKIM or DK signature from author's domain 0.1 DKIM_SIGNED Message has a DKIM or DK signature, not necessarily valid -0.1 DKIM_VALID Message has at least one valid DKIM or DK signature -0.7 DKIMWL_WL_HIGH DKIMwl.org - High trust sender X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: "Gustavo A. R. Silva" , linux-crypto@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org Set _err_ to the return error code -EFAULT before jumping to the new label err_d, so resources for _d_ can be released before returning from function sun8i_ss_prng_generate(). Addresses-Coverity-ID: 1497459 ("Resource leak") Fixes: ac2614d721de ("crypto: sun8i-ss - Add support for the PRNG") Signed-off-by: Gustavo A. R. Silva --- drivers/crypto/allwinner/sun8i-ss/sun8i-ss-prng.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/drivers/crypto/allwinner/sun8i-ss/sun8i-ss-prng.c b/drivers/crypto/allwinner/sun8i-ss/sun8i-ss-prng.c index 08a1473b2145..0573f6289e8b 100644 --- a/drivers/crypto/allwinner/sun8i-ss/sun8i-ss-prng.c +++ b/drivers/crypto/allwinner/sun8i-ss/sun8i-ss-prng.c @@ -103,7 +103,8 @@ int sun8i_ss_prng_generate(struct crypto_rng *tfm, const u8 *src, dma_iv = dma_map_single(ss->dev, ctx->seed, ctx->slen, DMA_TO_DEVICE); if (dma_mapping_error(ss->dev, dma_iv)) { dev_err(ss->dev, "Cannot DMA MAP IV\n"); - return -EFAULT; + err = -EFAULT; + goto err_d; } dma_dst = dma_map_single(ss->dev, d, todo, DMA_FROM_DEVICE); @@ -160,7 +161,7 @@ int sun8i_ss_prng_generate(struct crypto_rng *tfm, const u8 *src, dma_unmap_single(ss->dev, dma_dst, todo, DMA_FROM_DEVICE); err_iv: dma_unmap_single(ss->dev, dma_iv, ctx->slen, DMA_TO_DEVICE); - +err_d: if (!err) { memcpy(dst, d, dlen); /* Update seed */