Received: by 2002:a05:6a10:d5a5:0:0:0:0 with SMTP id gn37csp3981825pxb; Mon, 4 Oct 2021 14:21:32 -0700 (PDT) X-Google-Smtp-Source: ABdhPJy9k6NIaqM4WdC7u/HzHSwDaACJmSRUK6Vc+zHw2ZHRN9qT5tn1t7KyBAeZUlCcghGDI+be X-Received: by 2002:a63:7d46:: with SMTP id m6mr12979596pgn.409.1633382492298; Mon, 04 Oct 2021 14:21:32 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1633382492; cv=none; d=google.com; s=arc-20160816; b=FMEa661mEpkGuqakI4nBbljOedyg/uwG0D6lqwEZl7vxv/2slwTLGod+EHqjn6oZih fFhdPLSmfmzk1ChhgW6RSzVfZk0OZWrSnGvyvY6gYQ4HlPDc8VS7Odk31PGLixDr9xCa NM5Qqh0nXf30X1ikC+4Dt7eTJOPyA6LAKAz3PJRmToAwfbqpdfb9zs0U2qdSyLu+JWVP izoZQNCD+lllpbO7EEuYjFTEqiR3VYVEUl117f68c+M9GUP2z6Hd1McqYBCdtxfnV1wH yyyfGAnvi4Y9KPqqi4tnUecayncXjvxfusBm7ZlkCAROaWSZjEOF2GhV5gQ0nkdvpNYo toIw== 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=k9bDf23KvZf5S0a8hDUmXHtF5J4RuX5bzpna97LlZ+M=; b=VZ6Cp4vp4qHRiBJz9YNpNMRxUJ6ZmGTs2tnSDr6FKMnQoGmpnaQauKNW0BwvuInalW 0o5zoUWYKcZ4BGaq1vJWfE0hf1gc+xVfQYAseY66DjyoEu2Ob/BG9eSb5mw6cWYAw3N/ 1IIauk8SOGPIrAe35mn5dhBmFwL97joY+v+FFfHCr33D17n3geDZYEhDmdkG5lcps+FG kc41T1B+eepLzGN6Lo82rX4myNsyZ/6B3W6SavicMTPr3GRX1S8zPVqZBO4WW/jH71xu Miat8cS9bXOEI5JU1hzZccg15gNKG9l71sT9p1YkxOvujbTGRICcAnZf/3w/ktwvuTUG 9Qmg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=XyPPoHOA; 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 t21si20822768pfh.287.2021.10.04.14.21.19; Mon, 04 Oct 2021 14:21:32 -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=XyPPoHOA; 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 S237287AbhJDNaJ (ORCPT + 99 others); Mon, 4 Oct 2021 09:30:09 -0400 Received: from mail.kernel.org ([198.145.29.99]:43148 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237321AbhJDN2V (ORCPT ); Mon, 4 Oct 2021 09:28:21 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 6721161CF3; Mon, 4 Oct 2021 13:12:36 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1633353156; bh=cdNiLtdRMDWRSvsDXWSNBqeLxgb0Io6im/yFMGrmzTU=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=XyPPoHOAcgIZgM/JbiCv8RCqPqb9oDtsv+XQFmNeReg6cdpDnHrkOdTwUOlS/8gRM 0lRgrghPGjUJ/tGZUrmQD4o5UtDdw/EMsjTA+Ldc4JpUCIa3VI8y9Y6R+y/sdji2Ya bDpj2eZWV3G3iixWM2ABJZKOK1oAw7JoAWazTDwU= 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 , Sasha Levin Subject: [PATCH 5.14 018/172] crypto: ccp - fix resource leaks in ccp_run_aes_gcm_cmd() Date: Mon, 4 Oct 2021 14:51:08 +0200 Message-Id: <20211004125045.553502993@linuxfoundation.org> X-Mailer: git-send-email 2.33.0 In-Reply-To: <20211004125044.945314266@linuxfoundation.org> References: <20211004125044.945314266@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 [ Upstream commit 505d9dcb0f7ddf9d075e729523a33d38642ae680 ] 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: Sasha Levin --- drivers/crypto/ccp/ccp-ops.c | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/drivers/crypto/ccp/ccp-ops.c b/drivers/crypto/ccp/ccp-ops.c index bb88198c874e..aa4e1a500691 100644 --- a/drivers/crypto/ccp/ccp-ops.c +++ b/drivers/crypto/ccp/ccp-ops.c @@ -778,7 +778,7 @@ ccp_run_aes_gcm_cmd(struct ccp_cmd_queue *cmd_q, struct ccp_cmd *cmd) in_place ? DMA_BIDIRECTIONAL : DMA_TO_DEVICE); if (ret) - goto e_ctx; + goto e_aad; if (in_place) { dst = src; @@ -863,7 +863,7 @@ ccp_run_aes_gcm_cmd(struct ccp_cmd_queue *cmd_q, struct ccp_cmd *cmd) 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. */ @@ -873,17 +873,19 @@ ccp_run_aes_gcm_cmd(struct ccp_cmd_queue *cmd_q, struct ccp_cmd *cmd) 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: -- 2.33.0