mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: "tip-bot2 for Lv Yunlong" <tip-bot2@linutronix.de>
To: linux-tip-commits@vger.kernel.org
Cc: Lv Yunlong <lyl2019@mail.ustc.edu.cn>,
	Ard Biesheuvel <ardb@kernel.org>,
	x86@kernel.org, linux-kernel@vger.kernel.org
Subject: [tip: efi/urgent] firmware/efi: Fix a use after bug in efi_mem_reserve_persistent
Date: Fri, 19 Mar 2021 13:29:09 -0000	[thread overview]
Message-ID: <161616054920.398.5501549197969092499.tip-bot2@tip-bot2> (raw)

The following commit has been merged into the efi/urgent branch of tip:

Commit-ID:     9ceee7d0841a8f7d7644021ba7d4cc1fbc7966e3
Gitweb:        https://git.kernel.org/tip/9ceee7d0841a8f7d7644021ba7d4cc1fbc7966e3
Author:        Lv Yunlong <lyl2019@mail.ustc.edu.cn>
AuthorDate:    Wed, 10 Mar 2021 00:31:27 -08:00
Committer:     Ard Biesheuvel <ardb@kernel.org>
CommitterDate: Fri, 19 Mar 2021 07:44:27 +01:00

firmware/efi: Fix a use after bug in efi_mem_reserve_persistent

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>
Signed-off-by: Ard Biesheuvel <ardb@kernel.org>
---
 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 df3f9bc..4b7ee3f 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);
 	}
 

                 reply	other threads:[~2021-03-19 13:30 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=161616054920.398.5501549197969092499.tip-bot2@tip-bot2 \
    --to=tip-bot2@linutronix.de \
    --cc=ardb@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-tip-commits@vger.kernel.org \
    --cc=lyl2019@mail.ustc.edu.cn \
    --cc=x86@kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®