From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail05.groups.io (mail05.groups.io [45.79.224.7]) by spool.mail.gandi.net (Postfix) with ESMTPS id CA87A941548 for ; Mon, 22 Apr 2024 10:47:38 +0000 (UTC) DKIM-Signature: a=rsa-sha256; bh=omKHY/561hKsWMxW8+WgyusUI9AIsznxPt11KgZaPZg=; c=relaxed/simple; d=groups.io; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References:MIME-Version:Precedence:List-Subscribe:List-Help:Sender:List-Id:Mailing-List:Delivered-To:Resent-Date:Resent-From:Reply-To:List-Unsubscribe-Post:List-Unsubscribe:Content-Transfer-Encoding:Content-Type; s=20240206; t=1713782857; v=1; b=UROTJ28FtM2B7/M+GWJvZY+FWCA8Y+2hnrSRGfZQ50MCY1COcvgBRCUSTwmSK9f7UQwDYYvi MfNqJ0QboVJaS8VtruRoa1+d7zvluT/qLSoRliWwf1SB/Ylo19YrdUzpdpG7Z7PSBYzAlzJCuGS vvfT+nfe4eKTMm7Vu9kZPDpfQRuCGkxQzgaZh0TsCEPlGuRyBpRKDCc9J8CGvpyqYfLcfRJxJEi y/990ie/AZIpuIy4u4PWhjoXx4sKIAJoayluDjOtHsgIo7cACDQrvEhmQIJhSRcLfL2snry3HJL R0TzMQBAAJUJOhgFJ9suzgjlEhfiaKE1ypHwSvsR+eXfw== X-Received: by 127.0.0.2 with SMTP id lHByYY7687511x5GSYTPnoA9; Mon, 22 Apr 2024 03:47:37 -0700 X-Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by mx.groups.io with SMTP id smtpd.web10.15589.1713782856651528911 for ; Mon, 22 Apr 2024 03:47:36 -0700 X-Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-563-UcPe2m36PIW9lBjfsRvAJw-1; Mon, 22 Apr 2024 06:47:34 -0400 X-MC-Unique: UcPe2m36PIW9lBjfsRvAJw-1 X-Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.rdu2.redhat.com [10.11.54.7]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 055B1812C54; Mon, 22 Apr 2024 10:47:34 +0000 (UTC) X-Received: from sirius.home.kraxel.org (unknown [10.39.192.150]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 9D3231C060D0; Mon, 22 Apr 2024 10:47:33 +0000 (UTC) X-Received: by sirius.home.kraxel.org (Postfix, from userid 1000) id 4FFC518009DC; Mon, 22 Apr 2024 12:47:29 +0200 (CEST) From: "Gerd Hoffmann" To: devel@edk2.groups.io Cc: Konstantin Kostiuk , Oliver Steffen , Jiewen Yao , Ard Biesheuvel , Gerd Hoffmann , Jiewen Yao Subject: [edk2-devel] [PATCH v3 4/5] OvmfPkg/VirtHstiDxe: add code flash check Date: Mon, 22 Apr 2024 12:47:28 +0200 Message-ID: <20240422104729.502112-5-kraxel@redhat.com> In-Reply-To: <20240422104729.502112-1-kraxel@redhat.com> References: <20240422104729.502112-1-kraxel@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.7 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Precedence: Bulk List-Subscribe: List-Help: Sender: devel@edk2.groups.io List-Id: Mailing-List: list devel@edk2.groups.io; contact devel+owner@edk2.groups.io Resent-Date: Mon, 22 Apr 2024 03:47:36 -0700 Resent-From: kraxel@redhat.com Reply-To: devel@edk2.groups.io,kraxel@redhat.com List-Unsubscribe-Post: List-Unsubscribe=One-Click List-Unsubscribe: X-Gm-Message-State: TLHYIGybo73shPX0lXczzwOOx7686176AA= Content-Transfer-Encoding: 8bit Content-Type: text/plain; charset="US-ASCII"; x-default=true X-GND-Status: LEGIT Authentication-Results: spool.mail.gandi.net; dkim=pass header.d=groups.io header.s=20240206 header.b=UROTJ28F; dmarc=fail reason="SPF not aligned (relaxed), DKIM not aligned (relaxed)" header.from=redhat.com (policy=none); spf=pass (spool.mail.gandi.net: domain of bounce@groups.io designates 45.79.224.7 as permitted sender) smtp.mailfrom=bounce@groups.io Detects qemu config issue: code pflash is writable. Checked for both PC and Q35. Cc: Ard Biesheuvel Cc: Jiewen Yao Cc: Konstantin Kostiuk Signed-off-by: Gerd Hoffmann Reviewed-by: Jiewen Yao --- OvmfPkg/VirtHstiDxe/VirtHstiDxe.inf | 2 ++ OvmfPkg/VirtHstiDxe/VirtHstiDxe.h | 13 +++++++++++ OvmfPkg/VirtHstiDxe/QemuCommon.c | 36 +++++++++++++++++++++++++++++ OvmfPkg/VirtHstiDxe/VirtHstiDxe.c | 4 ++++ 4 files changed, 55 insertions(+) create mode 100644 OvmfPkg/VirtHstiDxe/QemuCommon.c diff --git a/OvmfPkg/VirtHstiDxe/VirtHstiDxe.inf b/OvmfPkg/VirtHstiDxe/VirtHstiDxe.inf index b6bdd1f22e83..9514933011e8 100644 --- a/OvmfPkg/VirtHstiDxe/VirtHstiDxe.inf +++ b/OvmfPkg/VirtHstiDxe/VirtHstiDxe.inf @@ -22,6 +22,7 @@ [Sources] VirtHstiDxe.c QemuPC.c QemuQ35.c + QemuCommon.c Flash.c [Packages] @@ -48,6 +49,7 @@ [FeaturePcd] gUefiOvmfPkgTokenSpaceGuid.PcdSmmSmramRequire [Pcd] + gUefiOvmfPkgTokenSpaceGuid.PcdBfvBase gUefiOvmfPkgTokenSpaceGuid.PcdOvmfFlashNvStorageVariableBase [Depex] diff --git a/OvmfPkg/VirtHstiDxe/VirtHstiDxe.h b/OvmfPkg/VirtHstiDxe/VirtHstiDxe.h index ceff41c03711..f8bdcfe8f219 100644 --- a/OvmfPkg/VirtHstiDxe/VirtHstiDxe.h +++ b/OvmfPkg/VirtHstiDxe/VirtHstiDxe.h @@ -8,6 +8,7 @@ SPDX-License-Identifier: BSD-2-Clause-Patent #define VIRT_HSTI_BYTE0_SMM_SMRAM_LOCK BIT0 #define VIRT_HSTI_BYTE0_SMM_SECURE_VARS_FLASH BIT1 +#define VIRT_HSTI_BYTE0_READONLY_CODE_FLASH BIT2 typedef struct { // ADAPTER_INFO_PLATFORM_SECURITY @@ -67,6 +68,18 @@ VirtHstiQemuPCVerify ( VOID ); +/* QemuCommon.c */ + +VOID +VirtHstiQemuCommonInit ( + VIRT_ADAPTER_INFO_PLATFORM_SECURITY *VirtHsti + ); + +VOID +VirtHstiQemuCommonVerify ( + VOID + ); + /* Flash.c */ #define QEMU_FIRMWARE_FLASH_UNKNOWN 0 diff --git a/OvmfPkg/VirtHstiDxe/QemuCommon.c b/OvmfPkg/VirtHstiDxe/QemuCommon.c new file mode 100644 index 000000000000..4ab3fe2d6e63 --- /dev/null +++ b/OvmfPkg/VirtHstiDxe/QemuCommon.c @@ -0,0 +1,36 @@ +/** @file + +SPDX-License-Identifier: BSD-2-Clause-Patent + +**/ + +#include +#include + +#include "VirtHstiDxe.h" + +VOID +VirtHstiQemuCommonInit ( + VIRT_ADAPTER_INFO_PLATFORM_SECURITY *VirtHsti + ) +{ + VirtHstiSetSupported (VirtHsti, 0, VIRT_HSTI_BYTE0_READONLY_CODE_FLASH); +} + +VOID +VirtHstiQemuCommonVerify ( + VOID + ) +{ + CHAR16 *ErrorMsg; + + switch (VirtHstiQemuFirmwareFlashCheck (PcdGet32 (PcdBfvBase))) { + case QEMU_FIRMWARE_FLASH_WRITABLE: + ErrorMsg = L"qemu code pflash is writable"; + break; + default: + ErrorMsg = NULL; + } + + VirtHstiTestResult (ErrorMsg, 0, VIRT_HSTI_BYTE0_READONLY_CODE_FLASH); +} diff --git a/OvmfPkg/VirtHstiDxe/VirtHstiDxe.c b/OvmfPkg/VirtHstiDxe/VirtHstiDxe.c index 74e5e6bd9d4f..b6e53a1219d1 100644 --- a/OvmfPkg/VirtHstiDxe/VirtHstiDxe.c +++ b/OvmfPkg/VirtHstiDxe/VirtHstiDxe.c @@ -104,9 +104,11 @@ VirtHstiOnReadyToBoot ( switch (VirtHstiGetHostBridgeDevId ()) { case INTEL_82441_DEVICE_ID: VirtHstiQemuPCVerify (); + VirtHstiQemuCommonVerify (); break; case INTEL_Q35_MCH_DEVICE_ID: VirtHstiQemuQ35Verify (); + VirtHstiQemuCommonVerify (); break; default: ASSERT (FALSE); @@ -142,9 +144,11 @@ VirtHstiDxeEntrypoint ( switch (DevId) { case INTEL_82441_DEVICE_ID: VirtHsti = VirtHstiQemuPCInit (); + VirtHstiQemuCommonInit (VirtHsti); break; case INTEL_Q35_MCH_DEVICE_ID: VirtHsti = VirtHstiQemuQ35Init (); + VirtHstiQemuCommonInit (VirtHsti); break; default: DEBUG ((DEBUG_INFO, "%a: unknown platform (0x%x)\n", __func__, DevId)); -- 2.44.0 -=-=-=-=-=-=-=-=-=-=-=- Groups.io Links: You receive all messages sent to this group. View/Reply Online (#118083): https://edk2.groups.io/g/devel/message/118083 Mute This Topic: https://groups.io/mt/105667072/7686176 Group Owner: devel+owner@edk2.groups.io Unsubscribe: https://edk2.groups.io/g/devel/unsub [rebecca@openfw.io] -=-=-=-=-=-=-=-=-=-=-=-