Received: by 2002:a25:4158:0:0:0:0:0 with SMTP id o85csp2308065yba; Thu, 25 Apr 2019 14:13:56 -0700 (PDT) X-Google-Smtp-Source: APXvYqw8lduckJjCvt4rylkjFIyrKLz3sJvfgwubOAJ6ez9hP59tqoLlmCooDAtHpSnkWZ2SX1Py X-Received: by 2002:a63:ef4c:: with SMTP id c12mr40254307pgk.43.1556226836304; Thu, 25 Apr 2019 14:13:56 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1556226836; cv=none; d=google.com; s=arc-20160816; b=nwxhw+3M3r6kRpJIw9XL201I92BAKGaov0ajLWGpd9CGud7pl86UCi9+J/7+xh4zYh rF49AUP0rjIdoksfGLPIDfphpV2SsIcgQttvWYGwzeF/IXJ3dTmVgjHbRx1eEDdBVt1q YpOq4w2Q3zyqQoE3nGx9RnBWbtLfTPyLCtSRP2iJc3haCo14pKSIsgbLSH0WqY6ZY38e HREPjSkkVwnf9X3NUHPxVjBmotgtU5J7IR6AFw+t6J2xTaeDUUMNtrYPRQ2KjLi4Ekd0 gyiA7w+fdppUEM1E0ZDluE7zg+dSdmBb3oAJfoPj/pfo9mjcEQS5xBowl8kU86OSExXF /6Ow== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:subject:cc:to:from:date; bh=XxG05rJDa5fG85rmeev2w2HQKqVZaPXeBK/QpvFWlRw=; b=BbAcNAZq+dVXWMvUUAH9V6fLiXC9kP7ToF3stH8Mg1t3FMVYPnkk4Y9ix/ymJ3Z5ov LW+thHTwDJdFcXsSz+Rb964evyBVMT5J6kM9BamI6uTsS1Gfm0o1nCCB2qnnUDa8InES rAg+mJpHCTLhzxm3mtfTNv10/I2c7EFAT7onDHxbP6jEwS6XmkLt4KzNnGI32opaiR9A V9oezYcmK4QpEKppKP6wMhMNbgxyR0JdNove6tebqXxpZzK5Fx9SkU5bMqv49QLFPz7v QZVfVg7b+G6n+QvJrV/FrniNWffNb7FefwatkbuM0+xkysbsLZa6Xr9XerIlkAEtoV7p mMoQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id g11si22929924plp.278.2019.04.25.14.13.41; Thu, 25 Apr 2019 14:13:56 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728130AbfDYS2I (ORCPT + 99 others); Thu, 25 Apr 2019 14:28:08 -0400 Received: from mail.kernel.org ([198.145.29.99]:39950 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726040AbfDYS2I (ORCPT ); Thu, 25 Apr 2019 14:28:08 -0400 Received: from gandalf.local.home (cpe-66-24-58-225.stny.res.rr.com [66.24.58.225]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id CAC8E2067C; Thu, 25 Apr 2019 18:28:05 +0000 (UTC) Date: Thu, 25 Apr 2019 14:28:03 -0400 From: Steven Rostedt To: Rick Edgecombe Cc: Borislav Petkov , Andy Lutomirski , Ingo Molnar , linux-kernel@vger.kernel.org, x86@kernel.org, hpa@zytor.com, Thomas Gleixner , Nadav Amit , Dave Hansen , Peter Zijlstra , linux_dti@icloud.com, linux-integrity@vger.kernel.org, linux-security-module@vger.kernel.org, akpm@linux-foundation.org, kernel-hardening@lists.openwall.com, linux-mm@kvack.org, will.deacon@arm.com, ard.biesheuvel@linaro.org, kristen@linux.intel.com, deneen.t.dock@intel.com Subject: Re: [PATCH v4 19/23] x86/ftrace: Use vmalloc special flag Message-ID: <20190425142803.4f2e354a@gandalf.local.home> In-Reply-To: <20190422185805.1169-20-rick.p.edgecombe@intel.com> References: <20190422185805.1169-1-rick.p.edgecombe@intel.com> <20190422185805.1169-20-rick.p.edgecombe@intel.com> X-Mailer: Claws Mail 3.17.3 (GTK+ 2.24.32; x86_64-pc-linux-gnu) MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Mon, 22 Apr 2019 11:58:01 -0700 Rick Edgecombe wrote: > 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. > > Cc: Steven Rostedt > Acked-by: Steven Rostedt (VMware) > Signed-off-by: Rick Edgecombe Tested-by: Steven Rostedt (VMware) Acked-by: Steven Rostedt (VMware) -- Steve > --- > 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; > } >