From patchwork Thu Jan 14 00:41:16 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alex Hung X-Patchwork-Id: 1426089 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=none (no SPF record) smtp.mailfrom=lists.ubuntu.com (client-ip=91.189.94.19; helo=huckleberry.canonical.com; envelope-from=fwts-devel-bounces@lists.ubuntu.com; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=canonical.com Received: from huckleberry.canonical.com (huckleberry.canonical.com [91.189.94.19]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4DGQVJ7288z9sVw for ; Thu, 14 Jan 2021 11:41:27 +1100 (AEDT) Received: from localhost ([127.0.0.1] helo=huckleberry.canonical.com) by huckleberry.canonical.com with esmtp (Exim 4.86_2) (envelope-from ) id 1kzqhV-0005zr-Ef; Thu, 14 Jan 2021 00:41:21 +0000 Received: from youngberry.canonical.com ([91.189.89.112]) by huckleberry.canonical.com with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.86_2) (envelope-from ) id 1kzqhT-0005zj-Vu for fwts-devel@lists.ubuntu.com; Thu, 14 Jan 2021 00:41:19 +0000 Received: from 1.general.alexhung.us.vpn ([10.172.65.254] helo=canonical.com) by youngberry.canonical.com with esmtpsa (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.86_2) (envelope-from ) id 1kzqhT-0005Py-CY; Thu, 14 Jan 2021 00:41:19 +0000 From: Alex Hung To: fwts-devel@lists.ubuntu.com Subject: [PATCH] acpi: pmtt: fix infinite loops when length is incorrectly zero Date: Wed, 13 Jan 2021 17:41:16 -0700 Message-Id: <20210114004116.353679-1-alex.hung@canonical.com> X-Mailer: git-send-email 2.25.1 MIME-Version: 1.0 X-BeenThere: fwts-devel@lists.ubuntu.com X-Mailman-Version: 2.1.20 Precedence: list List-Id: Firmware Test Suite Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: fwts-devel-bounces@lists.ubuntu.com Sender: "fwts-devel" Signed-off-by: Alex Hung --- src/acpi/pmtt/pmtt.c | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/src/acpi/pmtt/pmtt.c b/src/acpi/pmtt/pmtt.c index 99fd510d..def44a51 100644 --- a/src/acpi/pmtt/pmtt.c +++ b/src/acpi/pmtt/pmtt.c @@ -104,6 +104,14 @@ static void pmtt_controller_test(fwts_framework *fw, fwts_acpi_table_pmtt_contro offset += sizeof(fwts_acpi_table_pmtt_domain) * entry->domain_count; header = (fwts_acpi_table_pmtt_header *) (((char *) entry) + offset); while (offset < entry->header.length) { + + if (header->length == 0) { + fwts_failed(fw, LOG_LEVEL_CRITICAL, + "PMTTBadSubtableLength", + "PMTT Controller has a subtable with zero length"); + break; + } + if (header->type == FWTS_ACPI_PMTT_TYPE_DIMM) { pmtt_physical_component_test(fw, (fwts_acpi_table_pmtt_physical_component *) header, passed); } else { @@ -132,7 +140,16 @@ static void pmtt_socket_test(fwts_framework *fw, fwts_acpi_table_pmtt_socket *en offset = sizeof(fwts_acpi_table_pmtt_socket); header = (fwts_acpi_table_pmtt_header *) (((char *) entry) + offset); + while (offset < entry->header.length) { + + if (header->length == 0) { + fwts_failed(fw, LOG_LEVEL_CRITICAL, + "PMTTBadSubtableLength", + "PMTT Socket has a subtable with zero length"); + break; + } + if (header->type == FWTS_ACPI_PMTT_TYPE_CONTROLLER) { pmtt_controller_test(fw, (fwts_acpi_table_pmtt_controller *) header, passed); } else {