Commit Graph

469 Commits

Author SHA1 Message Date
Gary Lin
9bc647e2b2 Cryptlib: implement strcmp() and strcasecmp()
strcmp() and strcasecmp() are widely used in openssl. Implement those
two functions to eliminate the gcc warnings and the potential crash.

Signed-off-by: Gary Lin <glin@suse.com>
2017-04-11 10:42:19 -04:00
Gary Lin
ae75df6232 MokManager: Update to new openssl API
X509_get_notBefore -> X509_getm_notBefore
X509_get_notAfter  -> X509_getm_notAfter

Signed-off-by: Gary Lin <glin@suse.com>
2017-04-11 10:42:19 -04:00
Gary Lin
e883479f35 Cryptlib: amend the headers and fix signness
- Declare some functions in the proper headers
  + We missed them for a long time...

- Cast offsetof to UINTN
  + The original casting triggers the gcc warning since int can not
    present the offset for the 64bit machines.

- Cast the "char" array to "CHAR8 *" to avoid the gcc warnings

- Implement atoi correctly

Signed-off-by: Gary Lin <glin@suse.com>
2017-04-11 10:42:19 -04:00
Gary Lin
97469449fd Cryptlib: Include stddef.h in CrtLibSupport.h
The changes in the openssl headers cause the inclusion of
CrtLibSupport.h eariler than the inclusion of stddef.h, so "offsetof"
was defined twice and this caused the followling build error:

In file included from Cryptlib/Include/openssl/buffer.h:23:0,
                 from Cryptlib/Include/openssl/x509.h:22,
                 from shim.c:56:
/usr/lib64/gcc/x86_64-suse-linux/6/include/stddef.h:417:0: error: "offsetof" redefined [-Werror]
 #define offsetof(TYPE, MEMBER) __builtin_offsetof (TYPE, MEMBER)

In file included from Cryptlib/Include/limits.h:15:0,
                 from Cryptlib/Include/openssl/ossl_typ.h:13,
                 from Cryptlib/Include/openssl/x509.h:20,
                 from shim.c:56:
Cryptlib/Include/CrtLibSupport.h:192:0: note: this is the location of the previous definition
 #define offsetof(type, member) ( (int) & ((type*)0) -> member )

We can lower the priority of the gcc include path or just remove the
path, but this might cause problem since the path was introduced on
purpose(*). Instead, including stddef.h first is more feasible.

(*) d51739a416

Signed-off-by: Gary Lin <glin@suse.com>
2017-04-11 10:42:19 -04:00
Gary Lin
e39692647f shim: Remove the obsolete OBJ_cleanup
Signed-off-by: Gary Lin <glin@suse.com>
2017-04-11 10:42:19 -04:00
Gary Lin
0f3dfc01e2 Cryptlib/OpenSSL: update to openssl 1.1.0e
- Delete the old openssl files and use the script to copy the new files

- Add "-DNO_SYSLOG" to CFLAGS and add crypto/include to the include path

Signed-off-by: Gary Lin <glin@suse.com>
2017-04-11 10:42:18 -04:00
Gary Lin
4da6ac8195 Cryptlib/OpenSSL: Update the script to copy the new openssl files
- Update update.sh to copy the openssl 1.1.0 source files

- Refresh the supplemental patch to reflect the change

Signed-off-by: Gary Lin <glin@suse.com>
2017-04-11 10:42:18 -04:00
Gary Lin
d064bd7eef Cryptlib: Update to the latest edk2 commit
- Update to edk2 commit 7c410b3d4180087020c7734bf67cdc4ad9fdb136
  CryptoPkg/BaseCryptLib: Adding NULL checking in time() wrapper.

- Update headers in Cryptlib/Include/openssl/ to 1.1.0e
  + Also copy the openssl internal headers

Signed-off-by: Gary Lin <glin@suse.com>
2017-04-11 10:42:18 -04:00
Gary Lin
9bc86cfd6f Cryptlib: Amend update.sh and refresh Cryptlib.diff
- Remove the openssl version from update.sh since edk2 doesn't use the
  version number in the directory name anymore.

- Refresh Cryptlib.diff to reflect the change

Signed-off-by: Gary Lin <glin@suse.com>
2017-04-11 10:42:18 -04:00
Gary Lin
ab9a05a10f Cryptlib: Rename OpenSslSupport.h as CrtLibSupport.h
Edk2 renamed OpenSslSupport.h, so we have to follow the change.
Also merge some changes from edk2 CrtLibSupport.h

Signed-off-by: Gary Lin <glin@suse.com>
2017-04-11 10:42:18 -04:00
Peter Jones
84d1118d00 make tag: always tag latest-release as well
Signed-off-by: Peter Jones <pjones@redhat.com>
2017-04-10 12:27:52 -04:00
Peter Jones
0fe4a80e9c Update version to 11
Signed-off-by: Peter Jones <pjones@redhat.com>
2017-04-03 14:59:38 -04:00
Lans Zhang
6dd948b57b generate_hash(): fix the regression
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-03 14:53:45 -04:00
Peter Jones
7a44b29edc Ignore BDS when it tells us we got our own path on the command line.
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-04-03 14:53:45 -04:00
Peter Jones
7bfe98b1e2 Update version to 10
Signed-off-by: Peter Jones <pjones@redhat.com>
2017-03-27 14:16:43 -04:00
Peter Jones
d00ea5558e Fix some i386 type casting errors
Signed-off-by: Peter Jones <pjones@redhat.com>
2017-03-27 14:16:42 -04:00
Peter Jones
29f3c91d4e shim: disambiguate our global image handle.
Signed-off-by: Peter Jones <pjones@redhat.com>
2017-03-27 14:16:42 -04:00
Gary Lin
f48505bfb2 Update to openssl 1.0.2k
Signed-off-by: Gary Lin <glin@suse.com>
2017-03-24 18:28:30 -04:00
Gary Lin
8321529865 Update Cryptlib
Update to edk2 commit 6e4489d8129d233ef0fe85eeb6eebfecafe9ea6e
(CryptoPkg: Refine type cast for pointer subtraction)

Also replaced CryptAes.c, CryptArc4.c, CryptTdes.c, CryptMd4.c,
CryptHmacMd5.c, and CryptHmacSha1.c with the Null version since
we don't really need those functions.

Signed-off-by: Gary Lin <glin@suse.com>
2017-03-24 18:28:30 -04:00
Gary Lin
3ee08dde9c httpboot: parse https prefix in the uri
This commit adds the check for "https://" in the uri to support HTTPs
Boot.

Signed-off-by: Gary Lin <glin@suse.com>
2017-03-24 18:27:48 -04:00
Ard Biesheuvel
97022acd36 Use EfiLoaderCode memory for loading PE/COFF executables
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-28 13:37:23 -05:00
Peter Jones
83c62ff582 Fix some type errors gcc7 finds in http boot code.
Signed-off-by: Peter Jones <pjones@redhat.com>
2017-02-27 15:45:54 -05:00
Peter Jones
4990d3fb95 Make shim_version live in a special aligned section.
This makes it so two builds of the same .deb on different hosts won't
have wildly different file offsets.

Signed-off-by: Peter Jones <pjones@redhat.com>
2017-02-23 16:08:42 -05:00
Peter Jones
9f2c83e60e Also just check for access denied anyway.
Signed-off-by: Peter Jones <pjones@redhat.com>
2017-02-06 16:49:28 -05:00
Peter Jones
6ebf9b8704 Ensure all of the SB verification returns the same error code.
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-06 13:34:20 -05:00
Lans Zhang
478f0f0948 shim/tpm: the EFI_TCG2_BOOT_SERVICE_CAPABILITY structure shouldn't be packed
According to TCG EFI Protocol Specification, this structure is not packed.

Signed-off-by: Lans Zhang <jia.zhang@windriver.com>
2017-02-06 11:18:07 -05:00
Lans Zhang
94c955bbbd shim/tpm: correct the definition of the capability structure version 1.0
EFI TrEE Protocol uses the same protocol GUID as EFI TCG2 protocol, and
defines the capability structure version 1.0. Hence, the structure and
name are all align the EFI TrEE Protocol.

Signed-off-by: Lans Zhang <jia.zhang@windriver.com>
2017-02-06 11:18:07 -05:00
Ivan Hu
07bda58596 shim: fix the mirroring MokSBState fail
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-06 11:16:24 -05:00
Peter Jones
03b9f800b9 generate_hash(): make check_size() set an error, and verify SecDir size.
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>
2017-02-06 11:16:24 -05:00
Gary Lin
431d893b41 Update the CryptLib
Update to the edk2 commit dab62c5ec8a88def3ee99c04d644720cb201de08

Signed-off-by: Gary Lin <glin@suse.com>
2016-11-30 12:57:35 -05:00
Gary Lin
b371a682fb Update to openssl 1.0.2j
Signed-off-by: Gary Lin <glin@suse.com>
2016-11-30 12:57:34 -05:00
Gary Lin
43ad947f6e Update the openssl update script to 1.0.2j
Signed-off-by: Gary Lin <glin@suse.com>
2016-11-30 12:57:34 -05:00
Gary Lin
7ab40ee92c Cryptlib: Implement memset() to avoid the potential crash
Although the prototype of memset() is already defined in OpenSslSupport.h,
the function was never implemented. It was fine since a macro was
designed to replace all memset() with SetMem() after including
OpenSslSupport.h. However, since openssl 1.0.2j, a new function pointer
in crypto/mem_clr.c requires the "real" memset() or the program would
crash due to the NULL function pointer access. This commit implements
memset() (just a wrapper of SetMem()) to avoid the potential crash.

Signed-off-by: Gary Lin <glin@suse.com>
2016-11-30 12:57:34 -05:00
Lans Zhang
7bfcd70801 shim/tpm: fix trigger failure caused by NULL arguments
Certain AMI BIOS (Intel NUC5i3MYBE BIOS version 0037) may make the strict
check on the last 3 arguments passed to get_event_log() and don't expect
NULL pointers are passed. In order to work around this failure
(EFI_INVALID_PARAMETER), pass them even though we really don't use it.

Signed-off-by: Lans Zhang <jia.zhang@windriver.com>
2016-11-30 12:56:55 -05:00
Lans Zhang
1ee26db0db shim/tpm: print the error status if trigger fails
Signed-off-by: Lans Zhang <jia.zhang@windriver.com>
2016-11-30 12:56:55 -05:00
Lans Zhang
d3884fe833 shim: trigger to record further logs to tcg 2.0 final event log area
According to TCG EFI Protocol Specification for TPM 2.0 family,
all events generated after the invocation of EFI_TCG2_GET_EVENT_LOG
shall be stored in an instance of an EFI_CONFIGURATION_TABLE aka
EFI TCG 2.0 final events table. Hence, it is necessary to trigger the
internal switch through calling get_event_log() in order to allow
to retrieve the logs from OS runtime.

Signed-off-by: Lans Zhang <jia.zhang@windriver.com>
2016-09-30 09:38:33 -04:00
Mathieu Trudel-Lapierre
6c180c6004 shim: verify Extended Key Usage flags
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-21 13:32:53 -04:00
Mathieu Trudel-Lapierre
8af6e22814 MokManager: list Extended Key Usage OIDs
Signed-off-by: Mathieu Trudel-Lapierre <mathieu.trudel-lapierre@canonical.com>
2016-09-21 13:32:53 -04:00
Gary Lin
903674a2c4 MokManager: free new_data after use
new_data in write_db() wasn't freed after SetVariable.

Signed-off-by: Gary Lin <glin@suse.com>
2016-09-09 12:07:26 -04:00
Gary Lin
e21068b499 MokManager: Try APPEND_WRITE first
Try to append the MOK/MOKX list first and then fallback to the normal
SetVariable if the firmware doesn't support EFI_VARIABLE_APPEND_WRITE.

Signed-off-by: Gary Lin <glin@suse.com>
2016-09-09 12:07:26 -04:00
Gary Lin
5597a493e2 MokManager: Remove the usage of APPEND_WRITE
We got the bug report about the usage of APPEND_WRITE that may cause the
failure when writing a variable in Lenovo machines. Although
EFI_VARIABLE_APPEND_WRITE already exists in the UEFI spec for years,
unfortunately, some vendors just ignore it and never implement the
attribute. This commit removes the usage of EFI_VARIABLE_APPEND_WRITE to
make MokManager work on those machines.

https://github.com/rhinstaller/shim/issues/55

Signed-off-by: Gary Lin <glin@suse.com>
2016-09-09 12:07:26 -04:00
Peter Jones
af13b3efc9 Fix up a merge error in 467878f3e0.
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-09 12:07:26 -04:00
Peter Jones
2de084689f verify_buffer: check that the value of cert->Hdr.dwLength is reasonable
Signed-off-by: Peter Jones <pjones@redhat.com>
2016-09-09 11:16:17 -04:00
Peter Jones
b8e27b3cfe Minor formatting fix
Signed-off-by: Peter Jones <pjones@redhat.com>
2016-09-06 15:19:08 -04:00
Sachin Agrawal
d241bbbdbf Use authenticode signature length from WIN_CERTIFICATE structure.
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-06 15:06:51 -04:00
Gary Lin
04d581c303 Update the CryptLib
Update to the edk2 commit 8ff7187cfd998d2b6db43075a4a7908281b6da00

Signed-off-by: Gary Lin <glin@suse.com>
2016-09-06 15:05:36 -04:00
Gary Lin
8dcfecc6c7 Update to openssl 1.0.2h
Signed-off-by: Gary Lin <glin@suse.com>
2016-09-06 15:05:36 -04:00
Gary Lin
d8b0e8e0ce Update the openssl update script to 1.0.2h
Signed-off-by: Gary Lin <glin@suse.com>
2016-09-06 15:05:36 -04:00
Gary Lin
0297aa3cf3 Update openssl to 1.0.2g
Signed-off-by: Gary Lin <glin@suse.com>
2016-09-06 15:05:36 -04:00
Gary Lin
7b9281af14 Update the CryptLib
Update to the edk2 commit 5e2318dd37a51948aaf845c7d920b11f47cdcfe6

Signed-off-by: Gary Lin <glin@suse.com>
2016-09-06 15:05:36 -04:00