On Fri, May 19, 2017 at 12:18 PM, Andy Lutomirski <l...@kernel.org> wrote: > On Fri, May 19, 2017 at 12:16 PM, Kees Cook <keesc...@chromium.org> wrote: >> On Fri, May 19, 2017 at 11:27 AM, Andy Lutomirski <l...@kernel.org> wrote: >>> One thing I've pondered: can we make some debugging mode (kmemleak, >>> perhaps?) check that freed memory is RW at the time it's freed? I >>> once wrote some buggy code that freed an R page and caused an OOPS >>> much later, and this bug here seems likely to be some code that frees >>> RWX memory. >> >> Which begs for even more checks: nothing should ever make a page RWX. >> Either R, RW, or RX only... (or X too I guess, in the future). > > I could see pages being RWX temporarily during boot. OTOH if we ban > RWX outright (after very early boot, anyway), then catching code that > messes up and leaves pages RWX gets much easier.
Right, early boot is kind of special. It'd be nice to have there, but I meant during normal runtime. We'd probably need to adjust set_memory_rw/ro/nx/x around to have the correct side-effects, instead of just controlling specific bits: set_memory_rw() (RW_) set_memory_ro() (R__) set_memory_rx() (R_X) set_memory_x() (__X) That kind of refactoring might be not _too_ bad: - add set_memory_rx() - s/\bset_memory_x\b/set_memory_rx/g - fix what breaks from expecting writable-executable memory - adjust set_memory_rw() to drop x - fix what breaks from expecting writable-executable memory - adjust set_memory_ro() to drop x - fix what breaks from expecting executable memory - add set_memory_x() some day... -Kees -- Kees Cook Pixel Security