Received: by 2002:a05:6358:d09b:b0:dc:cd0c:909e with SMTP id jc27csp1929091rwb; Thu, 17 Nov 2022 04:18:40 -0800 (PST) X-Google-Smtp-Source: AA0mqf45kFVzs5mi6/l0XccO5XP707ylWWiIutDWXpbdC4xsEsHv7pIlJdxt6keay7TiQV0ZCysl X-Received: by 2002:a50:ec82:0:b0:461:8cf7:4783 with SMTP id e2-20020a50ec82000000b004618cf74783mr1935685edr.385.1668687520530; Thu, 17 Nov 2022 04:18:40 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1668687520; cv=none; d=google.com; s=arc-20160816; b=BwL1pLvY8w4FX5qoxN3DgZ4KzMP9TquXzyAzEFNBm84U0+75NCQVhbdGoTbS4PhSES 77rdcSu2ySq6RMXHHqt7ZGEGb51KiNUrJgglQ0Dkow+BBvJMOKhOa9ev2JpcGXCxbZUi wxkAvaKh0S0bnhOiwEzCTAgZdULg+opl98CqBizs2HvhVt3ksmSZRB2LtJLa1DWbwPme OutMdFF0n0RVGbzVG/3aImRf4qU5bmr1sPlAst12e/cQ0ZhCmBKWedufNbxZv2s9Xf8k pAOiB+RgWaLW1zED21R1MDvAHvvNANtD8H/sXCwv5kqlDte2y05dsVhlaDc8B3cut8/p urWA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:references:in-reply-to:message-id :date:subject:cc:to:from; bh=IWQeUIyb4YiaAcuNSLDy4zixjEJIVZspR3NqGOROUqc=; b=pExfpNOpz5vyeupKxmKHhCFuc2ZdXUeGYNUfClXzL7IiAMHK+ixkd349/GydhD/fhL YUYLvpMCEZFCm730Y6ZApKhRIiFScbqKZpkChUiPsET25jSUCg/NApF1tj+7+5UWkj53 dLiwjIZFmRfeM4hX1iFyAk/EeF1CK9w02zg6ZsrtQKID08LfO4mPpO2vMTZ2v5MVPcbH IBoHHaLFuMIN2WR8AVMBoesEKb7Iuq0R7abVFSpb8OCkq+A7VhWK8E9o0egz1N/06TpP 3Rl5JnM3Txn1PCck6UsIUC57/rIMuZlZBBi0NgtTBUiV+Vi8O9EYDkijBu8nk6a8Nhmf Sbwg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=huawei.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id m3-20020a056402430300b004637e16cfa3si688462edc.598.2022.11.17.04.18.14; Thu, 17 Nov 2022 04:18:40 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=huawei.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S239805AbiKQLjm (ORCPT + 92 others); Thu, 17 Nov 2022 06:39:42 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45676 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S239839AbiKQLjI (ORCPT ); Thu, 17 Nov 2022 06:39:08 -0500 Received: from szxga02-in.huawei.com (szxga02-in.huawei.com [45.249.212.188]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 40E4A53ED9; Thu, 17 Nov 2022 03:39:06 -0800 (PST) Received: from dggpemm500020.china.huawei.com (unknown [172.30.72.53]) by szxga02-in.huawei.com (SkyGuard) with ESMTP id 4NCdGK03vRzHvrJ; Thu, 17 Nov 2022 19:38:33 +0800 (CST) Received: from dggpemm500002.china.huawei.com (7.185.36.229) by dggpemm500020.china.huawei.com (7.185.36.49) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.31; Thu, 17 Nov 2022 19:39:04 +0800 Received: from linux-ibm.site (10.175.102.37) by dggpemm500002.china.huawei.com (7.185.36.229) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.31; Thu, 17 Nov 2022 19:39:04 +0800 From: Hanjun Guo To: Jarkko Sakkinen , Peter Huewe CC: , , "Hanjun Guo" Subject: [PATCH v2 1/3] tpm: acpi: Call acpi_put_table() to fix memory leak Date: Thu, 17 Nov 2022 19:23:40 +0800 Message-ID: <1668684222-38457-2-git-send-email-guohanjun@huawei.com> X-Mailer: git-send-email 1.7.12.4 In-Reply-To: <1668684222-38457-1-git-send-email-guohanjun@huawei.com> References: <1668684222-38457-1-git-send-email-guohanjun@huawei.com> MIME-Version: 1.0 Content-Type: text/plain X-Originating-IP: [10.175.102.37] X-ClientProxiedBy: dggems702-chm.china.huawei.com (10.3.19.179) To dggpemm500002.china.huawei.com (7.185.36.229) X-CFilter-Loop: Reflected X-Spam-Status: No, score=-4.2 required=5.0 tests=BAYES_00,RCVD_IN_DNSWL_MED, SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org The start and length of the event log area are obtained from TPM2 or TCPA table, so we call acpi_get_table() to get the ACPI information, but the acpi_get_table() should be coupled with acpi_put_table() to release the ACPI memory, add the acpi_put_table() properly to fix the memory leak. While we are at it, remove the redundant empty line at the end of the tpm_read_log_acpi(). Fixes: 0bfb23746052 ("tpm: Move eventlog files to a subdirectory") Fixes: 85467f63a05c ("tpm: Add support for event log pointer found in TPM2 ACPI table") Cc: stable@vger.kernel.org Signed-off-by: Hanjun Guo --- drivers/char/tpm/eventlog/acpi.c | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/drivers/char/tpm/eventlog/acpi.c b/drivers/char/tpm/eventlog/acpi.c index 1b18ce5..0913d3eb 100644 --- a/drivers/char/tpm/eventlog/acpi.c +++ b/drivers/char/tpm/eventlog/acpi.c @@ -90,16 +90,21 @@ int tpm_read_log_acpi(struct tpm_chip *chip) return -ENODEV; if (tbl->header.length < - sizeof(*tbl) + sizeof(struct acpi_tpm2_phy)) + sizeof(*tbl) + sizeof(struct acpi_tpm2_phy)) { + acpi_put_table((struct acpi_table_header *)tbl); return -ENODEV; + } tpm2_phy = (void *)tbl + sizeof(*tbl); len = tpm2_phy->log_area_minimum_length; start = tpm2_phy->log_area_start_address; - if (!start || !len) + if (!start || !len) { + acpi_put_table((struct acpi_table_header *)tbl); return -ENODEV; + } + acpi_put_table((struct acpi_table_header *)tbl); format = EFI_TCG2_EVENT_LOG_FORMAT_TCG_2; } else { /* Find TCPA entry in RSDT (ACPI_LOGICAL_ADDRESSING) */ @@ -120,8 +125,10 @@ int tpm_read_log_acpi(struct tpm_chip *chip) break; } + acpi_put_table((struct acpi_table_header *)buff); format = EFI_TCG2_EVENT_LOG_FORMAT_TCG_1_2; } + if (!len) { dev_warn(&chip->dev, "%s: TCPA log area empty\n", __func__); return -EIO; @@ -156,5 +163,4 @@ int tpm_read_log_acpi(struct tpm_chip *chip) kfree(log->bios_event_log); log->bios_event_log = NULL; return ret; - } -- 1.7.12.4