summaryrefslogtreecommitdiff
path: root/include
AgeCommit message (Collapse)Author
2025-03-14Make 'make fanalyzer' work again.Peter Jones
It breaks every time somehow. Signed-off-by: Peter Jones <pjones@redhat.com>
2025-02-26Some save_logs() improvements.Peter Jones
In d972515e608e ("Save the debug and error logs in mok-variables") had a few deficiencies: 1) the size of the result table isn't correctly computed when either errlog or dbglog is 0 sized (much more likely for the former), 2) when we save the error log we leak the allocation for the previous mok variables, and 3) original mok variables were allocated with AllocatePages(), but the new ones were allocated with AllocateZeroPool(). The former guarantees page alignment, which we want here. This fixes all three of these. Signed-off-by: Peter Jones <pjones@redhat.com>
2025-02-25peimage.h: minor whitespace fixesPeter Jones
Signed-off-by: Peter Jones <pjones@redhat.com>
2025-02-25Add shim's current NX_COMPAT status to HSIStatusPeter Jones
hughsie asked me to also make it observable at runtime whether the shim binary that was used to boot was set as NX_COMPAT or not. This adds that into the HSIStatus data as "shim-has-nx-compat-set". Signed-off-by: Peter Jones <pjones@redhat.com>
2025-02-25pe: read_header(): allow skipping SecDir content validationPeter Jones
When we're parsing the PE header of shim itself from the Loaded Image object, the signatures aren't present, but the Certificate Table entry in the Data Directory has not been cleared, so it'll fail verification. We know when we're doing that, so this patch makes that test optional. Signed-off-by: Peter Jones <pjones@redhat.com>
2025-02-25HSI: Add decode_hsi_bits() for easier reading of the debug logPeter Jones
This changes all the HSI bitfield operations to print a string showing the change instead of just hex values. Signed-off-by: Peter Jones <pjones@redhat.com>
2025-02-25hexdump: give a different debug log for size==0Peter Jones
Signed-off-by: Peter Jones <pjones@redhat.com>
2025-02-24Add DXE Services information to HSIPeter Jones
This adds three more entries to our HSI data: has-dxe-services-table: technically only tells us if UEFI's LocateProtocol will give us a DXE services table, but practically also tells us if the machine is implementing DXE in any way. has-get-memory-space-descriptor: tells us if DXE->GetMemorySpaceDescriptor is populated has-set-memory-space-descriptor: tells us if DXE->SetMemorySpaceDescriptor is populated Signed-off-by: Peter Jones <pjones@redhat.com>
2025-02-24Add support for DXE memory attribute updates.Peter Jones
This adds DXE implementations of get_mem_attrs() and update_mem_attrs() for machines that implement DXE but don't yet have the EFI_MEMORY_ATTRIBUTE_PROTOCOL. Signed-off-by: Peter Jones <pjones@redhat.com>
2025-02-24Move mok state variable data flag definitions to the header.Peter Jones
Previously the mok mirror state flags were only used in the mok mirroring code. But there are other consumers of that data, namely our variable test cases, and it's useful for them to be able to check the flags. Signed-off-by: Peter Jones <pjones@redhat.com>
2025-02-24test-mock-variables: improve some debug printsPeter Jones
This changes test-mock-variables and related code to not print all debug messages at SHIM_DEBUG=1, and also adds some prints and comments for context as to what's going on in the tests. Signed-off-by: Peter Jones <pjones@redhat.com>
2025-02-24shim: add HSIStatus featurePeter Jones
hughsie asked me if I can make shim tell userland what kinds of accesses are allowed to the heap, stack, and allocations on the running platform, so that these could be reported up through fwupd's Host Security ID program (see https://fwupd.github.io/libfwupdplugin/hsi.html ). This adds a new config-only (i.e. not a UEFI variable) variable generated during boot, "/sys/firmware/efi/mok-variables/HSIStatus", which tells us those properties as well as if the EFI Memory Attribute Protocol is present. Signed-off-by: Peter Jones <pjones@redhat.com>
2025-02-24Move memory attribute support to its own file.Peter Jones
This moves the EFI Memory Attribute Protocol helper functions to their own file, since they're not related to PE things. Signed-off-by: Peter Jones <pjones@redhat.com>
2025-02-24mok variables: add a format callbackPeter Jones
This adds a member to the mok_state_variable struct to provide a callback function for formatting external data. It basically has snprintf()-like semantics for filling the buffer, but without the actual printf-like formatting bits. Signed-off-by: Peter Jones <pjones@redhat.com>
2025-02-24mok: add MOK_VARIABLE_CONFIG_ONLYPeter Jones
This adds a mok variable flag "MOK_VARIABLE_CONFIG_ONLY" to specify that the data should be added to our UEFI config table, but shim should not create a legacy UEFI variable. Signed-off-by: Peter Jones <pjones@redhat.com>
2025-02-24Save the debug and error logs in mok-variablesPeter Jones
This changes our debug and error logging to save the entire logs into mok-variables as "shim-dbg.txt" and "shim-log.txt". Signed-off-by: Peter Jones <pjones@redhat.com>
2025-02-24Move error logging decls out of shim.hPeter Jones
This moves decls for errlog.c into errlog.h Signed-off-by: Peter Jones <pjones@redhat.com>
2025-02-24compiler.h: minor ALIGN_... fixesPeter Jones
This fixes some minor errors with the testing of how ALIGN() and similar are defined, and makes an explicit "ALIGN_UP()" macro to complement the existing ALIGN_DOWN() macro. Signed-off-by: Peter Jones <pjones@redhat.com>
2025-02-18post-process-pe: add tests to validate NX complianceDennis Tseng
This changes post-process-pe to give warnings, and optionally errors, if a shim binary is built with Section Alignment or characteristics are not compatible with NX, or if the EFI_IMAGE_DLLCHARACTERISTICS_NX_COMPAT flag is not set and require_nx_compat is true. Co-authored-by: Peter Jones <pjones@redhat.com> Co-authored-by: Kamil Aronowski <kamil.aronowski@yahoo.com> Signed-off-by: Dennis Tseng <dennis.tseng@suse.com>
2025-02-18Allow indepdent SkuSi and SBAT revocation updatesJan Setje-Eilers
While a revocations.efi binary can contain either SBAT revocations, SkuSi revocations, or both, it is desirable to package them separately so that higher level tools such as fwupd can decide which ones to put in place at a given moment. This changes revocations.efi to revocations_sbat.efi and revocations_sku.efi Signed-off-by: Jan Setje-Eilers <Jan.SetjeEilers@oracle.com>
2025-02-18Suppress file open failures for some netboot casesJan Setje-Eilers
Reading files during a netboot comes with the caveat that fetching files from a network does not support anything like listing a directory. In the past this has meant that we do not try to open optional files during a netboot. However at least the revocation.efi file is now tested during a netboot, which will print an error when it is not found. Since that error is spurious we should allow for those errors to be suppressed. This is also desirable since we will likely go looking for additional files in the near future. Signed-off-by: Jan Setje-Eilers <Jan.SetjeEilers@oracle.com>
2025-02-11Implement the rest of the loader protocol functionsPeter Jones
This adds an implementation of Exit() and UnloadImage(), removes the whole "loader_is_participating" mechanism and its supporting code, and removes DISABLE_EBS_PROTECTION. Signed-off-by: Peter Jones <pjones@redhat.com>
2025-02-11Move some stuff aroundPeter Jones
This moves some things around to help with loader protocol changes: - Move replacements.c to loader-proto.c - likewise with replacements.h - move the SHIM_IMAGE_LOADER decl to loader-proto.h - move the LoadImage / StartImage interface setup to an init function - move shim_load_image() / shim_start_image() to loader-proto.c Signed-off-by: Peter Jones <pjones@redhat.com>
2025-02-11Implement shim image load protocolArd Biesheuvel
Define a new protocol for loading and starting images, encapsulating shim's PE loading facilities and verification/authentication against the same set of certificates that shim_lock::verify() authenticates against. This removes the need for loaders like GRUB to implement their own PE loader in order to be able to invoke loaded images as PE applications, rather than implementing a bespoke OS dependent handover protocol (e.g., invoke Linux via its EFI stub) Signed-off-by: Ard Biesheuvel <ardb@kernel.org>
2025-02-06Add configuration option to boot an alternative 2nd stageEric Snowberg
Add the ability for shim to load an optional configuration file. This new file is called "options.csv". The configuration file is completely optional. If used, it is located in the same directory as the booted shim. The "options.csv" file currently allows a single entry. Other options could be added to it in the future. The first and only entry in the file is the name of the secondary boot loader shim will load. The "options.csv" file is in Unicode LE format. This allows a signed shim to directly load a UKI without the need to rename it to grub. Shim's transitive trust is maintained. If the alternative 2nd stage can not be verified, it will not boot. Signed-off-by: Eric Snowberg <eric.snowberg@oracle.com>
2025-02-06Create utils fileEric Snowberg
Move some functions currently used within fallback that will later also be used in shim. Signed-off-by: Eric Snowberg <eric.snowberg@oracle.com>
2025-02-05Generate and use generated_sbat_var_defs.hJan Setje-Eilers
Build changes to generate include/generated_sbat_var_defs.h from SbatLevel_Variable.txt and use that header file. From here on forward SbatLevel_Variable.txt should be the only place a new revocation needs to be recorded. Signed-off-by: Jan Setje-Eilers <Jan.SetjeEilers@oracle.com>
2025-02-03test.mk: don't use a temporary random.binPeter Jones
Sometimes using a temp file to make test-random.h breaks builds because clean and test get made in parallel. Since debugging parallel make is anything but easy, it's better to just not use the intermediate file. This patch makes it use a pipe instead. Because we live in the worst possible world, we have to support RHEL 9, in which xxd does not support "-n prefix", and so we have to build the header variable definition lines in shell. Signed-off-by: Peter Jones <pjones@redhat.com>
2025-01-18test-mok-mirror: minor bug fixPeter Jones
In 70366a286552760863bacb521fb00c654586b494, I introduced a test case for test-mok-mirror to test the behavior when SetVariable() gives EFI_OUT_OF_RESOURCES. Unfortunately this includes a memory error in its cleanup functions: ==1972634== Invalid read of size 8 ==1972634== at 0x4032F3: mock_sv_adjust_usage_data (mock-variables.c:468) ==1972634== by 0x40387B: mock_delete_variable (mock-variables.c:541) ==1972634== by 0x4014E8: mock_reset_variables (mock-variables.c:1353) ==1972634== by 0x401348: mock_finalize_vars_and_configs (mock-variables.c:1405) ==1972634== by 0x401731: main (test-mok-mirror.c:688) ==1972634== Address 0x1ffeffc4f8 is on thread 1's stack ==1972634== 6784 bytes below stack pointer This is caused because the test data uses a linked-list data structure in an array in the test data, and we try to iterate the list to free the data, but of course the list pointers aren't initialized because it's an array. Whoops. This patch makes it so we don't try to clean up that list, because we don't need to. Signed-off-by: Peter Jones <pjones@redhat.com>
2025-01-17tests: make it possible to use different limits for variable spacePeter Jones
This splits up the API for setting default usage limits, adding a test API function to set alternate usage limits. Signed-off-by: Peter Jones <pjones@redhat.com>
2025-01-17Move is_removable_media_path() to a shared location.Peter Jones
We need to use is_removable_media_path(), and potentially other helpers, from Mok as well as shim. This moves it to a file just for Device Path utility functions to make that simpler. Signed-off-by: Peter Jones <pjones@redhat.com>
2025-01-15Backport EFI_HTTP_ERROR status codeDan Nicholson
The define can be dropped when gnu-efi is updated to include de6f9259e8476495c78babbc25250a59de7f3942. Signed-off-by: Dan Nicholson <dbn@endlessos.org>
2024-12-17includes: work around CLANG_PREREQ() double-definitionPeter Jones
Right now when doing test builds with clang, we wind up getting an error from two different definitions of CLANG_PREREQ() in the headers. It might be that we can just rip one of these out, but for now I'm just making one of them conditional. Signed-off-by: Peter Jones <pjones@redhat.com>
2024-04-09sbat: Also bump latest for grub,4 (and to todays date)Julian Andres Klode
Back in January we decided to bump the SBAT level for the shim CVE without bumping the grub level for the previous NTFS issues - CVE-2023-4692 CVE-2023-4693 - as not every vendor was signing the ntfs module. Catch up on this revocation to ensure it doesn't get lost. Doing so also allows us to remove the grub.debian,4 revocation as this happened before grub,4 and hence is obsolete. Also bump the date of the sbat variable to today's. Don't copy the April 5 one to a previous selection, as it wasn't shipped to anyone. Signed-off-by: Julian Andres Klode <julian.klode@canonical.com>
2024-04-09sbat: Add grub.peimage,2 to latest (CVE-2024-2312)Julian Andres Klode
Add the previous latest level to the switch for automatic. Signed-off-by: Julian Andres Klode <julian.klode@canonical.com>
2024-01-22Try to load revocations.efi even if directory read failsJan Setje-Eilers
Network booting tends to expose things like a tfpt server as a filesystem that doesn't implement directory listing This will blindly try to ingest a revocations.efi file in those cases, even if that may result in some console noise when the file does not exist. Signed-off-by: Jan Setje-Eilers <Jan.SetjeEilers@oracle.com>
2024-01-22netboot read_image() should not hardcode DEFAULT_LOADERJan Setje-Eilers
The netboot path up until now hardcodes DEFAULT_LOADER as the only possible filename to load. This is pretty limiting and needs to be fixed. Signed-off-by: Jan Setje-Eilers <Jan.SetjeEilers@oracle.com>
2024-01-22Build time selectable automatic SBATLevel revocationsJan Setje-Eilers
The ability to automatically apply SBATLevel revocations varies from distro to distro. This allows distros that are able to automatically apply SBATLevel revocations when shim is updated to select a level by supplying SBAT_AUTOMATIC_DATE=<datestamp> on the make command line. Currently the following options are available: 2021030218 no revocations - useful for distros that need to rely on an externally delivered revocations.efi 2022052400 grub,2 2022111500 shim,2 grub,3 2023012900 shim,2 grub,3 grub.debian,4 If no datestamp is specified the build will default to the most recent 2023012900. Signed-off-by: Jan Setje-Eilers <Jan.SetjeEilers@oracle.com>
2024-01-22Rename "previous" revocations to "automatic"Jan Setje-Eilers
When the term previous was introduced for revocations to be automatically applied there was a hope that everytime a new revocation was built into shim, the previous revocation could be applied automatically. Further experience has shown the real world to be more complex than that. The automatic payload will realistically contain a set of revocations governed by both the cadence at which a distro's customer base updates as well as the severity of the issue being revoked. This is not a functional change. Signed-off-by: Jan Setje-Eilers <Jan.SetjeEilers@oracle.com>
2024-01-22pe-relocate: Avoid __builtin_add_overflow() on GCC < 5Peter Jones
GCC 4 doesn't have __builtin_add_overflow() and friends, so this results in a compiler error. On platforms using that version, do the arithmetic without it. Signed-off-by: Peter Jones <pjones@redhat.com>
2024-01-17Updated Revocations for January 2024 CVEsJan Setje-Eilers
Since shim is inherently updated by shipping a new shim, the latest built in revocations can include the most recent shim revocations. Since CVE-2023-40547 is high impact, this revocation should be available to everyone as soon as possible. GRUB2 CVE-2023-4692 and CVE-2023-4693 are in the ntfs module that only some vendors ship. Since some vendors did not ship an updated GRUB2 for these issues, the revocation for these CVEs is not included in the payload at this time. Signed-off-by: Jan Setje-Eilers <jan.setjeeilers@oracle.com>
2023-12-05shim should not self revokeJan Setje-Eilers
Before applying an updated SbatLevel shim should re-run introspection and never apply a revocation level that would prevent the currently running shim from booting. The proper way forward is to update shim first. Signed-off-by: Jan Setje-Eilers <Jan.SetjeEilers@oracle.com>
2023-12-05BS Variables for bootmgr revocationsJan Setje-Eilers
This adds support for applying SkuSiPolicy UEFI BS variables. These varaibles are needed for non-dbx based Windows revocations and are described here: https://support.microsoft.com/en-us/topic/kb5027455-guidance-for-blocking-vulnerable-windows-boot-managers-522bb851-0a61-44ad-aa94-ad11119c5e91 Signed-off-by: Jan Setje-Eilers <Jan.SetjeEilers@oracle.com>
2023-12-05Allow SbatLevel data from external binaryJan Setje-Eilers
Ingest SBAT Levels from revocations binary thereby allowing level requirements to be updated independently from shipping a new shim. Do not automatically apply any revocations from a stock shim at this point. Signed-off-by: Jan Setje-Eilers <Jan.SetjeEilers@oracle.com>
2023-12-05Add primitives for overflow-checked arithmetic operations.Peter Jones
We need to do arithmetic on untrusted values sometimes, so this patch adds the following primitives as macros that wrap the compiler builtins. bool checked_add(TYPE addend0, TYPE addend1, TYPE *sum) bool checked_sub(TYPE minuend, TYPE subtrahend, TYPE *difference) bool checked_mul(TYPE factor0, TYPE factor1, TYPE *product) And also the following primitive which returns True if divisor is 0 and False otherwise: bool checked_div(TYPE dividend, TYPE divisor, TYPE *quotient) Signed-off-by: Peter Jones <pjones@redhat.com>
2023-08-25Make some of the static analysis tools a little easier to runPeter Jones
With "gcc -fanalyzer" and "scan-build", it's convenient to be able to continue even though the compiler has returned error on one or more source files. This makes it so compiler errors are ignored in some of those cases. Signed-off-by: Peter Jones <pjones@redhat.com>
2023-06-29Add libFuzzer support to the .sbat parser.Peter Jones
shim takes several forms of input from several sources that are not necessarily trustworthy. As such, we need to take measures to validate that we don't have unacceptable results from bad inputs. One such measure is "fuzzing" the inputs which parse untrusted data by running them with randomized or partially randomized input. This change adds such testing using clang's "libFuzzer" to our parser for ".sbat" sections. I've run it for about half an hour and so far it found one memory leak, but no other errors. Signed-off-by: Peter Jones <pjones@redhat.com>
2023-06-29Add libFuzzer support for csv.cPeter Jones
shim takes several forms of input from several sources that are not necessarily trustworthy. As such, we need to take measures to validate that we don't have unacceptable results from bad inputs. One such measure is "fuzzing" the inputs which parse untrusted data by running them with randomized or partially randomized input. This change adds such testing using clang's "libFuzzer" to our CSV parser. I've run this on 24-cores at 4GHz for half an hour, and so far each fuzzer has converged on 79% coverage. I expect the 21% that's not getting covered are the EFI API mock interfaces we're building in from test.c and similar. So far no errors have been found, which is what was expected since this particular API is being manually fuzzed with ~8kB of /dev/urandom on every build since 2021-02-23. Signed-off-by: Peter Jones <pjones@redhat.com>
2023-06-23Test (and fix) ImageAddress()Peter Jones
This adds a test case for our address sanitation checking function ImageAddresS(). In doing so it addresses two issues: - previously we allowed the address after the last byte of the image to be computed (may need to revert this or fix some callers, we'll see...) - bespoke overflow checking and using + directly instead of using __builtin_add_overflow() Signed-off-by: Peter Jones <pjones@redhat.com>
2023-06-23Split pe.c up even more.Peter Jones
This moves the parts of pe.c that *don't* depend on Cryptlib into pe-relocate.c, so we can write test cases for them without having to make a second openssl build without EFI support. Signed-off-by: Peter Jones <pjones@redhat.com>