> On Nov 27, 2018, at 4:07 PM, Rick Edgecombe <rick.p.edgecombe@xxxxxxxxx> wrote: > > Since vfree will lazily flush the TLB, but not lazily free the underlying pages, > it often leaves stale TLB entries to freed pages that could get re-used. This is > undesirable for cases where the memory being freed has special permissions such > as executable. So I am trying to finish my patch-set for preventing transient W+X mappings from taking space, by handling kprobes & ftrace that I missed (thanks again for pointing it out). But all of the sudden, I don’t understand why we have the problem that this (your) patch-set deals with at all. We already change the mappings to make the memory writable before freeing the memory, so why can’t we make it non-executable at the same time? Actually, why do we make the module memory, including its data executable before freeing it??? In other words: disable_ro_nx() is called by free_module() before freeing the memory. Wouldn’t inverting the logic makes much more sense? I am confused. -- >8 -- From: Nadav Amit <namit@xxxxxxxxxx> Subject: [PATCH] modules: disable_ro_nx() should enable nx --- kernel/module.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/kernel/module.c b/kernel/module.c index 7cb207249437..e12d760ea3b0 100644 --- a/kernel/module.c +++ b/kernel/module.c @@ -2029,14 +2029,13 @@ void set_all_modules_text_ro(void) static void disable_ro_nx(const struct module_layout *layout) { + frob_text(layout, set_memory_nx); + if (rodata_enabled) { frob_text(layout, set_memory_rw); frob_rodata(layout, set_memory_rw); frob_ro_after_init(layout, set_memory_rw); } - frob_rodata(layout, set_memory_x); - frob_ro_after_init(layout, set_memory_x); - frob_writable_data(layout, set_memory_x); } #else -- 2.17.1