Received: by 2002:a05:6a10:22f:0:0:0:0 with SMTP id 15csp3203487pxk; Mon, 28 Sep 2020 10:54:44 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwNEBMZunY3vh/llrRBxFrGnzxt3drMZruma0+ktRSKaQYU6yd4Axbhs7i1FINbgaC6LN8+ X-Received: by 2002:a17:906:33d8:: with SMTP id w24mr2734629eja.224.1601315684609; Mon, 28 Sep 2020 10:54:44 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1601315684; cv=none; d=google.com; s=arc-20160816; b=QOBmyFmCUl/6E3ssARTFrdzlUK1/TJ+j02bTZRhBNm/cAJw5IXHvrdixqOWqBIEr6V 2aztaE1V8GgMyf2H825WTcwlvNG+XwTF//M9XO/pbSwoni6tpNjOkJZpMAV7H1yrO3K8 kXiHXtXgbdo1PiJeCD12Lzm1RBcQYcTMMjmYU9WItizWSzvzCEHSY1Pe7+YYcCz1ulUm kTXNmFdn3gtLVzcjD/YtjJ6McLJ/3jNwl30Bo5nApMin5GFC0ksx3pCPOXsylVVDPfct SXEUFn+xeCQWEBCtmikJIK1ab/gmylQMG2VPV2BewYx7I0AkNo8gZqGwsVsYWlvpOmLK jlZw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:user-agent:content-disposition:mime-version :message-id:subject:cc:to:from:date:dkim-signature; bh=nUfTm1EICrUzQx+Wt4oyf2okgubX3kzWPWtkxGwYI3c=; b=MgkL89lazhFNexuFH8WtHEYcC8cNrkFnbfZABw4JWdv47U0zsiQd5TfUVkVG304//r l5S/MaHT053I+l3OuwqXEDIHi0AIZcGwtKAcErQj2q0+/VjyyAicVCh/z7oTSe5Ea22t N+7R9zoTgsusGxD1TzjIC/fqK5WsEPZ538KpZb2hZE5I12XWogSr/IZZ21suaoTcLIKh lUqtQmQuwryEHPfnnq1V9RprlNZ55TmqciYYm8zhs2taBnw1YlNUN9g4Q9kmifqvQwJR sRAxO4grkLHv6nrgA1FrTHTgFtzQ8tNPDL7/YsjFrCXV1UHES+uW7mU/GcK240jnnNXP 1BeQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=0dLGNWA5; spf=pass (google.com: domain of linux-crypto-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-crypto-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id md14si1016974ejb.548.2020.09.28.10.54.11; Mon, 28 Sep 2020 10:54:44 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-crypto-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=0dLGNWA5; spf=pass (google.com: domain of linux-crypto-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-crypto-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726564AbgI1RyH (ORCPT + 99 others); Mon, 28 Sep 2020 13:54:07 -0400 Received: from mail.kernel.org ([198.145.29.99]:58422 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726552AbgI1RyH (ORCPT ); Mon, 28 Sep 2020 13:54:07 -0400 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 Cc: linux-crypto@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, "Gustavo A. R. Silva" Subject: [PATCH][next] crypto: sun8i-ss - Fix memory leak in sun8i_ss_prng_generate() Message-ID: <20200928175945.GA11320@embeddedor> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline User-Agent: Mutt/1.9.4 (2018-02-28) Precedence: bulk List-ID: X-Mailing-List: linux-crypto@vger.kernel.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 */ -- 2.27.0