Received: by 2002:a05:6a10:1287:0:0:0:0 with SMTP id d7csp3333016pxv; Mon, 26 Jul 2021 01:30:50 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxNPToUvioNjg/LpnVgTLlqGhgLoSSIjsZGvzs9SucJAa449A1nT5LWoZ4sad6qUrY3gs9w X-Received: by 2002:a17:906:9513:: with SMTP id u19mr16293549ejx.284.1627288250411; Mon, 26 Jul 2021 01:30:50 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1627288250; cv=none; d=google.com; s=arc-20160816; b=tHYsXbi3GFSIfPGqIiVH2W/fSYqy9TkP+4rK+a/YGn0fSwxK+2TmbMjipqDADwMCNU r1uFEFWsVanWf46RiONiLl7R8LcQHX4xlHMFX6dJ/LpjbgRuggJZfpVg9jY57PCOIfr9 4aQE6yB8EslAXWNC5I79qIWuHsXVYwEqw5Cm9MI81DmrgMpEWiwxoc00pyLyJmzCVDaW I77aw048letfk+cvsdC9hSZzRyTl2kgtO32PYMToNxCQTolVsZBK89/Xo1Tf0bRG8kvt QZu6sOJuWsLHwv6PAqOTDa6RAL5GpZ1lvMJBSp2rQeen3GQpGwK5CwiB6AfPa6Qm8fke tJIQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-transfer-encoding :content-disposition:mime-version:references:message-id:subject:cc :to:from:date:dkim-signature; bh=n22KqpPAazgSksARsAU/X44h7JM3fyV54ywJMdrH1Wg=; b=uu+w67cC/ZrhUmjLYjmR6uB/0eevVCIUFEpeXVHa6zyRs0QI+motr0S21NZngUuXjk VEw7pc7t2kpfu3WpveVBisQU5lBh+rd/6hBD1F39MVXcHa+ScYbUdm5NQt4K5xbREoRR dM8PaGpUEk85qy0GReTXpYD1FyVqkMAu0kO+UKf1Gh3F3QVPaTubu2uWn6/MnOvEjV4G Mk8jp5Uf2BTHReqWyAIFzx84d1QHUbJlP6FBhCgJVonRfopBFr6avfuGypAAvlB6gfim O1J7rFP4cEWVt/0Snxp0euc4vR/V9XSdAs9ja1+OxBBUncf/47VwU1R37gd37XRenXza 7zkA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=MQOyJgGP; 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=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id q5si41639292edi.242.2021.07.26.01.30.19; Mon, 26 Jul 2021 01:30:50 -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=@gmail.com header.s=20161025 header.b=MQOyJgGP; 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=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231820AbhGZHsp (ORCPT + 99 others); Mon, 26 Jul 2021 03:48:45 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59502 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232279AbhGZHso (ORCPT ); Mon, 26 Jul 2021 03:48:44 -0400 Received: from mail-wr1-x433.google.com (mail-wr1-x433.google.com [IPv6:2a00:1450:4864:20::433]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D285FC061757; Mon, 26 Jul 2021 01:29:12 -0700 (PDT) Received: by mail-wr1-x433.google.com with SMTP id j2so9994430wrx.9; 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=Klrw7nHIgWJNXSRD3Qa4fTBS9JKS1MlD5Duu31rS1VO1K6QvpAPXhgNA9H7JoOZNHL GpFfYcY6C6hu5X05WAZH51IsRJtyCSYnSWAqYLR2a2cO90Mvt7VUhjUjruaHCFnNWwAZ Tn11wJs2ltbi+S4885X6DkWze3l2sTQx4JjK2r5eYyrmOi7/JVrZofqr7xd8FxEBTHTa AZ0B6KKoNmgEPFJfLuraZzwRTcmceQZvVmHKPwFlC+eMCFNamU/oLpK1KJYVSGMJT11T ByzKhKr6wcvciJxt4/X81YK0+UcoZY7eVADvNOCNSAVNOWL+cXknOW7dycUsQMCG+hcQ Masw== X-Gm-Message-State: AOAM532w+OxxTv902TgCAmZI51nU3R/xKn6FxHQGqyPRk7NeK/7W4R/1 3Agm84K2SbDYjG1irxDh+o0= 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-Type: text/plain; charset=iso-8859-1 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <20210726075957.2231287-1-mudongliangabcd@gmail.com> Precedence: bulk List-ID: X-Mailing-List: linux-crypto@vger.kernel.org Le Mon, Jul 26, 2021 at 03:59:36PM +0800, Dongliang Mu a ?crit : > 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 the error code. But for the error code, I am not sure it is needed, error code is already given 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 leak") 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 <= 0 || nr_sgs > MAX_SG) { > dev_err(ss->dev, "Invalid sg number %d\n", nr_sgs); > err = -EINVAL; > - goto theend; > + goto err_result; > } > > addr_res = dma_map_single(ss->dev, result, digestsize, DMA_FROM_DEVICE); > if (dma_mapping_error(ss->dev, addr_res)) { > dev_err(ss->dev, "DMA map dest\n"); > err = -EINVAL; > - goto theend; > + goto err_unmap_sg; > } > > len = areq->nbytes; > @@ -390,7 +389,7 @@ int sun8i_ss_hash_run(struct crypto_engine *engine, void *breq) > if (len > 0) { > dev_err(ss->dev, "remaining len %d\n", len); > err = -EINVAL; > - goto theend; > + goto err_addr_res; > } > > byte_count = areq->nbytes; > @@ -421,27 +420,28 @@ int sun8i_ss_hash_run(struct crypto_engine *engine, void *breq) > } > > addr_pad = dma_map_single(ss->dev, pad, j * 4, DMA_TO_DEVICE); > - rctx->t_src[i].addr = addr_pad; > - rctx->t_src[i].len = j; > - rctx->t_dst[i].addr = addr_res; > - rctx->t_dst[i].len = digestsize / 4; > if (dma_mapping_error(ss->dev, addr_pad)) { > dev_err(ss->dev, "DMA error on padding SG\n"); > err = -EINVAL; > - goto theend; > + goto err_addr_res; > } > + rctx->t_src[i].addr = addr_pad; > + rctx->t_src[i].len = j; > + rctx->t_dst[i].addr = addr_res; > + rctx->t_dst[i].len = 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