From nobody Mon May 6 12:13:07 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) client-ip=66.175.222.108; envelope-from=bounce+27952+71607+1787277+3901457@groups.io; helo=mail02.groups.io; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) smtp.mailfrom=bounce+27952+71607+1787277+3901457@groups.io; dmarc=fail(p=none dis=none) header.from=9elements.com ARC-Seal: i=1; a=rsa-sha256; t=1613045895; cv=none; d=zohomail.com; s=zohoarc; b=EroMxrK3Y3YOOS+eMesrKHXnvIjNe0Q1awXPTbRzK2pwRG8SE9jwSwFSxIjgqI7m8D0C4p8IEZgOdpRyzMmhkjy/LSi2q+D3H7vTUB8cdUWPaPa1EcpTS94JY2d4WfnxZJ9XWGn/HijW+L5eXAXlyLSU3aZxJ+g4XLQFUzyyAoY= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1613045895; h=Content-Transfer-Encoding:Cc:Date:From:List-Id:List-Unsubscribe:MIME-Version:Message-ID:Reply-To:Sender:Subject:To; bh=HzaZ04+EuZMgoU9WWNPsvocB/1iSITu9w5475jeCRWw=; b=gdRccB0slhciCyV+TL2CCZlePPjvT6rTbOlzaW6JubEhB6gqESj4GzTHBcwkwY41RO4WOxpptQIbT94byMhPtW8zWZAbzsSBdopmVLMm41lOglxwKjn+vPUSCaIt+JD1eams/6Q7511Tt79gwJ/aRVpKU1AUuYxXSu1e4wXdR3w= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) smtp.mailfrom=bounce+27952+71607+1787277+3901457@groups.io; dmarc=fail header.from= (p=none dis=none) header.from= Received: from mail02.groups.io (mail02.groups.io [66.175.222.108]) by mx.zohomail.com with SMTPS id 1613045894848932.7528944324787; Thu, 11 Feb 2021 04:18:14 -0800 (PST) Return-Path: X-Received: by 127.0.0.2 with SMTP id 9gs9YY1788612xtE6PcgFjXF; Thu, 11 Feb 2021 04:18:14 -0800 X-Received: from mail-ed1-f46.google.com (mail-ed1-f46.google.com [209.85.208.46]) by mx.groups.io with SMTP id smtpd.web12.7610.1613045888583670564 for ; Thu, 11 Feb 2021 04:18:08 -0800 X-Received: by mail-ed1-f46.google.com with SMTP id s5so6686619edw.8 for ; Thu, 11 Feb 2021 04:18:08 -0800 (PST) X-Gm-Message-State: 4N9sN8oMaw9USsQ9PsX581tKx1787277AA= X-Google-Smtp-Source: ABdhPJzJAvsCdU3cdEOTZ2xY9/8MZl0vETqrEmNS3xNLII8kfedRgHiuV2bYSPgFoJnz/RU+ujJvgw== X-Received: by 2002:aa7:cd8c:: with SMTP id x12mr8260135edv.355.1613045887093; Thu, 11 Feb 2021 04:18:07 -0800 (PST) X-Received: from rudolphp-notebook.9e.network (ip-178-202-79-247.hsi09.unitymediagroup.de. [178.202.79.247]) by smtp.gmail.com with ESMTPSA id m19sm3733320edq.81.2021.02.11.04.18.05 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 11 Feb 2021 04:18:06 -0800 (PST) From: "Patrick Rudolph" To: devel@edk2.groups.io Cc: dandan.bi@intel.com, star.zeng@intel.com, zhichao.gao@intel.com, benjamin.you@intel.com, philipp.deppenwiese@9elements.com, maurice.ma@intel.com, guo.dong@intel.com Subject: [edk2-devel] [PATCH] MdeModulePkg/Universal/SmbiosDxe: Scan for existing tables Date: Thu, 11 Feb 2021 13:18:04 +0100 Message-Id: <20210211121804.2045501-1-patrick.rudolph@9elements.com> MIME-Version: 1.0 Precedence: Bulk List-Unsubscribe: Sender: devel@edk2.groups.io List-Id: Mailing-List: list devel@edk2.groups.io; contact devel+owner@edk2.groups.io Reply-To: devel@edk2.groups.io,patrick.rudolph@9elements.com Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1613045894; bh=ze6IocNw8y5f/OIwqfmRO1pMdwKHLD3qVK3EvB3d5k0=; h=Cc:Date:From:Reply-To:Subject:To; b=C7OMY2jXqQLZ/s7+Cq0a4jTIsvNIB+fPhMwBn2lSh8uLlHORRqIPs1HaCGa3kYKen6/ W1cGANnAhF/qUcrqB0qzhji1FYMB445LrwNepxM0bMaj1soAUwu/HQXP7vXvQnfzd8NX8 mZF9ZaO/xQzCaQUKTCytYLiHcuv6g/PegU0= X-ZohoMail-DKIM: pass (identity @groups.io) Content-Type: text/plain; charset="utf-8" The default EfiSmbiosProtocol operates on an empty SMBIOS table. The SMBIOS tables are provided by the bootloader on UefiPayloadPkg. Scan for existing tables in SmbiosDxe and load them if they seem valid. This fixes the settings menu not showing any hardware information, instead only "0 MB RAM" was displayed. Tests showed that the OS can still see the SMBIOS tables. Signed-off-by: Patrick Rudolph --- MdeModulePkg/Universal/SmbiosDxe/SmbiosDxe.c | 223 +++++++++++++++++++- 1 file changed, 221 insertions(+), 2 deletions(-) diff --git a/MdeModulePkg/Universal/SmbiosDxe/SmbiosDxe.c b/MdeModulePkg/Un= iversal/SmbiosDxe/SmbiosDxe.c index 3cdb0b1ed7..958a249cf9 100644 --- a/MdeModulePkg/Universal/SmbiosDxe/SmbiosDxe.c +++ b/MdeModulePkg/Universal/SmbiosDxe/SmbiosDxe.c @@ -1408,6 +1408,177 @@ SmbiosTableConstruction ( } } =20 +/** + Validates a SMBIOS 2.0 table entry point. + + @param EntryPointStructure The SMBIOS_TABLE_ENTRY_POINT to validate. + + @retval TRUE SMBIOS table entry point is valid. + @retval FALSE SMBIOS table entry point is malformed. + +**/ +STATIC +BOOLEAN +ValidateSmbios20Table( + IN SMBIOS_TABLE_ENTRY_POINT *EntryPointStructure +) { + UINT8 Checksum; + + if (CompareMem (EntryPointStructure->AnchorString, "_SM_", 4) !=3D 0) { + return FALSE; + } + if (EntryPointStructure->EntryPointLength < 0x1E) { + return FALSE; + } + if (EntryPointStructure->MajorVersion < 2) { + return FALSE; + } + if (EntryPointStructure->SmbiosBcdRevision > 0 && + (EntryPointStructure->SmbiosBcdRevision >> 4) < 2) { + return FALSE; + } + if (EntryPointStructure->TableLength =3D=3D 0) { + return FALSE; + } + if (EntryPointStructure->TableAddress =3D=3D 0 || + EntryPointStructure->TableAddress =3D=3D ~0) { + return FALSE; + } + + Checksum =3D CalculateSum8((UINT8 *) EntryPointStructure, + EntryPointStructure->EntryPointLength); + if (Checksum !=3D 0) { + return FALSE; + } + + Checksum =3D CalculateSum8((UINT8 *) EntryPointStructure + 0x10, + EntryPointStructure->EntryPointLength - 0x10); + if (Checksum !=3D 0) { + return FALSE; + } + return TRUE; +} + +/** + Validates a SMBIOS 3.0 table entry point. + + @param Smbios30EntryPointStructure The SMBIOS_TABLE_3_0_ENTRY_POINT t= o validate. + + @retval TRUE SMBIOS table entry point is valid. + @retval FALSE SMBIOS table entry point is malformed. + +**/ +STATIC +BOOLEAN +ValidateSmbios30Table( + IN SMBIOS_TABLE_3_0_ENTRY_POINT *Smbios30EntryPointStructure +) { + UINT8 Checksum; + + if (CompareMem (Smbios30EntryPointStructure->AnchorString, "_SM3_", 5) != =3D 0) { + return FALSE; + } + if (Smbios30EntryPointStructure->EntryPointLength < 0x18) { + return FALSE; + } + if (Smbios30EntryPointStructure->MajorVersion < 3) { + return FALSE; + } + if (Smbios30EntryPointStructure->TableMaximumSize =3D=3D 0) { + return FALSE; + } + if (Smbios30EntryPointStructure->TableAddress =3D=3D 0 || + Smbios30EntryPointStructure->TableAddress =3D=3D ~0) { + return FALSE; + } + + Checksum =3D CalculateSum8((UINT8 *) Smbios30EntryPointStructure, + Smbios30EntryPointStructure->EntryPointLength); + if (Checksum !=3D 0) { + return FALSE; + } + return TRUE; +} + +/** + Parse an existing SMBIOS table and insert it using SmbiosAdd. + + @param ImageHandle The EFI_HANDLE to this driver. + @param Smbios The SMBIOS table to parse. + @param Length The length of the SMBIOS table. + + @retval EFI_SUCCESS SMBIOS table was parsed and installed. + @retval EFI_OUT_OF_RESOURCES Record was not added due to lack of system= resources. + +**/ +STATIC +EFI_STATUS +ParseAndAddExistingSmbiosTable( + IN EFI_HANDLE ImageHandle, + IN SMBIOS_STRUCTURE_POINTER Smbios, + IN UINTN Length +) { + EFI_STATUS Status; + CHAR8 *String; + EFI_SMBIOS_HANDLE SmbiosHandle; + SMBIOS_STRUCTURE_POINTER SmbiosEnd; + + SmbiosEnd.Raw =3D Smbios.Raw + Length; + + do { + // Check for end marker + if (Smbios.Hdr->Type =3D=3D 127) { + break; + } + + // Install the table + SmbiosHandle =3D SMBIOS_HANDLE_PI_RESERVED; + Status =3D SmbiosAdd ( + &mPrivateData.Smbios, + ImageHandle, + &SmbiosHandle, + Smbios.Hdr + ); + + ASSERT_EFI_ERROR (Status); + if (EFI_ERROR (Status)) { + return Status; + } + // + // Go to the next SMBIOS structure. Each SMBIOS structure may include = 2 parts: + // 1. Formatted section; 2. Unformatted string section. So, 2 steps ar= e needed + // to skip one SMBIOS structure. + // + + // + // Step 1: Skip over formatted section. + // + String =3D (CHAR8 *) (Smbios.Raw + Smbios.Hdr->Length); + + // + // Step 2: Skip over unformatted string section. + // + do { + // + // Each string is terminated with a NULL(00h) BYTE and the sets of s= trings + // is terminated with an additional NULL(00h) BYTE. + // + for ( ; *String !=3D 0; String++) { + } + + if (*(UINT8*)++String =3D=3D 0) { + // + // Pointer to the next SMBIOS structure. + // + Smbios.Raw =3D (UINT8 *)++String; + break; + } + } while (TRUE); + } while (Smbios.Raw < SmbiosEnd.Raw); + + return EFI_SUCCESS; +} + /** =20 Driver to produce Smbios protocol and pre-allocate 1 page for the final = SMBIOS table. @@ -1426,7 +1597,10 @@ SmbiosDriverEntryPoint ( IN EFI_SYSTEM_TABLE *SystemTable ) { - EFI_STATUS Status; + EFI_STATUS Status; + SMBIOS_TABLE_ENTRY_POINT *SmbiosTable; + SMBIOS_TABLE_3_0_ENTRY_POINT *Smbios30Table; + SMBIOS_STRUCTURE_POINTER Smbios; =20 mPrivateData.Signature =3D SMBIOS_INSTANCE_SIGNATURE; mPrivateData.Smbios.Add =3D SmbiosAdd; @@ -1450,6 +1624,51 @@ SmbiosDriverEntryPoint ( EFI_NATIVE_INTERFACE, &mPrivateData.Smbios ); + // + // Scan for existing SMBIOS tables installed by bootloader + // + Status =3D EfiGetSystemConfigurationTable ( + &gEfiSmbios3TableGuid, + (VOID **) &Smbios30Table + ); + if (!EFI_ERROR (Status) && ValidateSmbios30Table(Smbios30Table)) { + Smbios.Raw =3D AllocatePool(Smbios30Table->TableMaximumSize); + if (!Smbios.Raw) { + return EFI_OUT_OF_RESOURCES; + } + // + // Backup old table in case it gets overwritten while parsing it + // + CopyMem (Smbios.Raw, (VOID *)Smbios30Table, Smbios30Table->TableMaximu= mSize); + Status =3D ParseAndAddExistingSmbiosTable(ImageHandle, Smbios, Smbios3= 0Table->TableMaximumSize); + FreePool(Smbios.Raw); + if (EFI_ERROR (Status)) { + DEBUG ((DEBUG_ERROR, "SmbiosDriverEntryPoint: Failed to parse preins= talled tables\n")); + Status =3D EFI_SUCCESS; + } + } + + Status =3D EfiGetSystemConfigurationTable ( + &gEfiSmbiosTableGuid, + (VOID **) &SmbiosTable + ); + if (!EFI_ERROR (Status) && ValidateSmbios20Table(SmbiosTable)) { + Smbios.Raw =3D AllocatePool(SmbiosTable->TableLength); + if (!Smbios.Raw) { + return EFI_OUT_OF_RESOURCES; + } + // + // Backup old table in case it gets overwritten while parsing it + // + CopyMem (Smbios.Raw, (VOID *)(UINTN)SmbiosTable->TableAddress, SmbiosT= able->TableLength); =20 - return Status; + Status =3D ParseAndAddExistingSmbiosTable(ImageHandle, Smbios, SmbiosT= able->TableLength); + FreePool(Smbios.Raw); + if (EFI_ERROR (Status)) { + DEBUG ((DEBUG_ERROR, "SmbiosDriverEntryPoint: Failed to parse preins= talled tables\n")); + Status =3D EFI_SUCCESS; + } + } + + return EFI_SUCCESS; } --=20 2.26.2 -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- Groups.io Links: You receive all messages sent to this group. View/Reply Online (#71607): https://edk2.groups.io/g/devel/message/71607 Mute This Topic: https://groups.io/mt/80555727/1787277 Group Owner: devel+owner@edk2.groups.io Unsubscribe: https://edk2.groups.io/g/devel/unsub [importer@patchew.org] -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-