Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp4591739pxj; Wed, 12 May 2021 08:50:47 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyHWKs/i+kl5oBAMIivQibtkSwtonoby3AGQ9hH9qH0XTfob5+jG6BIZhnbkZXDy3AP7p2c X-Received: by 2002:a05:6830:1c67:: with SMTP id s7mr24035644otg.197.1620834647815; Wed, 12 May 2021 08:50:47 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1620834647; cv=none; d=google.com; s=arc-20160816; b=MbXUz91usV10r6QmZfA/dzyhxclpCQDbOWnu2ODZsIcrXr6vMbuGDCkg4JKhAGaAyf fNi0alvXwNpLJ/OnQrwa2XfrzpMraOeIqJANZhZnuaYivo+qO/e5GX82pIRuXbqJAzMz 0J7n0LoZsb4moVoEfU3MYYuUrly+m8icylv9ZFrCa/8rkxpiziL/lb0wIHjpE5BIY1bY fr4BXIu39CNI9x2+EGqUNPiNs+JyEcOdR8oV5UryFZKyiKelZ1Cbhk1pnmveHmvMoorY OLCdMgJbKQsm+4KaX9TT04zmDh5Iwelvjju4lC5uCwIJVXqvJfVAtm/0zLqyd9mmjQgU PZgw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=6Vn5nGWfzmbAp7fF/pIRR7TPz5ZZMeEtgHyf83hHoaU=; b=eIuxTX6BVC0baBFnyd57MFDL8tcEf4kriwzrkUxh4pW2D0Bby7UE0rdO5W1coPshlm cM3CiTKWUzw3sCRYU7MNV7hhPv1WOFqQQR4hI3R5n21qorxnnSHdA9EqE4tuj35iBQBs SP6TX92o69XfFLxggs8tcL6iZoZsx4w/oTLkwBynpDRZc7FgGSrVn+6bz+fNdnN+Rkco Dzb7AnwcmQQVP4XYXKUOismrq6rQu0KglJLpHZrSaIuSI+t3k8E44HRJ3UqqQqBUGgUP xGhZ5TblhlVhKqi4v6JtX60SvJxKnsFrPj8eoGkRnvRmVRobDBdq1E6W1dldt9+h3nLn WAIw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b="oc/zHxjf"; 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=pass (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 t17si217703oif.261.2021.05.12.08.50.33; Wed, 12 May 2021 08:50:47 -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=@linuxfoundation.org header.s=korg header.b="oc/zHxjf"; 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=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S237010AbhELPru (ORCPT + 99 others); Wed, 12 May 2021 11:47:50 -0400 Received: from mail.kernel.org ([198.145.29.99]:57412 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232808AbhELPWQ (ORCPT ); Wed, 12 May 2021 11:22:16 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id D9A8661963; Wed, 12 May 2021 15:09:05 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1620832146; bh=VdG7MfJyAOQlxsgl3SvZay79iRjHCdkdkkJTjITfmNw=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=oc/zHxjfhI6079Es7N/RPjtBhgfb2/GuDi1tPX8sgKO2+2RBkRZrCREt6UBpwQSf3 J+uNN6MvMa+y5N8H2wgVJxYpVDd1Sfa37r7nUKwWL8T1GDKbcbm89GP5kpUIJIbsTB uCfHsQqoHwEXnSR+PCHg21MGxu5OHajq1qhJcLh0= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Colin Ian King , Corentin Labbe , Herbert Xu , Sasha Levin Subject: [PATCH 5.10 161/530] crypto: sun8i-ss - Fix memory leak of object d when dma_iv fails to map Date: Wed, 12 May 2021 16:44:31 +0200 Message-Id: <20210512144825.130747288@linuxfoundation.org> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210512144819.664462530@linuxfoundation.org> References: <20210512144819.664462530@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Colin Ian King [ Upstream commit 98b5ef3e97b16eaeeedb936f8bda3594ff84a70e ] In the case where the dma_iv mapping fails, the return error path leaks the memory allocated to object d. Fix this by adding a new error return label and jumping to this to ensure d is free'd before the return. Addresses-Coverity: ("Resource leak") Fixes: ac2614d721de ("crypto: sun8i-ss - Add support for the PRNG") Signed-off-by: Colin Ian King Acked-by: Corentin Labbe Tested-by: Corentin Labbe Acked-by: Corentin Labbe Signed-off-by: Herbert Xu Signed-off-by: Sasha Levin --- drivers/crypto/allwinner/sun8i-ss/sun8i-ss-prng.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/drivers/crypto/allwinner/sun8i-ss/sun8i-ss-prng.c b/drivers/crypto/allwinner/sun8i-ss/sun8i-ss-prng.c index 08a1473b2145..3191527928e4 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_free; } dma_dst = dma_map_single(ss->dev, d, todo, DMA_FROM_DEVICE); @@ -167,6 +168,7 @@ err_iv: memcpy(ctx->seed, d + dlen, ctx->slen); } memzero_explicit(d, todo); +err_free: kfree(d); return err; -- 2.30.2