summaryrefslogtreecommitdiff
path: root/shim.c
AgeCommit message (Collapse)Author
2017-08-31Revert lots of Cryptlib updates.Peter Jones
OpenSSL changes quite a bit of the key validation, and most of the keys I can find in the wild aren't marked as trusted by the new checker. Intel noticed this too: https://github.com/vathpela/edk2/commit/f536d7c3ed but instead of fixing the compatibility error, they switched their test data to match the bug. So that's pretty broken. For now, I'm reverting OpenSSL 1.1.0e, because we need those certs in the wild to work. This reverts commit 513cbe2aea689bf968f171f894f3d4cdb43524d5. This reverts commit e9cc33d6f2b7f35c6f5e349fd83fb9ae0bc66226. This reverts commit 80d49f758ead0180bfe6161931838e0578248303. This reverts commit 9bc647e2b23bcfd69a0077c0717fbc454c919a57. This reverts commit ae75df6232ad30f3e8736e9449692d58a7439260. This reverts commit e883479f35644d17db7efed710657c8543cfcb68. This reverts commit 97469449fda5ba933a64280917e776487301a127. This reverts commit e39692647f78e13d757ddbfdd36f440d5f526050. This reverts commit 0f3dfc01e2d5e7df882c963dd8dc4a0dfbfc96ad. This reverts commit 4da6ac819510c7cc4ba21d7a735d69b45daa5873. This reverts commit d064bd7eef201f26cb926450a76260b5187ac689. This reverts commit 9bc86cfd6f9387f0da9d5c0102b6aa5627e91c91. This reverts commit ab9a05a10f16b33f7ee1e9da360c7801eebdb9d2. Signed-off-by: Peter Jones <pjones@redhat.com>
2017-08-31Drain the OpenSSL error stack and report crypto verification errorsPeter Jones
Signed-off-by: Peter Jones <pjones@redhat.com>
2017-08-31Init openssl so we can use its debug facilities.Peter Jones
Signed-off-by: Peter Jones <pjones@redhat.com>
2017-08-31Make msleep() be a thingPeter Jones
Signed-off-by: Peter Jones <pjones@redhat.com>
2017-08-11Add ENABLE_SHIM_CERT to make MokManager/fallback signing optional.Peter Jones
This makes shim not create its own keyring and sign MokManager and fallback by default. Signed-off-by: Peter Jones <pjones@redhat.com>
2017-08-03Always measure all of MokSBState, MokList, and MokListXPeter Jones
Even if errors occurred, always try to measure all of our Mok entries. This way we won't fail on e.g. MokList not being set. Signed-off-by: Peter Jones <pjones@redhat.com>
2017-08-03Measure stage 2 according to specMatthew Garrett
We're currently measuring the raw second stage loader into PCR 9, but we're closer to spec if we measure the semi-parsed PE into PCR 4. The hash that's logged is the same as the hash used for the Authenticode validation, so refactor shim.c a little to separate out the hash generation.
2017-08-01Extend PCR 7Matthew Garrett
It's desirable to be able to use PCR 7 for all TPM policy on Secure Boot systems, but right now Shim doesn't record any information about its configuration or the signature used to launch the second stage loader. Add support for that.
2017-06-15update verification_method if the loaded image is signed by shim/vendor certLans Zhang
Signed-off-by: Lans Zhang <jia.zhang@windriver.com>
2017-06-15skip the error message when creating MokListRT if vendor cert is emptyLans Zhang
EFI_NOT_FOUND will be returned when creating MokListRT if vendor cert is empty. This is harmless, meaningless and skippable. Signed-off-by: Lans Zhang <jia.zhang@windriver.com>
2017-04-27Fix buffer overrun / damaged options passed to second_stage.John S. Gruber
start is a UCS-2 character pointer and loader_len is a number of bytes. Adjust loader_len to count characters before adding to the start pointer.
2017-04-11shim: Remove the obsolete OBJ_cleanupGary Lin
Signed-off-by: Gary Lin <glin@suse.com>
2017-04-03generate_hash(): fix the regressionLans Zhang
The commit 03b9f800 introduces an issue in case the gap between SumOfBytesHashed and context->SecDir->VirtualAddress exists. This would be a typo because a formal PE image always meet SumOfBytesHashed + hashsize == context->SecDir->VirtualAddress either the gap exists or not. Signed-off-by: Lans Zhang <jia.zhang@windriver.com>
2017-04-03Ignore BDS when it tells us we got our own path on the command line.Peter Jones
Sometimes we get our own path in LoadOptions for no clear reason. Don't execute it, just ignore it. Signed-off-by: Peter Jones <pjones@redhat.com>
2017-03-27Fix some i386 type casting errorsPeter Jones
Signed-off-by: Peter Jones <pjones@redhat.com>
2017-03-27shim: disambiguate our global image handle.Peter Jones
Signed-off-by: Peter Jones <pjones@redhat.com>
2017-02-28Use EfiLoaderCode memory for loading PE/COFF executablesArd Biesheuvel
Under a strict memory protection policy, UEFI may give out EfiLoaderData memory with the XN attribute set. So use EfiLoaderCode explicitly. At the same time, use a page based allocation rather than a pool allocation, which is more appropriate when loading PE/COFF images. Signed-off-by: Ard Biesheuvel <ard.biesheuvel@linaro.org>
2017-02-06Also just check for access denied anyway.Peter Jones
Signed-off-by: Peter Jones <pjones@redhat.com>
2017-02-06Ensure all of the SB verification returns the same error code.Peter Jones
Previously we were returning EFI_ACCESS_DENIED at some places and EFI_SECURITY_VIOLATION at others. When we're checking whether to run MokManager, we're checking EFI_SECURITY_VIOLATION, which is more or less analogous with what the spec says StartImage() returns. So we should always have that as the return code. I believe this will fix github issue #44. Signed-off-by: Peter Jones <pjones@redhat.com>
2017-02-06shim: fix the mirroring MokSBState failIvan Hu
Some machines have already embedded MokSBStateRT varaible with EFI_VARIABLE_NON_VOLATILE attribute, and some users might disable shim vailidation manually by creating MokSBStateRT. It causes mirroring MokSBState fail because the variable cannot be set with different attribute again, and gets error massage every time when booting. Fix it with checking the MokSBStateRT existence and deleting it before mirroring it. Signed-off-by: Ivan Hu <ivan.hu@canonical.com>
2017-02-06generate_hash(): make check_size() set an error, and verify SecDir size.Peter Jones
Currently generate_hash() attempts to include any trailing data at the end of the binary in the resulting digest, but it won't include such data if the size computed is wrong because context->SecDir->Size is invalid. In this case the return code is EFI_SUCCESS, and the hash will match any a binary as if the Attribute Certificate Table and anything after it are missing. This is wrong. Signed-off-by: Peter Jones <pjones@redhat.com>
2016-09-21shim: verify Extended Key Usage flagsMathieu Trudel-Lapierre
For starters; don't allow the "module signing" OID; which ought to only ever be used for signing kernel modules, not signing EFI binaries. Signed-off-by: Mathieu Trudel-Lapierre <mathieu.trudel-lapierre@canonical.com>
2016-09-09Fix up a merge error in 467878f3e0.Peter Jones
In the branch I wrote the code on, "size" was a thing. On this branch it isn't. Signed-off-by: Peter Jones <pjones@redhat.com>
2016-09-09verify_buffer: check that the value of cert->Hdr.dwLength is reasonablePeter Jones
Signed-off-by: Peter Jones <pjones@redhat.com>
2016-09-06Minor formatting fixPeter Jones
Signed-off-by: Peter Jones <pjones@redhat.com>
2016-09-06Use authenticode signature length from WIN_CERTIFICATE structure.Sachin Agrawal
Authenticode Certificate length is available in Certificate Table (inside PE header) and also in signature header(WIN_CERTIFICATE) itself. Code in 'check_backlist()' method uses length from signature header, whereas, AuthenticodeVerify() call inside 'verify_buffer()' method uses the length in signature header. This causes a security vulnerability issue : Good Scenario : Assume shim1.crt is used for signing grub.efi and shim1.crt is embedded inside shim.efi. Also, assume shim1.crt got compromised and therefore it was added in 'dbx' database. Now, when shim.efi will attempt to load grub.efi, it will fail loading with log message "Binary is blacklisted" because 'check_blacklist' call will detect the presence of 'shim1.crt' in 'dbx'. Vulnerable Scenario : Similar as above. Add 'shim1.crt' in dbx database. Also, tamper the earlier signed grub.efi file by placing 0x0000 in the WIN_CERTIFICATE.dwLength. (Open grub.efi/vmlinuz signed binary with hex editor. Go to 0x128 address and read out the address from 0x128 until 0x12B in little Indian order from right to left. Jump to the address from 0x128 address area. First 8bytes are the signature header area which consist of signature size(4bytes), revision(2bytes) and type(2bytes). So tamper the first 4 bytes for signature size and save the binary. ) With this tampered grub.efi, shim.efi loads it successfully because 'check_blacklist()' call fails to detect the presence of shim1.crt in 'dbx' database. Signed-off-by: Sachin Agrawal <sachin.agrawal@intel.com>
2016-09-06Don't close file twice in should_use_fallback error pathBenjamin Antin
When fallback.efi is not present, the should_use_fallback error path attempts to close a file that has already been closed, resulting in a hang. This issue only affects certain systems. This is a regression from version 0.8 and was introduced by commit 4794822. Signed-off-by: Benjamin Antin <ben.antin@endlessm.com>
2016-09-06shim: remove unused variableGary Lin
Fix the compilation error from gcc: shim.c: In function ‘handle_image’: shim.c:1121:15: error: unused variable ‘size’ [-Werror=unused-variable] unsigned int size; ^~~~ Signed-off-by: Gary Lin <glin@suse.com>
2016-09-06Fix the size of MokDBStateLans Zhang
MokDBState is a 8-bit unsigned integer. Looks like a typo here. Signed-off-by: Lans Zhang <jia.zhang@windriver.com>
2016-09-06Add the optional HTTPBoot supportGary Ching-Pang Lin
This commit adds the basic support for HTTPBoot, i.e. to fetch the next stage loader with the HTTP protocol. It requires gnu-efi >= 3.0.3 to support the URI device path and Ip4Config2 or Ip6Config protocol support in the UEFI implementation. To build shim.efi with HTTPBoot support: make ENABLE_HTTPBOOT=1 shim.efi Signed-off-by: Gary Ching-Pang Lin <glin@suse.com>
2016-09-06read_header/handle_image: treat uninitialized file alignment as PAGE_SIZEPeter Jones
2016-09-06Make fallback and mokmanager know about multi-arch.Peter Jones
On baytrail, we've got 32-bit firmware, 32-bit efi utilities, and 64-bit kernel. So since most distros will want 32+64 EFI media booting a 64-bit kernel, we have to name them better on the filesystem. Signed-off-by: Peter Jones <pjones@redhat.com>
2016-06-09shim: make the PE loader less overzealous on rejectionsPeter Jones
2016-05-11Measure state and second stage into TPMMatthew Garrett
Add support for measuring the MOK database and secure boot state into a TPM, and do the same for the second stage loader. This avoids a hole in TPM measurement between the firmware and the second stage loader.
2016-05-11shim: dealing with only one string on loadoptionIvan Hu
The second stage set is not working after commit 3322257e611e2000f79726d295bb4845bbe449e7 for those which load option only have one string. Signed-off-by: Ivan Hu <ivan.hu@canonical.com>
2016-03-22shim: mirror MokSBState in runtime so the kernel can make use of it.Mathieu Trudel-Lapierre
Signed-off-by: Mathieu Trudel-Lapierre <mathieu.trudel-lapierre@canonical.com>
2015-11-17shim: check for EFI\BOOT\BOOT${ARCH}.EFI as well as the leading \ versionPeter Jones
I found a machine whose BDS gives us relative paths, yay! The rest of the code still works without that leading slash, so just make it one more item we let through our StrnCaseCmp() filter. Signed-off-by: Peter Jones <pjones@redhat.com>
2015-11-17shim: fix resource leak on should_use_fallback() error pathPeter Jones
ExitBootServices() and Exit() should both clean these up anyway, but we should do the right thing nonetheless. Signed-off-by: Peter Jones <pjones@redhat.com>
2015-11-17shim: if generate_path() gets a full path, just return it.Peter Jones
We decide if it's a full path by if it starts with \\EFI\\. That's quite lazy, but we can't just check \\ like you'd hope, because we need to stay compatible with what we've set as DEFAULT_LOADER in the past, and I don't feel like writing the full path traversal file test. Signed-off-by: Peter Jones <pjones@redhat.com>
2015-11-17shim: fix a wrong-abi call to Stall() and ResetSystem()Peter Jones
Woops. The net outcome of these is going to be a sleep of unknown duration, followed by either a) ResetSystem() with some random selection of warm/cold boot, or b) ResetSystem() returning an error and shim returning error from efi_main(). Signed-off-by: Peter Jones <pjones@redhat.com>
2015-11-17shim: handle BDS's li->LoadOptions and Shell's li->LoadOptions .Peter Jones
Load options are a giant pain in the ass, because the shell is a giant piece of junk. If we're invoked from the EFI shell, we get something like this: 00000000 5c 00 45 00 36 00 49 00 5c 00 66 00 65 00 64 00 |\.E.F.I.\.f.e.d.| 00000010 6f 00 72 00 61 00 5c 00 73 00 68 00 69 00 6d 00 |o.r.a.\.s.h.i.m.| 00000020 78 00 36 00 34 00 2e 00 64 00 66 00 69 00 20 00 |x.6.4...e.f.i. .| 00000030 5c 00 45 00 46 00 49 00 5c 00 66 00 65 00 64 00 |\.E.F.I.\.f.e.d.| 00000040 6f 00 72 00 61 00 5c 00 66 00 77 00 75 00 70 00 |o.r.a.\.f.w.u.p.| 00000050 64 00 61 00 74 00 65 00 2e 00 65 00 66 00 20 00 |d.a.t.e.e.f.i. .| 00000060 00 00 66 00 73 00 30 00 3a 00 5c 00 00 00 |..f.s.0.:.\...| which is just some paths rammed together separated by a UCS-2 NUL. But if we're invoked from BDS, we get something more like: 00000000 01 00 00 00 62 00 4c 00 69 00 6e 00 75 00 78 00 |....b.L.i.n.u.x.| 00000010 20 00 46 00 69 00 72 00 6d 00 77 00 61 00 72 00 | .F.i.r.m.w.a.r.| 00000020 65 00 20 00 55 00 70 00 64 00 61 00 74 00 65 00 |e. .U.p.d.a.t.e.| 00000030 72 00 00 00 40 01 2a 00 01 00 00 00 00 08 00 00 |r.....*.........| 00000040 00 00 00 00 00 40 06 00 00 00 00 00 1a 9e 55 bf |.....@........U.| 00000050 04 57 f2 4f b4 4a ed 26 4a 40 6a 94 02 02 04 04 |.W.O.:.&J@j.....| 00000060 34 00 5c 00 45 00 46 00 49 00 5c 00 66 00 65 00 |4.\.E.F.I.f.e.d.| 00000070 64 00 6f 00 72 00 61 00 5c 00 73 00 68 00 69 00 |o.r.a.\.s.h.i.m.| 00000080 6d 00 78 00 36 00 34 00 2e 00 65 00 66 00 69 00 |x.6.4...e.f.i...| 00000090 00 00 7f ff 40 00 20 00 5c 00 66 00 77 00 75 00 |...... .\.f.w.u.| 000000a0 70 00 78 00 36 00 34 00 2e 00 65 00 66 00 69 00 |p.x.6.4...e.f.i.| 000000b0 00 00 |..| which is clearly an EFI_LOAD_OPTION filled in halfway reasonably. In short, the UEFI shell is still a useless piece of junk. So anyway, try to determine which one we've got and handle it appropriately. Signed-off-by: Peter Jones <pjones@redhat.com>
2015-11-17Fix unsigned int overflow on our i386 debug hook test.Peter Jones
Signed-off-by: Peter Jones <pjones@redhat.com>
2015-06-30Improve our debuginfo path printPeter Jones
Signed-off-by: Peter Jones <pjones@redhat.com>
2015-06-29Only be verbose the first time secure_mode() is called.Peter Jones
It's annoying to find out we're not in SB mode over and over. Really it is. Signed-off-by: Peter Jones <pjones@redhat.com>
2015-06-29Add a conditional point for a debugger to attach.Peter Jones
Signed-off-by: Peter Jones <pjones@redhat.com>
2015-06-29Don't print anything or delay when start_image() succeeds.Peter Jones
Signed-off-by: Peter Jones <pjones@redhat.com>
2015-06-16Make shim to check MokXAuth for MOKX resetGary Ching-Pang Lin
Signed-off-by: Gary Ching-Pang Lin <glin@suse.com>
2015-06-16Verify the EFI images with MOK blacklistGary Ching-Pang Lin
Signed-off-by: Gary Ching-Pang Lin <glin@suse.com>
2015-06-16Copy the MOK blacklist to a RT variableGary Ching-Pang Lin
Signed-off-by: Gary Ching-Pang Lin <glin@suse.com>
2015-06-16Support MOK blacklistGary Ching-Pang Lin
The new blacklist, MokListX, stores the keys and hashes that are banned. Signed-off-by: Gary Ching-Pang Lin <glin@suse.com>