: Extending kernel support for PIC modules
Subsystems (10)
PATCH 6/6 : Extending kernel support for PIC modules
Extending kernel support 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).
--- Makefile | 4 arch/x86/Kconfig | 12 arch/x86/Makefile | 11 arch/x86/crypto/aes-x86_64-asm_64.S | 5 arch/x86/crypto/cast5-avx-x86_64-asm_64.S | 9 arch/x86/crypto/cast6-avx-x86_64-asm_64.S | 9 arch/x86/crypto/sha1-mb/sha1_mb_mgr_flush_avx2.S | 3 arch/x86/crypto/sha1-mb/sha1_mb_mgr_submit_avx2.S | 3 arch/x86/crypto/sha256-mb/sha256_mb_mgr_flush_avx2.S | 3 arch/x86/crypto/sha256-mb/sha256_mb_mgr_submit_avx2.S | 3 arch/x86/crypto/sha512-mb/sha512_mb_mgr_flush_avx2.S | 3 arch/x86/crypto/sha512-mb/sha512_mb_mgr_submit_avx2.S | 3 arch/x86/include/asm/alternative.h | 12 arch/x86/include/asm/arch_hweight.h | 5 arch/x86/include/asm/asm.h | 60 +++- arch/x86/include/asm/elf.h | 5 arch/x86/include/asm/jump_label.h | 4 arch/x86/include/asm/kvm_host.h | 15 - arch/x86/include/asm/module.h | 26 + arch/x86/include/asm/paravirt_types.h | 9 arch/x86/include/asm/percpu.h | 2 arch/x86/include/asm/uaccess.h | 6 arch/x86/include/asm/xen/hypercall.h | 31 +- arch/x86/kernel/ftrace.c | 14 arch/x86/kernel/module.c | 263 ++++++++++++++++-- arch/x86/kernel/module.lds | 1 arch/x86/kvm/emulate.c | 1 arch/x86/tools/relocs.c | 4 scripts/Makefile.modpost | 2 scripts/recordmcount.c | 3 30 files changed, 447 insertions(+), 84 deletions(-)
arch/x86/crypto/aes-x86_64-asm_64.S +3 -2
@@ -17,6 +17,7 @@ #include <linux/linkage.h> #include <asm/asm-offsets.h> +#include <asm/asm.h> #define R1 %rax #define R1E %eax
@@ -83,11 +84,11 @@ ENDPROC(FUNC); #define round_mov(tab_off, reg_i, reg_o) \ - leaq tab_off(%rip), RBASE; \ + _ASM_LEA_RIP(tab_off, RBASE); \ movl (RBASE,reg_i,4), reg_o; #define round_xor(tab_off, reg_i, reg_o) \ - leaq tab_off(%rip), RBASE; \ + _ASM_LEA_RIP(tab_off, RBASE); \ xorl (RBASE,reg_i,4), reg_o; #define round(TAB,OFFSET,r1,r2,r3,r4,r5,r6,r7,r8,ra,rb,rc,rd) \
arch/x86/crypto/cast5-avx-x86_64-asm_64.S +5 -4
@@ -25,6 +25,7 @@ #include <linux/linkage.h> #include <asm/frame.h> +#include <asm/asm.h> .file "cast5-avx-x86_64-asm_64.S"
@@ -99,17 +100,17 @@ #define lookup_32bit(src, dst, op1, op2, op3, interleave_op, il_reg) \ movzbl src ## bh, RID1d; \ - leaq s1(%rip), RID2; \ + _ASM_LEA_RIP(s1, RID2); \ movl (RID2, RID1, 4), dst ## d; \ movzbl src ## bl, RID2d; \ - leaq s2(%rip), RID1; \ + _ASM_LEA_RIP(s2, RID1); \ op1 (RID1, RID2, 4), dst ## d; \ shrq $16, src; \ movzbl src ## bh, RID1d; \ - leaq s3(%rip), RID2; \ + _ASM_LEA_RIP(s3, RID2); \ op2 (RID2, RID1, 4), dst ## d; \ movzbl src ## bl, RID2d; \ - leaq s4(%rip), RID1; \ + _ASM_LEA_RIP(s4, RID1); \ op3 (RID1, RID2, 4), dst ## d; \ interleave_op(il_reg);
arch/x86/crypto/cast6-avx-x86_64-asm_64.S +5 -4
@@ -25,6 +25,7 @@ #include <linux/linkage.h> #include <asm/frame.h> +#include <asm/asm.h> #include "glue_helper-asm-avx.S" .file "cast6-avx-x86_64-asm_64.S"
@@ -99,17 +100,17 @@ #define lookup_32bit(src, dst, op1, op2, op3, interleave_op, il_reg) \ movzbl src ## bh, RID1d; \ - leaq s1(%rip), RID2; \ + _ASM_LEA_RIP(s1, RID2); \ movl (RID2, RID1, 4), dst ## d; \ movzbl src ## bl, RID2d; \ - leaq s2(%rip), RID1; \ + _ASM_LEA_RIP(s2, RID1); \ op1 (RID1, RID2, 4), dst ## d; \ shrq $16, src; \ movzbl src ## bh, RID1d; \ - leaq s3(%rip), RID2; \ + _ASM_LEA_RIP(s3, RID2); \ op2 (RID2, RID1, 4), dst ## d; \ movzbl src ## bl, RID2d; \ - leaq s4(%rip), RID1; \ + _ASM_LEA_RIP(s4, RID1); \ op3 (RID1, RID2, 4), dst ## d; \ interleave_op(il_reg);
arch/x86/crypto/sha1-mb/sha1_mb_mgr_flush_avx2.S +2 -1
@@ -53,6 +53,7 @@ */ #include <linux/linkage.h> #include <asm/frame.h> +#include <asm/asm.h> #include "sha1_mb_mgr_datastruct.S"
@@ -183,7 +184,7 @@ LABEL skip_ %I # "state" and "args" are the same address, arg1 # len is arg2 - call sha1_x8_avx2 + _ASM_CALL(sha1_x8_avx2) # state and idx are intact
arch/x86/crypto/sha1-mb/sha1_mb_mgr_submit_avx2.S +2 -1
@@ -54,6 +54,7 @@ #include <linux/linkage.h> #include <asm/frame.h> +#include <asm/asm.h> #include "sha1_mb_mgr_datastruct.S"
@@ -163,7 +164,7 @@ start_loop: # "state" and "args" are the same address, arg1 # len is arg2 - call sha1_x8_avx2 + _ASM_CALL(sha1_x8_avx2) # state and idx are intact
arch/x86/crypto/sha256-mb/sha256_mb_mgr_flush_avx2.S +2 -1
@@ -52,6 +52,7 @@ */ #include <linux/linkage.h> #include <asm/frame.h> +#include <asm/asm.h> #include "sha256_mb_mgr_datastruct.S" .extern sha256_x8_avx2
@@ -181,7 +182,7 @@ LABEL skip_ %I # "state" and "args" are the same address, arg1 # len is arg2 - call sha256_x8_avx2 + _ASM_CALL(sha256_x8_avx2) # state and idx are intact len_is_0:
arch/x86/crypto/sha256-mb/sha256_mb_mgr_submit_avx2.S +2 -1
@@ -53,6 +53,7 @@ #include <linux/linkage.h> #include <asm/frame.h> +#include <asm/asm.h> #include "sha256_mb_mgr_datastruct.S" .extern sha256_x8_avx2
@@ -164,7 +165,7 @@ start_loop: # "state" and "args" are the same address, arg1 # len is arg2 - call sha256_x8_avx2 + _ASM_CALL(sha256_x8_avx2) # state and idx are intact
arch/x86/crypto/sha512-mb/sha512_mb_mgr_flush_avx2.S +2 -1
@@ -53,6 +53,7 @@ #include <linux/linkage.h> #include <asm/frame.h> +#include <asm/asm.h> #include "sha512_mb_mgr_datastruct.S" .extern sha512_x4_avx2
@@ -177,7 +178,7 @@ LABEL skip_ %I # "state" and "args" are the same address, arg1 # len is arg2 - call sha512_x4_avx2 + _ASM_CALL(sha512_x4_avx2) # state and idx are intact len_is_0:
arch/x86/crypto/sha512-mb/sha512_mb_mgr_submit_avx2.S +2 -1
@@ -53,6 +53,7 @@ #include <linux/linkage.h> #include <asm/frame.h> +#include <asm/asm.h> #include "sha512_mb_mgr_datastruct.S" .extern sha512_x4_avx2
@@ -167,7 +168,7 @@ start_loop: # "state" and "args" are the same address, arg1 # len is arg2 - call sha512_x4_avx2 + _ASM_CALL(sha512_x4_avx2) # state and idx are intact len_is_0:
arch/x86/include/asm/alternative.h +0 -0
@@ -207,8 +207,8 @@ static inline int alternatives_text_rese/* Like alternative_io, but for replacing a direct call with another
one. */
#define alternative_call(oldfunc, newfunc, feature, output, input...) \
- asm volatile (ALTERNATIVE("call %P[old]", "call %P[new]", feature) \
- : output : [old] "i" (oldfunc), [new] "i" (newfunc), ## input)
+ asm volatile (ALTERNATIVE(_ASM_CALL(%p[old]), _ASM_CALL(%p[new]), feature) \
+ : output : [old] "X" (oldfunc), [new] "X" (newfunc), ## input)
/*
* Like alternative_call, but there are two features and respective
functions.
@@ -218,11 +218,11 @@ static inline int alternatives_text_rese
*/
#define alternative_call_2(oldfunc, newfunc1, feature1, newfunc2,
feature2, \
output, input...) \
- asm volatile (ALTERNATIVE_2("call %P[old]", "call %P[new1]", feature1,\
- "call %P[new2]", feature2) \
+ asm volatile (ALTERNATIVE_2(_ASM_CALL(%p[old]), _ASM_CALL(%p[new1]), feature1,\
+ _ASM_CALL(%p[new2]), feature2) \
: output, ASM_CALL_CONSTRAINT \
- : [old] "i" (oldfunc), [new1] "i" (newfunc1), \
- [new2] "i" (newfunc2), ## input)
+ : [old] "X" (oldfunc), [new1] "X" (newfunc1), \
+ [new2] "X" (newfunc2), ## input)
/*
* use this macro(s) if you need more than one output parameter
arch/x86/include/asm/arch_hweight.h +3 -2
@@ -3,6 +3,7 @@#define _ASM_X86_HWEIGHT_H#include <asm/cpufeatures.h> +#include <asm/asm.h> #ifdef CONFIG_64BIT /* popcnt %edi, %eax */
@@ -24,7 +25,7 @@ static __always_inline unsigned int __ar {unsigned int res; - asm (ALTERNATIVE("call __sw_hweight32", POPCNT32, X86_FEATURE_POPCNT) + asm (ALTERNATIVE(_ASM_CALL(__sw_hweight32), POPCNT32, X86_FEATURE_POPCNT) : "="REG_OUT (res) : REG_IN (w));
@@ -52,7 +53,7 @@ static __always_inline unsigned long __a {unsigned long res; - asm (ALTERNATIVE("call __sw_hweight64", POPCNT64, X86_FEATURE_POPCNT) + asm (ALTERNATIVE(_ASM_CALL(__sw_hweight64), POPCNT64, X86_FEATURE_POPCNT) : "="REG_OUT (res) : REG_IN (w));
arch/x86/include/asm/asm.h +57 -3
89 lines not on this page · raw message
arch/x86/include/asm/elf.h +4 -1
@@ -63,7 +63,10 @@ typedef struct user_fxsr_struct elf_fpxr#define R_X86_64_8 14/* Direct 8 bit sign extended */ #define R_X86_64_PC8 15/* 8 bit sign extended pc relative */ -#define R_X86_64_NUM 16 +#define R_X86_64_GOTPCRELX 41 +#define R_X86_64_REX_GOTPCRELX 42 + +#define R_X86_64_NUM 43/* * These are used to set parameters in the core dumps.
arch/x86/include/asm/jump_label.h +2 -2
@@ -37,7 +37,7 @@ static __always_inline bool arch_static_ ".byte " __stringify(STATIC_KEY_INIT_NOP) "\n\t" ".pushsection __jump_table, \"aw\" \n\t" _ASM_ALIGN "\n\t" - _ASM_PTR "1b, %l[l_yes], %P0 \n\t" + _ASM_PTR "1b, %l[l_yes], %p0 \n\t" ".popsection \n\t" : : "X" (&((char *)key)[branch]) : : l_yes);
@@ -53,7 +53,7 @@ static __always_inline bool arch_static_ "2:\n\t" ".pushsection __jump_table, \"aw\" \n\t" _ASM_ALIGN "\n\t" - _ASM_PTR "1b, %l[l_yes], %P0 \n\t" + _ASM_PTR "1b, %l[l_yes], %p0 \n\t" ".popsection \n\t" : : "X" (&((char *)key)[branch]) : : l_yes);
arch/x86/include/asm/kvm_host.h +13 -2
@@ -1394,20 +1394,31 @@ enum {*/ asmlinkage void kvm_spurious_fault(void); +#if defined(MODULE ) && defined(CONFIG_X86_PIC ) +# define ___kvm_check_rebooting \ + "pushq %%rax \n\t" \ + "movq kvm_rebooting@GOTPCREL(%%rip), %%rax \n\t" \ + "cmpb $0, (%%rax) \n\t" \ + "popq %%rax \n\t" +#else +# define ___kvm_check_rebooting \ + "cmpb $0, kvm_rebooting" __ASM_SEL(,(%%rip)) " \n\t" +#endif +#define ____kvm_handle_fault_on_reboot (insn, cleanup_insn) \ "666: " insn "\n\t" \ "668: \n\t" \ ".pushsection .fixup, \"ax\" \n" \ "667: \n\t" \ cleanup_insn "\n\t" \ - "cmpb $0, kvm_rebooting" __ASM_SEL(,(%%rip)) " \n\t" \ + ___kvm_check_rebooting \ "jne 668b \n\t" \ __ASM_SIZE(push) "$0 \n\t" \ __ASM_SIZE(push) "%%" _ASM_AX " \n\t" \ _ASM_MOVABS " $666b, %%" _ASM_AX "\n\t" \ _ASM_MOV " %%" _ASM_AX ", " __ASM_SEL(4,8) "(%%" _ASM_SP ") \n\t" \ __ASM_SIZE(pop) "%%" _ASM_AX " \n\t" \ - "call kvm_spurious_fault \n\t" \ + _ASM_CALL(kvm_spurious_fault) " \n\t" \ ".popsection \n\t" \ _ASM_EXTABLE(666b, 667b)
arch/x86/include/asm/module.h +22 -4
@@ -5,13 +5,32 @@#include <asm-generic/module.h> #include <asm/orc_types.h> -#ifdef CONFIG_X86_PIE +extern const char __THUNK_FOR_PLT[]; +extern const unsigned int __THUNK_FOR_PLT_SIZE; + +#define PLT_ENTRY_ALIGNMENT 16 +struct plt_entry { +#ifdef CONFIG_RETPOLINE +u8 mov_ins[3 ]; +u32 rel_addr; +u8 thunk[0 ]; +#else +u16 jmp_ins; +u32 rel_addr; +#endif +} __packed__aligned(PLT_ENTRY_ALIGNMENT) ; +struct mod_got_sec {struct elf64_shdr *got;int got_num_entries;int got_max_entries; }; -#endif + +struct mod_plt_sec { +struct elf64_shdr *plt; +int plt_num_entries; +int plt_max_entries; +};struct mod_arch_specific {#ifdef CONFIG_UNWINDER_ORC
@@ -19,9 +38,8 @@ struct mod_arch_specific {int *orc_unwind_ip;struct orc_entry *orc_unwind;#endif -#ifdef CONFIG_X86_PIE struct mod_got_sec core; -#endif +struct mod_plt_sec core_plt; };#ifdef CONFIG_X86_64
arch/x86/include/asm/paravirt_types.h +7 -2
@@ -337,7 +337,7 @@ extern struct pv_lock_ops pv_lock_ops;#define PARAVIRT_PATCH (x) \ (offsetof(struct paravirt_patch_template, x) / sizeof(void *)) -#ifdef CONFIG_X86_PIE +#if defined(CONFIG_X86_PIE ) || (defined(MODULE ) && defined(CONFIG_X86_PIC ))#define paravirt_opptr_call "a"#define paravirt_opptr_type "p"#else
@@ -355,7 +355,11 @@ extern struct pv_lock_ops pv_lock_ops;* Generate some code, and mark it as patchable by the * apply_paravirt() alternate instruction patcher. */ -#define _paravirt_alt (insn_string, type, clobber) \ +#if defined(MODULE ) && defined(CONFIG_X86_PIC ) +# define _paravirt_alt (insn_string, type, clobber) \ + insn_string "\n" +#else +# define _paravirt_alt (insn_string, type, clobber) \ "771:\n\t" insn_string "\n" "772:\n" \ ".pushsection .parainstructions,\"a\"\n" \ _ASM_ALIGN "\n" \
@@ -364,6 +368,7 @@ extern struct pv_lock_ops pv_lock_ops;" .byte 772b-771b\n" \" .short " clobber"\n" \ ".popsection\n" +#endif /* Generate patchable code, with the default asm parameters. */ #define paravirt_alt (insn_string) \
arch/x86/include/asm/percpu.h +1 -1
@@ -216,7 +216,7 @@ do { \ })/* Position Independent code uses relative addresses only */ -#ifdef CONFIG_X86_PIE +#if defined(CONFIG_X86_PIE ) || (defined(MODULE ) && defined(CONFIG_X86_PIC ))#define __percpu_stable_arg __percpu_arg(a1)#else #define __percpu_stable_arg __percpu_arg(P1)
arch/x86/include/asm/uaccess.h +3 -3
@@ -174,7 +174,7 @@ __typeof__(__builtin_choose_expr(sizeof( register __inttype(*(ptr)) __val_gu asm("%"_ASM_DX); \__chk_user_ptr (ptr); \might_fault (); \ - asmvolatile ("call __get_user_%P4" \ + asm volatile(_ASM_CALL(__get_user_%P4) \ : "=a" (__ret_gu), "=r" (__val_gu), \ASM_CALL_CONSTRAINT \ : "0" (ptr), "i" (sizeof(*(ptr)))); \
@@ -183,7 +183,7 @@ __typeof__(__builtin_choose_expr(sizeof( })#define __put_user_x (size, x, ptr, __ret_pu) \ - asm volatile("call __put_user_" #size : "=a" (__ret_pu) \ + asm volatile(_ASM_CALL(__put_user_##size) : "=a" (__ret_pu) \ : "0" ((typeof(*(ptr)))(x)), "c" (ptr) : "ebx")
@@ -213,7 +213,7 @@ __typeof__(__builtin_choose_expr(sizeof( : : "A" (x), "r" (addr))#define __put_user_x8 (x, ptr, __ret_pu) \ - asm volatile("call __put_user_8" : "=a" (__ret_pu) \ + asm volatile(_ASM_CALL(__put_user_8) : "=a" (__ret_pu) \ : "A" ((typeof(*(ptr)))(x)), "c" (ptr) : "ebx")#else #define __put_user_asm_u64 (x, ptr, retval, errret) \
arch/x86/include/asm/xen/hypercall.h +23 -8
@@ -88,9 +88,24 @@ struct xen_dm_op_buf;extern struct {char _entry[32 ]; } hypercall_page[]; -#define __HYPERCALL "call hypercall_page+%c[offset]" -#define __HYPERCALL_ENTRY (x) \ +#if defined(MODULE ) && defined(CONFIG_X86_PIC ) +# ifdef CONFIG_RETPOLINE +# define HYPERCALL (x) long xen_hypercall_##x(void); +# include <asm/xen-hypercalls.h> +# undef HYPERCALL +# include <asm/nospec-branch.h> +# define __HYPERCALL (x) CALL_NOSPEC +# define __HYPERCALL_ENTRY (x) \ + [thunk_target] "a" (xen_hypercall_##x) +# else +# define __HYPERCALL (x) "call *xen_hypercall_" #x "@GOTPCREL(%%rip)" +# define __HYPERCALL_ENTRY (x) +# endif +#else +# define __HYPERCALL (x) "call hypercall_page+%c[offset]" +# define __HYPERCALL_ENTRY (x) \ [offset] "i" (__HYPERVISOR_##x * sizeof(hypercall_page[0])) +#endif #ifdef CONFIG_X86_32 #define __HYPERCALL_RETREG "eax"
@@ -146,7 +161,7 @@ extern struct { char _entry[32]; } hyper ({ \ __HYPERCALL_DECLS; \ __HYPERCALL_0ARG(); \ - asm volatile (__HYPERCALL \ + asm volatile (__HYPERCALL(name) \ : __HYPERCALL_0PARAM \ : __HYPERCALL_ENTRY(name) \ : __HYPERCALL_CLOBBER0); \
@@ -157,7 +172,7 @@ extern struct { char _entry[32]; } hyper ({ \ __HYPERCALL_DECLS; \ __HYPERCALL_1ARG(a1); \ - asm volatile (__HYPERCALL \ + asm volatile (__HYPERCALL(name) \ : __HYPERCALL_1PARAM \ : __HYPERCALL_ENTRY(name) \ : __HYPERCALL_CLOBBER1); \
@@ -168,7 +183,7 @@ extern struct { char _entry[32]; } hyper ({ \ __HYPERCALL_DECLS; \ __HYPERCALL_2ARG(a1, a2); \ - asm volatile (__HYPERCALL \ + asm volatile (__HYPERCALL(name) \ : __HYPERCALL_2PARAM \ : __HYPERCALL_ENTRY(name) \ : __HYPERCALL_CLOBBER2); \
@@ -179,7 +194,7 @@ extern struct { char _entry[32]; } hyper ({ \ __HYPERCALL_DECLS; \ __HYPERCALL_3ARG(a1, a2, a3); \ - asm volatile (__HYPERCALL \ + asm volatile (__HYPERCALL(name) \ : __HYPERCALL_3PARAM \ : __HYPERCALL_ENTRY(name) \ : __HYPERCALL_CLOBBER3); \
@@ -190,7 +205,7 @@ extern struct { char _entry[32]; } hyper ({ \ __HYPERCALL_DECLS; \ __HYPERCALL_4ARG(a1, a2, a3, a4); \ - asm volatile (__HYPERCALL \ + asm volatile (__HYPERCALL(name) \ : __HYPERCALL_4PARAM \ : __HYPERCALL_ENTRY(name) \ : __HYPERCALL_CLOBBER4); \
@@ -201,7 +216,7 @@ extern struct { char _entry[32]; } hyper ({ \ __HYPERCALL_DECLS; \ __HYPERCALL_5ARG(a1, a2, a3, a4, a5); \ - asm volatile (__HYPERCALL \ + asm volatile (__HYPERCALL(name) \ : __HYPERCALL_5PARAM \ : __HYPERCALL_ENTRY(name) \ : __HYPERCALL_CLOBBER5); \
arch/x86/Kconfig +11 -1
@@ -2238,9 +2238,19 @@ config X86_PIE select DYNAMIC_MODULE_BASE select MODULE_REL_CRCS if MODVERSIONS +config X86_PIC + bool + prompt "Enable PIC modules" + depends on X86_64 + default y + select MODULE_REL_CRCS if MODVERSIONS + ---help--- + Compile position-independent modules which can + be placed anywhere in the 64-bit address space. + config RANDOMIZE_BASE_LARGE bool "Increase the randomization range of the kernel image" - depends on X86_64 && RANDOMIZE_BASE + depends on X86_64 && RANDOMIZE_BASE && X86_PIC select X86_PIE select X86_MODULE_PLTS if MODULES default n
arch/x86/kernel/ftrace.c +5 -9
@@ -144,13 +144,6 @@ ftrace_modify_initial_code(unsigned long {unsigned char replaced[MCOUNT_INSN_SIZE +1 ]; -/* -* If PIE is not enabled default to the original approach to code -* modification. -*/ -if (!IS_ENABLED (CONFIG_X86_PIE )) -return ftrace_modify_code_direct (ip, old_code, new_code); - ftrace_expected = old_code;/* Ensure the instructions point to a call to the GOT */
@@ -159,9 +152,12 @@ ftrace_modify_initial_code(unsigned longreturn -EFAULT ; } +/* +* For non-PIC code, default to the original approach to code +* modification. +*/ if (memcmp (replaced, got_call_preinsn,sizeof (got_call_preinsn))) { -WARN_ONCE (1 ,"invalid function call" ); -return -EINVAL ; +return ftrace_modify_code_direct (ip, old_code, new_code); }/*
arch/x86/kernel/module.c +244 -19
376 lines not on this page · raw message
arch/x86/kernel/module.lds +1 -0
@@ -1,3 +1,4 @@ SECTIONS { .got (NOLOAD) : { BYTE(0) } + .plt (NOLOAD) : { BYTE(0) } }
arch/x86/kvm/emulate.c +0 -1
@@ -428,7 +428,6 @@ static int fastop(struct x86_emulate_ctx FOP_RET asm(".pushsection .fixup, \"ax\"\n" -".global kvm_fastop_exception \n" "kvm_fastop_exception: xor %esi, %esi; ret\n" ".popsection");
arch/x86/Makefile +11 -0
@@ -136,6 +136,17 @@ else KBUILD_CFLAGS += $(cflags-y) KBUILD_CFLAGS += -mno-red-zone + +ifdef CONFIG_X86_PIC + KBUILD_CFLAGS_MODULE += -fPIC -mcmodel=small -fno-stack-protector -fvisibility=hidden + ifdef CONFIG_RETPOLINE + MOD_EXTRA_LINK += $(srctree)/arch/$(SRCARCH)/module-lib/retpoline.o + else + KBUILD_CFLAGS_MODULE += -fno-plt + endif +endif + KBUILD_LDFLAGS_MODULE += -T $(srctree)/arch/x86/kernel/module.lds + ifdef CONFIG_X86_PIE KBUILD_CFLAGS += -fPIE KBUILD_LDFLAGS_MODULE += -T $(srctree)/arch/x86/kernel/module.lds
arch/x86/tools/relocs.c +4 -0
@@ -210,6 +210,8 @@ static const char *rel_type(unsigned typREL_TYPE (R_X86_64_JUMP_SLOT ),REL_TYPE (R_X86_64_RELATIVE ),REL_TYPE (R_X86_64_GOTPCREL ), +REL_TYPE (R_X86_64_REX_GOTPCRELX ), +REL_TYPE (R_X86_64_GOTPCRELX ),REL_TYPE (R_X86_64_32 ),REL_TYPE (R_X86_64_32S ), REL_TYPE(R_X86_64_16),
@@ -866,6 +868,8 @@ static int do_reloc64(struct section *se offset += per_cpu_load_addr;switch (r_type) { +case R_X86_64_REX_GOTPCRELX : +case R_X86_64_GOTPCRELX :case R_X86_64_GOTPCREL :case R_X86_64_NONE :/* NONE can be ignored. */
Makefile +1 -1
@@ -1207,10 +1207,10 @@ all: modules # using awk while concatenating to the final file. PHONY += modules -modules: $(vmlinux-dirs) $(if $(KBUILD_BUILTIN),vmlinux) modules.builtin +modules: $(vmlinux-dirs) $(if $(KBUILD_BUILTIN),vmlinux) modules.builtin $(MOD_EXTRA_LINK) $(Q)$(AWK) '!x[$$0]++' $(vmlinux-dirs:%=$(objtree)/%/modules.order) >
$(objtree)/modules.order
@$(kecho) ' Building modules, stage 2.';
- $(Q)$(MAKE) -f $(srctree)/scripts/Makefile.modpost
+ $(Q)$(MAKE) -f $(srctree)/scripts/Makefile.modpost MOD_EXTRA_LINK=$(MOD_EXTRA_LINK)
modules.builtin: $(vmlinux-dirs:%=%/modules.builtin)
$(Q)$(AWK) '!x[$$0]++' $^ > $(objtree)/modules.builtin
scripts/Makefile.modpost +1 -1
@@ -125,7 +125,7 @@ quiet_cmd_ld_ko_o = LD [M] $@ -o $@ $(filter-out FORCE,$^) ; \ $(if $(ARCH_POSTLINK), $(MAKE) -f $(ARCH_POSTLINK) $@, true) -$(modules): %.ko :%.o %.mod.o FORCE +$(modules): %.ko :%.o %.mod.o $(MOD_EXTRA_LINK) FORCE +$(call if_changed,ld_ko_o) targets += $(modules)
scripts/recordmcount.c +2 -1
@@ -453,7 +453,8 @@ static int make_nop_x86(void *map, size_/* Swap the stub and nop for a got call if the binary is built with PIE */ static int is_fake_mcount_x86_x64 (Elf64_Rel const *rp) { -if (ELF64_R_TYPE (rp->r_info) ==R_X86_64_GOTPCREL ) { +if (ELF64_R_TYPE (rp->r_info) ==R_X86_64_GOTPCREL || +ELF64_R_TYPE (rp->r_info) ==R_X86_64_GOTPCRELX ) { ideal_nop = ideal_nop6_x86_64; ideal_nop_x86_size =sizeof (ideal_nop6_x86_64); stub_x86 = stub_got_x86;