Re: [PATCH] x86/ftrace: Make sure that ftrace trampolines are not RWX

From: Thomas Gleixner
Date: Thu May 25 2017 - 02:25:53 EST


On Wed, 24 May 2017, Steven Rostedt wrote:
> The trampolines uses the module allocation, and it appears, that needs
> to become rw before freeing again.

Indeed. I realized that when enabling more debug options, which led to a
reliable triple fault.

How intuitive.

> I applied this patch, and it appears to fix the bug for me.

It fixes the bug, but ...

> -static inline void tramp_free(void *tramp)
> +static inline void tramp_free(void *tramp, int size)
> {
> + int npages;
> +
> + npages = PAGE_ALIGN(size) >> PAGE_SHIFT;

For correctness sake this wants

set_memory_nx(...);

as well.

> + set_memory_rw((unsigned long)tramp, npages);
> module_memfree(tramp);
> }

I'll clean that up and post a V2.

Thanks,

tglx