[PATCH 3/3 V13] RO/NX protection for loadable kernel

Previous message: [thread] [date] [author]
Next message: [thread] [date] [author]
From: matthieu castet
Date: Tuesday, November 16, 2010 - 2:35 pm

This patch is a logical extension of the protection provided by
CONFIG_DEBUG_RODATA to LKMs. The protection is provided by splitting
module_core and module_init into three logical parts each and setting
appropriate page access permissions for each individual section:

 1. Code: RO+X
 2. RO data: RO+NX
 3. RW data: RW+NX

In order to achieve proper protection, layout_sections() have been
modified to align each of the three parts mentioned above onto page
boundary. Next, the corresponding page access permissions are set
right before successful exit from load_module(). Further, free_module()
and sys_init_module have been modified to set module_core and
module_init as RW+NX right before calling module_free().

By default, the original section layout and access flags are preserved.
When compiled with CONFIG_DEBUG_SET_MODULE_RONX=y, the patch
will page-align each group of sections to ensure that each page contains
only one type of content and will enforce RO/NX for each group of pages.

V1: Initial proof-of-concept patch.
V2: The patch have been re-written to reduce the number of #ifdefs and
to make it architecture-agnostic. Code formatting have been corrected also.
V3: Opportunistic RO/NX protectiuon is now unconditional. Section
page-alignment is enabled when CONFIG_DEBUG_RODATA=y.
V4: Removed most macros and improved coding style.
V5: Changed page-alignment and RO/NX section size calculation
V6: Fixed comments. Restricted RO/NX enforcement to x86 only
V7: Introduced CONFIG_DEBUG_SET_MODULE_RONX, added calls to
set_all_modules_text_rw() and set_all_modules_text_ro() in ftrace
V8: updated for compatibility with linux 2.6.33-rc5
V9: coding style fixes
V10: more coding style fixes
V11: minor adjutments for -tip
V12: minor adjutments for v2.6.35-rc2-tip
V13: minor adjutments for v2.6.37-rc1-tip

Signed-off-by: Siarhei Liakh <sliakh.lkml@gmail.com>
Signed-off-by: Xuxian Jiang <jiang@cs.ncsu.edu>
Acked-by: Arjan van de Ven <arjan@linux.intel.com>
Reviewed-by: James Morris <jmorris@namei.org>
Signed-off-by: H. Peter Anvin <hpa@zytor.com>
Previous message: [thread] [date] [author]
Next message: [thread] [date] [author]

Messages in current thread:
[PATCH 3/3 V13] RO/NX protection for loadable kernel, matthieu castet, (Tue Nov 16, 2:35 pm)
[tip:x86/security] x86: Add RO/NX protection for loadable ..., tip-bot for matthieu ..., (Thu Nov 18, 7:13 am)
Re: [PATCH 3/3 V13] RO/NX protection for loadable kernel, Valdis.Kletnieks, (Wed Nov 24, 8:41 pm)
Re: [PATCH 3/3 V13] RO/NX protection for loadable kernel, Valdis.Kletnieks, (Mon Nov 29, 9:59 am)
Re: [PATCH 3/3 V13] RO/NX protection for loadable kernel, Steven Rostedt, (Mon Nov 29, 11:15 am)
Re: [PATCH 3/3 V13] RO/NX protection for loadable kernel, Rusty Russell, (Mon Nov 29, 4:35 pm)
Re: [PATCH 3/3 V13] RO/NX protection for loadable kernel, Steven Rostedt, (Tue Nov 30, 7:46 am)
Re: [PATCH 3/3 V13] RO/NX protection for loadable kernel, Steven Rostedt, (Tue Nov 30, 5:38 pm)
Re: [PATCH 3/3 V13] RO/NX protection for loadable kernel, Valdis.Kletnieks, (Wed Dec 22, 2:35 pm)
Re: [PATCH 3/3 V13] RO/NX protection for loadable kernel, Steven Rostedt, (Wed Dec 22, 3:02 pm)
Re: [PATCH 3/3 V13] RO/NX protection for loadable kernel, Steven Rostedt, (Thu Dec 23, 8:01 am)
Re: [PATCH 3/3 V13] RO/NX protection for loadable kernel, Valdis.Kletnieks, (Thu Dec 23, 6:43 pm)