diff options
author | Alexander Graf <agraf@suse.de> | 2018-11-05 00:30:46 +0100 |
---|---|---|
committer | Alexander Graf <agraf@suse.de> | 2018-12-02 21:59:37 +0100 |
commit | c2e1ad70a75048d802bf5c3296a043761939dae6 (patch) | |
tree | a028f0210ed113a4ccbd305f695d565ccb5c8509 /lib | |
parent | afdc4fcc8931589f2fab75d8830ab9b43d2725c4 (diff) | |
download | u-boot-c2e1ad70a75048d802bf5c3296a043761939dae6.tar.gz u-boot-c2e1ad70a75048d802bf5c3296a043761939dae6.tar.bz2 u-boot-c2e1ad70a75048d802bf5c3296a043761939dae6.zip |
efi_loader: Ensure memory allocations are page aligned
When the max_addr parameter of efi_find_free_memory() is within bounds
of an existing map and fits the reservation, we just return that address
as allocation value.
That breaks however if max_addr is not page aligned. So ensure that it
always comes to us page aligned, simplifying the allocation logic.
Without this, I've seen breakage where we were allocating pages at -1U
(32bit) which fits into a region that spans beyond 0x100000000. In that
case, we would return 0xffffffff as a valid memory allocation, although
we usually do guarantee they are all page aligned.
Fix this by aligning the max address argument always.
Signed-off-by: Alexander Graf <agraf@suse.de>
Diffstat (limited to 'lib')
-rw-r--r-- | lib/efi_loader/efi_memory.c | 6 |
1 files changed, 6 insertions, 0 deletions
diff --git a/lib/efi_loader/efi_memory.c b/lib/efi_loader/efi_memory.c index 5bd4f4d7fc..1ffcf92eb2 100644 --- a/lib/efi_loader/efi_memory.c +++ b/lib/efi_loader/efi_memory.c @@ -294,6 +294,12 @@ static uint64_t efi_find_free_memory(uint64_t len, uint64_t max_addr) { struct list_head *lhandle; + /* + * Prealign input max address, so we simplify our matching + * logic below and can just reuse it as return pointer. + */ + max_addr &= ~EFI_PAGE_MASK; + list_for_each(lhandle, &efi_mem) { struct efi_mem_list *lmem = list_entry(lhandle, struct efi_mem_list, link); |