aboutsummaryrefslogtreecommitdiff
path: root/lib/efi_loader/efi_variable.c
Commit message (Collapse)AuthorAgeFilesLines
* efi_loader: update SetVariable attribute checkMasahisa Kojima2023-03-131-6/+25
| | | | | | | | | | | | | | UEFI specification v2.10 says that EFI_VARIABLE_AUTHENTICATED_WRITE_ACCESS is deprecated and EFI_UNSUPPORTED should be returned in SetVariable variable service. Current implementation returns EFI_INVALID_PARAMETER, let's fix the return value. Together with above change, this commit also updates the SetVariable attribute check to be aligned with the EDK2 reference implementation. Signed-off-by: Masahisa Kojima <masahisa.kojima@linaro.org> Reviewed-by: Heinrich Schuchardt <heinrich.schuchardt@canonical.com>
* efi_loader: fix wrong attribute check for QueryVariableInfoMasahisa Kojima2023-02-191-3/+0
| | | | | | | | | QueryVariableInfo with EFI_VARIABLE_HARDWARE_ERROR_RECORD is accepted, remove wrong attribute check. Fixes: 454a9442fbce ("efi_loader: update attribute check for QueryVariableInfo()") Signed-off-by: Masahisa Kojima <masahisa.kojima@linaro.org> Reviewed-by: Heinrich Schuchardt <heinrich.schuchardt@canonical.com>
* efi_loader: static efi_query_variable_info_runtime()Heinrich Schuchardt2023-02-101-1/+1
| | | | | | This function is not used externally and hence should be static. Signed-off-by: Heinrich Schuchardt <heinrich.schuchardt@canonical.com>
* efi_loader: update attribute check for QueryVariableInfo()Masahisa Kojima2023-02-101-0/+23
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | Current U-Boot supports two EFI variable service, U-Boot own implementation and op-tee based StMM variable service. With ACS Security Interface Extension(SIE) v22.10_SIE_REL1.1.0, there are several failure items of QueryVariableInfo(). Current attribute check for QueryVariableInfo() was implemented based on the Self Certification Test (SCT) II Case Specification, June 2017, chapter 4.1.4 QueryVariableInfo(). This test case specification is outdated and don't align at all with the SCT test case code, and UEFI specification v2.10 does not clearly define the priority of the attribute check. For U-Boot standard case that EFI variables are stored in a file in the ESP, this commit modifies the attribute check to get align to the EDK2 implementation. For latter case(op-tee based StMM variable service), parameter check should be delegated to StMM. Now all ACS SIE QueryVariableInfo() test cases passed both EFI variable storage implementations. Signed-off-by: Masahisa Kojima <masahisa.kojima@linaro.org> Acked-by: Heinrich Schuchardt <heinrich.schuchardt@canonical.com> Signed-off-by: Heinrich Schuchardt <heinrich.schuchardt@canonical.com>
* efi_loader: ensure that file ubootefi.var is createdHeinrich Schuchardt2023-01-201-3/+5
| | | | | | | | | | | Currently file ubootefi.var is only created if the user sets a non-volatile EFI variable. If the file is missing, a warning is written. With the change PlatformLang is always persisted. So the file will exist on second boot. Signed-off-by: Heinrich Schuchardt <heinrich.schuchardt@canonical.com> Reviewed-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>
* efi_loader: avoid adding variables twiceIlias Apalodimas2022-12-291-3/+3
| | | | | | | | | | | | | | | | When the efi subsystem starts we restore variables that are both in a file or stored into the .efi_runtime section of U-Boot. However once a variable gets created or changed the preseeded entries will end up in the file. As a consequence on the next boot we will end up adding identical variable entries twice. Fix this by checking if the to be inserted variable already exists. Also swap the restoration order and start with the file instead of the builtin variables, so a user can replace the preseeded ones if needed. Tested-by: Leo Yan <leo.yan@linaro.org> Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org> Reviewed-by: Heinrich Schuchardt <heinrich.schuchardt@canonical.com>
* efi: Use 16-bit unicode stringsSimon Glass2022-02-031-3/+3
| | | | | | | | | | At present we use wide characters for unicode but this is not necessary. Change the code to use the 'u' literal instead. This helps to fix build warnings for sandbox on rpi. Signed-off-by: Simon Glass <sjg@chromium.org> Suggested-by: Heinrich Schuchardt <xypron.glpk@gmx.de> Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
* efi_loader: treat UEFI variable name as constHeinrich Schuchardt2021-10-251-4/+5
| | | | | | | | | | | | UEFI variable names are typically constants and hence should be defined as const. Unfortunately some of our API functions do not define the parameters for UEFI variable names as const. This requires unnecessary conversions. Adjust parameters of several internal functions to tre UEFI variable names as const. Signed-off-by: Heinrich Schuchardt <heinrich.schuchardt@canonical.com> Reviewed-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>
* efi_loader: efi_auth_var_type for AuditMode, DeployedModeHeinrich Schuchardt2021-09-041-2/+2
| | | | | | | | | | Writing variables AuditMode and DeployedMode serves to switch between Secure Boot modes. Provide a separate value for these in efi_auth_var_type. With this patch the variables will not be read from from file even if they are marked as non-volatile by mistake. Signed-off-by: Heinrich Schuchardt <heinrich.schuchardt@canonical.com>
* efi_loader: don't load signature database from fileHeinrich Schuchardt2021-09-041-1/+1
| | | | | | | | The UEFI specification requires that the signature database may only be stored in tamper-resistant storage. So these variable may not be read from an unsigned file. Signed-off-by: Heinrich Schuchardt <heinrich.schuchardt@canonical.com>
* efi_loader: Make the pkcs7 header parsing function an externSughosh Ganu2020-12-311-89/+4
| | | | | | | | The pkcs7 header parsing functionality is pretty generic, and can be used by other features like capsule authentication. Make the function an extern, also changing it's name to efi_parse_pkcs7_header Signed-off-by: Sughosh Ganu <sughosh.ganu@linaro.org>
* efi_loader: non-volatile variable not deleted from fileHeinrich Schuchardt2020-11-091-0/+1
| | | | | | | | | | | | When deleting a non-volatile variable it was deleted from memory but the deletion was not persisted to the file system. SetVariable() may be called with attributes == 0 to delete a variable. To determine if the deletion shall be persisted we have to consider the non-volatile flag in the attributes of the deleted variable and not the value passed in the call parameter. Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
* efi_loader: variable: fix secure state initializationAKASHI Takahiro2020-08-131-5/+5
| | | | | | | | | | | | | | | | Under the new file-based variable implementation, the secure state is always and falsely set to 0 (hence, the secure boot gets disabled) after the reboot even if PK (and other signature database) has already been enrolled in the previous boot. This is because the secure state is set up *before* loading non-volatile variables' values from saved data. This patch fixes the order of variable initialization and secure state initialization. Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org> Fixes: 5f7dcf079de8 ("efi_loader: UEFI variable persistence")
* efi_loader: signature: rework for intermediate certificates supportAKASHI Takahiro2020-08-131-3/+2
| | | | | | | | | | | | | | | | | | | In this commit, efi_signature_verify(with_sigdb) will be re-implemented using pcks7_verify_one() in order to support certificates chain, where the signer's certificate will be signed by an intermediate CA (certificate authority) and the latter's certificate will also be signed by another CA and so on. What we need to do here is to search for certificates in a signature, build up a chain of certificates and verify one by one. pkcs7_verify_one() handles most of these steps except the last one. pkcs7_verify_one() returns, if succeeded, the last certificate to verify, which can be either a self-signed one or one that should be signed by one of certificates in "db". Re-worked efi_signature_verify() will take care of this step. Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
* efi_loader: variable: keep temporary buffer during the authenticationAKASHI Takahiro2020-08-131-7/+20
| | | | | | | | | | | | | | | This is a bug fix; Setting an authenticated variable may fail due to a memory corruption in the authentication. A temporary buffer will, if needed, be allocated to parse a variable's authentication data, and some portion of buffer, specifically signer's certificates, will be referenced by efi_signature_verify(). So the buffer should be kept valid until the authentication process is finished. Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org> Tested-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
* efi_loader: Enable run-time variable support for tee based variablesIlias Apalodimas2020-08-011-99/+2
| | | | | | | | | | | | | | | | | | | | We recently added functions for storing/restoring variables from a file to a memory backed buffer marked as __efi_runtime_data commit f1f990a8c958 ("efi_loader: memory buffer for variables") commit 5f7dcf079de8 ("efi_loader: UEFI variable persistence") Using the same idea we now can support GetVariable() and GetNextVariable() on the OP-TEE based variables as well. So let's re-arrange the code a bit and move the commmon code for accessing variables out of efi_variable.c. Create common functions for reading variables from memory that both implementations can use on run-time. Then just use those functions in the run-time variants of the OP-TEE based EFI variable implementation and initialize the memory buffer on ExitBootServices() Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org> Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
* efi_loader: pre-seed UEFI variablesHeinrich Schuchardt2020-07-161-2/+17
| | | | | | | | Include a file with the initial values for non-volatile UEFI variables into the U-Boot binary. If this variable is set, changes to variable PK will not be allowed. Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
* efi_loader: identify PK, KEK, db, dbx correctlyHeinrich Schuchardt2020-07-161-13/+14
| | | | | | | | | | To determine if a varible is on the of the authentication variables PK, KEK, db, dbx we have to check both the name and the GUID. Provide a function converting the variable-name/guid pair to an enum and use it consistently. Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
* efi_loader: restructure code for TEE variablesHeinrich Schuchardt2020-07-161-159/+0
| | | | | | | When using secure boot functions needed both for file and TEE based UEFI variables have to be moved to the common code module efi_var_common.c. Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
* efi_loader: enable UEFI variables at runtimeHeinrich Schuchardt2020-07-111-2/+12
| | | | | | Enable UEFI variables at runtime. Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
* efi_loader: use memory based variable storageHeinrich Schuchardt2020-07-111-468/+94
| | | | | | | | | Saving UEFI variable as encoded U-Boot environment variables does not allow implement run-time support. Use a memory buffer for storing UEFI variables. Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
* efi_loader: UEFI variable persistenceHeinrich Schuchardt2020-07-111-1/+9
| | | | | | | | | | | | Persist non-volatile UEFI variables in a file on the EFI system partition. The file is written whenever a non-volatile UEFI variable is changed after initialization of the UEFI sub-system. The file is read during the UEFI sub-system initialization to restore non-volatile UEFI variables. Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
* efi_loader: secure boot flagHeinrich Schuchardt2020-07-111-6/+2
| | | | | | | | | In audit mode the UEFI variable SecureBoot is set to zero but the efi_secure_boot flag is set to true. The efi_secure_boot flag should match the UEFIvariable SecureBoot. Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
* efi_loader: read-only AuditMode and DeployedModeHeinrich Schuchardt2020-07-111-9/+13
| | | | | | | Set the read only property of the UEFI variables AuditMode and DeployedMode conforming to the UEFI specification. Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
* efi_loader: value of VendorKeysHeinrich Schuchardt2020-07-111-60/+15
| | | | | | | | | | According to the UEFI specification the variable VendorKeys is 1 if the "system is configured to use only vendor-provided keys". As we do not supply any vendor keys yet the variable VendorKeys must be zero. Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
* efi_loader: keep attributes in efi_set_variable_intHeinrich Schuchardt2020-07-111-12/+12
| | | | | | | | | | Do not change the value of parameter attributes in function efi_set_variable_int(). This allows to use it later. Do not use variable attr for different purposes but declare separate variables (attr and old_attr). Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
* efi_loader: separate UEFI variable API from implemementationHeinrich Schuchardt2020-07-111-33/+23
| | | | | | | Separate the remaining UEFI variable API functions GetNextVariableName and QueryVariableInfo() from internal functions implementing them. Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
* efi_loader: prepare for read only OP-TEE variablesHeinrich Schuchardt2020-07-111-127/+48
| | | | | | | | | | | | | | | | | | We currently have two implementations of UEFI variables: * variables provided via an OP-TEE module * variables stored in the U-Boot environment Read only variables are up to now only implemented in the U-Boot environment implementation. Provide a common interface for both implementations that allows handling read-only variables. As variable access is limited to very few source files put variable related definitions into new include efi_variable.h instead of efi_loader. Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
* efi_loader: rtc_mktime() called twiceHeinrich Schuchardt2020-07-031-1/+1
| | | | | | | Don't call rtc_mktime() twice with the same argument in efi_variable_authenticate(). Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
* efi_loader: time based authenticationHeinrich Schuchardt2020-07-031-6/+11
| | | | | | | When overwriting an existing time base authenticated variable we should compare to the preceding time value and not to the start of the epoch. Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
* efi_loader: add missing validation of timestampHeinrich Schuchardt2020-07-031-1/+5
| | | | | | | | The UEFI specification requires that when UEFI variables are set using time based authentication we have to check that unused fields of the timestamp are zero Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
* efi_loader: variable: replace debug to EFI_PRINTAKASHI Takahiro2020-07-031-13/+14
| | | | | | | | Just for style consistency, replace all the uses of debug() to EFI_PRINT in efi_variable.c. Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org> Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
* efi_loader: fix incorrect use of EFI_EXIT()Heinrich Schuchardt2020-06-291-1/+1
| | | | | | | | efi_get_variable_common() does not use EFI_ENTRY(). So we should not use EFI_EXIT() either. Fixes: 767f6eeb01d3 ("efi_loader: variable: support variable authentication") Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
* efi_loader: size of secure boot variablesHeinrich Schuchardt2020-06-241-6/+6
| | | | | | | | | | | | The variables SetupMode, AuditMode, DeployedMode are explicitly defined as UINT8 in the UEFI specification. The type of SecureBoot is UINT8 in EDK2. Use variable name secure_boot instead of sec_boot for the value of the UEFI variable SecureBoot. Avoid abbreviations in function descriptions. Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
* efi_loader: type of efi_secure_modeHeinrich Schuchardt2020-06-241-1/+1
| | | | | | | Variable efi_secure_mode is meant to hold a value of enum efi_secure_mode. So it should not be defined as int but as enum efi_secure_mode. Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
* efi_loader: signature: move efi_guid_cert_type_pkcs7 to efi_signature.cAKASHI Takahiro2020-06-031-1/+0
| | | | | | | | | | | | | | | The global variable, efi_guid_cert_type_pkcs7, will also be used in efi_image_loader.c in a succeeding patch so as to correctly handle a signature type of authenticode in signed image. Meanwhile, it is currently defined in efi_variable.c. Once some secure storage solution for UEFI variables is introduced, efi_variable.c may not always be compiled in. So move the definition to efi_signature.c as a common place. Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org> Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
* efi_loader: Remove unnecessary debugPragnesh Patel2020-05-211-2/+0
| | | | | | | | Remove unnecessary debug() from efi_set_variable_common(). native_name is NULL, so there is no meaning to print it. Signed-off-by: Pragnesh Patel <pragnesh.patel@sifive.com> Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
* common: Drop linux/bitops.h from common headerSimon Glass2020-05-181-0/+1
| | | | | | Move this uncommon header out of the common header. Signed-off-by: Simon Glass <sjg@chromium.org>
* command: Remove the cmd_tbl_t typedefSimon Glass2020-05-181-0/+1
| | | | | | | | | | | | | We should not use typedefs in U-Boot. They cannot be used as forward declarations which means that header files must include the full header to access them. Drop the typedef and rename the struct to remove the _s suffix which is now not useful. This requires quite a few header-file additions. Signed-off-by: Simon Glass <sjg@chromium.org>
* common: Drop uuid.h from common headerSimon Glass2020-05-181-0/+1
| | | | | | Move this uncommon header out of the common header. Signed-off-by: Simon Glass <sjg@chromium.org>
* efi_loader: variable: check a return value of uuid__str_to_bin()AKASHI Takahiro2020-05-091-1/+4
| | | | | | | | | The only error case is that a given UUID is in wrong format. So just return EFI_INVALID_PARAMETER here. Reported-by: Coverity (CID 300333) Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org> Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
* efi_loader: efi_variable_parse_signature() returns NULL on errorPatrick Wildt2020-05-071-2/+1
| | | | | | | | | efi_variable_parse_signature() returns NULL on error, so IS_ERR() is an incorrect check. The goto err leads to pkcs7_free_message(), which works fine on a NULL ptr. Signed-off-by: Patrick Wildt <patrick@blueri.se> Reviewed-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
* efi_loader: do not unnecessarily use EFI_CALL()Heinrich Schuchardt2020-05-071-15/+19
| | | | | | | | | There is no need to call efi_get_variable() instead of efi_get_variable_common(). So let's use the internal function. Move forward declarations to the top of the file. Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
* efi_loader: error handling in efi_set_variable_common().Heinrich Schuchardt2020-05-071-1/+1
| | | | | | Fix unreachable code. Free memory on error. Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
* efi_loader: correct comments for efi_status_tHeinrich Schuchardt2020-05-041-3/+3
| | | | | | | EFI_STATUS is unsigned (UINTN). Hence it cannot be negative. Correct comments for 'Return:'. Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
* efi_loader: eliminate efi_set_(non)volatile_variableHeinrich Schuchardt2020-05-041-104/+37
| | | | | | | Eliminate superfluous functions efi_set_volatile_variable() and efi_set_nonvolatile_variable(). Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
* efi_loader: eliminate efi_get_(non)volatile_variableHeinrich Schuchardt2020-05-041-29/+3
| | | | | | | Eliminate superfluous functions efi_get_volatile_variable() and efi_get_nonvolatile_variable(). Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
* efi_loader: factor out the common code from efi_transfer_secure_state()AKASHI Takahiro2020-05-041-130/+64
| | | | | | | | | | efi_set_secure_stat() provides the common code for each stat transition caused by efi_transfer_secure_state(). Suggested-by: Heinrich Schuchardt <xypron.glpk@gmx.de> Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org> Correct description of return value. Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
* lib/crypto, efi_loader: move some headers to include/cryptoAKASHI Takahiro2020-05-041-1/+1
| | | | | | | | | | Pkcs7_parse.h and x509_parser.h are used in UEFI subsystem, in particular, secure boot. So move them to include/crypto to avoid relative paths. Suggested-by: Heinrich Schuchardt <xypron.glpk@gmx.de> Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org> Don't include include x509_parser.h twice. Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
* efi_loader: variable: add VendorKeys variableAKASHI Takahiro2020-04-161-6/+63
| | | | | | | | | | The following variable is exported as UEFI specification defines: VendorKeys: whether the system is configured to use only vendor-provided keys or not The value will have to be modified if a platform has its own way of initializing signature database, in particular, PK. Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>