From patchwork Thu Nov 17 11:23:40 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hanjun Guo X-Patchwork-Id: 21588 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:f944:0:0:0:0:0 with SMTP id q4csp351020wrr; Thu, 17 Nov 2022 03:41:15 -0800 (PST) X-Google-Smtp-Source: AA0mqf6v1HdwsadsIUFSrq8cWSR9mtM6sFJ68OBdpXei3kJHo7qHPqP1Yrwsq0u1tCqhyvqMjRLc X-Received: by 2002:a17:907:2129:b0:7ad:dcf7:c61 with SMTP id qo9-20020a170907212900b007addcf70c61mr1794641ejb.638.1668685275831; Thu, 17 Nov 2022 03:41:15 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1668685275; cv=none; d=google.com; s=arc-20160816; b=Ebu4BtFpCfio63ffMvTDKKc3pSKsypSvbrJbM1TDuB+uXIpo1+cIMCilFtHKWP/NQ5 LbFVqo3OLyEjJPLqE4g8vdIsTJxYqXs50OdG/uigzMG3ab3JFMS62ofrD8UTGmDqXdAp oJZdHKDI+4XpIDrvFBPsJQEMeaYjjjrClK52qgFzhR+hLXNul4HBYFkmK7y4H/HwH2eZ Ld7TP3Zuk3GfNuyCSI/1IddTnnaEomP9gApfwo9+tE9oJoq0AzqabqaTTjHaRn0GSenI 9ie/g7TFL/wS1h8dwWn/i6CBa1c3vulcrcMRlJP6rMvYv6pBrWUBpiCBtCR5+ApmSmgt PQKQ== 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 Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id g12-20020a1709065d0c00b0078315844537si430413ejt.378.2022.11.17.03.40.51; Thu, 17 Nov 2022 03:41:15 -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 + 99 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 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 X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1749743331792772564?= X-GMAIL-MSGID: =?utf-8?q?1749743331792772564?= 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 Reviewed-by: Jarkko Sakkinen --- 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; - }