summaryrefslogtreecommitdiff
path: root/lib
Commit message (Collapse)AuthorAgeFilesLines
* efi_loader: parameter check OutputStringHeinrich Schuchardt2019-05-191-0/+5
| | | | | | Check the parameters against NULL. Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
* efi_loader: EFI_SIMPLE_TEXT_INPUT_EX_PROTOCOL.SetState() correct parameterHeinrich Schuchardt2019-05-191-3/+3
| | | | | | KeyToggleState is a pointer according to UEFI spec 2.8. Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
* efi_loader: GetNextMonotonicCount() check parameterHeinrich Schuchardt2019-05-191-1/+8
| | | | | | | | Do not write to address indicated by NULL pointer. UEFI SCT II 2.6 (2017), 3.6.5 GetNextMonotonicCount(), 5.1.5.5.1 Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
* efi_loader: parameter checks CalculateCrc32()Heinrich Schuchardt2019-05-191-1/+8
| | | | | | | Not checking the parameters may lead reading or writing from NULL. Implement the parameter checks prescribed in the UEFI spec. Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
* efi_loader: check device path in InstallMultipleProtocolInterfacesHeinrich Schuchardt2019-05-191-0/+12
| | | | | | | | | | | According to the UEFI spec InstallMultipleProtocolInterfaces() must check if a device path has already been installed. In this case it must return EFI_ALREADY_STARTED. Cf. UEFI SCT II 2.6 A (2017), 3.3.16 InstallMultipleProtocolInterfaces(), 5.1.3.16.1. Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
* efi_loader: implement deprecated Unicode collation protocolHeinrich Schuchardt2019-05-193-1/+44
| | | | | | | | | | | | | | | | | | In EFI 1.10 a version of the Unicode collation protocol using ISO 639-2 language codes existed. This protocol is not part of the UEFI specification any longer. Unfortunately it is required to run the UEFI Self Certification Test (SCT) II, version 2.6, 2017. So we implement it here for the sole purpose of running the SCT. It can be removed once a compliant SCT is available. The configuration option defaults to no. Signed-off-by: Rob Clark <robdclark@gmail.com> Most of Rob's original patch is already merged. Only the deprecated protocol is missing. Rebase it and make it configurable. Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
* efi_loader: rename Unicode collation protocol 2 variablesHeinrich Schuchardt2019-05-195-10/+11
| | | | | | | Rename variables to make it clear they refer to the Unicode collation protocol identified by the EFI_UNICODE_PROTOCOL2_GUID. Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
* efi_loader: merge adjacent sprintf()Heinrich Schuchardt2019-05-191-3/+2
| | | | | | | In the implementation of the device path to text protocol join adjacent sprintf() statements. Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
* efi_loader: parameter checks simple network protocolHeinrich Schuchardt2019-05-191-3/+3
| | | | | | | | | Check buffer pointers are not NULL as required by the UEFI 2.7 spec. Return EFI_UNSUPPORTED instead of EFI_INVALID_PARAMETER when trying to transmit with non-zero header_size. Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
* efi_loader: GetVariable set attributes for EFI_BUFFER_TOO_SMALLHeinrich Schuchardt2019-05-191-5/+10
| | | | | | | | | | | | UEFI spec 2.7 erratum A leaves it undefined if Attributes should be set if GetVariable() returns EFI_BUFFER_TOO_SMALL. UEFI spec 2.8 defines that Attributes should be set if the return value is either EFI_SUCCESS or EFI_BUFFER_TOO_SMALL. Set Attributes if the return value is EFI_BUFFER_TOO_SMALL. Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
* efi_loader: ACPI device node to textHeinrich Schuchardt2019-05-121-3/+3
| | | | | | | | | | | The device path to text protocol renders ACPI device nodes incorrectly. Use capital hexadecimal numbers as shown in the UEFI spec examples. Always output the optional UID. This matches what UEFI SCT expects and saves us an `if`. Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
* efi_loader: infinite recursion notifying eventsHeinrich Schuchardt2019-05-121-1/+3
| | | | | | | | | | | | | | | | UEFI SCT uses this call sequence to determine the current TPL level inside notification functions: OldTpl = BS->RaiseTPL(TPL_HIGH_LEVEL); BS->RestoreTPL(OldTpl); In RestoreTPL() we trigger the notification function of queued events. If we do not mark the event as non-queued before calling the notification function, this results in an infinite recursive call sequence. Mark the event as non-queued before entering the notification function. Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
* efi_loader: simplify efi_allocate_pages()Heinrich Schuchardt2019-05-121-28/+15
| | | | | | Replace unnecessary control structures by using return statements. Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
* efi_loader: AllocateAdress error handlingHeinrich Schuchardt2019-05-121-6/+13
| | | | | | | | | | | | | | If AllocatePages() is called with AllocateAddress, the UEFI spec requires to return EFI_NOT_FOUND in case the memory page does not exist. The UEFI SCT II 2017 spec additionally requires to return EFI_NOT_FOUND if the page is already allocated. Check that *Memory refers to an unallocated page. UEFI SCT II (2017): AllocatePages(), 5.1.2.1.9 - 5.1.2.1.10 Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
* efi_loader: out of resources in AllocatePages()Heinrich Schuchardt2019-05-121-2/+2
| | | | | | | | | | | According to the UEFI AllocatePages() has to return EFI_OUT_OF_RESOURCES if sufficient memory is not available. Change the return value. UEFI SCT II (2017): 3.2.1 AllocatePages(), 5.1.2.1.8 Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
* efi_loader: check memory address before freeingHeinrich Schuchardt2019-05-121-5/+47
| | | | | | | | | | | | | | When we call FreePages() we essentially add memory to our memory map. We shouldn't do this for memory that does not exit. Check if the memory that is to be freed via FreePages() or FreePool() is in our memory map and is not EFI_CONVENTIONAL_MEMORY. This check is mandated by the UEFI specification. Cf. UEFI SCT II (2017), 3.2.2 FreePages(), 5.1.2.1 - 5.1.2.2 Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
* efi_loader: error code in UninstallProtocolInterface()Heinrich Schuchardt2019-05-121-1/+1
| | | | | | | | | | | According to the UEFI specification UninstallProtocolInteface() has to return EFI_NOT_FOUND if the interface is not found. Correct the return value. Cf. UEFI SCT II spec (2017), 3.3.2 UninstallProtocolInterface(), 5.1.3.2.4 Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
* efi_loader: superfluous check in efi_remove_protocol()Heinrich Schuchardt2019-05-121-2/+0
| | | | | | | efi_search_protocol() already checks that the GUID matches. Don't check a second time. Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
* efi_loader: LocateDevicePath() incorrect parameter checkHeinrich Schuchardt2019-05-121-1/+5
| | | | | | | | | | | | A parameter check in LocateDevicePath() does not match the requirements of the UEFI spec. If device is NULL, only return EFI_INVALID_PARAMETER if a matching handle is found. Cf. UEFI SCT II specification (2017)3.3.7 LocateDevicePath(), 5.1.3.7.3 Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
* efi_loader: fix typo in efi_locate_handle() commentHeinrich Schuchardt2019-05-121-1/+1
| | | | | | %s/not buffer/no buffer/ Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
* efi_loader: make device path to text protocol customizableHeinrich Schuchardt2019-05-125-3/+14
| | | | | | | The device path to text protocol is not needed for EBBR compliance. So let's make it a customizable option. Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
* efi_loader: make Unicode collation protocol customizableHeinrich Schuchardt2019-05-124-2/+16
| | | | | | | | | | The Unicode collation protocol is not needed for EBBR compliance. So let's make it a customizable option. The Unicode capitalization table is only needed by this protocol. So let it depend on the Unicode collation protocol. Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
* efi_loader: reword the EFI_LOADER config optionHeinrich Schuchardt2019-05-121-5/+5
| | | | | | | No need to mention U-Boot in brief description. Fix several typos, mention iPXE. Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
* efi_loader: format KconfigHeinrich Schuchardt2019-05-121-21/+22
| | | | | | | | | | Use if/endif for dependencies to give structure to the configuration menu. Sort important settings to the top. Abbreviate the short description of EFI_LOADER_HII. Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
* efi_loader: observe CONFIG_EFI_LOADER_HIIHeinrich Schuchardt2019-05-121-1/+1
| | | | | | | If EFI_LOADER_HII is not set, do not unnecessarily compile files for HII protocols. Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
* efi_loader: signature of ExitBootServices()Heinrich Schuchardt2019-05-071-2/+2
| | | | | | | Consistently use efi_uintn_t as type of memory keys. Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de> Reviewed-by: Alexander Graf <graf@amazon.com>
* efi_loader: LoadImage() check source sizeHeinrich Schuchardt2019-05-071-0/+4
| | | | | | | If the size of the source buffer is 0, return EFI_LOAD_ERROR. (UEFI SCT II 2017: 3.4.1 LoadImage() - 5.1.4.1.6) Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
* efi_loader: LoadImage() check parent imageHeinrich Schuchardt2019-05-072-23/+32
| | | | | | | | | | | If the parent image handle does not refer to a loaded image return EFI_INVALID_PARAMETER. (UEFI SCT II 2017: 3.4.1 LoadImage() - 5.1.4.1.1) Mark our root node as a loaded image to avoid an error when using it as parent image. Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
* efi_loader: HandleProtocol parameter checksHeinrich Schuchardt2019-05-071-1/+8
| | | | | | | HandleProtocol() and OpenProtocol() have to return EFI_UNSUPPORTED if the protocol is not installed on the handle. Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
* efi_loader: use EFI_PRINT instead of debugHeinrich Schuchardt2019-05-071-10/+7
| | | | | | | For correct indentation of messages in the UEFI API implementation use EFI_PRINT() instead of debug(). Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
* efi_loader: CloseProtocol() requires valid agent handleHeinrich Schuchardt2019-05-071-2/+5
| | | | | | | | | | | | Return EFI_INVALID_PARAMETER from CloseProtcol() if the agent handle is not valid. Return EFI_INVALID_PARAMETER if the optional controller handle is not valid. Return immediately from efi_search_obj if the handle is NULL. Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
* efi_selftest: unit test for RegisterProtocolNotify()Heinrich Schuchardt2019-05-072-0/+232
| | | | | | Provide a unit test for the RegisterProtocolNotify() boot service. Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
* efi_loader: implement RegisterProtocolNotify()Heinrich Schuchardt2019-05-071-14/+69
| | | | | | | | | | The RegisterProtocolNotify() boot service registers an event to be notified upon the installation of a protocol interface with the specified GUID. Add the missing implementation. Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
* efi_loader: EVT_NOTIFY_SIGNAL eventsHeinrich Schuchardt2019-05-071-1/+1
| | | | | | | The notification function of events of type EVT_NOTIFY_SIGNAL should always be queued when SignalEvent() is called. Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
* efi_selftest: remove redundant function efi_st_memcmp()Heinrich Schuchardt2019-05-0710-46/+29
| | | | | | | | | Function memcmp() is available in efi_freestanding.c. So we do not remove a further implementation. Replace all usages of efi_st_memcmp() by memcmp(). Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
* efi_loader: unload applications upon Exit()Heinrich Schuchardt2019-05-072-6/+32
| | | | | | | | | | Implement unloading of images in the Exit() boot services: * unload images that are not yet started, * unload started applications, * unload drivers returning an error. Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
* efi_loader: implement UnloadImage()Heinrich Schuchardt2019-05-071-4/+51
| | | | | | Implement the UnloadImage() boot service Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
* efi_loader: move efi_unload_image() down in sourceHeinrich Schuchardt2019-05-071-23/+23
| | | | | | | Move efi_unload_image() down in source to avoid forward declaration in follwing page. Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
* efi_loader: mark started imagesHeinrich Schuchardt2019-05-071-0/+2
| | | | | | | | In UnloadImage() we need to know if an image is already started. Add a field to the handle structure identifying loaded and started images. Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
* efi_loader: correct parameter check in LocateHandle()Heinrich Schuchardt2019-05-071-10/+10
| | | | | | | If LocateHandle() does not find an entry EFI_NOT_FOUND has to be returned even if BufferSize is NULL. Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
* efi_loader: allowable event types in CreateEventEx()Heinrich Schuchardt2019-05-071-2/+18
| | | | | | | | | | | | CreateEventEx() does not allow the following event types: * EVT_SIGNAL_EXIT_BOOT_SERVICES * EVT_SIGNAL_VIRTUAL_ADDRESS_CHANGE This check is needed to pass the UEFI SCT conformance test. Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de> Reviewed-by: Alexander Graf <agraf@csgraf.de>
* efi_loader: clean up UEFI sub-system initializationHeinrich Schuchardt2019-05-071-0/+16
| | | | | | | | | | | | allow_unaligned(), switch_to_non_secure_mode(), and efi_init_obj_list() are called in sequence in multiple places. Move calls to allow_unaligned() and switch_to_non_secure_mode() to efi_init_obj_list(). Remove unused includes. Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
* lib: add Zstandard decompression supportMarek Behún2019-05-0515-0/+6555
| | | | | | | | | Add the zstd library from Linux kernel (only decompression support). There are minimal changes to build with U-Boot, otherwise the files are identical to Linux commit dc35da16 from March 2018, the files had not been touched since in kernel. Also SPDX lincese tags were added. Signed-off-by: Marek Behún <marek.behun@nic.cz>
* lib: Add xxhash supportMarek Behún2019-05-053-0/+471
| | | | | | | | | | This adds the xxhash support from Linux. Files are almost identical to those added to Linux in commit 5d240522 ("lib: Add xxhash module") (they haven't been touched since in Linux). The only difference is to add some includes to be compatible with U-Boot. Also SPDX lincese tags were added. Signed-off-by: Marek Behún <marek.behun@nic.cz>
* lib/display_options: avoid illegal memory accessHeinrich Schuchardt2019-05-051-1/+3
| | | | | | | | | | | | display_options_get_banner_priv() overwrites bytes before the start of the buffer if the buffer size is less then 3. This case occurs in the Sandbox when executing the `ut_print` command. Correctly handle small buffer sizes. Adjust the print unit test to catch when bytes before the buffer are overwritten. Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de> Reviewed-by: Simon Glass <sjg@chromium.org>
* Merge branch '2019-05-03-master-imports'Tom Rini2019-05-032-2/+1
|\ | | | | | | | | | | - Various btrfs fixes - Various TI platform fixes - Other fixes (cross build, taurus update, Kconfig help text)
| * lib: Kconfig: fix help text for GZIPHeiko Schocher2019-05-031-1/+1
| | | | | | | | | | | | | | | | | | | | commit 95f4bbd581cf ("lib: fdt: Allow LZO and GZIP DT compression in U-Boot") introduced Kconfig option for gzip in U-Boot, but help text says gzip for SPL, which is wrong. Fix this. Signed-off-by: Heiko Schocher <hs@denx.de> Acked-by: Marek Vasut <marex@denx.de>
| * lib/vsprintf: remove #include <uuid.h> from vsprintf.cHeinrich Schuchardt2019-05-031-1/+0
| | | | | | | | | | | | common.h already includes uuid.h Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
* | lib: uuid: Fix unseeded PRNG on RANDOM_UUID=yEugeniu Rosca2019-05-021-0/+2
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | The random uuid values (enabled via CONFIG_RANDOM_UUID=y) on our platform are always the same. Below is consistent on each cold boot: => ### interrupt autoboot => env default -a; gpt write mmc 1 $partitions; print uuid_gpt_misc ... uuid_gpt_misc=d117f98e-6f2c-d04b-a5b2-331a19f91cb2 => env default -a; gpt write mmc 1 $partitions; print uuid_gpt_misc ... uuid_gpt_misc=ad5ec4b6-2d9f-8544-9417-fe3bd1c9b1b3 => env default -a; gpt write mmc 1 $partitions; print uuid_gpt_misc ... uuid_gpt_misc=cceb0b18-39cb-d547-9db7-03b405fa77d4 => env default -a; gpt write mmc 1 $partitions; print uuid_gpt_misc ... uuid_gpt_misc=d4981a2b-0478-544e-9607-7fd3c651068d => env default -a; gpt write mmc 1 $partitions; print uuid_gpt_misc ... uuid_gpt_misc=6d6c9a36-e919-264d-a9ee-bd00379686c7 While the uuids do change on every 'gpt write' command, the values appear to be taken from the same pool, in the same order. Assuming U-Boot with RANDOM_UUID=y is deployed on a large number of devices, all those devices would essentially expose the same UUID, breaking the assumption of system/RFS/application designers who rely on UUID as being globally unique (e.g. a database using UUID as key would alias/mix up entries/records due to duplicated UUID). The root cause seems to be simply _not_ seeding PRNG before generating a random value. It turns out this belongs to an established class of PRNG-specific problems, commonly known as "unseeded randomness", for which I am able to find below bugs/CVE/CWE: - https://bugzilla.redhat.com/show_bug.cgi?id=CVE-2015-0285 ("CVE-2015-0285 openssl: handshake with unseeded PRNG") - https://bugzilla.redhat.com/show_bug.cgi?id=CVE-2015-9019 ("CVE-2015-9019 libxslt: math.random() in xslt uses unseeded randomness") - https://cwe.mitre.org/data/definitions/336.html ("CWE-336: Same Seed in Pseudo-Random Number Generator (PRNG)") The first revision [1] of this patch updated the seed based on the output of get_timer(), similar to [4]. There are two problems with this approach: - get_timer() has a poor _ms_ resolution - when gen_rand_uuid() is called in a loop, get_timer() returns the same result, leading to the same seed being passed to srand(), leading to the same uuid being generated for several partitions with different names The above drawbacks have been addressed in the second version [2]. In its third revision (current), the patch reworded the description and summary line to emphasize it is a *fix* rather than an improvement. Testing [3] consisted of running 'gpt write mmc 1 $partitions' in a loop on R-Car3 for several minutes, collecting 8844 randomly generated UUIDS. Two consecutive cold boots are concatenated in the log. As a result, all uuid values are unique (scripted check). Thanks to Roman, who reported the issue and provided support in fixing. [1] https://patchwork.ozlabs.org/patch/1091802/ [2] https://patchwork.ozlabs.org/patch/1092945/ [3] https://gist.github.com/erosca/2820be9d554f76b982edd48474d0e7ca [4] commit da384a9d7628 ("net: rename and refactor eth_rand_ethaddr() function") Reported-by: Roman Stratiienko <roman.stratiienko@globallogic.com> Signed-off-by: Eugeniu Rosca <erosca@de.adit-jv.com> Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
* | efi_loader: description of efi_add_handle()Heinrich Schuchardt2019-05-021-3/+5
| | | | | | | | | | | | Correct the comments describing function efi_add_handle(). Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>