kernel-hardening.lists.openwall.com archive mirror
 help / color / mirror / Atom feed
* [PATCH v1 04/06]: The PLT stub for PIC modules
@ 2019-01-15 19:01 Ruslan Nikolaev
  0 siblings, 0 replies; only message in thread
From: Ruslan Nikolaev @ 2019-01-15 19:01 UTC (permalink / raw)
  To: kernel-hardening; +Cc: thgarnie, x86, kstewart, gregkh, keescook

The PLT stub for PIC modules

The patch is by Hassan Nadeem and Ruslan Nikolaev. This extends
the prior PIE kernel patch (by Thomas Garnier) to also support
position-independent modules that can be placed anywhere in the
48/64-bit address space (for better KASLR).

Signed-off-by: Ruslan Nikolaev <nruslan_devel@yahoo.com>
---
  Makefile          |    3 ++-
  module-plt-stub.S |   23 +++++++++++++++++++++++
  2 files changed, 25 insertions(+), 1 deletion(-)

diff -uprN a/arch/x86/kernel/Makefile b/arch/x86/kernel/Makefile
--- a/arch/x86/kernel/Makefile	2019-01-15 11:20:45.271168382 -0500
+++ b/arch/x86/kernel/Makefile	2019-01-15 11:30:12.576999665 -0500
@@ -104,7 +104,8 @@ obj-$(CONFIG_KEXEC_CORE)	+= relocate_ker
  obj-$(CONFIG_KEXEC_FILE)	+= kexec-bzimage64.o
  obj-$(CONFIG_CRASH_DUMP)	+= crash_dump_$(BITS).o
  obj-y				+= kprobes/
-obj-$(CONFIG_MODULES)		+= module.o
+obj-$(CONFIG_MODULES)		+= module.o module-plt-stub.o
+OBJECT_FILES_NON_STANDARD_module-plt-stub.o := y
  obj-$(CONFIG_DOUBLEFAULT)	+= doublefault.o
  obj-$(CONFIG_KGDB)		+= kgdb.o
  obj-$(CONFIG_VM86)		+= vm86_32.o
diff -uprN a/arch/x86/kernel/module-plt-stub.S 
b/arch/x86/kernel/module-plt-stub.S
--- a/arch/x86/kernel/module-plt-stub.S	1969-12-31 19:00:00.000000000 -0500
+++ b/arch/x86/kernel/module-plt-stub.S	2019-01-15 11:30:12.580999706 -0500
@@ -0,0 +1,23 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+
+#include <linux/stringify.h>
+#include <linux/linkage.h>
+#include <asm/dwarf2.h>
+#include <asm/cpufeatures.h>
+#include <asm/alternative-asm.h>
+#include <asm/export.h>
+#include <asm/nospec-branch.h>
+
+/* The following code is used for PLT generation only
+   and should never be executed directly. */
+.section .rodata
+.globl __THUNK_FOR_PLT
+.globl __THUNK_FOR_PLT_SIZE
+__THUNK_FOR_PLT:
+#ifdef CONFIG_RETPOLINE
+	movq 0(%rip), %rax
+	JMP_NOSPEC %rax
+#else
+	jmpq   *0(%rip)
+#endif
+__THUNK_FOR_PLT_SIZE: .long . - __THUNK_FOR_PLT

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2019-01-15 19:01 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-01-15 19:01 [PATCH v1 04/06]: The PLT stub for PIC modules Ruslan Nikolaev

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).