Commit 7fdfe1e4 authored by Rick Edgecombe's avatar Rick Edgecombe Committed by Ingo Molnar

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: default avatarSteven Rostedt (VMware) <rostedt@goodmis.org>
Signed-off-by: default avatarRick Edgecombe <rick.p.edgecombe@intel.com>
Signed-off-by: default avatarPeter Zijlstra (Intel) <peterz@infradead.org>
Acked-by: default avatarSteven 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.comSigned-off-by: default avatarIngo Molnar <mingo@kernel.org>
parent d53d2f78
...@@ -678,12 +678,8 @@ static inline void *alloc_tramp(unsigned long size) ...@@ -678,12 +678,8 @@ static inline void *alloc_tramp(unsigned long size)
{ {
return module_alloc(size); return module_alloc(size);
} }
static inline void tramp_free(void *tramp, int size) static inline void tramp_free(void *tramp)
{ {
int npages = PAGE_ALIGN(size) >> PAGE_SHIFT;
set_memory_nx((unsigned long)tramp, npages);
set_memory_rw((unsigned long)tramp, npages);
module_memfree(tramp); module_memfree(tramp);
} }
#else #else
...@@ -692,7 +688,7 @@ static inline void *alloc_tramp(unsigned long size) ...@@ -692,7 +688,7 @@ static inline void *alloc_tramp(unsigned long size)
{ {
return NULL; return NULL;
} }
static inline void tramp_free(void *tramp, int size) { } static inline void tramp_free(void *tramp) { }
#endif #endif
/* Defined as markers to the end of the ftrace default trampolines */ /* 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,6 +804,8 @@ create_trampoline(struct ftrace_ops *ops, unsigned int *tramp_size)
/* ALLOC_TRAMP flags lets us know we created it */ /* ALLOC_TRAMP flags lets us know we created it */
ops->flags |= FTRACE_OPS_FL_ALLOC_TRAMP; ops->flags |= FTRACE_OPS_FL_ALLOC_TRAMP;
set_vm_flush_reset_perms(trampoline);
/* /*
* Module allocation needs to be completed by making the page * Module allocation needs to be completed by making the page
* executable. The page is still writable, which is a security hazard, * 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,7 +814,7 @@ create_trampoline(struct ftrace_ops *ops, unsigned int *tramp_size)
set_memory_x((unsigned long)trampoline, npages); set_memory_x((unsigned long)trampoline, npages);
return (unsigned long)trampoline; return (unsigned long)trampoline;
fail: fail:
tramp_free(trampoline, *tramp_size); tramp_free(trampoline);
return 0; return 0;
} }
...@@ -947,7 +945,7 @@ void arch_ftrace_trampoline_free(struct ftrace_ops *ops) ...@@ -947,7 +945,7 @@ void arch_ftrace_trampoline_free(struct ftrace_ops *ops)
if (!ops || !(ops->flags & FTRACE_OPS_FL_ALLOC_TRAMP)) if (!ops || !(ops->flags & FTRACE_OPS_FL_ALLOC_TRAMP))
return; return;
tramp_free((void *)ops->trampoline, ops->trampoline_size); tramp_free((void *)ops->trampoline);
ops->trampoline = 0; ops->trampoline = 0;
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment