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]
Date:	Mon, 23 Mar 2015 00:46:38 -0700
From:	Jim Kukunas <james.t.kukunas@...ux.intel.com>
To:	Linux Kernel <linux-kernel@...r.kernel.org>,
	tom.zanussi@...ux.intel.com
Cc:	Arjan van de Ven <arjan@...ux.intel.com>,
	"H. Peter Anvin" <hpa@...or.com>, tglx@...utronix.de,
	mingo@...hat.com, x86@...nel.org
Subject: [PATCH 09/11] x86/xip: snip the kernel text out of the memory mapping

If the kernel tries to create an identity region for a memory range
that spans the kernel text, split it into two pieces, skipping the
text section. Otherwise, this will setup the standard text mapping,
which will point to the normal RAM location for text instead of the
XIP_BASE location.

Signed-off-by: Jim Kukunas <james.t.kukunas@...ux.intel.com>
---
 arch/x86/mm/init.c | 78 ++++++++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 78 insertions(+)

diff --git a/arch/x86/mm/init.c b/arch/x86/mm/init.c
index a110efc..07b20c6 100644
--- a/arch/x86/mm/init.c
+++ b/arch/x86/mm/init.c
@@ -391,6 +391,82 @@ bool pfn_range_is_mapped(unsigned long start_pfn, unsigned long end_pfn)
 	return false;
 }
 
+#ifdef CONFIG_XIP_KERNEL
+/*
+ * Cut the .text virtual address out of mem range b/c the mapping
+ * is already correctly setup
+ */
+static inline void snip_xip_text(struct map_range *mr, int *nr_range)
+{
+	int i;
+
+	for (i = 0; i < *nr_range; i++) {
+		long diff;
+
+		if (mr[i].start <= CONFIG_PHYSICAL_START &&
+		mr[i].end <= CONFIG_PHYSICAL_START)
+			continue;
+		if (mr[i].start >= __pa_symbol(_sdata))
+			continue;
+
+		diff = mr[i].start - CONFIG_PHYSICAL_START;
+		if (diff < 0) { /* range starts below .text and includes it */
+			diff = mr[i].end - __pa_symbol(_sdata);
+
+			/* shorten segment so it ends just before .text */
+			mr[i].end = CONFIG_PHYSICAL_START;
+
+			/* if segment goes past .text, add 2nd segment*/
+			if (diff > 0) {
+				/* move next section down 1 */
+				if (i + 1 < *nr_range) {
+					memmove(&mr[i + 1], &mr[i + 2],
+						sizeof(struct map_range[
+						*nr_range - i - 2]));
+				}
+				mr[i + 1].start = __pa_symbol(_sdata);
+				mr[i + 1].end =  mr[i + 1].start + diff;
+				mr[i + 1].page_size_mask = 0;
+				*nr_range = *nr_range + 1;
+				i++;
+			}
+		} else if (diff == 0) {
+			diff = mr[i].end - __pa_symbol(_sdata);
+			if (diff > 0) {
+				mr[i].start = __pa_symbol(_sdata);
+				mr[i].end = mr[i].start + diff;
+				mr[i].page_size_mask = 0;
+			} else {
+				/* delete this range */
+				memmove(&mr[i + 1], &mr[i], sizeof(
+					struct map_range[*nr_range - i - 1]));
+				*nr_range = *nr_range - 1;
+				i--;
+			}
+		} else if (diff > 0) {
+			long ediff = mr[i].end - __pa_symbol(_sdata);
+
+			if (ediff > 0) {
+				mr[i].start = __pa_symbol(_sdata);
+				mr[i].end = mr[i].start + ediff;
+				mr[i].page_size_mask = 0;
+			} else {
+				/* delete this range */
+				memmove(&mr[i + 1], &mr[i], sizeof(
+					struct map_range[*nr_range - i - 1]));
+				*nr_range = *nr_range - 1;
+				i--;
+			}
+		}
+		break;
+	}
+}
+#else
+static inline void snip_xip_text(struct map_range *mr, int *mr_range)
+{
+}
+#endif
+
 /*
  * Setup the direct mapping of the physical memory at PAGE_OFFSET.
  * This runs before bootmem is initialized and gets pages directly from
@@ -409,6 +485,8 @@ unsigned long __init_refok init_memory_mapping(unsigned long start,
 	memset(mr, 0, sizeof(mr));
 	nr_range = split_mem_range(mr, 0, start, end);
 
+	snip_xip_text(mr, &nr_range);
+
 	for (i = 0; i < nr_range; i++)
 		ret = kernel_physical_mapping_init(mr[i].start, mr[i].end,
 						   mr[i].page_size_mask);
-- 
2.1.0

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

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ