Received: by 2002:a05:6a10:f347:0:0:0:0 with SMTP id d7csp9080687pxu; Mon, 28 Dec 2020 06:10:31 -0800 (PST) X-Google-Smtp-Source: ABdhPJz9A27GPUpj0w9kj+J1ngRQp4tFOERiLQMoVqJ2NTtTj4Cw9XcSvOBVvPvurqESZn+NdBPz X-Received: by 2002:a05:6402:2377:: with SMTP id a23mr41942763eda.34.1609164631535; Mon, 28 Dec 2020 06:10:31 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1609164631; cv=none; d=google.com; s=arc-20160816; b=HxaQwPbrLq0pypG97h00cN0JSrlmt/cVvUz20eR5UCvg1xot4tN6KUQMQM45GsHo2w PYOoxXLu8494O++T0t4Ky/Qt5KiFNr5A4AGfnKD4Tp7f5IEOpcOELhJaA/WIe30KeBFe VbG51kHRbCMLgq0W+P4UfMK50MVDLmbYWzAnX1UTwl0CcJvoLAs819xwhr2UKjSZxAke prmsZps1/FofJJ8qKSUREy3vT3vBASzDZaV2ehIg/KSZJ4GQM5sGmzZLx+pLNjeaN+u3 YqgHaNVq9F0QNsVIVCAls35D4i3NLpYZedcfQB88595y7Cn3Hz5fbccKbZcKdAdXGgsa CbJw== 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=leyKtG4CbJEywXwS9/D9jTqH75UE4gC0G1IHg5s4Sh0=; b=vjAeLrNq8wQdNNqn+r5EYKE5Abk2P79US1QEEM0fwDVaTv4Zp6J5D9eCg8gUoYYuKU Xrs226rJbxtwiUki6E9oEcK634YLR+fN+oyFkisWQbK1rGBzOgIcCYIuoJiVNwbNLXbJ bnqQM6Dy/6ySo3U/vSbCB8g37jnD/0Y1rP+WaXbFjCkUUHaL6zhP+9EpW9EGVliE1nIY 0jPMVwEpIJgZF/6e9Bx4kLdt0wOwehy1tXbA7lJHX37ozWhmn8IXlSA4XTxNYRTm+tnO quPOZp/WyuABPoy6c7xiaG7uBnMdfItl7qBGdE0Qwg0bIoSElwR6ROR9k7xuBmIpaKEZ 5zBQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b="ZMqOq/9O"; 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 x2si18557361ejb.174.2020.12.28.06.10.08; Mon, 28 Dec 2020 06:10:31 -0800 (PST) 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="ZMqOq/9O"; 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 S2438493AbgL1OHl (ORCPT + 99 others); Mon, 28 Dec 2020 09:07:41 -0500 Received: from mail.kernel.org ([198.145.29.99]:42176 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2438133AbgL1OHj (ORCPT ); Mon, 28 Dec 2020 09:07:39 -0500 Received: by mail.kernel.org (Postfix) with ESMTPSA id 3E979207B2; Mon, 28 Dec 2020 14:06:58 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1609164418; bh=Bs/ZR5rMdwoamsfCJATM59R0BP69ypLw8UgV7JKnTFM=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=ZMqOq/9OoIIm2zWC58RjeImn70DUTJOjTtH+W0KhPomKjF8Tj4a4yakE/JdUJmptK rB/cTYFzIyhF1xyeaCOGaREioFeUjXfAkVUx8hYSpOQIFWHnwpo7o57XNFn2kfvzSw wFnXsbEtieUA3WHJnjGlHXIXKdMgzKiBE2dzcPEU= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, kernel test robot , Dan Carpenter , Corentin Labbe , Herbert Xu , Sasha Levin Subject: [PATCH 5.10 172/717] crypto: sun8i-ce - fix two error paths memory leak Date: Mon, 28 Dec 2020 13:42:50 +0100 Message-Id: <20201228125029.200071592@linuxfoundation.org> X-Mailer: git-send-email 2.29.2 In-Reply-To: <20201228125020.963311703@linuxfoundation.org> References: <20201228125020.963311703@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: Corentin Labbe [ Upstream commit 732b764099f651a088fd931d7b8121b6aa84e62e ] This patch fixes the following smatch warnings: drivers/crypto/allwinner/sun8i-ce/sun8i-ce-hash.c:412 sun8i_ce_hash_run() warn: possible memory leak of 'result' Note: "buf" is leaked as well. Furthermore, in case of ENOMEM, crypto_finalize_hash_request() was not called which was an error. Fixes: 56f6d5aee88d ("crypto: sun8i-ce - support hash algorithms") Reported-by: kernel test robot Reported-by: Dan Carpenter Signed-off-by: Corentin Labbe Signed-off-by: Herbert Xu Signed-off-by: Sasha Levin --- .../crypto/allwinner/sun8i-ce/sun8i-ce-hash.c | 20 +++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/drivers/crypto/allwinner/sun8i-ce/sun8i-ce-hash.c b/drivers/crypto/allwinner/sun8i-ce/sun8i-ce-hash.c index a94bf28f858a7..4c5a2c11d7141 100644 --- a/drivers/crypto/allwinner/sun8i-ce/sun8i-ce-hash.c +++ b/drivers/crypto/allwinner/sun8i-ce/sun8i-ce-hash.c @@ -262,13 +262,13 @@ int sun8i_ce_hash_run(struct crypto_engine *engine, void *breq) u32 common; u64 byte_count; __le32 *bf; - void *buf; + void *buf = NULL; int j, i, todo; int nbw = 0; u64 fill, min_fill; __be64 *bebits; __le64 *lebits; - void *result; + void *result = NULL; u64 bs; int digestsize; dma_addr_t addr_res, addr_pad; @@ -285,13 +285,17 @@ int sun8i_ce_hash_run(struct crypto_engine *engine, void *breq) /* the padding could be up to two block. */ buf = kzalloc(bs * 2, GFP_KERNEL | GFP_DMA); - if (!buf) - return -ENOMEM; + if (!buf) { + err = -ENOMEM; + goto theend; + } bf = (__le32 *)buf; result = kzalloc(digestsize, GFP_KERNEL | GFP_DMA); - if (!result) - return -ENOMEM; + if (!result) { + err = -ENOMEM; + goto theend; + } flow = rctx->flow; chan = &ce->chanlist[flow]; @@ -403,11 +407,11 @@ int sun8i_ce_hash_run(struct crypto_engine *engine, void *breq) dma_unmap_sg(ce->dev, areq->src, nr_sgs, DMA_TO_DEVICE); dma_unmap_single(ce->dev, addr_res, digestsize, DMA_FROM_DEVICE); - kfree(buf); memcpy(areq->result, result, algt->alg.hash.halg.digestsize); - kfree(result); theend: + kfree(buf); + kfree(result); crypto_finalize_hash_request(engine, breq, err); return 0; } -- 2.27.0