linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] firmware/efi: Fix a use after bug in efi_mem_reserve_persistent
@ 2021-03-10  8:31 Lv Yunlong
  2021-03-18 18:17 ` Ard Biesheuvel
  0 siblings, 1 reply; 2+ messages in thread
From: Lv Yunlong @ 2021-03-10  8:31 UTC (permalink / raw)
  To: ardb, jonathan.richardson; +Cc: linux-efi, linux-kernel, Lv Yunlong

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: 18df7577adae6 ("efi/memreserve: deal with memreserve entries in unmapped memory")
Signed-off-by: Lv Yunlong <lyl2019@mail.ustc.edu.cn>
---
 drivers/firmware/efi/efi.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/drivers/firmware/efi/efi.c b/drivers/firmware/efi/efi.c
index df3f9bcab581..4b7ee3fa9224 100644
--- a/drivers/firmware/efi/efi.c
+++ b/drivers/firmware/efi/efi.c
@@ -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);
 	}
 
-- 
2.25.1



^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH] firmware/efi: Fix a use after bug in efi_mem_reserve_persistent
  2021-03-10  8:31 [PATCH] firmware/efi: Fix a use after bug in efi_mem_reserve_persistent Lv Yunlong
@ 2021-03-18 18:17 ` Ard Biesheuvel
  0 siblings, 0 replies; 2+ messages in thread
From: Ard Biesheuvel @ 2021-03-18 18:17 UTC (permalink / raw)
  To: Lv Yunlong; +Cc: jonathan.richardson, linux-efi, Linux Kernel Mailing List

On Wed, 10 Mar 2021 at 09:37, Lv Yunlong <lyl2019@mail.ustc.edu.cn> wrote:
>
> 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: 18df7577adae6 ("efi/memreserve: deal with memreserve entries in unmapped memory")
> Signed-off-by: Lv Yunlong <lyl2019@mail.ustc.edu.cn>

Queued as a fix, thanks.

> ---
>  drivers/firmware/efi/efi.c | 3 ++-
>  1 file changed, 2 insertions(+), 1 deletion(-)
>
> diff --git a/drivers/firmware/efi/efi.c b/drivers/firmware/efi/efi.c
> index df3f9bcab581..4b7ee3fa9224 100644
> --- a/drivers/firmware/efi/efi.c
> +++ b/drivers/firmware/efi/efi.c
> @@ -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);
>         }
>
> --
> 2.25.1
>
>

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2021-03-18 18:18 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-03-10  8:31 [PATCH] firmware/efi: Fix a use after bug in efi_mem_reserve_persistent Lv Yunlong
2021-03-18 18:17 ` Ard Biesheuvel

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).