aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRick Edgecombe <rick.p.edgecombe@intel.com>2019-04-25 20:11:39 -0400
committerIngo Molnar <mingo@kernel.org>2019-04-30 06:38:00 -0400
commit7fdfe1e40b225b1d163f9afed2fa3f04442dbaad (patch)
tree0940db41a9bbf4b372cc124bdbda48f06965bfcc
parentd53d2f78ceadba081fc7785570798c3c8d50a718 (diff)
x86/ftrace: Use vmalloc special flag
Use new flag VM_FLUSH_RESET_PERMS for handling freeing of special permissioned memory in vmalloc and remove places where memory was set NX and RW before freeing which is no longer needed. Tested-by: Steven Rostedt (VMware) <rostedt@goodmis.org> Signed-off-by: Rick Edgecombe <rick.p.edgecombe@intel.com> Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org> Acked-by: Steven Rostedt (VMware) <rostedt@goodmis.org> Cc: <akpm@linux-foundation.org> Cc: <ard.biesheuvel@linaro.org> Cc: <deneen.t.dock@intel.com> Cc: <kernel-hardening@lists.openwall.com> Cc: <kristen@linux.intel.com> Cc: <linux_dti@icloud.com> Cc: <will.deacon@arm.com> Cc: Andy Lutomirski <luto@kernel.org> Cc: Borislav Petkov <bp@alien8.de> Cc: Dave Hansen <dave.hansen@linux.intel.com> Cc: H. Peter Anvin <hpa@zytor.com> Cc: Linus Torvalds <torvalds@linux-foundation.org> Cc: Nadav Amit <nadav.amit@gmail.com> Cc: Rik van Riel <riel@surriel.com> Cc: Thomas Gleixner <tglx@linutronix.de> Link: https://lkml.kernel.org/r/20190426001143.4983-20-namit@vmware.com Signed-off-by: Ingo Molnar <mingo@kernel.org>
-rw-r--r--arch/x86/kernel/ftrace.c14
1 files changed, 6 insertions, 8 deletions
diff --git a/arch/x86/kernel/ftrace.c b/arch/x86/kernel/ftrace.c
index 53ba1aa3a01f..0caf8122d680 100644
--- a/arch/x86/kernel/ftrace.c
+++ b/arch/x86/kernel/ftrace.c
@@ -678,12 +678,8 @@ static inline void *alloc_tramp(unsigned long size)
678{ 678{
679 return module_alloc(size); 679 return module_alloc(size);
680} 680}
681static inline void tramp_free(void *tramp, int size) 681static inline void tramp_free(void *tramp)
682{ 682{
683 int npages = PAGE_ALIGN(size) >> PAGE_SHIFT;
684
685 set_memory_nx((unsigned long)tramp, npages);
686 set_memory_rw((unsigned long)tramp, npages);
687 module_memfree(tramp); 683 module_memfree(tramp);
688} 684}
689#else 685#else
@@ -692,7 +688,7 @@ static inline void *alloc_tramp(unsigned long size)
692{ 688{
693 return NULL; 689 return NULL;
694} 690}
695static inline void tramp_free(void *tramp, int size) { } 691static inline void tramp_free(void *tramp) { }
696#endif 692#endif
697 693
698/* Defined as markers to the end of the ftrace default trampolines */ 694/* Defined as markers to the end of the ftrace default trampolines */
@@ -808,6 +804,8 @@ create_trampoline(struct ftrace_ops *ops, unsigned int *tramp_size)
808 /* ALLOC_TRAMP flags lets us know we created it */ 804 /* ALLOC_TRAMP flags lets us know we created it */
809 ops->flags |= FTRACE_OPS_FL_ALLOC_TRAMP; 805 ops->flags |= FTRACE_OPS_FL_ALLOC_TRAMP;
810 806
807 set_vm_flush_reset_perms(trampoline);
808
811 /* 809 /*
812 * Module allocation needs to be completed by making the page 810 * Module allocation needs to be completed by making the page
813 * executable. The page is still writable, which is a security hazard, 811 * executable. The page is still writable, which is a security hazard,
@@ -816,7 +814,7 @@ create_trampoline(struct ftrace_ops *ops, unsigned int *tramp_size)
816 set_memory_x((unsigned long)trampoline, npages); 814 set_memory_x((unsigned long)trampoline, npages);
817 return (unsigned long)trampoline; 815 return (unsigned long)trampoline;
818fail: 816fail:
819 tramp_free(trampoline, *tramp_size); 817 tramp_free(trampoline);
820 return 0; 818 return 0;
821} 819}
822 820
@@ -947,7 +945,7 @@ void arch_ftrace_trampoline_free(struct ftrace_ops *ops)
947 if (!ops || !(ops->flags & FTRACE_OPS_FL_ALLOC_TRAMP)) 945 if (!ops || !(ops->flags & FTRACE_OPS_FL_ALLOC_TRAMP))
948 return; 946 return;
949 947
950 tramp_free((void *)ops->trampoline, ops->trampoline_size); 948 tramp_free((void *)ops->trampoline);
951 ops->trampoline = 0; 949 ops->trampoline = 0;
952} 950}
953 951