[PATCH 6/6] extend the upper limit of kernel physical address randomization to 4G

From: Baoquan He
Date: Tue Jan 20 2015 - 22:38:19 EST


Since now kaslr can separately do randomization of physical and virtual
address, the physical address doesn't have to be
CONFIG_RANDOMIZE_BASE_MAX_OFFSET any more. At this time the identity
mapping only covers [0, 4G], so extend the upper limit of kernel physical
address randomization to 4G.

Signed-off-by: Baoquan He <bhe@xxxxxxxxxx>
---
arch/x86/boot/compressed/aslr.c | 11 ++++++-----
1 file changed, 6 insertions(+), 5 deletions(-)

diff --git a/arch/x86/boot/compressed/aslr.c b/arch/x86/boot/compressed/aslr.c
index 20a5f23..b112f90 100644
--- a/arch/x86/boot/compressed/aslr.c
+++ b/arch/x86/boot/compressed/aslr.c
@@ -207,14 +207,15 @@ static bool mem_avoid_overlap(struct mem_vector *img)
return false;
}

-static unsigned long slots[CONFIG_RANDOMIZE_BASE_MAX_OFFSET /
+#define PHYS_RANDOM_UPPER_LIMIT 0x100000000UL
+static unsigned long slots[PHYS_RANDOM_UPPER_LIMIT /
CONFIG_PHYSICAL_ALIGN];
static unsigned long slot_max;

static void slots_append(unsigned long addr)
{
/* Overflowing the slots list should be impossible. */
- if (slot_max >= CONFIG_RANDOMIZE_BASE_MAX_OFFSET /
+ if (slot_max >= PHYS_RANDOM_UPPER_LIMIT /
CONFIG_PHYSICAL_ALIGN)
return;

@@ -241,7 +242,7 @@ static void process_e820_entry(struct e820entry *entry,
return;

/* Ignore entries entirely above our maximum. */
- if (entry->addr >= CONFIG_RANDOMIZE_BASE_MAX_OFFSET)
+ if (entry->addr >= PHYS_RANDOM_UPPER_LIMIT)
return;

/* Ignore entries entirely below our minimum. */
@@ -266,8 +267,8 @@ static void process_e820_entry(struct e820entry *entry,
region.size -= region.start - entry->addr;

/* Reduce maximum size to fit end of image within maximum limit. */
- if (region.start + region.size > CONFIG_RANDOMIZE_BASE_MAX_OFFSET)
- region.size = CONFIG_RANDOMIZE_BASE_MAX_OFFSET - region.start;
+ if (region.start + region.size > PHYS_RANDOM_UPPER_LIMIT)
+ region.size = PHYS_RANDOM_UPPER_LIMIT - region.start;

/* Walk each aligned slot and check for avoided areas. */
for (img.start = region.start, img.size = image_size ;
--
1.9.3

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/