From patchwork Wed Sep 14 08:40:25 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ivan Hu X-Patchwork-Id: 1677716 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) 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: legolas.ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=canonical.com header.i=@canonical.com header.a=rsa-sha256 header.s=20210705 header.b=G72US3Vr; dkim-atps=neutral Received: from huckleberry.canonical.com (huckleberry.canonical.com [91.189.94.19]) (using TLSv1.2 with cipher ECDHE-ECDSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4MSDLf2FJ7z1ynm for ; Wed, 14 Sep 2022 18:40:41 +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 1oYNwi-0002MJ-VE; Wed, 14 Sep 2022 08:40:36 +0000 Received: from smtp-relay-canonical-0.internal ([10.131.114.83] helo=smtp-relay-canonical-0.canonical.com) by huckleberry.canonical.com with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.86_2) (envelope-from ) id 1oYNwg-0002M7-TG for fwts-devel@lists.ubuntu.com; Wed, 14 Sep 2022 08:40:34 +0000 Received: from canonical.com (123-204-5-118.dynamic.seed.net.tw [123.204.5.118]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange ECDHE (P-256) server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by smtp-relay-canonical-0.canonical.com (Postfix) with ESMTPSA id B83F63F59B for ; Wed, 14 Sep 2022 08:40:32 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=canonical.com; s=20210705; t=1663144833; bh=uxwgg3+rDu8RfqqoFA27IE9mw62Ts32cI7H6cw6k29o=; h=From:To:Subject:Date:Message-Id:MIME-Version; b=G72US3VrdJA8Mnfrw7ImnL5VRHFRRq1Cvaj+3p2xeZ2KN2i0KBqLV/b7C/PIlJ+6/ Lag4evuClRmS3Lnxn19+2ydFzmm8Y+amqaE1GulGyM2uMXl5VSPMy0J4NeWNYPQF1s tRumqchticb1shxWFTe+9IJxBPxogi04MdXkYeMILXRGG8vlUodbFso2YxQokQO87S Nscw6wHT+tXje15CZlF51tkb4LAYPLrHElQKj6iLT7vkm0o/GKQnlsMsncozbUZFpb JzHjf9tJ4Z3kd6CHeCilR3QnT2vJr3Dzm+HR0WMB0wYdVYjECVokp9a8myGQ1zgYn/ H1fg0mN3P7ICQ== From: Ivan Hu To: fwts-devel@lists.ubuntu.com Subject: [PATCH 1/2] acpi: svkl: add test for SVKL table (mantis 2162) Date: Wed, 14 Sep 2022 16:40:25 +0800 Message-Id: <20220914084026.69362-1-ivan.hu@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: Ivan Hu --- src/Makefile.am | 1 + src/acpi/svkl/svkl.c | 122 ++++++++++++++++++++++++++++++++++++ src/lib/include/fwts_acpi.h | 17 +++++ 3 files changed, 140 insertions(+) create mode 100644 src/acpi/svkl/svkl.c diff --git a/src/Makefile.am b/src/Makefile.am index a8c60b79..e1a6f094 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -140,6 +140,7 @@ fwts_SOURCES = main.c \ acpi/spmi/spmi.c \ acpi/srat/srat.c \ acpi/stao/stao.c \ + acpi/svkl/svkl.c \ acpi/syntaxcheck/syntaxcheck.c \ acpi/tcpa/tcpa.c \ acpi/tpm2/tpm2.c \ diff --git a/src/acpi/svkl/svkl.c b/src/acpi/svkl/svkl.c new file mode 100644 index 00000000..4149c541 --- /dev/null +++ b/src/acpi/svkl/svkl.c @@ -0,0 +1,122 @@ +/* + * Copyright (C) 2022 Canonical + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + */ +#include "fwts.h" + +#if defined(FWTS_HAS_ACPI) + +#include +#include +#include +#include +#include +#include + +static fwts_acpi_table_info *table; +acpi_table_init(SVKL, &table) + +static int svkl_test1(fwts_framework *fw) +{ + fwts_acpi_table_svkl *svkl = (fwts_acpi_table_svkl *) table->data; + fwts_acpi_table_svkl_key_structure *key_structure; + uint32_t offset, count, i; + bool passed = true; + + if (table->length < (size_t)svkl->header.length) { + fwts_failed(fw, LOG_LEVEL_HIGH, + "SVKLTooShort", + "SVKL table incorrectly sized, SVKL " + "header reports it is %" PRIu32 " bytes, " + "instead got %zu bytes", + svkl->header.length, table->length); + return FWTS_OK; + } + + if (table->length < sizeof(fwts_acpi_table_svkl)) { + fwts_failed(fw, LOG_LEVEL_HIGH, + "SVKLTooShort", + "SVKL table too short, expecting %zu bytes, " + "instead got %zu bytes", + sizeof(fwts_acpi_table_svkl), table->length); + return FWTS_OK; + } + + fwts_log_info_verbatim(fw, "SVKL Storage Volume Key Data Table:"); + fwts_log_info_simp_int(fw, " Key Count: ", svkl->key_count); + + offset = sizeof(fwts_acpi_table_svkl); + key_structure = (fwts_acpi_table_svkl_key_structure *) (table->data + offset); + + count = (svkl->header.length - offset) / sizeof(fwts_acpi_table_svkl_key_structure); + if (count != svkl->key_count) { + passed = false; + fwts_failed(fw, LOG_LEVEL_CRITICAL, + "SVKLBadStructureCount", + "SVKL should have %" PRId32 " key structures, got %" PRId32, + svkl->key_count, count); + return FWTS_OK; + } + + for (i = 0; i < svkl->key_count; i++) { + fwts_log_info_verbatim(fw, " Storage Volume Key Structure %" PRIu8, (i + 1)); + fwts_log_info_simp_int(fw, " Key Type: ", key_structure->key_type); + if (key_structure->key_type != 0) { + passed = false; + fwts_failed(fw, LOG_LEVEL_HIGH, + "SVKLBadKeyType", + "SVKL key type not zero, 1~0xFFFF reserved."); + } + fwts_log_info_simp_int(fw, " Key Format: ", key_structure->key_format); + if (key_structure->key_format != 0) { + passed = false; + fwts_failed(fw, LOG_LEVEL_HIGH, + "SVKLBadKeyFormat", + "SVKL key format not zero, 1~0xFFFF reserved."); + } + fwts_log_info_simp_int(fw, " Key Size: ", key_structure->key_size); + fwts_log_info_simp_int(fw, " Key Address: ", key_structure->key_addr); + + if ((offset += sizeof(fwts_acpi_table_svkl_key_structure)) > table->length) { + passed = false; + fwts_failed(fw, LOG_LEVEL_CRITICAL, + "SVKLBadTableLength", + "SVKL has more key structures than its size can handle"); + break; + } + + key_structure = (fwts_acpi_table_svkl_key_structure *) (table->data + offset); + } + + fwts_log_nl(fw); + + if (passed) + fwts_passed(fw, "No issues found in SVKL table."); + + return FWTS_OK; +} + +static fwts_framework_minor_test svkl_tests[] = { + { svkl_test1, "Validate SVKL table." }, + { NULL, NULL } +}; + +static fwts_framework_ops svkl_ops = { + .description = "SVKL Storage Volume Key Data table test.", + .init = SVKL_init, + .minor_tests = svkl_tests +}; + +FWTS_REGISTER("svkl", &svkl_ops, FWTS_TEST_ANYTIME, FWTS_FLAG_BATCH | FWTS_FLAG_ACPI) + +#endif diff --git a/src/lib/include/fwts_acpi.h b/src/lib/include/fwts_acpi.h index 8381c351..d87224a5 100644 --- a/src/lib/include/fwts_acpi.h +++ b/src/lib/include/fwts_acpi.h @@ -2219,4 +2219,21 @@ typedef struct { uint32_t amrt_addr_end; } __attribute__ ((packed)) fwts_acpi_table_aspt; +/* + * ACPI SVKL (Storage Volume Key Data) + * https://cdrdv2.intel.com/v1/dl/getContent/726790 + */ +typedef struct { + uint16_t key_type; + uint16_t key_format; + uint32_t key_size; + uint64_t key_addr; +} __attribute__ ((packed)) fwts_acpi_table_svkl_key_structure; + +typedef struct { + fwts_acpi_table_header header; + uint32_t key_count; + fwts_acpi_table_svkl_key_structure key_struct[0]; +} __attribute__ ((packed)) fwts_acpi_table_svkl; + #endif