From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S969997AbdEYRqI (ORCPT ); Thu, 25 May 2017 13:46:08 -0400 Received: from mx2.suse.de ([195.135.220.15]:47663 "EHLO mx1.suse.de" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1760162AbdEYRqG (ORCPT ); Thu, 25 May 2017 13:46:06 -0400 Date: Thu, 25 May 2017 19:46:04 +0200 From: "Luis R. Rodriguez" To: Thomas Gleixner Cc: Steven Rostedt , Kees Cook , LKML , x86@kernel.org, Masami Hiramatsu , "Luis R. Rodriguez" , Peter Zijlstra Subject: Re: [PATCH V2] x86/ftrace: Make sure that ftrace trampolines are not RWX Message-ID: <20170525174604.GY8951@wotan.suse.de> References: <20170524134728.61a896c9@vmware.local.home> <20170524182547.5c085dc7@vmware.local.home> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.6.0 (2016-04-01) Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, May 25, 2017 at 10:57:51AM +0200, Thomas Gleixner wrote: > ftrace use module_alloc() to allocate trampoline pages. The mapping of > module_alloc() is RWX, which makes sense as the memory is written to right > after allocation. But nothing makes these pages RO after writing to them. > > Add proper set_memory_rw/ro() calls to protect the trampolines after > modification. > > Signed-off-by: Thomas Gleixner > --- > arch/x86/kernel/ftrace.c | 20 ++++++++++++++------ > 1 file changed, 14 insertions(+), 6 deletions(-) > > --- a/arch/x86/kernel/ftrace.c > +++ b/arch/x86/kernel/ftrace.c > @@ -689,8 +689,12 @@ static inline void *alloc_tramp(unsigned > { > return module_alloc(size); > } > -static inline void tramp_free(void *tramp) > +static inline void tramp_free(void *tramp, int size) > { > + int npages = PAGE_ALIGN(size) >> PAGE_SHIFT; > + > + set_memory_nx((unsigned long)tramp, npages); > + set_memory_rw((unsigned long)tramp, npages); > module_memfree(tramp); > } Can/should module_memfree() just do this for users? With Masami's fix that'd be 2 users already. Luis