Received: by 2002:a05:6a10:d5a5:0:0:0:0 with SMTP id gn37csp3923409pxb; Mon, 4 Oct 2021 12:45:04 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzyMsGFu3VyaibyNT9ynjWto0QqPxxM2NwYNwYQSFkQU9HzfueYf6GrPybveMzd/xFX1iGv X-Received: by 2002:a17:907:3e8e:: with SMTP id hs14mr10783136ejc.35.1633376704383; Mon, 04 Oct 2021 12:45:04 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1633376704; cv=none; d=google.com; s=arc-20160816; b=GfEEBhtA1RrDoWYNzWg4s+y6lbnRk2WxrEoxFa6CkParg9XStUamEGcbugJigGG5wU TuAuGiB7CE180zd6xATf5c+ZylkoH2rB8mqPIATl1QiyiBno1GPopMQfO/MkVu/+ydIi zP8bR5mOV5dbz1lqZBrvckztGi6hdX/L5+/kERJdyUwteMx0VKLQRtlsDN/O8uebZ08H CkkfWnuQQUkhduDPHNSjLipfOBZRiZPL8VD7YQaW18TAznxaxPLFqZ/GYZB+Rm6d9TOk jw6rvIMiHPVhpmRVhzc6KePEG6v+5tfppC3YNf5JHs3n9YVmeJfxVstAnTrdhrJ8JhwO 1++A== 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=f4zgKWgcIafgpun1ZbH0R0fv1veKTzvl5U+muCIyOJ4=; b=dp39OIJYY+K7h+Qw31wj4KTc9xHOGlDqpIU6XCthicvXs6jq0pv+W9X8NRKZlXWXG1 drfAQp59crwWSmpwqtm66McEFwwO631VSexAQps8W6hMk8FhL0Ta+bS3tIhjaVfxK3Sx 2hK3EP4TeeLKp9LtnoSPzoRHQHJPidLC1+y3Fw9kl1cRg/OoX6/1/u5D2xmJ80OndVgo /ysAjhYmVJrCd634UrWmxeIQeoJucfbX/2KFRMXzytGjBWEaJaY0QwOaZXmcBXzeDu+5 41BckpZP1QO46nLEf+wEeiQA1EJAYX+1QeN7UWF/s9Ka1I2xs+4A/ItxDnvOT8mCAbat 6R7Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=ANLLtOUi; 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 ds7si36430261ejc.6.2021.10.04.12.44.40; Mon, 04 Oct 2021 12:45:04 -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=ANLLtOUi; 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 S236135AbhJDNPx (ORCPT + 99 others); Mon, 4 Oct 2021 09:15:53 -0400 Received: from mail.kernel.org ([198.145.29.99]:53200 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236338AbhJDNNv (ORCPT ); Mon, 4 Oct 2021 09:13:51 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 8700961B95; Mon, 4 Oct 2021 13:05:28 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1633352729; bh=WzMOgXrvb4YTkBj40OMzlVskVhLCOeCwBl4ym3E/mt0=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=ANLLtOUiXwx1Qtnodf3rpE/KOwAk3VL+3927DdZhAlb1Ms09Pw5fLlcnEm31oykI4 3c7k+Yj8D7Zt6XnFzYlUQ5Q/QkA7zIIYEk7gPqx+ompwyFp1qZwnYWsg3E8+JjFK0D 9DI0cV3u5auv9UtmJK2ZxPDz0b8zq0CrkyLbLghk= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, =?UTF-8?q?minihanshen ?= , Dan Carpenter , John Allen , Herbert Xu Subject: [PATCH 4.19 91/95] crypto: ccp - fix resource leaks in ccp_run_aes_gcm_cmd() Date: Mon, 4 Oct 2021 14:53:01 +0200 Message-Id: <20211004125036.548491377@linuxfoundation.org> X-Mailer: git-send-email 2.33.0 In-Reply-To: <20211004125033.572932188@linuxfoundation.org> References: <20211004125033.572932188@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: Dan Carpenter commit 505d9dcb0f7ddf9d075e729523a33d38642ae680 upstream. There are three bugs in this code: 1) If we ccp_init_data() fails for &src then we need to free aad. Use goto e_aad instead of goto e_ctx. 2) The label to free the &final_wa was named incorrectly as "e_tag" but it should have been "e_final_wa". One error path leaked &final_wa. 3) The &tag was leaked on one error path. In that case, I added a free before the goto because the resource was local to that block. Fixes: 36cf515b9bbe ("crypto: ccp - Enable support for AES GCM on v5 CCPs") Reported-by: "minihanshen(沈明航)" Signed-off-by: Dan Carpenter Reviewed-by: John Allen Tested-by: John Allen Signed-off-by: Herbert Xu Signed-off-by: Greg Kroah-Hartman --- drivers/crypto/ccp/ccp-ops.c | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) --- a/drivers/crypto/ccp/ccp-ops.c +++ b/drivers/crypto/ccp/ccp-ops.c @@ -783,7 +783,7 @@ ccp_run_aes_gcm_cmd(struct ccp_cmd_queue in_place ? DMA_BIDIRECTIONAL : DMA_TO_DEVICE); if (ret) - goto e_ctx; + goto e_aad; if (in_place) { dst = src; @@ -868,7 +868,7 @@ ccp_run_aes_gcm_cmd(struct ccp_cmd_queue op.u.aes.size = 0; ret = cmd_q->ccp->vdata->perform->aes(&op); if (ret) - goto e_dst; + goto e_final_wa; if (aes->action == CCP_AES_ACTION_ENCRYPT) { /* Put the ciphered tag after the ciphertext. */ @@ -878,17 +878,19 @@ ccp_run_aes_gcm_cmd(struct ccp_cmd_queue ret = ccp_init_dm_workarea(&tag, cmd_q, authsize, DMA_BIDIRECTIONAL); if (ret) - goto e_tag; + goto e_final_wa; ret = ccp_set_dm_area(&tag, 0, p_tag, 0, authsize); - if (ret) - goto e_tag; + if (ret) { + ccp_dm_free(&tag); + goto e_final_wa; + } ret = crypto_memneq(tag.address, final_wa.address, authsize) ? -EBADMSG : 0; ccp_dm_free(&tag); } -e_tag: +e_final_wa: ccp_dm_free(&final_wa); e_dst: