lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-Id: <ef89c0c761be20ead8bd9a3275743e6259b6092a.1469135598.git.luto@kernel.org>
Date:	Thu, 21 Jul 2016 14:16:52 -0700
From:	Andy Lutomirski <luto@...nel.org>
To:	"H. Peter Anvin" <hpa@...or.com>, x86@...nel.org
Cc:	Mario Limonciello <mario_limonciello@...l.com>,
	Matthew Garrett <mjg59@...f.ucam.org>,
	linux-kernel@...r.kernel.org, Andy Lutomirski <luto@...nel.org>
Subject: [PATCH 2/2] x86/boot: Simplify EBDA-vs-BIOS reservation logic

Both the intent and the effect of reserve_bios_regions() is simple:
reserve the range from the apparent BIOS start (suitably filtered)
through 1MB and, if the EBDA start address is sensible, extend that
reservation downward to cover the EBDA as well.

The code is overcomplicated, though, and contains head-scratchers
like:

	if (ebda_start < BIOS_START_MIN)
		ebda_start = BIOS_START_MAX;

That snipped is trying to say "if ebda_start < BIOS_START_MIN,
ignore it".

Simplify it: reorder the code so that it makes sense.  This should
have no functional effect under any circumstances.

Signed-off-by: Andy Lutomirski <luto@...nel.org>
---
 arch/x86/kernel/ebda.c | 34 +++++++++++-----------------------
 1 file changed, 11 insertions(+), 23 deletions(-)

diff --git a/arch/x86/kernel/ebda.c b/arch/x86/kernel/ebda.c
index 6219eef20e2e..4312f8ae71b7 100644
--- a/arch/x86/kernel/ebda.c
+++ b/arch/x86/kernel/ebda.c
@@ -65,22 +65,6 @@ void __init reserve_bios_regions(void)
 	if (!x86_platform.legacy.reserve_bios_regions)
 		return;
 
-	/* Get the start address of the EBDA page: */
-	ebda_start = get_bios_ebda();
-
-	/*
-	 * Quirk: some old Dells seem to have a 4k EBDA without
-	 * reporting so in their BIOS RAM size value, so just
-	 * consider the memory above 640K to be off limits
-	 * (bugzilla 2990).
-	 *
-	 * We detect this case by filtering for nonsensical EBDA
-	 * addresses below 128K, where we can assume that they
-	 * are bogus and bump it up to a fixed 640K value:
-	 */
-	if (ebda_start < BIOS_START_MIN)
-		ebda_start = BIOS_START_MAX;
-
 	/*
 	 * BIOS RAM size is encoded in kilobytes, convert it
 	 * to bytes to get a first guess at where the BIOS
@@ -91,18 +75,22 @@ void __init reserve_bios_regions(void)
 
 	/*
 	 * If bios_start is less than 128K, assume it is bogus
-	 * and bump it up to 640K:
+	 * and bump it up to 640K.  Similarly, if bios_start is above 640K,
+	 * don't trust it.
 	 */
-	if (bios_start < BIOS_START_MIN)
+	if (bios_start < BIOS_START_MIN || bios_start > BIOS_START_MAX)
 		bios_start = BIOS_START_MAX;
 
+	/* Get the start address of the EBDA page: */
+	ebda_start = get_bios_ebda();
+
 	/*
-	 * Use the lower of the bios_start and ebda_start
-	 * as the starting point, but don't allow it to
-	 * go beyond 640K:
+	 * If the EBDA start address is sane and is below the BIOS region,
+	 * then also reserve everything from the EBDA start address up to
+	 * the BIOS region.
 	 */
-	bios_start = min(bios_start, ebda_start);
-	bios_start = min(bios_start, BIOS_START_MAX);
+	if (ebda_start >= BIOS_START_MIN && ebda_start < bios_start)
+		bios_start = ebda_start;
 
 	/* Reserve all memory between bios_start and the 1MB mark: */
 	memblock_reserve(bios_start, 0x100000 - bios_start);
-- 
2.7.4

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ