summaryrefslogtreecommitdiff
AgeCommit message (Collapse)Author
2023-06-21pe: only process RelocDir->Size of reloc sectionMike Beaton
Previously processing full padding-aligned Section->Misc.VirtualSize relied on padding reloc entries being inserted by GenFw, which is not required by spec. This changes it to only process the amount referenced by Size, rather than VirtualSize which may be bigger than the data present. Signed-off-by: Mike Beaton <mjsbeaton@gmail.com>
2023-06-21Work around malformed path delimiters in file paths from DHCPAlberto Perez
shim uses path delimiters to determine the file path for the second stage. Currently only / (slash) is detected, but some DHCP implementations supply \ (backslash) as the path specifier. This patch changes it to accept either delimiter. Fixes issue #524. Signed-off-by: Alberto Perez <aperezguevar@microsoft.com>
2023-06-06Add a security contact email address in README.mdPeter Jones
Signed-off-by: Peter Jones <pjones@redhat.com>
2023-05-02SBAT-related documents formatting and spellingKamil Aronowski
A rendering error which caused the `<Vendor>_key.EFI` text to be rendered as `_key.EFI` has been fixed. The text was being rendered incorrectly by GitHub since the <Vendor> part was being treated as an HTML tag and therefore ignored. Two misspellings have been fixed Tables have been reformatted to be more readable as plaintext. Rendering remains the same. Signed-off-by: Kamil Aronowski <kamil.aronowski@yahoo.com>
2023-05-02Further improve load_certs() for non-compliant drivers/firmwaresPete Batard
Following the discovery of more problematic firmwares and drivers affected by the issue f23883ccf78f1f605a272f9e5700f47e5494a71d is designed to address (e.g. https://github.com/rhboot/shim/issues/558), this patch further improves the code so that, instead of simply bailing out, we progressively increase the buffer sizes, until either success or a maximum size limit is reached. In most cases, this workaround should be enough to ensure completion of the directory read and thus provide full shim functionality (while still warning the user about the non-compliance of their environment). Signed-off-by: Pete Batard <pete@akeo.ie>
2023-05-02Block Debian grub binaries with SBAT < 4Steve McIntyre
(See https://bugs.debian.org/1024617) One of the Debian builds of grub bumped the SBAT to 3, but didn't include the patches needed. Add "grub.debian,4" to block those binaries. Signed-off-by: Steve McIntyre <steve@einval.com>
2023-05-02test-sbat: Fix exit codeNicholas Bishop
Fix the `main` function in `test-sbat.c` to return the `status` variable like the other `test-*.c` files. Signed-off-by: Nicholas Bishop <nicholasbishop@google.com>
2023-05-02Drop invalid calls to `CRYPTO_set_mem_functions`Nicholas Bishop
These calls did not check the return value. If they had, it would have shown that the calls were failing due to passing `NULL` for the `realloc` function pointer. That causes an early return, so the calls weren't actually doing anything. The `malloc`/`realloc`/`free` functions defined in Cryptlib/SysCall/BaseMemAllocation.c are what actually get used, so just drop the explicit call to `CRYPTO_set_mem_functions`. Signed-off-by: Nicholas Bishop <nicholasbishop@google.com>
2023-05-02Optionally allow to keep shim protocol installedLuca Boccassi
If the ShimRetainProtocol variable is set, avoid uninstalling our protocol. For example, this allows sd-stub in a UKI to use the shim protocol to validate PE binaries, even if it is executed by a second stage, before the kernel is loaded. Ensure that the variable is volatile and for BootServices access. Also delete it on startup, so that we can be sure it was really set by a second stage. Example use case in sd-boot/sd-stub: https://github.com/systemd/systemd/pull/27358 Signed-off-by: Luca Boccassi <bluca@debian.org>
2023-02-01Don't loop forever in load_certs() with buggy firmwareRenaud Métrich
On DELL R350 booting DVD through RFS with BIOS 1.4.2 in Secure Boot, firmware returns EFI_BUFFER_TOO_SMALL but with new buffersize set to 0, which causes the load_certs() code to loop forever: while (1) { efi_status = dir->Read(dir, &buffersize, buffer); if (efi_status == EFI_BUFFER_TOO_SMALL) { ... continue; } ... } This commit prevents such infinite loop. Signed-off-by: Renaud Métrich <rmetrich@redhat.com>
2023-01-31Release 15.7-1debian/15.7-1Steve McIntyre
2023-01-30Swith to using the upstream "enable NX" patchSteve McIntyre
2023-01-29Block Debian grub binaries with sbat < 4 (see #1024617)Steve McIntyre
2023-01-27pe: Add IS_PAGE_ALIGNED macroNicholas Bishop
This makes some checks in `get_mem_attrs` and `update_mem_attrs` clearer. Also add `test-pe-util.c` with a test for the new macro. The file is named that way instead of `test-pe.c` to avoid having to get `pe.c` building in the unit test environment. Signed-off-by: Nicholas Bishop <nicholasbishop@google.com>
2023-01-27pe: Align section size up to page size for mem attrsNicholas Bishop
Setting memory attributes is generally done at page granularity, and this is enforced by checks in `get_mem_attrs` and `update_mem_attrs`. But unlike the section address, the section size isn't necessarily aligned to 4KiB. Round up the section size to fix this. Signed-off-by: Nicholas Bishop <nicholasbishop@google.com>
2023-01-27CryptoPkg/BaseCryptLib: Fix buffer overflow issue in realloc wrapperLong Qin
There is one long-standing problem in CRT realloc wrapper, which will cause the obvious buffer overflow issue when re-allocating one bigger memory block: void *realloc (void *ptr, size_t size) { // // BUG: hardcode OldSize == size! We have no any knowledge about // memory size of original pointer ptr. // return ReallocatePool ((UINTN) size, (UINTN) size, ptr); } This patch introduces one extra header to record the memory buffer size information when allocating memory block from malloc routine, and re-wrap the realloc() and free() routines to remove this BUG. Cc: Laszlo Ersek <lersek@redhat.com> Cc: Ting Ye <ting.ye@intel.com> Cc: Jian J Wang <jian.j.wang@intel.com> Contributed-under: TianoCore Contribution Agreement 1.0 Signed-off-by: Qin Long <qin.long@intel.com> Reviewed-by: Jian J Wang <jian.j.wang@intel.com> Validated-by: Jian J Wang <jian.j.wang@intel.com> Cherry picked from https://github.com/tianocore/edk2.git, commit cf8197a39d07179027455421a182598bd6989999. Changes: * `SIGNATURE_32` -> `EFI_SIGNATURE_32` * Added definition of `MIN` Fixes https://github.com/rhboot/shim/issues/538 Signed-off-by: Nicholas Bishop <nicholasbishop@google.com>
2023-01-27Enable the NX compatibility flag by default.Peter Jones
Currently by default, when we build shim we do not set the PE NX-compatibility DLL Characteristic flag. This signifies to the firmware that shim (including the components it loads) is not prepared for several related firmware changes: - non-executable stack - non-executable pages from AllocatePages()/AllocatePool()/etc. - non-writable 0 page (not strictly related but some firmware will be transitioning at the same time) - the need to use the UEFI 2.10 Memory Attribute Protocol to set page permissions. This patch changes that default to be enabled by default. Distributors of shim will need to ensure that either their builds disable this bit (using "post-process-pe -N"), or that the bootloaders and kernels you support loading are all compliant with this change. A new make variable, POST_PROCESS_PE_FLAGS, has been added to simplify doing so. Signed-off-by: Peter Jones <pjones@redhat.com>
2023-01-24Enable NX support at build timeSteve McIntyre
As required by policy for signing new shim binaries.
2023-01-22Update upstream commit hash in buildSteve McIntyre
We're using 657b2483ca6e9fcf2ad8ac7ee577ff546d24c3aa, which is the 15.7 release plus the one patch we're applying.
2023-01-22Update to Standards-Version 4.6.2 (no changes needed)Steve McIntyre
2023-01-22Switch to using gcc-12Steve McIntyre
Closes: #1022180
2023-01-22Switch to new upstream (15.7)Steve McIntyre
Also import patch to deal with buggy binutils
2023-01-22Update upstream source from tag 'upstream/15.7'Steve McIntyre
Update to upstream version '15.7' with Debian dir f802105ae061241b13ab962854f56388092fc703
2023-01-22New upstream version 15.7upstream/15.7Steve McIntyre
2022-12-07Make sbat_var.S parse right with buggy gcc/binutilsPeter Jones
In https://github.com/rhboot/shim/issues/533 , iokomin noticed that gas in binutils before 2.36 appears to be incorrectly concatenating string literals in '.asciz' directives, including an extra NUL character in between the strings, and this will cause us to incorrectly parse the .sbatlevel section in shim binaries. This patch adds test cases that will cause the build to fail if this has happened, as well as changing sbat_var.S to to use '.ascii' and '.byte' to construct the data, rather than using '.asciz'. Signed-off-by: Peter Jones <pjones@redhat.com>
2022-11-16Update version to 15.715.7Peter Jones
Signed-off-by: Peter Jones <pjones@redhat.com>
2022-11-16Bump grub's sbat requirement to grub,3Peter Jones
Due to the issues addressed in the 2022-11-15 batch of grub CVEs[0], we need to bump the sbat version from grub. This patch changes it from 2 to 3. [0] https://lists.gnu.org/archive/html/grub-devel/2022-11/msg00059.html Signed-off-by: Peter Jones <pjones@redhat.com>
2022-11-16Update shim's .sbat to sbat,3Peter Jones
Though we don't need to bump SBAT_LEVEL for this, we've decided to change the level to 3 here in case 53509eaf2253e23bfb552e9386fd0877abe592b4 turns out to be worse than we think it is, so we can fix that easily later. Signed-off-by: Peter Jones <pjones@redhat.com>
2022-11-16More coverity modelingPeter Jones
This adds a few more UEFI functions to our coverity model, so we see a few less false positives during scanning. It also fixes an error in our model for OpenSSL's OBJ_dup(). Signed-off-by: Peter Jones <pjones@redhat.com>
2022-11-15CryptoPkg/BaseCryptLib: fix NULL dereferenceJian J Wang
AuthenticodeVerify() calls OpenSSLs d2i_PKCS7() API to parse asn encoded signed authenticode pkcs#7 data. when this successfully returns, a type check is done by calling PKCS7_type_is_signed() and then Pkcs7->d.sign->contents->type is used. It is possible to construct an asn1 blob that successfully decodes and have d2i_PKCS7() return a valid pointer and have PKCS7_type_is_signed() also return success but have Pkcs7->d.sign be a NULL pointer. Looking at how PKCS7_verify() [inside of OpenSSL] implements checking for pkcs7 structs it does the following: - call PKCS7_type_is_signed() - call PKCS7_get_detached() Looking into how PKCS7_get_detatched() is implemented, it checks to see if p7->d.sign is NULL or if p7->d.sign->contents->d.ptr is NULL. As such, the fix is to do the same as OpenSSL after calling d2i_PKCS7(). - Add call to PKS7_get_detached() to existing error handling Cc: Chao Zhang <chao.b.zhang@intel.com> Cc: Jiewen Yao <jiewen.yao@intel.com> Signed-off-by: Jian J Wang <jian.j.wang@intel.com> Cherry-picked-from: https://github.com/tianocore/edk2/commit/26442d11e620a9e81c019a24a4ff38441c64ba10
2022-11-14mok: remove MokListTrusted from PCR 7Arthur Gautier
MokListTrusted was added by mistake to PCR 7 in 4e513405. The value of MokListTrusted does not alter the behavior of secure boot so, as per https://trustedcomputinggroup.org/wp-content/uploads/TCG_PCClient_PFP_r1p05_v23_pub.pdf#page=36 (section 3.3.4 PCR usage) so it should not be factored in the value of PCR 7. See: https://github.com/rhboot/shim/pull/423 https://github.com/rhboot/shim/commit/4e513405b4f1641710115780d19dcec130c5208f Fixes https://github.com/rhboot/shim/issues/484 Fixes https://github.com/rhboot/shim/issues/492 Signed-off-by: Arthur Gautier <arthur.gautier@arista.com>
2022-11-14make-archive: Build reproducible tarballJulian Andres Klode
Remove timestamps, user names, etc. from the tarball so that it can be built reproducibly by multiple people, on different machines. The outer bzip2 layer might still be different, no reproducible bzip2 known. Signed-off-by: Julian Andres Klode <julian.klode@canonical.com>
2022-11-14pe: Fix image section entry-point validationIlya Okomin
Seen mokmanager image load failure '2 sections contain entry point' for shim built on Oracle Linux 9 aarch64. found_entry_point counter in handle_image() uses SizeOfRawData to calculate section boundary. PE spec defines VirtualSize for the total size of the section when loaded into memory. SizeOfRawData is the size of the section (for object files) or the size of the initialized data on disk. Fix this issue by updating section in-memory size limit to VirtualSize. Resolves: #517 Signed-off-by: Ilya Okomin <ilya.okomin@oracle.com>
2022-11-14Add -malign-double to IA32 compiler flagsNicholas Bishop
This changes the alignment of UINT64 data to 8 bytes on IA32, which matches EDK2's understanding of alignment. In particular this change affects the offset where shim writes `EFI_LOADED_IMAGE.ImageSize`. Fixes https://github.com/rhboot/shim/issues/515 Signed-off-by: Nicholas Bishop <nicholasbishop@google.com>
2022-11-08load_cert_file: Use EFI RT memory functionEric Snowberg
Use the EFI RT memory function CopyMem instead of memcpy in load_cert_file. Signed-off-by: Eric Snowberg <eric.snowberg@oracle.com>
2022-11-08load_cert_file: Fix stack issueEric Snowberg
0214cd9cef5a fixes a NULL pointer dereference problem, it introduces two new problems. First it incorrectly assumes li.FilePath is a string. Second, it puts EFI_LOADED_IMAGE li on the stack. It has been found that not all archectures can handle this being on the stack. The shim_li variable will be setup properly from the read_image call. Use the global shim_li variable instead when calling verify_image. Signed-off-by: Eric Snowberg <eric.snowberg@oracle.com>
2022-10-04shim: Flush the memory region from i-cache before executiondann frazier
We've seen crashes in early GRUB code on an ARM Cortex-A72-based platform that point at seemingly harmless instructions. Flushing the i-cache of those instructions prior to executing has been shown to avoid the problem, which has parallels with this story: https://www.mail-archive.com/osv-dev@googlegroups.com/msg06203.html Add a cache flushing utility function and provide an implementation using a GCC intrinsic. This will need to be extended to support other compilers. Note that this intrinsic is a no-op for x86 platforms. This fixes issue #498. Signed-off-by: dann frazier <dann.frazier@canonical.com>
2022-09-01Discard load-options that start with a NULRobbie Harwood
In 6c8d08c0af4768c715b79c8ec25141d56e34f8b4 ("shim: Ignore UEFI LoadOptions that are just NUL characters."), a check was added to discard load options that are entirely NUL. We now see some firmwares that start LoadOptions with a NUL, and then follow it with garbage (path to directory containing loaders). Widen the check to just discard anything that starts with a NUL. Resolves: #490 Related: #95 See-also: https://bugzilla.redhat.com/show_bug.cgi?id=2113005 Signed-off-by: Robbie Harwood <rharwood@redhat.com>
2022-08-16Enable TDX measurement to RTMR registerLu Ken
Intel Trust Domain Extensions (Intel TDX) extends Virtual Machine Extensions (VMX) and Multi-Key Total Memory Encryption (MK-TME) with a new kind of virtual machine guest called a Trust Domain(TD)[1]. A TD runs in a CPU mode that is designed to protect the confidentiality of its memory contents and its CPU state from any other software, including the hosting Virtual Machine Monitor (VMM). Trust Domain Virtual Firmware (TDVF) is required to provide Intel TDX implementation and service for EFI_CC_MEASUREMENT_PROTOCOL[2]. The bugzilla for TDVF is at https://bugzilla.tianocore.org/show_bug.cgi?id=3625. To support CC measurement/attestation with Intel TDX technology, these 4 RTMR registers will be extended by TDX service like TPM/TPM2 PCR: - RTMR[0] for TDVF configuration - RTMR[1] for the TD OS loader and kernel - RTMR[2] for the OS application - RTMR[3] reserved for special usage only Add a TDX Implementation for CC Measurement protocol along with TPM/TPM2 protocol. References: [1] https://software.intel.com/content/dam/develop/external/us/en/documents/tdx-whitepaper-v4.pdf [2] https://software.intel.com/content/dam/develop/external/us/en/documents/tdx-virtual-firmware-design-guide-rev-1.pdf [3] https://software.intel.com/content/dam/develop/external/us/en/documents/intel-tdx-guest-hypervisor-communication-interface-1.0-344426-002.pdf Signed-off-by: Lu Ken <ken.lu@intel.com> [rharwood: style pass on code and commit message] Signed-off-by: Robbie Harwood <rharwood@redhat.com>
2022-08-04Add a link to the test plan in the readme.Peter Jones
It's been suggested that we should link to the test plan in the readme. This seems pretty reasonable to me, so here it is. Signed-off-by: Peter Jones <pjones@redhat.com>
2022-08-03Reference MokListRT instead of MokListEric Snowberg
When calling back into shim from grub, the MokListRT may contain additional entries not available in the original MokList, an example being the certs included via user_cert. Use the MokListRT instead when calling check_db_cert and check_db_hash. Signed-off-by: Eric Snowberg <eric.snowberg@oracle.com>
2022-08-03Make SBAT variable payload introspectableChris Coulson
Given a set of EFI variables and boot assets, it should be possible to compute what the value of PCR 7 will be on the next boot. As shim manages the contents of the SbatLevel variable and this is measured to PCR 7, export the payloads that shim contains in a new COFF section (.sbatlevel) so that it can be introspected by code outside of shim. The new section works a bit like .vendor_cert - it contains a header and then the payload. In this case, the header contains no size fields because the strings are NULL terminated. Shim uses this new section internally in set_sbat_uefi_variable. The .sbatlevel section starts with a 4 byte version field which is not used by shim but may be useful for external auditors if the format of the section contents change in the future. Signed-off-by: Chris Coulson <chris.coulson@canonical.com>
2022-07-21Release 15.6-1debian/15.6-1Steve McIntyre
2022-06-23Start packaging updates for the new 15.6 upstream releaseSteve McIntyre
Remove all our patches, all upstream now
2022-06-23New upstream version 15.6upstream/15.6Steve McIntyre
2022-06-23Update upstream source from tag 'upstream/15.6'Steve McIntyre
Update to upstream version '15.6' with Debian dir 952ad3d5a92a2003f3496a79d1875a951c255396
2022-06-01bump version to shim-15.615.6Peter Jones
Signed-off-by: Peter Jones <pjones@redhat.com>
2022-06-01sbat: add the parsed SBAT variable entries to the debug logPeter Jones
Signed-off-by: Peter Jones <pjones@redhat.com>
2022-05-31shim-15.6~rc215.6-rc2Peter Jones
Signed-off-by: Peter Jones <pjones@redhat.com>
2022-05-24Also avoid CVE-2022-28737 in verify_image()Peter Jones
PR 446 ("Add verify_image") duplicates some of the code affected by Chris Coulson's defense in depth patch against CVE-2022-28737 ("pe: Perform image verification earlier when loading grub"). This patch makes the same change to the new function. Signed-off-by: Peter Jones <pjones@redhat.com>