Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > linux.kernel > #1362386

[PATCH v4 14/20] x86, kaslr: Add two functions which will be used later

From Baoquan He <bhe@redhat.com>
Newsgroups linux.kernel
Subject [PATCH v4 14/20] x86, kaslr: Add two functions which will be used later
Date 2016-03-22 08:40 +0100
Message-ID <rfp51-1bB-45@gated-at.bofh.it> (permalink)
References <rfp4Z-1bB-5@gated-at.bofh.it>
Organization linux.* mail to news gateway

Show all headers | View raw


Function store_slot_info() is used to calculate the slot info of passed
in memory region and store it into slot_areas[].

Function mem_min_overlap is used to iterate all avoid regions to find the
one which overlap with it in the lowest address. E.g there's a memory
region[1024M, 2048M), after iterating all avoid regions we found the first
avoid region by starting address from low to high is [1536M, 1664M). With
this information we can split memory region [1024M, 1536M) out as the
avaliable slot area and save it into array slot_areas[].

Signed-off-by: Baoquan He <bhe@redhat.com>
---
 arch/x86/boot/compressed/aslr.c | 51 +++++++++++++++++++++++++++++++++++++++++
 1 file changed, 51 insertions(+)

diff --git a/arch/x86/boot/compressed/aslr.c b/arch/x86/boot/compressed/aslr.c
index 0431c19..44c6768 100644
--- a/arch/x86/boot/compressed/aslr.c
+++ b/arch/x86/boot/compressed/aslr.c
@@ -257,6 +257,40 @@ static bool mem_avoid_overlap(struct mem_vector *img)
 	return false;
 }
 
+static unsigned long
+mem_min_overlap(struct mem_vector *img, struct mem_vector *out)
+{
+	int i;
+	struct setup_data *ptr;
+	unsigned long min = img->start + img->size;
+
+	for (i = 0; i < MEM_AVOID_MAX; i++) {
+		if (mem_overlaps(img, &mem_avoid[i]) &&
+			(mem_avoid[i].start < min)) {
+			*out = mem_avoid[i];
+			min = mem_avoid[i].start;
+		}
+	}
+
+	/* Check all entries in the setup_data linked list. */
+	ptr = (struct setup_data *)(unsigned long)real_mode->hdr.setup_data;
+	while (ptr) {
+		struct mem_vector avoid;
+
+		avoid.start = (unsigned long)ptr;
+		avoid.size = sizeof(*ptr) + ptr->len;
+
+		if (mem_overlaps(img, &avoid) && (avoid.start < min)) {
+			*out = avoid;
+			min = avoid.start;
+		}
+
+		ptr = (struct setup_data *)(unsigned long)ptr->next;
+	}
+
+	return min;
+}
+
 static unsigned long slots[CONFIG_RANDOMIZE_BASE_MAX_OFFSET /
 			   CONFIG_PHYSICAL_ALIGN];
 
@@ -273,6 +307,23 @@ static unsigned long slot_max;
 
 static unsigned long slot_area_index;
 
+static void store_slot_info(struct mem_vector *region, unsigned long image_size)
+{
+	struct slot_area slot_area;
+
+	slot_area.addr = region->start;
+	if (image_size <= CONFIG_PHYSICAL_ALIGN)
+		slot_area.num = region->size / CONFIG_PHYSICAL_ALIGN;
+	else
+		slot_area.num = (region->size - image_size) /
+				CONFIG_PHYSICAL_ALIGN + 1;
+
+	if (slot_area.num > 0) {
+		slot_areas[slot_area_index++] = slot_area;
+		slot_max += slot_area.num;
+	}
+}
+
 static void slots_append(unsigned long addr)
 {
 	/* Overflowing the slots list should be impossible. */
-- 
2.5.0

Back to linux.kernel | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

[PATCH v4 00/20] x86, boot: kaslr cleanup and 64bit kaslr support Baoquan He <bhe@redhat.com> - 2016-03-22 08:40 +0100
  [PATCH v4 08/20] x86, kaslr: Get correct max_addr for relocs pointer Baoquan He <bhe@redhat.com> - 2016-03-22 08:40 +0100
    Re: [PATCH v4 08/20] x86, kaslr: Get correct max_addr for relocs pointer Kees Cook <keescook@chromium.org> - 2016-03-22 22:00 +0100
  [PATCH v4 19/20] x86, kaslr: Allow random address to be below loaded address Baoquan He <bhe@redhat.com> - 2016-03-22 08:40 +0100
    Re: [PATCH v4 19/20] x86, kaslr: Allow random address to be below  loaded address Kees Cook <keescook@chromium.org> - 2016-03-22 21:00 +0100
      Re: [PATCH v4 19/20] x86, kaslr: Allow random address to be below  loaded address Baoquan He <bhe@redhat.com> - 2016-03-23 02:50 +0100
    [PATCH v5 19/20] x86, kaslr: Allow random address to be below loaded  address Baoquan He <bhe@redhat.com> - 2016-03-23 10:00 +0100
  [PATCH v4 12/20] x86, boot: Add checking for memcpy Baoquan He <bhe@redhat.com> - 2016-03-22 08:40 +0100
  [PATCH v4 14/20] x86, kaslr: Add two functions which will be used later Baoquan He <bhe@redhat.com> - 2016-03-22 08:40 +0100
  Re: [PATCH v4 00/20] x86, boot: kaslr cleanup and 64bit kaslr support Kees Cook <keescook@chromium.org> - 2016-03-22 21:30 +0100
    Re: [PATCH v4 00/20] x86, boot: kaslr cleanup and 64bit kaslr support Kees Cook <keescook@chromium.org> - 2016-03-23 23:50 +0100

csiph-web