linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v2 0/1] Add ro_after_init support for modules
@ 2016-07-25  9:25 Jessica Yu
  2016-07-25  9:25 ` [PATCH v2 1/1] modules: add ro_after_init support Jessica Yu
  0 siblings, 1 reply; 9+ messages in thread
From: Jessica Yu @ 2016-07-25  9:25 UTC (permalink / raw)
  To: Rusty Russell, Kees Cook
  Cc: linux-api, linux-kernel, live-patching, Jessica Yu

Hi,

This patch adds ro_after_init support for modules by adding an additional
page-aligned section in the module layout. This new ro_after_init section
sits between rodata and writable data.

So, the new module layout looks like:
   [text] [rodata] [ro_after_init] [writable data]

RO after init data remains RW during init and RO protection is enabled
separately after module init runs.

Did some light testing with lkdtm compiled as a module, verified that
ro_after_init data is writable during init, and that it oopsed after attempted
writes after init. Also tested livepatch (which uses module_{enable,disable}_ro
for its own purposes) to make sure nothing broke. More testing is appreciated :-)

Some remarks on the implementation:
 * A new SHF_RO_AFTER_INIT flag is introduced in elf.h to make
   identification of .data..ro_after_init sections and the work of
   layout_sections() easier. Its chosen value is within the SHF_MASKOS
   range.
 * If a module doesn't have a ro_after_init section, then
   core_layout.ro_after_init_size just takes the value of
   core_layout.ro_size, and frob_ro_after_init() should do nothing.

Based on linux-next.

v1 here:
http://lkml.kernel.org/g/1465863198-15947-1-git-send-email-jeyu@redhat.com

v2:
 - Add a bool after_init parameter to module_enable_ro(), it's much clearer
   than checking module->state.
 - Since the function signature for module_enable_ro() has changed, livepatch
   needs to slightly adjust its call to module_enable_ro()

Jessica Yu (1):
  modules: add ro_after_init support

 include/linux/module.h   |  6 +++--
 include/uapi/linux/elf.h |  1 +
 kernel/livepatch/core.c  |  2 +-
 kernel/module.c          | 66 +++++++++++++++++++++++++++++++++++++++---------
 4 files changed, 60 insertions(+), 15 deletions(-)

-- 
2.5.5

^ permalink raw reply	[flat|nested] 9+ messages in thread
* [PATCH 0/1] Add ro_after_init support for modules
@ 2016-06-14  0:13 Jessica Yu
  2016-06-14  0:13 ` [PATCH 1/1] modules: add ro_after_init support Jessica Yu
  0 siblings, 1 reply; 9+ messages in thread
From: Jessica Yu @ 2016-06-14  0:13 UTC (permalink / raw)
  To: Rusty Russell, Kees Cook; +Cc: linux-api, linux-kernel, Jessica Yu

Hi,

This patch adds ro_after_init support for modules by adding an additional
page-aligned section in the module layout. This new ro_after_init section
sits between rodata and writable data.

So, the new module layout looks like:
   [text] [rodata] [ro_after_init] [writable data]

RO after init data remains RW during init and RO protection is enabled
separately after module init runs.

Did some light testing with lkdtm compiled as a module, verified that
ro_after_init data is writable during init, and that it oopsed after attempted
writes after init. Also tested livepatch (which uses module_{enable,disable}_ro
for its own purposes) to make sure nothing broke. More testing is appreciated :-)

Some remarks on the implementation:
 * A new SHF_RO_AFTER_INIT flag is introduced in elf.h to make
   identification of .data..ro_after_init sections and the work of
   layout_sections() easier. Its chosen value is within the SHF_MASKOS
   range. If people don't like adding a new SHF flag to elf.h, I could
   just make the flag internal to module.c.

 * frob_ro_after_init() could have been separated from
   module_enable_ro() (i.e., put it in its own function, something
   like module_enable_ro_after_init()), but given that livepatch also
   uses module_enable_ro(), I did not want to make livepatch worry
   about calling yet another function just to re-enable all RO protections
   for a module.

 * If a module doesn't have a ro_after_init section, then
   core_layout.ro_after_init_size just takes the value of
   core_layout.ro_size, and frob_ro_after_init() should do nothing.

Based on linux-next.

Previous discussion here:
http://comments.gmane.org/gmane.linux.kernel/2234606

Jessica Yu (1):
  modules: add ro_after_init support

 include/linux/module.h   |  2 ++
 include/uapi/linux/elf.h |  1 +
 kernel/module.c          | 73 +++++++++++++++++++++++++++++++++++++++++-------
 3 files changed, 66 insertions(+), 10 deletions(-)

-- 
2.4.3

^ permalink raw reply	[flat|nested] 9+ messages in thread

end of thread, other threads:[~2016-07-25 18:04 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-07-25  9:25 [PATCH v2 0/1] Add ro_after_init support for modules Jessica Yu
2016-07-25  9:25 ` [PATCH v2 1/1] modules: add ro_after_init support Jessica Yu
2016-07-25 10:01   ` Jessica Yu
2016-07-25 18:04   ` [PATCH v2 1/1] " Kees Cook
  -- strict thread matches above, loose matches on Subject: below --
2016-06-14  0:13 [PATCH 0/1] Add ro_after_init support for modules Jessica Yu
2016-06-14  0:13 ` [PATCH 1/1] modules: add ro_after_init support Jessica Yu
2016-06-14 21:33   ` Kees Cook
2016-06-14 23:53     ` Jessica Yu
2016-06-29  1:08   ` [PATCH 1/1] " Rusty Russell
2016-06-29 21:27     ` Jessica Yu
2016-06-30  4:56       ` Rusty Russell
2016-07-21 23:03         ` Kees Cook
2016-07-21 23:11           ` Jessica Yu

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).