From patchwork Tue Apr 30 11:28:13 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: tip-bot for Kobe Wu X-Patchwork-Id: 10923329 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id C9CA892A for ; Tue, 30 Apr 2019 11:32:56 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id B58DF28AAC for ; Tue, 30 Apr 2019 11:32:56 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id A6B9F28AB0; Tue, 30 Apr 2019 11:32:56 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-5.0 required=2.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED autolearn=ham version=3.3.1 Received: from mother.openwall.net (mother.openwall.net [195.42.179.200]) by mail.wl.linuxfoundation.org (Postfix) with SMTP id CDCFA28AAC for ; Tue, 30 Apr 2019 11:32:54 +0000 (UTC) Received: (qmail 27708 invoked by uid 550); 30 Apr 2019 11:31:03 -0000 Mailing-List: contact kernel-hardening-help@lists.openwall.com; run by ezmlm Precedence: bulk List-Post: List-Help: List-Unsubscribe: List-Subscribe: List-ID: Delivered-To: mailing list kernel-hardening@lists.openwall.com Delivered-To: moderator for kernel-hardening@lists.openwall.com Received: (qmail 12222 invoked from network); 30 Apr 2019 11:29:03 -0000 DKIM-Filter: OpenDKIM Filter v2.11.0 terminus.zytor.com x3UBSFGg1350429 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=zytor.com; s=2019041745; t=1556623696; bh=oDZ5KraJL4KgMsljNN1FiEACozdkKt3NmYXo5R8ae7E=; h=Date:From:Cc:Reply-To:In-Reply-To:References:To:Subject:From; b=CffJBua1JSJ8mVi7LKwDnpfEYh6QNMhQfKneGTrlzQp0Rb9IlvNqQf5fJFiYNS8q9 lW1HIUAy5Rk+hiodiNjbzRdgfcT18dZbbgkZCuXCGZqdTMRoaPVz+U+osBbXtq+kvC grpd1WKaEk1Fc810E/b0zbvF4/b877LJt5BACwlkN7q3979fQ6ykeDzR9wWN9GbTZo THfnHkXbH9dazeu+EJsDNwmijsn46P9tPbSnmfAkMt/CtS00otuNy2pYH3/RJJHTC6 kS0Ed70289R+tyjj6vUe7T6vACuNiUfi9rJ8eJByxhy83kZB5ZnXpMccVvg3u5WM4/ qihrHt3rt9rdA== Date: Tue, 30 Apr 2019 04:28:13 -0700 X-Authentication-Warning: terminus.zytor.com: tipbot set sender to tipbot@zytor.com using -f Sender: tip tree robot From: tip-bot for Rick Edgecombe Message-ID: Cc: hpa@zytor.com, bp@alien8.de, torvalds@linux-foundation.org, tglx@linutronix.de, mingo@kernel.org, akpm@linux-foundation.org, nadav.amit@gmail.com, will.deacon@arm.com, peterz@infradead.org, rostedt@goodmis.org, linux_dti@icloud.com, dave.hansen@linux.intel.com, linux-kernel@vger.kernel.org, rick.p.edgecombe@intel.com, ard.biesheuvel@linaro.org, kernel-hardening@lists.openwall.com, kristen@linux.intel.com, riel@surriel.com, deneen.t.dock@intel.com, luto@kernel.org In-Reply-To: <20190426001143.4983-20-namit@vmware.com> References: <20190426001143.4983-20-namit@vmware.com> To: linux-tip-commits@vger.kernel.org Subject: [tip:x86/mm] x86/ftrace: Use vmalloc special flag Git-Commit-ID: 7fdfe1e40b225b1d163f9afed2fa3f04442dbaad X-Mailer: tip-git-log-daemon Robot-ID: Robot-Unsubscribe: Contact to get blacklisted from these emails MIME-Version: 1.0 Content-Disposition: inline X-Virus-Scanned: ClamAV using ClamSMTP Commit-ID: 7fdfe1e40b225b1d163f9afed2fa3f04442dbaad Gitweb: https://git.kernel.org/tip/7fdfe1e40b225b1d163f9afed2fa3f04442dbaad Author: Rick Edgecombe AuthorDate: Thu, 25 Apr 2019 17:11:39 -0700 Committer: Ingo Molnar CommitDate: Tue, 30 Apr 2019 12:38:00 +0200 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) Signed-off-by: Rick Edgecombe Signed-off-by: Peter Zijlstra (Intel) Acked-by: Steven Rostedt (VMware) Cc: Cc: Cc: Cc: Cc: Cc: Cc: Cc: Andy Lutomirski Cc: Borislav Petkov Cc: Dave Hansen Cc: H. Peter Anvin Cc: Linus Torvalds Cc: Nadav Amit Cc: Rik van Riel Cc: Thomas Gleixner Link: https://lkml.kernel.org/r/20190426001143.4983-20-namit@vmware.com Signed-off-by: Ingo Molnar --- arch/x86/kernel/ftrace.c | 14 ++++++-------- 1 file 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) { 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); } #else @@ -692,7 +688,7 @@ static inline void *alloc_tramp(unsigned long size) { return NULL; } -static inline void tramp_free(void *tramp, int size) { } +static inline void tramp_free(void *tramp) { } #endif /* 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) /* ALLOC_TRAMP flags lets us know we created it */ ops->flags |= FTRACE_OPS_FL_ALLOC_TRAMP; + set_vm_flush_reset_perms(trampoline); + /* * Module allocation needs to be completed by making the page * 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) set_memory_x((unsigned long)trampoline, npages); return (unsigned long)trampoline; fail: - tramp_free(trampoline, *tramp_size); + tramp_free(trampoline); return 0; } @@ -947,7 +945,7 @@ void arch_ftrace_trampoline_free(struct ftrace_ops *ops) if (!ops || !(ops->flags & FTRACE_OPS_FL_ALLOC_TRAMP)) return; - tramp_free((void *)ops->trampoline, ops->trampoline_size); + tramp_free((void *)ops->trampoline); ops->trampoline = 0; }