From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-10.7 required=3.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED,DKIM_SIGNED,DKIM_VALID,FREEMAIL_FORGED_FROMDOMAIN, FREEMAIL_FROM,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 72C00C4338F for ; Mon, 26 Jul 2021 08:40:06 +0000 (UTC) Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (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 3C91D6024A for ; Mon, 26 Jul 2021 08:40:06 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org 3C91D6024A Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=gmail.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:In-Reply-To:MIME-Version:References: Message-ID:Subject:Cc:To:From:Date:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=inVHgGAC7diPqFpaHYtNxjAJ6D0relxkcCcIUpv/yI8=; b=axntZNM0s4qSY3 RjlPK73Zj1zsW/ahX2hlVerLzrjvmeAYKRfOs8FivMaxub7IkIrGXfi6MB/hYomR1ylHUzoxpM5ze jV/r0kBcuczOeSvn3OMTw8+PdK9pXOnfqKTI2lC5usehdYJf6MYAAZbvxbHK5fNnZRfJiNh94zxCJ 1gT1CWvYinA5aajqwdBcyW3DYJ2ywuim2pgZg958BJN3lqqg0/ygYXXF62weiaIkjBcvFb1NhxJWI WD7c25QQS9/VDUJIE5my4FAuMfokxbKL+VxBKjsvqQ3weym/j1P6I5oHRN7JHZuU6k1iJU795WFHv 3RHgvymK8elvC9wYjzPQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1m7vzG-00ACm7-9S; Mon, 26 Jul 2021 08:29:22 +0000 Received: from mail-wr1-x42b.google.com ([2a00:1450:4864:20::42b]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1m7vz7-00ACk3-7i for linux-arm-kernel@lists.infradead.org; Mon, 26 Jul 2021 08:29:14 +0000 Received: by mail-wr1-x42b.google.com with SMTP id z7so9975050wrn.11 for ; Mon, 26 Jul 2021 01:29:12 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:content-transfer-encoding:in-reply-to; bh=n22KqpPAazgSksARsAU/X44h7JM3fyV54ywJMdrH1Wg=; b=MQOyJgGP3H0Qwd3EZsdIBT7b6O/W9S9SsA0h4t425dME6/6e1ft+IXDbzCuMfqbFbs uhN3HGZ2DvMHJQaNwadAe6kkc3PkMqa9J/Edh68+Kju0Yu/Qdiu1I2/FcJzqWQkReyUA 6vZUAD+4dz6ULTV+vxYPsQCBQ2JZQx62BtW2i3ZmxVz+0OPneDsy5PxoblS+7oyRAvGk bV0Hp5E1HFrpiQ1cNi0159EnMdwHd6e4BO5mkG52bqcFmuRTRN48QQ/BmPPsZKZkfHEa qpNTxXTtO+RBNQAOJ41TX3QuYN9yHP4SGv/gB0SR6827E6Zzy3OraznJCGsmBqPALV7q Hqog== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:content-transfer-encoding :in-reply-to; bh=n22KqpPAazgSksARsAU/X44h7JM3fyV54ywJMdrH1Wg=; b=VDuHpNvA5urnKSpXDI9qZ0SNQxDjsY1GpERHXHkDIi80m80veHP1zW7Knf1LIE6DYG T7YiYXY5P4WlrvMGezq6k4T1enuzXICeak7TXO59bjoxpzUo4T5elYQRgGmXFrAmb621 +GWYmVF0Z9Y02iGJj1Nw/KfWmpg+j9pDeeDqjNUR1WXIPY4TZ6xI9WSMf2XiQxnbh5e+ Dlmx6qWicd1zVKwk+OEVn4IyvqOvgw67K+xakxEcXhbPKk+mjWSf+daKFlU8hJzsm5ra IfOh32u/PJBdMHF1gty9oANKzCKa2WI6uy1qRu8wrwqof24rUX0Nvq94p5adsRYWMCdN 5P2g== X-Gm-Message-State: AOAM530faRD1IO1U6uO16L8QtLwJX6fPbh23PV8W5LkM6d7xMZhmaBFY z8mySGb3FdBBIsKbepuZk2A= X-Google-Smtp-Source: ABdhPJx2CObKDuRvwR8Y7nZ6jwmf6jEfBwMYvNyPgZtIdXaevpTVTg7oe+aKZLOi/9UY6KXdvGlUgA== X-Received: by 2002:a5d:4527:: with SMTP id j7mr17958282wra.137.1627288151479; Mon, 26 Jul 2021 01:29:11 -0700 (PDT) Received: from Red ([2a01:cb1d:3d5:a100:264b:feff:fe03:2806]) by smtp.googlemail.com with ESMTPSA id l39sm9877874wms.1.2021.07.26.01.29.10 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 26 Jul 2021 01:29:11 -0700 (PDT) Date: Mon, 26 Jul 2021 10:29:08 +0200 From: Corentin Labbe To: Dongliang Mu Cc: Herbert Xu , "David S. Miller" , Maxime Ripard , Chen-Yu Tsai , Jernej Skrabec , "Jason A. Donenfeld" , Eric Biggers , Colin Ian King , Xiang Chen , Ard Biesheuvel , linux-crypto@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-sunxi@lists.linux.dev, linux-kernel@vger.kernel.org Subject: Re: [PATCH v2] crypto: sun8i-ce: fix memory leak and return value of sun8i_ce_hash_run Message-ID: References: <20210726075957.2231287-1-mudongliangabcd@gmail.com> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <20210726075957.2231287-1-mudongliangabcd@gmail.com> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20210726_012913_371304_CB742DC8 X-CRM114-Status: GOOD ( 25.37 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org Le Mon, Jul 26, 2021 at 03:59:36PM +0800, Dongliang Mu a =E9crit : > This patch fixes some memory leak caused by dma_mmap_sg/single > in the error handling code. In addition, it fixes the return value > when errors related with dma_mmap_sg/single occur. > = Hello "some" is too imprecise, exactly which allocation is leaked ? In fact it will be easier to say that all dma_map_xx are leaked, I just saw= that my code is really bad. Furthermore, you should have two fixes, one for the memory leak, one for th= e error code. But for the error code, I am not sure it is needed, error code is already g= iven to user via crypto_finalize_hash_request(). The "return 0" is for crypto/crypto_engine API, returning an error will not= change anything since we dont have retry_support. So I propose you to focus on dma_map_xxx() fix patch. > Reported-by: Dongliang Mu "Reported-by:" is for credit when someone else give you informations. > Fixes: 732b764099f65 ("crypto: sun8i-ce - fix two error path's memory lea= k") This is not the patch which introduces the problem, the problem is from the= beginning ("crypto: sun8i-ss - support hash algorithms") > Signed-off-by: Dongliang Mu > --- > v1->v2: move crypto_finalize_hash_request to the end of function; move > the memcpy after the dma_mmap_sg/single functions. = > .../crypto/allwinner/sun8i-ss/sun8i-ss-hash.c | 28 +++++++++---------- > 1 file changed, 14 insertions(+), 14 deletions(-) > = > diff --git a/drivers/crypto/allwinner/sun8i-ss/sun8i-ss-hash.c b/drivers/= crypto/allwinner/sun8i-ss/sun8i-ss-hash.c > index 3c073eb3db03..fe5db3c84754 100644 > --- a/drivers/crypto/allwinner/sun8i-ss/sun8i-ss-hash.c > +++ b/drivers/crypto/allwinner/sun8i-ss/sun8i-ss-hash.c > @@ -324,11 +324,10 @@ int sun8i_ss_hash_run(struct crypto_engine *engine,= void *breq) > struct sun8i_ss_alg_template *algt; > struct sun8i_ss_dev *ss; > struct scatterlist *sg; > - int nr_sgs, err, digestsize; > + int j, i, todo, nr_sgs, digestsize, err; > unsigned int len; > u64 fill, min_fill, byte_count; > void *pad, *result; > - int j, i, todo; This is a change unrelated with the subject. > __be64 *bebits; > __le64 *lebits; > dma_addr_t addr_res, addr_pad; > @@ -368,14 +367,14 @@ int sun8i_ss_hash_run(struct crypto_engine *engine,= void *breq) > if (nr_sgs <=3D 0 || nr_sgs > MAX_SG) { > dev_err(ss->dev, "Invalid sg number %d\n", nr_sgs); > err =3D -EINVAL; > - goto theend; > + goto err_result; > } > = > addr_res =3D dma_map_single(ss->dev, result, digestsize, DMA_FROM_DEVIC= E); > if (dma_mapping_error(ss->dev, addr_res)) { > dev_err(ss->dev, "DMA map dest\n"); > err =3D -EINVAL; > - goto theend; > + goto err_unmap_sg; > } > = > len =3D areq->nbytes; > @@ -390,7 +389,7 @@ int sun8i_ss_hash_run(struct crypto_engine *engine, v= oid *breq) > if (len > 0) { > dev_err(ss->dev, "remaining len %d\n", len); > err =3D -EINVAL; > - goto theend; > + goto err_addr_res; > } > = > byte_count =3D areq->nbytes; > @@ -421,27 +420,28 @@ int sun8i_ss_hash_run(struct crypto_engine *engine,= void *breq) > } > = > addr_pad =3D dma_map_single(ss->dev, pad, j * 4, DMA_TO_DEVICE); > - rctx->t_src[i].addr =3D addr_pad; > - rctx->t_src[i].len =3D j; > - rctx->t_dst[i].addr =3D addr_res; > - rctx->t_dst[i].len =3D digestsize / 4; > if (dma_mapping_error(ss->dev, addr_pad)) { > dev_err(ss->dev, "DMA error on padding SG\n"); > err =3D -EINVAL; > - goto theend; > + goto err_addr_res; > } > + rctx->t_src[i].addr =3D addr_pad; > + rctx->t_src[i].len =3D j; > + rctx->t_dst[i].addr =3D addr_res; > + rctx->t_dst[i].len =3D digestsize / 4; This is right, it is useless to set addr_pad if it is "bad". But this is a change unrelated with the subject. Regards _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel