]> git.baikalelectronics.ru Git - kernel.git/commitdiff
firmware/efi: Fix a use after bug in efi_mem_reserve_persistent
authorLv Yunlong <lyl2019@mail.ustc.edu.cn>
Wed, 10 Mar 2021 08:31:27 +0000 (00:31 -0800)
committerArd Biesheuvel <ardb@kernel.org>
Fri, 19 Mar 2021 06:44:27 +0000 (07:44 +0100)
In the for loop in efi_mem_reserve_persistent(), prsv = rsv->next
use the unmapped rsv. Use the unmapped pages will cause segment
fault.

Fixes: b7fce60a1ef24 ("efi/memreserve: deal with memreserve entries in unmapped memory")
Signed-off-by: Lv Yunlong <lyl2019@mail.ustc.edu.cn>
Signed-off-by: Ard Biesheuvel <ardb@kernel.org>
drivers/firmware/efi/efi.c

index df3f9bcab581c430df52347c2eba41950811d07e..4b7ee3fa9224ff809a89b88bbae5cea765d9dbeb 100644 (file)
@@ -927,7 +927,7 @@ int __ref efi_mem_reserve_persistent(phys_addr_t addr, u64 size)
        }
 
        /* first try to find a slot in an existing linked list entry */
-       for (prsv = efi_memreserve_root->next; prsv; prsv = rsv->next) {
+       for (prsv = efi_memreserve_root->next; prsv; ) {
                rsv = memremap(prsv, sizeof(*rsv), MEMREMAP_WB);
                index = atomic_fetch_add_unless(&rsv->count, 1, rsv->size);
                if (index < rsv->size) {
@@ -937,6 +937,7 @@ int __ref efi_mem_reserve_persistent(phys_addr_t addr, u64 size)
                        memunmap(rsv);
                        return efi_mem_reserve_iomem(addr, size);
                }
+               prsv = rsv->next;
                memunmap(rsv);
        }