From patchwork Thu May 13 19:20:35 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alex Hung X-Patchwork-Id: 1478178 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=) 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 4Fh1ht1hfCz9sWW for ; Fri, 14 May 2021 05:20:45 +1000 (AEST) Received: from localhost ([127.0.0.1] helo=huckleberry.canonical.com) by huckleberry.canonical.com with esmtp (Exim 4.86_2) (envelope-from ) id 1lhGsz-0007Vg-BW; Thu, 13 May 2021 19:20:41 +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 1lhGsx-0007VC-NY for fwts-devel@lists.ubuntu.com; Thu, 13 May 2021 19:20:39 +0000 Received: from d75-158-101-9.abhsia.telus.net ([75.158.101.9] helo=canonical.com) by youngberry.canonical.com with esmtpsa (TLS1.2) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.93) (envelope-from ) id 1lhGsx-0005Zr-2x; Thu, 13 May 2021 19:20:39 +0000 From: Alex Hung To: fwts-devel@lists.ubuntu.com Subject: [PATCH 1/2] acpi: refactor by fwts_acpi_structure_range_check Date: Thu, 13 May 2021 13:20:35 -0600 Message-Id: <20210513192036.1692916-1-alex.hung@canonical.com> X-Mailer: git-send-email 2.31.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 Acked-by: Colin Ian King Acked-by: Ivan Hu --- src/acpi/hmat/hmat.c | 7 +++---- src/acpi/nfit/nfit.c | 6 ++++++ src/acpi/pmtt/pmtt.c | 5 +++++ src/acpi/pptt/pptt.c | 7 +++---- src/acpi/sdev/sdev.c | 6 ++---- 5 files changed, 19 insertions(+), 12 deletions(-) diff --git a/src/acpi/hmat/hmat.c b/src/acpi/hmat/hmat.c index 7de8b077..c2efdc93 100644 --- a/src/acpi/hmat/hmat.c +++ b/src/acpi/hmat/hmat.c @@ -199,13 +199,12 @@ static int hmat_test1(fwts_framework *fw) break; } - if ((offset += entry->length) > table->length) { + offset += entry->length; + if (fwts_acpi_structure_range_check(fw, "HMAT", table->length, offset)) { passed = false; - fwts_failed(fw, LOG_LEVEL_CRITICAL, - "HMATBadTableLength", - "HMAT has more subtypes than its size can handle"); break; } + entry = (fwts_acpi_table_hmat_header *) (table->data + offset); fwts_log_nl(fw); } diff --git a/src/acpi/nfit/nfit.c b/src/acpi/nfit/nfit.c index a819fa3e..7e250aba 100644 --- a/src/acpi/nfit/nfit.c +++ b/src/acpi/nfit/nfit.c @@ -516,7 +516,13 @@ static int nfit_test1(fwts_framework *fw) fwts_acpi_reserved_zero_check("NFIT", "Reserved", reserved_passed, &passed); fwts_log_nl(fw); + offset += entry->length; + if (fwts_acpi_structure_range_check(fw, "NFIT", nfit_table->length, offset)) { + passed = false; + break; + } + entry = (fwts_acpi_table_nfit_struct_header *)(nfit_table->data + offset); } diff --git a/src/acpi/pmtt/pmtt.c b/src/acpi/pmtt/pmtt.c index 7cd0952b..74e49717 100644 --- a/src/acpi/pmtt/pmtt.c +++ b/src/acpi/pmtt/pmtt.c @@ -206,6 +206,11 @@ static int pmtt_test1(fwts_framework *fw) pmtt_memory_device(fw, entry, offset, &passed); offset += entry->length; + if (fwts_acpi_structure_range_check(fw, "PMTT", table->length, offset)) { + passed = false; + break; + } + entry = (fwts_acpi_table_pmtt_header *) (table->data + offset); fwts_log_nl(fw); } diff --git a/src/acpi/pptt/pptt.c b/src/acpi/pptt/pptt.c index 817b0c77..2a4513a6 100644 --- a/src/acpi/pptt/pptt.c +++ b/src/acpi/pptt/pptt.c @@ -163,13 +163,12 @@ static int pptt_test1(fwts_framework *fw) break; } - if ((offset += entry->length) > table->length) { + offset += entry->length; + if (fwts_acpi_structure_range_check(fw, "PPTT", table->length, offset)) { passed = false; - fwts_failed(fw, LOG_LEVEL_CRITICAL, - "PPTTBadTableLength", - "PPTT has more subtypes than its size can handle"); break; } + entry = (fwts_acpi_table_pptt_header *) (table->data + offset); fwts_log_nl(fw); } diff --git a/src/acpi/sdev/sdev.c b/src/acpi/sdev/sdev.c index f03566e8..8946c5e9 100644 --- a/src/acpi/sdev/sdev.c +++ b/src/acpi/sdev/sdev.c @@ -104,11 +104,9 @@ static int sdev_test1(fwts_framework *fw) break; } - if ((offset += entry->length) > table->length) { + offset += entry->length; + if (fwts_acpi_structure_range_check(fw, "SDEV", table->length, offset)) { passed = false; - fwts_failed(fw, LOG_LEVEL_CRITICAL, - "SDEVBadTableLength", - "SDEV has more subtypes than its size can handle"); break; } From patchwork Thu May 13 19:20:36 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alex Hung X-Patchwork-Id: 1478177 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=) 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 4Fh1ht04Byz9sWQ for ; Fri, 14 May 2021 05:20:46 +1000 (AEST) Received: from localhost ([127.0.0.1] helo=huckleberry.canonical.com) by huckleberry.canonical.com with esmtp (Exim 4.86_2) (envelope-from ) id 1lhGt1-0007WJ-FM; Thu, 13 May 2021 19:20:43 +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 1lhGt0-0007Vx-5G for fwts-devel@lists.ubuntu.com; Thu, 13 May 2021 19:20:42 +0000 Received: from d75-158-101-9.abhsia.telus.net ([75.158.101.9] helo=canonical.com) by youngberry.canonical.com with esmtpsa (TLS1.2) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.93) (envelope-from ) id 1lhGsz-0005a3-HH; Thu, 13 May 2021 19:20:41 +0000 From: Alex Hung To: fwts-devel@lists.ubuntu.com Subject: [PATCH 2/2] acpi: refactor by fwts_acpi_reserved_type_check Date: Thu, 13 May 2021 13:20:36 -0600 Message-Id: <20210513192036.1692916-2-alex.hung@canonical.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210513192036.1692916-1-alex.hung@canonical.com> References: <20210513192036.1692916-1-alex.hung@canonical.com> 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 Acked-by: Colin Ian King Acked-by: Ivan Hu --- src/acpi/hmat/hmat.c | 6 +----- src/acpi/nfit/nfit.c | 8 ++------ src/acpi/pptt/pptt.c | 6 +----- src/lib/include/fwts_acpi.h | 2 ++ 4 files changed, 6 insertions(+), 16 deletions(-) diff --git a/src/acpi/hmat/hmat.c b/src/acpi/hmat/hmat.c index c2efdc93..e1105481 100644 --- a/src/acpi/hmat/hmat.c +++ b/src/acpi/hmat/hmat.c @@ -181,11 +181,7 @@ static int hmat_test1(fwts_framework *fw) type_length = sizeof(fwts_acpi_table_hmat_cache) + ((fwts_acpi_table_hmat_cache *) entry)->num_smbios * 2; } else { - passed = false; - fwts_failed(fw, LOG_LEVEL_HIGH, - "HMATBadSubtableType", - "HMAT must have subtable with Type 0..2, got " - "0x%2.2" PRIx8 " instead", entry->type); + fwts_acpi_reserved_type_check(fw, "HMAT", entry->type, 0, FWTS_ACPI_HMAT_TYPE_RESERVED - 1, &passed); break; } diff --git a/src/acpi/nfit/nfit.c b/src/acpi/nfit/nfit.c index 7e250aba..6eba2058 100644 --- a/src/acpi/nfit/nfit.c +++ b/src/acpi/nfit/nfit.c @@ -506,12 +506,8 @@ static int nfit_test1(fwts_framework *fw) reserved_passed = nfit_struct->reserved2; } else { - passed = false; - fwts_failed(fw, LOG_LEVEL_HIGH, - "NFITBadSubType", - "NFIT Structure supports type 0..%" PRId8 ", got " - "0x%4.4" PRIx16 " instead", FWTS_ACPI_NFIT_TYPE_RESERVED - 1, - entry->type); + fwts_acpi_reserved_type_check(fw, "NFIT", entry->type, 0, FWTS_ACPI_NFIT_TYPE_RESERVED - 1, &passed); + break; } fwts_acpi_reserved_zero_check("NFIT", "Reserved", reserved_passed, &passed); diff --git a/src/acpi/pptt/pptt.c b/src/acpi/pptt/pptt.c index 2a4513a6..54eef4a2 100644 --- a/src/acpi/pptt/pptt.c +++ b/src/acpi/pptt/pptt.c @@ -145,11 +145,7 @@ static int pptt_test1(fwts_framework *fw) pptt_id_test(fw, (fwts_acpi_table_pptt_id *) entry, &passed); type_length = sizeof(fwts_acpi_table_pptt_id); } else { - passed = false; - fwts_failed(fw, LOG_LEVEL_HIGH, - "PPTTBadSubtableType", - "PPTT must have subtable with Type 0..2, got " - "0x%2.2" PRIx8 " instead", entry->type); + fwts_acpi_reserved_type_check(fw, "PPTT", entry->type, 0, FWTS_ACPI_PPTT_RESERVED - 1, &passed); break; } diff --git a/src/lib/include/fwts_acpi.h b/src/lib/include/fwts_acpi.h index 24a58d81..0bad5452 100644 --- a/src/lib/include/fwts_acpi.h +++ b/src/lib/include/fwts_acpi.h @@ -1393,6 +1393,7 @@ typedef enum { FWTS_ACPI_HMAT_TYPE_PROXIMITY_DOMAIN = 0, FWTS_ACPI_HMAT_TYPE_LOCALITY = 1, FWTS_ACPI_HMAT_TYPE_CACHE = 2, + FWTS_ACPI_HMAT_TYPE_RESERVED } fwts_acpi_hmat_type; typedef struct { @@ -1460,6 +1461,7 @@ typedef enum { FWTS_ACPI_PPTT_PROCESSOR = 0, FWTS_ACPI_PPTT_CACHE = 1, FWTS_ACPI_PPTT_ID = 2, + FWTS_ACPI_PPTT_RESERVED } fwts_acpi_pptt_type; typedef struct {