Skip to contentSkip to conversation

LSM: Explict LSM ordering

PATCH Superseded Kees Cook 4 participants 45 messages Sep 20, 2018 – Sep 21, 2018

Subsystems (20)

v2 of 5 Superseded Latest is v5 →

lore
Share & tools
lore

Kees Cook

author
#0 lore raw

v2 cover LSM: Explict LSM ordering

v2:
- add "lsm.order=" and CONFIG_LSM_ORDER instead of overloading "security="
- reorganize introduction of ordering logic code

Updated cover letter:

This refactors the LSM registration and initialization infrastructure to more centrally support different LSM types. What was considered a "major" LSM is kept for legacy use of the "security=" boot parameter, and now overlaps with the new class of "exclusive" LSMs for the future blob sharing (to be added later). The "minor" LSMs become more well defined as a result of the refactoring.

Instead of continuing to (somewhat improperly) overload the kernel's initcall system, this changes the LSM infrastructure to store a registration structure (struct lsm_info) table instead, where metadata about each LSM can be recorded (name, flags, order, enable flag, init function). This can be extended in the future to include things like required blob size for the coming "blob sharing" LSMs.

The "major" LSMs had to individually negotiate which of them should be enabled. This didn't provide a way to negotiate combinations of other LSMs (as will be needed for "blob sharing" LSMs). This is solved by providing the LSM infrastructure with all the details needed to make the choice (exposing the per-LSM "enabled" flag, if used, the LSM characteristics, and ordering expectations).

As a result of the refactoring, the "minor" LSMs are able to remove the open-coded security_add_hooks() calls for "capability", "yama", and "loadpin", and to redefine "integrity" properly as a general LSM. (Note that "integrity" actually defined _no_ hooks, but needs the early initialization).

With all LSMs being proessed centrally, it was possible to implement a new boot parameter "lsm.order=" to provide explicit ordering, which is helpful for the future "blob sharing" LSMs. Matching this is the new CONFIG_LSM_ORDER, which replaces CONFIG_DEFAULT_SECURITY, as it provides a higher granularity of control.

To better show LSMs activation some debug reporting was added (enabled with the "lsm.debug" boot commandline option).

Finally, I added a WARN() around LSM initialization failures, which appear to have always been silently ignored. (Realistically any LSM init failures would have only been due to catastrophic kernel issues that would render a system unworkable anyway, but it'd be better to expose the problem as early as possible.)

-Kees

Kees Cook (26):
LSM: Correctly announce start of LSM initialization vmlinux.lds.h: Avoid copy/paste of security_init section
LSM: Rename .security_initcall section to .lsm_info
LSM: Remove initcall tracing
LSM: Convert from initcall to struct lsm_info vmlinux.lds.h: Move LSM_TABLE into INIT_DATA
LSM: Convert security_initcall() into DEFINE_LSM()
LSM: Record LSM name in struct lsm_info
LSM: Provide init debugging infrastructure
LSM: Don't ignore initialization failures
LSM: Introduce LSM_FLAG_LEGACY_MAJOR
LSM: Provide separate ordered initialization
LSM: Plumb visibility into optional "enabled" state
LSM: Lift LSM selection out of individual LSMs
LSM: Introduce lsm.enable= and lsm.disable=
LSM: Prepare for reorganizing "security=" logic
LSM: Refactor "security=" in terms of enable/disable
LSM: Build ordered list of ordered LSMs for init
LSM: Introduce CONFIG_LSM_ORDER
LSM: Introduce "lsm.order=" for boottime ordering
LoadPin: Initialize as ordered LSM
Yama: Initialize as ordered LSM
LSM: Introduce enum lsm_order
capability: Mark as LSM_ORDER_FIRST
LSM: Separate idea of "major" LSM from "exclusive" LSM
LSM: Add all exclusive LSMs to ordered initialization

 .../admin-guide/kernel-parameters.txt         |   7 +
 arch/arc/kernel/vmlinux.lds.S                 |   1 -
 arch/arm/kernel/vmlinux-xip.lds.S             |   1 -
 arch/arm64/kernel/vmlinux.lds.S               |   1 -
 arch/h8300/kernel/vmlinux.lds.S               |   1 -
 arch/microblaze/kernel/vmlinux.lds.S          |   2 -
 arch/powerpc/kernel/vmlinux.lds.S             |   2 -
 arch/um/include/asm/common.lds.S              |   2 -
 arch/xtensa/kernel/vmlinux.lds.S              |   1 -
 include/asm-generic/vmlinux.lds.h             |  25 +-
 include/linux/init.h                          |   2 -
 include/linux/lsm_hooks.h                     |  43 ++-
 include/linux/module.h                        |   1 -
 security/Kconfig                              |  42 +--
 security/apparmor/lsm.c                       |  16 +-
 security/commoncap.c                          |   8 +-
 security/integrity/iint.c                     |   5 +-
 security/loadpin/loadpin.c                    |  10 +-
 security/security.c                           | 304 ++++++++++++++----
 security/selinux/hooks.c                      |  16 +-
 security/smack/smack_lsm.c                    |   8 +-
 security/tomoyo/tomoyo.c                      |   7 +-
 security/yama/yama_lsm.c                      |   7 +-
 23 files changed, 348 insertions(+), 164 deletions(-)
Signature · 1 line
2.17.1
author
#1 lore raw

PATCH v2 1/26 LSM: Correctly announce start of LSM initialization

For a while now, the LSM core has said it was "initializED", rather than "initializING". This adjust the report to be more accurate (i.e. before this was reported before any LSMs had been initialized.)

---
 security/security.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
security/security.c +2 -1
index 736e78da1ab9..4cbcf244a965 100644
@@ -72,10 +72,11 @@ int __init security_init(void)
 	int i;
 	struct hlist_head *list = (struct hlist_head *) &security_hook_heads;
 
+	pr_info("Security Framework initializing\n");
+
 	for (i = 0; i < sizeof(security_hook_heads) / sizeof(struct hlist_head);
 	     i++)
 		INIT_HLIST_HEAD(&list[i]);
-	pr_info("Security Framework initialized\n");
 
 	/*
 	 * Load minor LSMs, with the capability module always first.
Signature · 1 line
2.17.1
maintainer Reviewed-by on v2 1/26
#2 lore raw

Re: [PATCH security-next v2 01/26] LSM: Correctly announce start of LSM initialization

Quoted 5 lines · Kees Cook

For a while now, the LSM core has said it was "initializED", rather than "initializING". This adjust the report to be more accurate (i.e. before this was reported before any LSMs had been initialized.)

Quoted 21 lines
---
 security/security.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
security/security.c +2 -1
index 736e78da1ab9..4cbcf244a965 100644
@@ -72,10 +72,11 @@ int __init security_init(void)
 	int i;
 	struct hlist_head *list = (struct hlist_head *) &security_hook_heads;
 
+	pr_info("Security Framework initializing\n");
+
 	for (i = 0; i < sizeof(security_hook_heads) / sizeof(struct hlist_head);
 	     i++)
 		INIT_HLIST_HEAD(&list[i]);
-	pr_info("Security Framework initialized\n");
 
 	/*
 	 * Load minor LSMs, with the capability module always first.
author
#3 lore raw

PATCH v2 2/26 vmlinux.lds.h: Avoid copy/paste of security_init section

In reply to Kees Cook

Avoid copy/paste by defining SECURITY_INIT in terms of SECURITY_INITCALL.

---
 include/asm-generic/vmlinux.lds.h | 13 ++++++-------
 1 file changed, 6 insertions(+), 7 deletions(-)
include/asm-generic/vmlinux.lds.h +6 -7
index 7b75ff6e2fce..934a45395547 100644
@@ -473,13 +473,6 @@
 #define RODATA          RO_DATA_SECTION(4096)
 #define RO_DATA(align)  RO_DATA_SECTION(align)
 
-#define SECURITY_INIT							\
-	.security_initcall.init : AT(ADDR(.security_initcall.init) - LOAD_OFFSET) { \
-		__security_initcall_start = .;				\
-		KEEP(*(.security_initcall.init))			\
-		__security_initcall_end = .;				\
-	}
-
 /*
  * .text section. Map to function alignment to avoid address changes
  * during second ld run in second ld pass when generating System.map
@@ -798,6 +791,12 @@
 		KEEP(*(.security_initcall.init))			\
 		__security_initcall_end = .;
 
+/* Older linker script style for security init. */
+#define SECURITY_INIT							\
+	.security_initcall.init : AT(ADDR(.security_initcall.init) - LOAD_OFFSET) { \
+		SECURITY_INITCALL					\
+	}
+
 #ifdef CONFIG_BLK_DEV_INITRD
 #define INIT_RAM_FS							\
 	. = ALIGN(4);							\
Signature · 1 line
2.17.1
author
#4 lore raw

PATCH v2 3/26 LSM: Rename .security_initcall section to .lsm_info

In reply to Kees Cook

In preparation for switching from initcall to just a regular set of pointers in a section, rename the internal section name.

---
 include/asm-generic/vmlinux.lds.h | 10 +++++-----
 include/linux/init.h              |  4 ++--
 security/security.c               |  4 ++--
 3 files changed, 9 insertions(+), 9 deletions(-)
include/asm-generic/vmlinux.lds.h +5 -5
index 934a45395547..5079a969e612 100644
@@ -787,14 +787,14 @@
 		__con_initcall_end = .;
 
 #define SECURITY_INITCALL						\
-		__security_initcall_start = .;				\
-		KEEP(*(.security_initcall.init))			\
-		__security_initcall_end = .;
+		__start_lsm_info = .;					\
+		KEEP(*(.lsm_info.init))					\
+		__end_lsm_info = .;
 
 /* Older linker script style for security init. */
 #define SECURITY_INIT							\
-	.security_initcall.init : AT(ADDR(.security_initcall.init) - LOAD_OFFSET) { \
-		SECURITY_INITCALL					\
+	.lsm_info.init : AT(ADDR(.lsm_info.init) - LOAD_OFFSET) {	\
+		LSM_INFO						\
 	}
 
 #ifdef CONFIG_BLK_DEV_INITRD
include/linux/init.h +2 -2
index 2538d176dd1f..77636539e77c 100644
@@ -133,7 +133,7 @@ static inline initcall_t initcall_from_entry(initcall_entry_t *entry)
 #endif
 
 extern initcall_entry_t __con_initcall_start[], __con_initcall_end[];
-extern initcall_entry_t __security_initcall_start[], __security_initcall_end[];
+extern initcall_entry_t __start_lsm_info[], __end_lsm_info[];
 
 /* Used for contructor calls. */
 typedef void (*ctor_fn_t)(void);
@@ -236,7 +236,7 @@ extern bool initcall_debug;
 	static exitcall_t __exitcall_##fn __exit_call = fn
 
 #define console_initcall(fn)	___define_initcall(fn,, .con_initcall)
-#define security_initcall(fn)	___define_initcall(fn,, .security_initcall)
+#define security_initcall(fn)	___define_initcall(fn,, .lsm_info)
 
 struct obs_kernel_param {
 	const char *str;
security/security.c +2 -2
index 4cbcf244a965..892fe6b691cf 100644
@@ -51,9 +51,9 @@ static void __init do_security_initcalls(void)
 	initcall_t call;
 	initcall_entry_t *ce;
 
-	ce = __security_initcall_start;
+	ce = __start_lsm_info;
 	trace_initcall_level("security");
-	while (ce < __security_initcall_end) {
+	while (ce < __end_lsm_info) {
 		call = initcall_from_entry(ce);
 		trace_initcall_start(call);
 		ret = call();
Signature · 1 line
2.17.1
author
#5 lore raw

PATCH v2 4/26 LSM: Remove initcall tracing

In reply to Kees Cook

This partially reverts commit 58eacfffc417 ("init, tracing: instrument security and console initcall trace events") since security init calls are about to no longer resemble regular init calls.

---
 security/security.c | 8 +-------
 1 file changed, 1 insertion(+), 7 deletions(-)
security/security.c +1 -7
index 892fe6b691cf..41a5da2c7faf 100644
@@ -30,8 +30,6 @@
 #include <linux/string.h>
 #include <net/flow.h>
 
-#include <trace/events/initcall.h>
-
 #define MAX_LSM_EVM_XATTR	2
 
 /* Maximum number of letters for an LSM name string */
@@ -47,17 +45,13 @@ static __initdata char chosen_lsm[SECURITY_NAME_MAX + 1] =
 
 static void __init do_security_initcalls(void)
 {
-	int ret;
 	initcall_t call;
 	initcall_entry_t *ce;
 
 	ce = __start_lsm_info;
-	trace_initcall_level("security");
 	while (ce < __end_lsm_info) {
 		call = initcall_from_entry(ce);
-		trace_initcall_start(call);
-		ret = call();
-		trace_initcall_finish(call, ret);
+		call();
 		ce++;
 	}
 }
Signature · 1 line
2.17.1
author
#6 lore raw

PATCH v2 5/26 LSM: Convert from initcall to struct lsm_info

In reply to Kees Cook

In preparation for doing more interesting LSM init probing, this converts the existing initcall system into an explicit call into a function pointer from a section-collected struct lsm_info array.

---
 include/linux/init.h      |  2 --
 include/linux/lsm_hooks.h | 12 ++++++++++++
 include/linux/module.h    |  1 -
 security/integrity/iint.c |  1 +
 security/security.c       | 14 +++++---------
 5 files changed, 18 insertions(+), 12 deletions(-)
include/linux/init.h +0 -2
index 77636539e77c..9c2aba1dbabf 100644
@@ -133,7 +133,6 @@ static inline initcall_t initcall_from_entry(initcall_entry_t *entry)
 #endif
 
 extern initcall_entry_t __con_initcall_start[], __con_initcall_end[];
-extern initcall_entry_t __start_lsm_info[], __end_lsm_info[];
 
 /* Used for contructor calls. */
 typedef void (*ctor_fn_t)(void);
@@ -236,7 +235,6 @@ extern bool initcall_debug;
 	static exitcall_t __exitcall_##fn __exit_call = fn
 
 #define console_initcall(fn)	___define_initcall(fn,, .con_initcall)
-#define security_initcall(fn)	___define_initcall(fn,, .lsm_info)
 
 struct obs_kernel_param {
 	const char *str;
include/linux/lsm_hooks.h +12 -0
index 97a020c616ad..ad04761e5587 100644
@@ -2039,6 +2039,18 @@ extern char *lsm_names;
 extern void security_add_hooks(struct security_hook_list *hooks, int count,
 				char *lsm);
 
+struct lsm_info {
+	int (*init)(void);
+};
+
+extern struct lsm_info __start_lsm_info[], __end_lsm_info[];
+
+#define security_initcall(lsm)						\
+	static struct lsm_info __lsm_##lsm				\
+		__used __section(.lsm_info.init)			\
+		__aligned(sizeof(unsigned long))			\
+		= { .init = lsm, }
+
 #ifdef CONFIG_SECURITY_SELINUX_DISABLE
 /*
  * Assuring the safety of deleting a security module is up to
include/linux/module.h +0 -1
index f807f15bebbe..264979283756 100644
@@ -123,7 +123,6 @@ extern void cleanup_module(void);
 #define late_initcall_sync(fn)		module_init(fn)
 
 #define console_initcall(fn)		module_init(fn)
-#define security_initcall(fn)		module_init(fn)
 
 /* Each module must use one module_init(). */
 #define module_init(initfn)					\
security/integrity/iint.c +1 -0
index 5a6810041e5c..70d21b566955 100644
@@ -22,6 +22,7 @@
 #include <linux/file.h>
 #include <linux/uaccess.h>
 #include <linux/security.h>
+#include <linux/lsm_hooks.h>
 #include "integrity.h"
 
 static struct rb_root integrity_iint_tree = RB_ROOT;
security/security.c +5 -9
index 41a5da2c7faf..e74f46fba591 100644
@@ -43,16 +43,12 @@ char *lsm_names;
 static __initdata char chosen_lsm[SECURITY_NAME_MAX + 1] =
 	CONFIG_DEFAULT_SECURITY;
 
-static void __init do_security_initcalls(void)
+static void __init major_lsm_init(void)
 {
-	initcall_t call;
-	initcall_entry_t *ce;
+	struct lsm_info *lsm;
 
-	ce = __start_lsm_info;
-	while (ce < __end_lsm_info) {
-		call = initcall_from_entry(ce);
-		call();
-		ce++;
+	for (lsm = __start_lsm_info; lsm < __end_lsm_info; lsm++) {
+		lsm->init();
 	}
 }
 
@@ -82,7 +78,7 @@ int __init security_init(void)
 	/*
 	 * Load all the remaining security modules.
 	 */
-	do_security_initcalls();
+	major_lsm_init();
 
 	return 0;
 }
Signature · 1 line
2.17.1
author
#7 lore raw

PATCH v2 6/26 vmlinux.lds.h: Move LSM_TABLE into INIT_DATA

In reply to Kees Cook

Since the struct lsm_info table is not an initcall, we can just move it into INIT_DATA like all the other tables.

---
 arch/arc/kernel/vmlinux.lds.S        |  1 -
 arch/arm/kernel/vmlinux-xip.lds.S    |  1 -
 arch/arm64/kernel/vmlinux.lds.S      |  1 -
 arch/h8300/kernel/vmlinux.lds.S      |  1 -
 arch/microblaze/kernel/vmlinux.lds.S |  2 --
 arch/powerpc/kernel/vmlinux.lds.S    |  2 --
 arch/um/include/asm/common.lds.S     |  2 --
 arch/xtensa/kernel/vmlinux.lds.S     |  1 -
 include/asm-generic/vmlinux.lds.h    | 24 +++++++++++-------------
 9 files changed, 11 insertions(+), 24 deletions(-)
arch/arc/kernel/vmlinux.lds.S +0 -1
index f35ed578e007..8fb16bdabdcf 100644
@@ -71,7 +71,6 @@ SECTIONS
 		INIT_SETUP(L1_CACHE_BYTES)
 		INIT_CALLS
 		CON_INITCALL
-		SECURITY_INITCALL
 	}
 
 	.init.arch.info : {
arch/arm/kernel/vmlinux-xip.lds.S +0 -1
index 3593d5c1acd2..8c74037ade22 100644
@@ -96,7 +96,6 @@ SECTIONS
 		INIT_SETUP(16)
 		INIT_CALLS
 		CON_INITCALL
-		SECURITY_INITCALL
 		INIT_RAM_FS
 	}
 
arch/arm64/kernel/vmlinux.lds.S +0 -1
index 605d1b60469c..7d23d591b03c 100644
@@ -166,7 +166,6 @@ SECTIONS
 		INIT_SETUP(16)
 		INIT_CALLS
 		CON_INITCALL
-		SECURITY_INITCALL
 		INIT_RAM_FS
 		*(.init.rodata.* .init.bss)	/* from the EFI stub */
 	}
arch/h8300/kernel/vmlinux.lds.S +0 -1
index 35716a3048de..49f716c0a1df 100644
@@ -56,7 +56,6 @@ SECTIONS
 	__init_begin = .;
 	INIT_TEXT_SECTION(4)
 	INIT_DATA_SECTION(4)
-	SECURITY_INIT
 	__init_end = .;
 	_edata = . ;
 	_begin_data = LOADADDR(.data);
arch/microblaze/kernel/vmlinux.lds.S +0 -2
index 289d0e7f3e3a..e1f3e8741292 100644
@@ -117,8 +117,6 @@ SECTIONS {
 		CON_INITCALL
 	}
 
-	SECURITY_INIT
-
 	__init_end_before_initramfs = .;
 
 	.init.ramfs : AT(ADDR(.init.ramfs) - LOAD_OFFSET) {
arch/powerpc/kernel/vmlinux.lds.S +0 -2
index 07ae018e550e..105a976323aa 100644
@@ -212,8 +212,6 @@ SECTIONS
 		CON_INITCALL
 	}
 
-	SECURITY_INIT
-
 	. = ALIGN(8);
 	__ftr_fixup : AT(ADDR(__ftr_fixup) - LOAD_OFFSET) {
 		__start___ftr_fixup = .;
arch/um/include/asm/common.lds.S +0 -2
index 7adb4e6b658a..4049f2c46387 100644
@@ -53,8 +53,6 @@
 	CON_INITCALL
   }
 
-  SECURITY_INIT
-
   .exitcall : {
 	__exitcall_begin = .;
 	*(.exitcall.exit)
arch/xtensa/kernel/vmlinux.lds.S +0 -1
index a1c3edb8ad56..b727b18a68ac 100644
@@ -197,7 +197,6 @@ SECTIONS
     INIT_SETUP(XCHAL_ICACHE_LINESIZE)
     INIT_CALLS
     CON_INITCALL
-    SECURITY_INITCALL
     INIT_RAM_FS
   }
 
include/asm-generic/vmlinux.lds.h +11 -13
index 5079a969e612..b31ea8bdfef9 100644
@@ -203,6 +203,15 @@
 #define EARLYCON_TABLE()
 #endif
 
+#ifdef CONFIG_SECURITY
+#define LSM_TABLE()	. = ALIGN(8);					\
+			__start_lsm_info = .;				\
+			KEEP(*(.lsm_info.init))				\
+			__end_lsm_info = .;
+#else
+#define LSM_TABLE()
+#endif
+
 #define ___OF_TABLE(cfg, name)	_OF_TABLE_##cfg(name)
 #define __OF_TABLE(cfg, name)	___OF_TABLE(cfg, name)
 #define OF_TABLE(cfg, name)	__OF_TABLE(IS_ENABLED(cfg), name)
@@ -597,7 +606,8 @@
 	IRQCHIP_OF_MATCH_TABLE()					\
 	ACPI_PROBE_TABLE(irqchip)					\
 	ACPI_PROBE_TABLE(timer)						\
-	EARLYCON_TABLE()
+	EARLYCON_TABLE()						\
+	LSM_TABLE()
 
 #define INIT_TEXT							\
 	*(.init.text .init.text.*)					\
@@ -786,17 +796,6 @@
 		KEEP(*(.con_initcall.init))				\
 		__con_initcall_end = .;
 
-#define SECURITY_INITCALL						\
-		__start_lsm_info = .;					\
-		KEEP(*(.lsm_info.init))					\
-		__end_lsm_info = .;
-
-/* Older linker script style for security init. */
-#define SECURITY_INIT							\
-	.lsm_info.init : AT(ADDR(.lsm_info.init) - LOAD_OFFSET) {	\
-		LSM_INFO						\
-	}
-
 #ifdef CONFIG_BLK_DEV_INITRD
 #define INIT_RAM_FS							\
 	. = ALIGN(4);							\
@@ -963,7 +962,6 @@
 		INIT_SETUP(initsetup_align)				\
 		INIT_CALLS						\
 		CON_INITCALL						\
-		SECURITY_INITCALL					\
 		INIT_RAM_FS						\
 	}
 
Signature · 1 line
2.17.1
author
#8 lore raw

PATCH v2 7/26 LSM: Convert security_initcall() into DEFINE_LSM()

In reply to Kees Cook

Instead of using argument-based initializers, switch to defining the contents of struct lsm_info on a per-LSM basis. This also drops the final use of the now inaccurate "initcall" naming.

---
 include/linux/lsm_hooks.h  | 6 ++++--
 security/apparmor/lsm.c    | 4 +++-
 security/integrity/iint.c  | 4 +++-
 security/selinux/hooks.c   | 4 +++-
 security/smack/smack_lsm.c | 4 +++-
 security/tomoyo/tomoyo.c   | 4 +++-
 6 files changed, 19 insertions(+), 7 deletions(-)
include/linux/lsm_hooks.h +4 -2
index ad04761e5587..02ec717189f9 100644
@@ -2045,11 +2045,13 @@ struct lsm_info {
 
 extern struct lsm_info __start_lsm_info[], __end_lsm_info[];
 
-#define security_initcall(lsm)						\
+#define DEFINE_LSM(lsm)							\
 	static struct lsm_info __lsm_##lsm				\
 		__used __section(.lsm_info.init)			\
 		__aligned(sizeof(unsigned long))			\
-		= { .init = lsm, }
+		= {							\
+
+#define END_LSM	  }
 
 #ifdef CONFIG_SECURITY_SELINUX_DISABLE
 /*
security/apparmor/lsm.c +3 -1
index 8b8b70620bbe..7fa7b4464cf4 100644
@@ -1606,4 +1606,6 @@ static int __init apparmor_init(void)
 	return error;
 }
 
-security_initcall(apparmor_init);
+DEFINE_LSM(apparmor)
+	.init = apparmor_init,
+END_LSM;
security/integrity/iint.c +3 -1
index 70d21b566955..20e60df929a3 100644
@@ -175,7 +175,9 @@ static int __init integrity_iintcache_init(void)
 			      0, SLAB_PANIC, init_once);
 	return 0;
 }
-security_initcall(integrity_iintcache_init);
+DEFINE_LSM(integrity)
+	.init = integrity_iintcache_init,
+END_LSM;
 
 
 /*
security/selinux/hooks.c +3 -1
index ad9a9b8e9979..469a90806bc6 100644
@@ -7202,7 +7202,9 @@ void selinux_complete_init(void)
 
 /* SELinux requires early initialization in order to label
    all processes and objects when they are created. */
-security_initcall(selinux_init);
+DEFINE_LSM(selinux)
+	.init = selinux_init,
+END_LSM;
 
 #if defined(CONFIG_NETFILTER)
 
security/smack/smack_lsm.c +3 -1
index 340fc30ad85d..1e1ace718e75 100644
@@ -4882,4 +4882,6 @@ static __init int smack_init(void)
  * Smack requires early initialization in order to label
  * all processes and objects when they are created.
  */
-security_initcall(smack_init);
+DEFINE_LSM(smack)
+	.init = smack_init,
+END_LSM;
security/tomoyo/tomoyo.c +3 -1
index 9f932e2d6852..a280d4eab456 100644
@@ -550,4 +550,6 @@ static int __init tomoyo_init(void)
 	return 0;
 }
 
-security_initcall(tomoyo_init);
+DEFINE_LSM(tomoyo)
+	.init = tomoyo_init,
+END_LSM;
Signature · 1 line
2.17.1
author
#9 lore raw

PATCH v2 8/26 LSM: Record LSM name in struct lsm_info

In reply to Kees Cook

In preparation for making LSM selections outside of the LSMs, include the name of LSMs in struct lsm_info.

---
 include/linux/lsm_hooks.h | 4 ++++
 1 file changed, 4 insertions(+)
include/linux/lsm_hooks.h +4 -0
index 02ec717189f9..543636f18152 100644
@@ -2040,16 +2040,20 @@ extern void security_add_hooks(struct security_hook_list *hooks, int count,
 				char *lsm);
 
 struct lsm_info {
+	const char *name;	/* Populated automatically. */
 	int (*init)(void);
 };
 
 extern struct lsm_info __start_lsm_info[], __end_lsm_info[];
 
 #define DEFINE_LSM(lsm)							\
+	static const char __lsm_name_##lsm[] __initconst		\
+		__aligned(1) = #lsm;					\
 	static struct lsm_info __lsm_##lsm				\
 		__used __section(.lsm_info.init)			\
 		__aligned(sizeof(unsigned long))			\
 		= {							\
+			.name = __lsm_name_##lsm,			\
 
 #define END_LSM	  }
 
Signature · 1 line
2.17.1
author
#10 lore raw

PATCH v2 9/26 LSM: Provide init debugging infrastructure

In reply to Kees Cook

Booting with "lsm.debug" will report future details on how LSM ordering decisions are being made.

---
 .../admin-guide/kernel-parameters.txt          |  2 ++
 security/security.c                            | 18 ++++++++++++++++++
 2 files changed, 20 insertions(+)
Documentation/admin-guide/kernel-parameters.txt +2 -0
index 9871e649ffef..32d323ee9218 100644
@@ -2274,6 +2274,8 @@
 	ltpc=		[NET]
 			Format: <io>,<irq>,<dma>
 
+	lsm.debug	[SECURITY] Enable LSM initialization debugging output.
+
 	machvec=	[IA-64] Force the use of a particular machine-vector
 			(machvec) in a generic kernel.
 			Example: machvec=hpzx1_swiotlb
security/security.c +18 -0
index e74f46fba591..ee49b921d750 100644
@@ -12,6 +12,8 @@
  *	(at your option) any later version.
  */
 
+#define pr_fmt(fmt) "LSM: " fmt
+
 #include <linux/bpf.h>
 #include <linux/capability.h>
 #include <linux/dcache.h>
@@ -43,11 +45,19 @@ char *lsm_names;
 static __initdata char chosen_lsm[SECURITY_NAME_MAX + 1] =
 	CONFIG_DEFAULT_SECURITY;
 
+static bool debug __initdata;
+#define init_debug(...)						\
+	do {							\
+		if (debug)					\
+			pr_info(__VA_ARGS__);			\
+	} while (0)
+
 static void __init major_lsm_init(void)
 {
 	struct lsm_info *lsm;
 
 	for (lsm = __start_lsm_info; lsm < __end_lsm_info; lsm++) {
+		init_debug("initializing %s\n", lsm->name);
 		lsm->init();
 	}
 }
@@ -91,6 +101,14 @@ static int __init choose_lsm(char *str)
 }
 __setup("security=", choose_lsm);
 
+/* Enable LSM order debugging. */
+static int __init enable_debug(char *str)
+{
+	debug = true;
+	return 1;
+}
+__setup("lsm.debug", enable_debug);
+
 static bool match_last_lsm(const char *list, const char *lsm)
 {
 	const char *last;
Signature · 1 line
2.17.1
author
#11 lore raw

PATCH v2 10/26 LSM: Don't ignore initialization failures

In reply to Kees Cook

LSM initialization failures have traditionally been ignored. We should at least WARN when something goes wrong.

---
 security/security.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
security/security.c +3 -1
index ee49b921d750..1f055936a746 100644
@@ -55,10 +55,12 @@ static bool debug __initdata;
 static void __init major_lsm_init(void)
 {
 	struct lsm_info *lsm;
+	int ret;
 
 	for (lsm = __start_lsm_info; lsm < __end_lsm_info; lsm++) {
 		init_debug("initializing %s\n", lsm->name);
-		lsm->init();
+		ret = lsm->init();
+		WARN(ret, "%s failed to initialize: %d\n", lsm->name, ret);
 	}
 }
 
Signature · 1 line
2.17.1
author
#12 lore raw

PATCH v2 11/26 LSM: Introduce LSM_FLAG_LEGACY_MAJOR

In reply to Kees Cook

This adds a flag for the current "major" LSMs to distinguish them when we have a universal method for ordering all LSMs. It's called "legacy" since the distinction of "major" will go away in the blob-sharing world.

---
 include/linux/lsm_hooks.h  | 3 +++
 security/apparmor/lsm.c    | 1 +
 security/selinux/hooks.c   | 1 +
 security/smack/smack_lsm.c | 1 +
 security/tomoyo/tomoyo.c   | 1 +
 5 files changed, 7 insertions(+)
include/linux/lsm_hooks.h +3 -0
index 543636f18152..38cbefabff71 100644
@@ -2039,8 +2039,11 @@ extern char *lsm_names;
 extern void security_add_hooks(struct security_hook_list *hooks, int count,
 				char *lsm);
 
+#define LSM_FLAG_LEGACY_MAJOR	(1 << 0)
+
 struct lsm_info {
 	const char *name;	/* Populated automatically. */
+	unsigned long flags;	/* Optional: flags describing LSM */
 	int (*init)(void);
 };
 
security/apparmor/lsm.c +1 -0
index 7fa7b4464cf4..4c5f63e9aeba 100644
@@ -1607,5 +1607,6 @@ static int __init apparmor_init(void)
 }
 
 DEFINE_LSM(apparmor)
+	.flags = LSM_FLAG_LEGACY_MAJOR,
 	.init = apparmor_init,
 END_LSM;
security/selinux/hooks.c +1 -0
index 469a90806bc6..615cf6498c0f 100644
@@ -7203,6 +7203,7 @@ void selinux_complete_init(void)
 /* SELinux requires early initialization in order to label
    all processes and objects when they are created. */
 DEFINE_LSM(selinux)
+	.flags = LSM_FLAG_LEGACY_MAJOR,
 	.init = selinux_init,
 END_LSM;
 
security/smack/smack_lsm.c +1 -0
index 1e1ace718e75..4aef844fc0e2 100644
@@ -4883,5 +4883,6 @@ static __init int smack_init(void)
  * all processes and objects when they are created.
  */
 DEFINE_LSM(smack)
+	.flags = LSM_FLAG_LEGACY_MAJOR,
 	.init = smack_init,
 END_LSM;
security/tomoyo/tomoyo.c +1 -0
index a280d4eab456..528b6244a648 100644
@@ -551,5 +551,6 @@ static int __init tomoyo_init(void)
 }
 
 DEFINE_LSM(tomoyo)
+	.flags = LSM_FLAG_LEGACY_MAJOR,
 	.init = tomoyo_init,
 END_LSM;
Signature · 1 line
2.17.1
author
#13 lore raw

PATCH v2 12/26 LSM: Provide separate ordered initialization

In reply to Kees Cook

This provides a place for ordered LSMs to be initialized, separate from the "major" LSMs. This is mainly a copy/paste from major_lsm_init() to ordered_lsm_init(), but it will change drastically in later patches.

What is not obvious in the patch is that this change moves the integrity LSM from major_lsm_init() into ordered_lsm_init(), since it is not marked with the LSM_FLAG_LEGACY_MAJOR. As it is the only LSM in the "ordered" list, there is no reordering yet created.

---
 security/security.c | 21 +++++++++++++++++++++
 1 file changed, 21 insertions(+)
security/security.c +21 -0
index 1f055936a746..a886a978214a 100644
@@ -52,12 +52,30 @@ static bool debug __initdata;
 			pr_info(__VA_ARGS__);			\
 	} while (0)
 
+static void __init ordered_lsm_init(void)
+{
+	struct lsm_info *lsm;
+	int ret;
+
+	for (lsm = __start_lsm_info; lsm < __end_lsm_info; lsm++) {
+		if ((lsm->flags & LSM_FLAG_LEGACY_MAJOR) != 0)
+			continue;
+
+		init_debug("initializing %s\n", lsm->name);
+		ret = lsm->init();
+		WARN(ret, "%s failed to initialize: %d\n", lsm->name, ret);
+	}
+}
+
 static void __init major_lsm_init(void)
 {
 	struct lsm_info *lsm;
 	int ret;
 
 	for (lsm = __start_lsm_info; lsm < __end_lsm_info; lsm++) {
+		if ((lsm->flags & LSM_FLAG_LEGACY_MAJOR) == 0)
+			continue;
+
 		init_debug("initializing %s\n", lsm->name);
 		ret = lsm->init();
 		WARN(ret, "%s failed to initialize: %d\n", lsm->name, ret);
@@ -87,6 +105,9 @@ int __init security_init(void)
 	yama_add_hooks();
 	loadpin_add_hooks();
 
+	/* Load LSMs in specified order. */
+	ordered_lsm_init();
+
 	/*
 	 * Load all the remaining security modules.
 	 */
Signature · 1 line
2.17.1
author
#14 lore raw

PATCH v2 13/26 LSM: Plumb visibility into optional "enabled" state

In reply to Kees Cook

In preparation for lifting the "is this LSM enabled?" logic out of the individual LSMs, pass in any special enabled state tracking (as needed for SELinux, AppArmor, and LoadPin). This must be an "int" to include handling cases where "enabled" is exposed via sysctl which has no "bool" type (i.e. LoadPin's use).

LoadPin's "enabled" tracking will be added later when it gets added to the "ordered LSM" stack.

---
 include/linux/lsm_hooks.h | 1 +
 security/apparmor/lsm.c   | 5 +++--
 security/selinux/hooks.c  | 1 +
 3 files changed, 5 insertions(+), 2 deletions(-)
include/linux/lsm_hooks.h +1 -0
index 38cbefabff71..118e12f678df 100644
@@ -2044,6 +2044,7 @@ extern void security_add_hooks(struct security_hook_list *hooks, int count,
 struct lsm_info {
 	const char *name;	/* Populated automatically. */
 	unsigned long flags;	/* Optional: flags describing LSM */
+	int *enabled;		/* Optional: NULL means enabled. */
 	int (*init)(void);
 };
 
security/apparmor/lsm.c +3 -2
index 4c5f63e9aeba..d03133a267f2 100644
@@ -1303,8 +1303,8 @@ bool aa_g_paranoid_load = true;
 module_param_named(paranoid_load, aa_g_paranoid_load, aabool, S_IRUGO);
 
 /* Boot time disable flag */
-static bool apparmor_enabled = CONFIG_SECURITY_APPARMOR_BOOTPARAM_VALUE;
-module_param_named(enabled, apparmor_enabled, bool, S_IRUGO);
+static int apparmor_enabled = CONFIG_SECURITY_APPARMOR_BOOTPARAM_VALUE;
+module_param_named(enabled, apparmor_enabled, int, 0444);
 
 static int __init apparmor_enabled_setup(char *str)
 {
@@ -1608,5 +1608,6 @@ static int __init apparmor_init(void)
 
 DEFINE_LSM(apparmor)
 	.flags = LSM_FLAG_LEGACY_MAJOR,
+	.enabled = &apparmor_enabled,
 	.init = apparmor_init,
 END_LSM;
security/selinux/hooks.c +1 -0
index 615cf6498c0f..3f999ed98cfd 100644
@@ -7204,6 +7204,7 @@ void selinux_complete_init(void)
    all processes and objects when they are created. */
 DEFINE_LSM(selinux)
 	.flags = LSM_FLAG_LEGACY_MAJOR,
+	.enabled = &selinux_enabled,
 	.init = selinux_init,
 END_LSM;
 
Signature · 1 line
2.17.1
author
#15 lore raw

PATCH v2 14/26 LSM: Lift LSM selection out of individual LSMs

In reply to Kees Cook

As a prerequisite to adjusting LSM selection logic in the future, this moves the selection logic up out of the individual major LSMs, making their init functions only run when actually enabled.

---
 include/linux/lsm_hooks.h  |  1 -
 security/apparmor/lsm.c    |  6 ---
 security/security.c        | 76 ++++++++++++++++++++++----------------
 security/selinux/hooks.c   | 10 -----
 security/smack/smack_lsm.c |  3 --
 security/tomoyo/tomoyo.c   |  2 -
 6 files changed, 45 insertions(+), 53 deletions(-)
include/linux/lsm_hooks.h +0 -1
index 118e12f678df..ec1c0a97dfe3 100644
@@ -2091,7 +2091,6 @@ static inline void security_delete_hooks(struct security_hook_list *hooks,
 #define __lsm_ro_after_init	__ro_after_init
 #endif /* CONFIG_SECURITY_WRITABLE_HOOKS */
 
-extern int __init security_module_enable(const char *module);
 extern void __init capability_add_hooks(void);
 #ifdef CONFIG_SECURITY_YAMA
 extern void __init yama_add_hooks(void);
security/apparmor/lsm.c +0 -6
index d03133a267f2..5399c2f03536 100644
@@ -1542,12 +1542,6 @@ static int __init apparmor_init(void)
 {
 	int error;
 
-	if (!apparmor_enabled || !security_module_enable("apparmor")) {
-		aa_info_message("AppArmor disabled by boot time parameter");
-		apparmor_enabled = false;
-		return 0;
-	}
-
 	aa_secids_init();
 
 	error = aa_setup_dfa_engine();
security/security.c +45 -31

107 lines not on this page · raw message

security/selinux/hooks.c +0 -10
index 3f999ed98cfd..409a9252aeb6 100644
@@ -7133,16 +7133,6 @@ static struct security_hook_list selinux_hooks[] __lsm_ro_after_init = {
 
 static __init int selinux_init(void)
 {
-	if (!security_module_enable("selinux")) {
-		selinux_enabled = 0;
-		return 0;
-	}
-
-	if (!selinux_enabled) {
-		pr_info("SELinux:  Disabled at boot.\n");
-		return 0;
-	}
-
 	pr_info("SELinux:  Initializing.\n");
 
 	memset(&selinux_state, 0, sizeof(selinux_state));
security/smack/smack_lsm.c +0 -3
index 4aef844fc0e2..e79fad43a8e3 100644
@@ -4834,9 +4834,6 @@ static __init int smack_init(void)
 	struct cred *cred;
 	struct task_smack *tsp;
 
-	if (!security_module_enable("smack"))
-		return 0;
-
 	smack_inode_cache = KMEM_CACHE(inode_smack, 0);
 	if (!smack_inode_cache)
 		return -ENOMEM;
security/tomoyo/tomoyo.c +0 -2
index 528b6244a648..39bb994ebe09 100644
@@ -540,8 +540,6 @@ static int __init tomoyo_init(void)
 {
 	struct cred *cred = (struct cred *) current_cred();
 
-	if (!security_module_enable("tomoyo"))
-		return 0;
 	/* register ourselves with the security framework */
 	security_add_hooks(tomoyo_hooks, ARRAY_SIZE(tomoyo_hooks), "tomoyo");
 	printk(KERN_INFO "TOMOYO Linux initialized\n");
Signature · 1 line
2.17.1
author
#16 lore raw

PATCH v2 15/26 LSM: Introduce lsm.enable= and lsm.disable=

In reply to Kees Cook

This has identical functionality to the existing per-LSM enable handling, but provides a centralized place to perform it. If multiple instances of a parameter (either with the custom LSM-specific parameter or the "lsm.{enable,disable}" parameter) for a specific LSM are on the boot command line, the last one takes precedent.

Disabling an LSM means it will not be considered when performing initializations. Enabling an LSM means either undoing a previous disabling or a undoing a default-disabled CONFIG setting.

For example: "lsm.disable=apparmor apparmor.enabled=1" will leave AppArmor enabled. "selinux.enabled=0 lsm.enable=selinux" will leave SELinux enabled.

---
 security/security.c | 47 ++++++++++++++++++++++++++++++++++++++++++++-
 1 file changed, 46 insertions(+), 1 deletion(-)
security/security.c +46 -1
index 85533d4e534a..72d1ef2fc4cc 100644
@@ -53,10 +53,29 @@ static bool debug __initdata;
 	} while (0)
 
 /* Mark an LSM's enabled flag, if it exists. */
+static int lsm_enabled_true __initdata = 1;
+static int lsm_enabled_false __initdata = 0;
 static void __init set_enabled(struct lsm_info *lsm, bool enabled)
 {
-	if (lsm->enabled)
+	if (!lsm->enabled) {
+		/*
+		 * If the LSM hasn't configured an enable flag, we
+		 * can use a hard-coded setting for storing the
+		 * state ourselves.
+		 */
+		if (enabled)
+			lsm->enabled = &lsm_enabled_true;
+		else
+			lsm->enabled = &lsm_enabled_false;
+	} else if (lsm->enabled == &lsm_enabled_true) {
+		if (!enabled)
+			lsm->enabled = &lsm_enabled_false;
+	} else if (lsm->enabled == &lsm_enabled_false) {
+		if (enabled)
+			lsm->enabled = &lsm_enabled_true;
+	} else {
 		*lsm->enabled = enabled;
+	}
 }
 
 /* Is an LSM allowed to be enabled? */
@@ -169,6 +188,32 @@ static int __init enable_debug(char *str)
 }
 __setup("lsm.debug", enable_debug);
 
+/* Explicitly enable an LSM */
+static int __init enable_lsm(char *str)
+{
+	struct lsm_info *lsm;
+
+	for (lsm = __start_lsm_info; lsm < __end_lsm_info; lsm++) {
+		if (strcmp(str, lsm->name) == 0)
+			set_enabled(lsm, true);
+	}
+	return 1;
+}
+__setup("lsm.enable=", enable_lsm);
+
+/* Explicitly disable an LSM */
+static int __init disable_lsm(char *str)
+{
+	struct lsm_info *lsm;
+
+	for (lsm = __start_lsm_info; lsm < __end_lsm_info; lsm++) {
+		if (strcmp(str, lsm->name) == 0)
+			set_enabled(lsm, false);
+	}
+	return 1;
+}
+__setup("lsm.disable=", disable_lsm);
+
 static bool match_last_lsm(const char *list, const char *lsm)
 {
 	const char *last;
Signature · 1 line
2.17.1
author
#17 lore raw

PATCH v2 16/26 LSM: Prepare for reorganizing "security=" logic

In reply to Kees Cook

This moves the string handling for "security=" boot parameter into a stored pointer instead of a string duplicate. This will allow easier handling of the string when switching logic to use the coming enable/disable infrastructure.

---
 security/security.c | 17 ++++++++---------
 1 file changed, 8 insertions(+), 9 deletions(-)
security/security.c +8 -9
index 72d1ef2fc4cc..5cacbcefbc32 100644
@@ -34,16 +34,12 @@
 
 #define MAX_LSM_EVM_XATTR	2
 
-/* Maximum number of letters for an LSM name string */
-#define SECURITY_NAME_MAX	10
-
 struct security_hook_heads security_hook_heads __lsm_ro_after_init;
 static ATOMIC_NOTIFIER_HEAD(lsm_notifier_chain);
 
 char *lsm_names;
 /* Boot-time LSM user choice */
-static __initdata char chosen_lsm[SECURITY_NAME_MAX + 1] =
-	CONFIG_DEFAULT_SECURITY;
+static __initdata const char *chosen_major_lsm;
 
 static bool debug __initdata;
 #define init_debug(...)						\
@@ -90,7 +86,7 @@ static bool __init lsm_allowed(struct lsm_info *lsm)
 		return true;
 
 	/* Disabled if this LSM isn't the chosen one. */
-	if (strcmp(lsm->name, chosen_lsm) != 0)
+	if (strcmp(lsm->name, chosen_major_lsm) != 0)
 		return false;
 
 	return true;
@@ -154,6 +150,9 @@ int __init security_init(void)
 	     i++)
 		INIT_HLIST_HEAD(&list[i]);
 
+	if (!chosen_major_lsm)
+		chosen_major_lsm = CONFIG_DEFAULT_SECURITY;
+
 	/*
 	 * Load minor LSMs, with the capability module always first.
 	 */
@@ -173,12 +172,12 @@ int __init security_init(void)
 }
 
 /* Save user chosen LSM */
-static int __init choose_lsm(char *str)
+static int __init choose_major_lsm(char *str)
 {
-	strncpy(chosen_lsm, str, SECURITY_NAME_MAX);
+	chosen_major_lsm = str;
 	return 1;
 }
-__setup("security=", choose_lsm);
+__setup("security=", choose_major_lsm);
 
 /* Enable LSM order debugging. */
 static int __init enable_debug(char *str)
Signature · 1 line
2.17.1
author
#18 lore raw

PATCH v2 17/26 LSM: Refactor "security=" in terms of enable/disable

In reply to Kees Cook

For what are marked as the Legacy Major LSMs, make them effectively exclusive when selected on the "security=" boot parameter, to handle the future case of when a previously major LSMs become non-exclusive (e.g. when TOMOYO starts blob-sharing).

---
 security/security.c | 24 ++++++++++++++++--------
 1 file changed, 16 insertions(+), 8 deletions(-)
security/security.c +16 -8
index 5cacbcefbc32..25a019cc4a2b 100644
@@ -81,14 +81,6 @@ static bool __init lsm_allowed(struct lsm_info *lsm)
 	if (lsm->enabled && !*lsm->enabled)
 		return false;
 
-	/* Skip major-specific checks if not a major LSM. */
-	if ((lsm->flags & LSM_FLAG_LEGACY_MAJOR) == 0)
-		return true;
-
-	/* Disabled if this LSM isn't the chosen one. */
-	if (strcmp(lsm->name, chosen_major_lsm) != 0)
-		return false;
-
 	return true;
 }
 
@@ -150,8 +142,24 @@ int __init security_init(void)
 	     i++)
 		INIT_HLIST_HEAD(&list[i]);
 
+	/* Process "security=", if given. */
 	if (!chosen_major_lsm)
 		chosen_major_lsm = CONFIG_DEFAULT_SECURITY;
+	if (chosen_major_lsm) {
+		struct lsm_info *lsm;
+
+		/*
+		 * To match the original "security=" behavior, this
+		 * explicitly does NOT fallback to another Legacy Major
+		 * if the selected one was separately disabled: disable
+		 * all non-matching Legacy Major LSMs.
+		 */
+		for (lsm = __start_lsm_info; lsm < __end_lsm_info; lsm++) {
+			if ((lsm->flags & LSM_FLAG_LEGACY_MAJOR) &&
+			    strcmp(lsm->name, chosen_major_lsm) != 0)
+				set_enabled(lsm, false);
+		}
+	}
 
 	/*
 	 * Load minor LSMs, with the capability module always first.
Signature · 1 line
2.17.1
author
#19 lore raw

PATCH v2 18/26 LSM: Build ordered list of ordered LSMs for init

In reply to Kees Cook

This constructs a list of ordered LSMs to initialize, using a hard-coded list of only "integrity": minor LSMs continue to have direct hook calls, and major LSMs continue to initialize separately.

---
 security/security.c | 59 +++++++++++++++++++++++++++++++++++++++------
 1 file changed, 52 insertions(+), 7 deletions(-)
security/security.c +52 -7
index 25a019cc4a2b..2541a512a0f7 100644
@@ -34,6 +34,9 @@
 
 #define MAX_LSM_EVM_XATTR	2
 
+/* How many LSMs were built into the kernel? */
+#define LSM_COUNT (__end_lsm_info - __start_lsm_info)
+
 struct security_hook_heads security_hook_heads __lsm_ro_after_init;
 static ATOMIC_NOTIFIER_HEAD(lsm_notifier_chain);
 
@@ -41,6 +44,9 @@ char *lsm_names;
 /* Boot-time LSM user choice */
 static __initdata const char *chosen_major_lsm;
 
+/* Ordered list of LSMs to initialize. */
+static __initdata struct lsm_info **ordered_lsms;
+
 static bool debug __initdata;
 #define init_debug(...)						\
 	do {							\
@@ -74,6 +80,45 @@ static void __init set_enabled(struct lsm_info *lsm, bool enabled)
 	}
 }
 
+/* Is an LSM already listed in the ordered LSMs list? */
+static bool __init exists_ordered_lsm(struct lsm_info *lsm)
+{
+	struct lsm_info **check;
+
+	for (check = ordered_lsms; *check; check++)
+		if (*check == lsm)
+			return true;
+
+	return false;
+}
+
+/* Append an LSM to the list of ordered LSMs to initialize. */
+static int last_lsm __initdata;
+static void __init append_ordered_lsm(struct lsm_info *lsm, const char *from)
+{
+	/* Ignore duplicate selections. */
+	if (exists_ordered_lsm(lsm))
+		return;
+
+	if (WARN(last_lsm == LSM_COUNT, "%s: out of LSM slots!?\n", from))
+		return;
+
+	ordered_lsms[last_lsm++] = lsm;
+	init_debug("%s ordering: %s (%sabled)\n", from, lsm->name,
+		   (!lsm->enabled || *lsm->enabled) ? "en" : "dis");
+}
+
+/* Populate ordered LSMs list from hard-coded list of LSMs. */
+static void __init prepare_lsm_order(void)
+{
+	struct lsm_info *lsm;
+
+	for (lsm = __start_lsm_info; lsm < __end_lsm_info; lsm++) {
+		if (strcmp(lsm->name, "integrity") == 0)
+			append_ordered_lsm(lsm, "builtin");
+	}
+}
+
 /* Is an LSM allowed to be enabled? */
 static bool __init lsm_allowed(struct lsm_info *lsm)
 {
@@ -104,14 +149,10 @@ static void __init maybe_initialize_lsm(struct lsm_info *lsm)
 
 static void __init ordered_lsm_init(void)
 {
-	struct lsm_info *lsm;
-
-	for (lsm = __start_lsm_info; lsm < __end_lsm_info; lsm++) {
-		if ((lsm->flags & LSM_FLAG_LEGACY_MAJOR) != 0)
-			continue;
+	struct lsm_info **lsm;
 
-		maybe_initialize_lsm(lsm);
-	}
+	for (lsm = ordered_lsms; *lsm; lsm++)
+		maybe_initialize_lsm(*lsm);
 }
 
 static void __init major_lsm_init(void)
@@ -141,6 +182,8 @@ int __init security_init(void)
 	for (i = 0; i < sizeof(security_hook_heads) / sizeof(struct hlist_head);
 	     i++)
 		INIT_HLIST_HEAD(&list[i]);
+	ordered_lsms = kcalloc(LSM_COUNT + 1, sizeof(*ordered_lsms),
+				GFP_KERNEL);
 
 	/* Process "security=", if given. */
 	if (!chosen_major_lsm)
@@ -169,6 +212,7 @@ int __init security_init(void)
 	loadpin_add_hooks();
 
 	/* Load LSMs in specified order. */
+	prepare_lsm_order();
 	ordered_lsm_init();
 
 	/*
@@ -176,6 +220,7 @@ int __init security_init(void)
 	 */
 	major_lsm_init();
 
+	kfree(ordered_lsms);
 	return 0;
 }
 
Signature · 1 line
2.17.1
maintainer
#20 lore raw

Re: [PATCH security-next v2 18/26] LSM: Build ordered list of ordered LSMs for init

Quoted 5 lines · Kees Cook

This constructs a list of ordered LSMs to initialize, using a hard-coded list of only "integrity": minor LSMs continue to have direct hook calls, and major LSMs continue to initialize separately.

Do you think that this mechanism will be sufficiently flexible to accommodate dynamically loaded security modules in the future? While I am not personally an advocate of dynamically loaded security modules I have been working to ensure that I haven't done anything that would actively interfere with someone who did.

Quoted 117 lines
---
 security/security.c | 59 +++++++++++++++++++++++++++++++++++++++------
 1 file changed, 52 insertions(+), 7 deletions(-)
security/security.c +52 -7
index 25a019cc4a2b..2541a512a0f7 100644
@@ -34,6 +34,9 @@
 
 #define MAX_LSM_EVM_XATTR	2
 
+/* How many LSMs were built into the kernel? */
+#define LSM_COUNT (__end_lsm_info - __start_lsm_info)
+
 struct security_hook_heads security_hook_heads __lsm_ro_after_init;
 static ATOMIC_NOTIFIER_HEAD(lsm_notifier_chain);
 
@@ -41,6 +44,9 @@ char *lsm_names;
 /* Boot-time LSM user choice */
 static __initdata const char *chosen_major_lsm;
 
+/* Ordered list of LSMs to initialize. */
+static __initdata struct lsm_info **ordered_lsms;
+
 static bool debug __initdata;
 #define init_debug(...)						\
 	do {							\
@@ -74,6 +80,45 @@ static void __init set_enabled(struct lsm_info *lsm, bool enabled)
 	}
 }
 
+/* Is an LSM already listed in the ordered LSMs list? */
+static bool __init exists_ordered_lsm(struct lsm_info *lsm)
+{
+	struct lsm_info **check;
+
+	for (check = ordered_lsms; *check; check++)
+		if (*check == lsm)
+			return true;
+
+	return false;
+}
+
+/* Append an LSM to the list of ordered LSMs to initialize. */
+static int last_lsm __initdata;
+static void __init append_ordered_lsm(struct lsm_info *lsm, const char *from)
+{
+	/* Ignore duplicate selections. */
+	if (exists_ordered_lsm(lsm))
+		return;
+
+	if (WARN(last_lsm == LSM_COUNT, "%s: out of LSM slots!?\n", from))
+		return;
+
+	ordered_lsms[last_lsm++] = lsm;
+	init_debug("%s ordering: %s (%sabled)\n", from, lsm->name,
+		   (!lsm->enabled || *lsm->enabled) ? "en" : "dis");
+}
+
+/* Populate ordered LSMs list from hard-coded list of LSMs. */
+static void __init prepare_lsm_order(void)
+{
+	struct lsm_info *lsm;
+
+	for (lsm = __start_lsm_info; lsm < __end_lsm_info; lsm++) {
+		if (strcmp(lsm->name, "integrity") == 0)
+			append_ordered_lsm(lsm, "builtin");
+	}
+}
+
 /* Is an LSM allowed to be enabled? */
 static bool __init lsm_allowed(struct lsm_info *lsm)
 {
@@ -104,14 +149,10 @@ static void __init maybe_initialize_lsm(struct lsm_info *lsm)
 
 static void __init ordered_lsm_init(void)
 {
-	struct lsm_info *lsm;
-
-	for (lsm = __start_lsm_info; lsm < __end_lsm_info; lsm++) {
-		if ((lsm->flags & LSM_FLAG_LEGACY_MAJOR) != 0)
-			continue;
+	struct lsm_info **lsm;
 
-		maybe_initialize_lsm(lsm);
-	}
+	for (lsm = ordered_lsms; *lsm; lsm++)
+		maybe_initialize_lsm(*lsm);
 }
 
 static void __init major_lsm_init(void)
@@ -141,6 +182,8 @@ int __init security_init(void)
 	for (i = 0; i < sizeof(security_hook_heads) / sizeof(struct hlist_head);
 	     i++)
 		INIT_HLIST_HEAD(&list[i]);
+	ordered_lsms = kcalloc(LSM_COUNT + 1, sizeof(*ordered_lsms),
+				GFP_KERNEL);
 
 	/* Process "security=", if given. */
 	if (!chosen_major_lsm)
@@ -169,6 +212,7 @@ int __init security_init(void)
 	loadpin_add_hooks();
 
 	/* Load LSMs in specified order. */
+	prepare_lsm_order();
 	ordered_lsm_init();
 
 	/*
@@ -176,6 +220,7 @@ int __init security_init(void)
 	 */
 	major_lsm_init();
 
+	kfree(ordered_lsms);
 	return 0;
 }
 
author
#21 lore raw

Re: [PATCH security-next v2 18/26] LSM: Build ordered list of ordered LSMs for init

Quoted 5 lines · Casey Schaufler
Quoted 4 lines · Kees Cook

This constructs a list of ordered LSMs to initialize, using a hard-coded list of only "integrity": minor LSMs continue to have direct hook calls, and major LSMs continue to initialize separately.

Quoted 8 lines
Quoted 1 line

Do you think that this mechanism will be sufficiently flexible to accommodate dynamically loaded security modules in the future? While I am not personally an advocate of dynamically loaded security modules I have been working to ensure that I haven't done anything that would actively interfere with someone who did.

I don't think it does, no. This is all just the boot time initialization order, so a dynamic LSM would be unchanged: it would initialize at module load time. :)

-Kees

Signature · 2 lines
Kees Cook
Pixel Security
author
#22 lore raw

PATCH v2 19/26 LSM: Introduce CONFIG_LSM_ORDER

In reply to Kees Cook

This provides a way to declare LSM initialization order via Kconfig.

---
 security/Kconfig    | 11 +++++++++++
 security/security.c | 38 +++++++++++++++++++++++++++++++++++---
 2 files changed, 46 insertions(+), 3 deletions(-)
security/Kconfig +11 -0
index 27d8b2688f75..de8202886c1d 100644
@@ -276,5 +276,16 @@ config DEFAULT_SECURITY
 	default "apparmor" if DEFAULT_SECURITY_APPARMOR
 	default "" if DEFAULT_SECURITY_DAC
 
+config LSM_ORDER
+	string "Default initialization order of builtin LSMs"
+	default "integrity"
+	help
+	  A comma-separated list of LSMs, in initialization order.
+	  Any LSMs left off this list will be link-order initialized
+	  after any listed LSMs. Any LSMs listed here but not built in
+	  the kernel will be ignored.
+
+	  If unsure, leave this as the default.
+
 endmenu
 
security/security.c +35 -3
index 2541a512a0f7..063ee2466e58 100644
@@ -44,6 +44,8 @@ char *lsm_names;
 /* Boot-time LSM user choice */
 static __initdata const char *chosen_major_lsm;
 
+static __initconst const char * const builtin_lsm_order = CONFIG_LSM_ORDER;
+
 /* Ordered list of LSMs to initialize. */
 static __initdata struct lsm_info **ordered_lsms;
 
@@ -108,14 +110,44 @@ static void __init append_ordered_lsm(struct lsm_info *lsm, const char *from)
 		   (!lsm->enabled || *lsm->enabled) ? "en" : "dis");
 }
 
-/* Populate ordered LSMs list from hard-coded list of LSMs. */
+/* Populate ordered LSMs list from given string. */
+static void __init parse_lsm_order(const char *order, const char *origin)
+{
+	struct lsm_info *lsm;
+	char *sep, *name, *next;
+
+	sep = kstrdup(order, GFP_KERNEL);
+	next = sep;
+	/* Walk the list, looking for matching LSMs. */
+	while ((name = strsep(&next, ",")) != NULL) {
+		bool found = false;
+
+		for (lsm = __start_lsm_info; lsm < __end_lsm_info; lsm++) {
+			if ((lsm->flags & LSM_FLAG_LEGACY_MAJOR) == 0 &&
+			    strcmp(lsm->name, name) == 0) {
+				append_ordered_lsm(lsm, origin);
+				found = true;
+			}
+		}
+
+		if (!found)
+			init_debug("%s ignored: %s\n", origin, name);
+	}
+	kfree(sep);
+}
+
+/* Populate ordered LSMs list from builtin list of LSMs. */
 static void __init prepare_lsm_order(void)
 {
 	struct lsm_info *lsm;
 
+	/* Parse order from builtin list. */
+	parse_lsm_order(builtin_lsm_order, "builtin");
+
+	/* Add any missing LSMs, in link order. */
 	for (lsm = __start_lsm_info; lsm < __end_lsm_info; lsm++) {
-		if (strcmp(lsm->name, "integrity") == 0)
-			append_ordered_lsm(lsm, "builtin");
+		if ((lsm->flags & LSM_FLAG_LEGACY_MAJOR) == 0)
+			append_ordered_lsm(lsm, "link-time");
 	}
 }
 
Signature · 1 line
2.17.1
maintainer
#23 lore raw

Re: [PATCH security-next v2 19/26] LSM: Introduce CONFIG_LSM_ORDER

Quoted 13 lines · Kees Cook

This provides a way to declare LSM initialization order via Kconfig.

---
 security/Kconfig    | 11 +++++++++++
 security/security.c | 38 +++++++++++++++++++++++++++++++++++---
 2 files changed, 46 insertions(+), 3 deletions(-)
security/Kconfig +0 -0
index 27d8b2688f75..de8202886c1d 100644

security/Kconfig config DEFAULT_SECURITY · line 281

Quoted 6 lines
security/Kconfig +3 -0
@@ -276,5 +276,16 @@ config DEFAULT_SECURITY
 	default "apparmor" if DEFAULT_SECURITY_APPARMOR
 	default "" if DEFAULT_SECURITY_DAC
 
+config LSM_ORDER
+	string "Default initialization order of builtin LSMs"
+	default "integrity"

I would like to see the default spelled out rather than provided implicitly.

+ default "integrity,yama,loadpin,selinux,smack,apparmor,tomoyo"

security/Kconfig config DEFAULT_SECURITY · line 286

Quoted 5 lines
security/Kconfig +5 -0
+	help
+	  A comma-separated list of LSMs, in initialization order.
+	  Any LSMs left off this list will be link-order initialized
+	  after any listed LSMs. Any LSMs listed here but not built in
+	  the kernel will be ignored.

This should also describe what will happen if you include multiple major modules in the list.

Quoted 66 lines
security/Kconfig +3 -0
+
+	  If unsure, leave this as the default.
+
 endmenu
 
security/security.c +35 -3
index 2541a512a0f7..063ee2466e58 100644
@@ -44,6 +44,8 @@ char *lsm_names;
 /* Boot-time LSM user choice */
 static __initdata const char *chosen_major_lsm;
 
+static __initconst const char * const builtin_lsm_order = CONFIG_LSM_ORDER;
+
 /* Ordered list of LSMs to initialize. */
 static __initdata struct lsm_info **ordered_lsms;
 
@@ -108,14 +110,44 @@ static void __init append_ordered_lsm(struct lsm_info *lsm, const char *from)
 		   (!lsm->enabled || *lsm->enabled) ? "en" : "dis");
 }
 
-/* Populate ordered LSMs list from hard-coded list of LSMs. */
+/* Populate ordered LSMs list from given string. */
+static void __init parse_lsm_order(const char *order, const char *origin)
+{
+	struct lsm_info *lsm;
+	char *sep, *name, *next;
+
+	sep = kstrdup(order, GFP_KERNEL);
+	next = sep;
+	/* Walk the list, looking for matching LSMs. */
+	while ((name = strsep(&next, ",")) != NULL) {
+		bool found = false;
+
+		for (lsm = __start_lsm_info; lsm < __end_lsm_info; lsm++) {
+			if ((lsm->flags & LSM_FLAG_LEGACY_MAJOR) == 0 &&
+			    strcmp(lsm->name, name) == 0) {
+				append_ordered_lsm(lsm, origin);
+				found = true;
+			}
+		}
+
+		if (!found)
+			init_debug("%s ignored: %s\n", origin, name);
+	}
+	kfree(sep);
+}
+
+/* Populate ordered LSMs list from builtin list of LSMs. */
 static void __init prepare_lsm_order(void)
 {
 	struct lsm_info *lsm;
 
+	/* Parse order from builtin list. */
+	parse_lsm_order(builtin_lsm_order, "builtin");
+
+	/* Add any missing LSMs, in link order. */
 	for (lsm = __start_lsm_info; lsm < __end_lsm_info; lsm++) {
-		if (strcmp(lsm->name, "integrity") == 0)
-			append_ordered_lsm(lsm, "builtin");
+		if ((lsm->flags & LSM_FLAG_LEGACY_MAJOR) == 0)
+			append_ordered_lsm(lsm, "link-time");
 	}
 }
 
maintainer
#24 lore raw

Re: [PATCH security-next v2 19/26] LSM: Introduce CONFIG_LSM_ORDER

Quoted 17 lines · Casey Schaufler
Quoted 16 lines · Kees Cook

This provides a way to declare LSM initialization order via Kconfig.

---
 security/Kconfig    | 11 +++++++++++
 security/security.c | 38 +++++++++++++++++++++++++++++++++++---
 2 files changed, 46 insertions(+), 3 deletions(-)
security/Kconfig +0 -0
index 27d8b2688f75..de8202886c1d 100644
@@ -276,5 +276,16 @@ config DEFAULT_SECURITY
 	default "apparmor" if DEFAULT_SECURITY_APPARMOR
 	default "" if DEFAULT_SECURITY_DAC
 
Quoted 7 lines

security/Kconfig config DEFAULT_SECURITY · line 281

Quoted 3 lines
security/Kconfig +3 -0
+config LSM_ORDER
+	string "Default initialization order of builtin LSMs"
+	default "integrity"

I would like to see the default spelled out rather than provided implicitly.

+ default "integrity,yama,loadpin,selinux,smack,apparmor,tomoyo"

I see now that comes later in the patch set. Never mind.

author
#25 lore raw

PATCH v2 20/26 LSM: Introduce "lsm.order=" for boottime ordering

In reply to Kees Cook

Provide a way to reorder LSM initialization using the new "lsm.order=" comma-separated list of LSMs. Any LSMs not listed will be added in builtin order.

---
 Documentation/admin-guide/kernel-parameters.txt |  5 +++++
 security/security.c                             | 15 ++++++++++++++-
 2 files changed, 19 insertions(+), 1 deletion(-)
Documentation/admin-guide/kernel-parameters.txt +5 -0
index 32d323ee9218..5ac4c1056ffa 100644
@@ -2276,6 +2276,11 @@
 
 	lsm.debug	[SECURITY] Enable LSM initialization debugging output.
 
+	lsm.order=lsm1,...,lsmN
+			[SECURITY] Choose order of LSM initialization. Any
+			builtin LSMs not listed here will be implicitly
+			added to the list in builtin order.
+
 	machvec=	[IA-64] Force the use of a particular machine-vector
 			(machvec) in a generic kernel.
 			Example: machvec=hpzx1_swiotlb
security/security.c +14 -1
index 063ee2466e58..4db194f81419 100644
@@ -43,6 +43,7 @@ static ATOMIC_NOTIFIER_HEAD(lsm_notifier_chain);
 char *lsm_names;
 /* Boot-time LSM user choice */
 static __initdata const char *chosen_major_lsm;
+static __initdata const char *chosen_lsm_order;
 
 static __initconst const char * const builtin_lsm_order = CONFIG_LSM_ORDER;
 
@@ -136,11 +137,15 @@ static void __init parse_lsm_order(const char *order, const char *origin)
 	kfree(sep);
 }
 
-/* Populate ordered LSMs list from builtin list of LSMs. */
+/* Populate ordered LSMs list from commandline and builtin list of LSMs. */
 static void __init prepare_lsm_order(void)
 {
 	struct lsm_info *lsm;
 
+	/* Parse order from commandline, if present. */
+	if (chosen_lsm_order)
+		parse_lsm_order(chosen_lsm_order, "cmdline");
+
 	/* Parse order from builtin list. */
 	parse_lsm_order(builtin_lsm_order, "builtin");
 
@@ -264,6 +269,14 @@ static int __init choose_major_lsm(char *str)
 }
 __setup("security=", choose_major_lsm);
 
+/* Explicitly choose LSM initialization order. */
+static int __init choose_lsm_order(char *str)
+{
+	chosen_lsm_order = str;
+	return 1;
+}
+__setup("lsm.order=", choose_lsm_order);
+
 /* Enable LSM order debugging. */
 static int __init enable_debug(char *str)
 {
Signature · 1 line
2.17.1
maintainer
#26 lore raw

Re: [PATCH security-next v2 20/26] LSM: Introduce "lsm.order=" for boottime ordering

Quoted 15 lines · Kees Cook

Provide a way to reorder LSM initialization using the new "lsm.order=" comma-separated list of LSMs. Any LSMs not listed will be added in builtin order.

---
 Documentation/admin-guide/kernel-parameters.txt |  5 +++++
 security/security.c                             | 15 ++++++++++++++-
 2 files changed, 19 insertions(+), 1 deletion(-)
Documentation/admin-guide/kernel-parameters.txt +0 -0
index 32d323ee9218..5ac4c1056ffa 100644

Documentation/admin-guide/kernel-parameters.txt line 2282

Quoted 7 lines
Documentation/admin-guide/kernel-parameters.txt +4 -0
@@ -2276,6 +2276,11 @@
 
 	lsm.debug	[SECURITY] Enable LSM initialization debugging output.
 
+	lsm.order=lsm1,...,lsmN
+			[SECURITY] Choose order of LSM initialization. Any
+			builtin LSMs not listed here will be implicitly
+			added to the list in builtin order.

Added at the end of the list, or beginning of the list?

Quoted 48 lines
Documentation/admin-guide/kernel-parameters.txt +1 -0
+
 	machvec=	[IA-64] Force the use of a particular machine-vector
 			(machvec) in a generic kernel.
 			Example: machvec=hpzx1_swiotlb
security/security.c +14 -1
index 063ee2466e58..4db194f81419 100644
@@ -43,6 +43,7 @@ static ATOMIC_NOTIFIER_HEAD(lsm_notifier_chain);
 char *lsm_names;
 /* Boot-time LSM user choice */
 static __initdata const char *chosen_major_lsm;
+static __initdata const char *chosen_lsm_order;
 
 static __initconst const char * const builtin_lsm_order = CONFIG_LSM_ORDER;
 
@@ -136,11 +137,15 @@ static void __init parse_lsm_order(const char *order, const char *origin)
 	kfree(sep);
 }
 
-/* Populate ordered LSMs list from builtin list of LSMs. */
+/* Populate ordered LSMs list from commandline and builtin list of LSMs. */
 static void __init prepare_lsm_order(void)
 {
 	struct lsm_info *lsm;
 
+	/* Parse order from commandline, if present. */
+	if (chosen_lsm_order)
+		parse_lsm_order(chosen_lsm_order, "cmdline");
+
 	/* Parse order from builtin list. */
 	parse_lsm_order(builtin_lsm_order, "builtin");
 
@@ -264,6 +269,14 @@ static int __init choose_major_lsm(char *str)
 }
 __setup("security=", choose_major_lsm);
 
+/* Explicitly choose LSM initialization order. */
+static int __init choose_lsm_order(char *str)
+{
+	chosen_lsm_order = str;
+	return 1;
+}
+__setup("lsm.order=", choose_lsm_order);
+
 /* Enable LSM order debugging. */
 static int __init enable_debug(char *str)
 {
author
#27 lore raw

Re: [PATCH security-next v2 20/26] LSM: Introduce "lsm.order=" for boottime ordering

Quoted 17 lines · Casey Schaufler
Quoted 16 lines · Kees Cook

Provide a way to reorder LSM initialization using the new "lsm.order=" comma-separated list of LSMs. Any LSMs not listed will be added in builtin order.

---
 Documentation/admin-guide/kernel-parameters.txt |  5 +++++
 security/security.c                             | 15 ++++++++++++++-
 2 files changed, 19 insertions(+), 1 deletion(-)
Documentation/admin-guide/kernel-parameters.txt +0 -0
index 32d323ee9218..5ac4c1056ffa 100644
@@ -2276,6 +2276,11 @@
 
Quoted 8 lines

Documentation/admin-guide/kernel-parameters.txt line 2282

Quoted 6 lines
Documentation/admin-guide/kernel-parameters.txt +4 -0
      lsm.debug       [SECURITY] Enable LSM initialization debugging output.
 
+     lsm.order=lsm1,...,lsmN
+                     [SECURITY] Choose order of LSM initialization. Any
+                     builtin LSMs not listed here will be implicitly
+                     added to the list in builtin order.

Added at the end of the list, or beginning of the list?

Whoops, I had an earlier version that was more clear. I meant to say "appended" instead of "added" here. Fixed for the next version.

-Kees

Signature · 2 lines
Kees Cook
Pixel Security
author
#28 lore raw

PATCH v2 21/26 LoadPin: Initialize as ordered LSM

In reply to Kees Cook

This converts LoadPin from being a direct "minor" LSM into an ordered LSM.

---
 include/linux/lsm_hooks.h  |  5 -----
 security/Kconfig           |  2 +-
 security/loadpin/loadpin.c | 10 ++++++++--
 security/security.c        |  1 -
 4 files changed, 9 insertions(+), 9 deletions(-)
include/linux/lsm_hooks.h +0 -5
index ec1c0a97dfe3..7a38ffdd690f 100644
@@ -2097,10 +2097,5 @@ extern void __init yama_add_hooks(void);
 #else
 static inline void __init yama_add_hooks(void) { }
 #endif
-#ifdef CONFIG_SECURITY_LOADPIN
-void __init loadpin_add_hooks(void);
-#else
-static inline void loadpin_add_hooks(void) { };
-#endif
 
 #endif /* ! __LINUX_LSM_HOOKS_H */
security/Kconfig +1 -1
index de8202886c1d..f2003bd03ef6 100644
@@ -278,7 +278,7 @@ config DEFAULT_SECURITY
 
 config LSM_ORDER
 	string "Default initialization order of builtin LSMs"
-	default "integrity"
+	default "loadpin,integrity"
 	help
 	  A comma-separated list of LSMs, in initialization order.
 	  Any LSMs left off this list will be link-order initialized
security/loadpin/loadpin.c +8 -2
index 0716af28808a..e638fba7363d 100644
@@ -184,12 +184,18 @@ static struct security_hook_list loadpin_hooks[] __lsm_ro_after_init = {
 	LSM_HOOK_INIT(kernel_load_data, loadpin_load_data),
 };
 
-void __init loadpin_add_hooks(void)
+static int __init loadpin_init(void)
 {
-	pr_info("ready to pin (currently %sabled)", enabled ? "en" : "dis");
+	pr_info("ready to pin\n");
 	security_add_hooks(loadpin_hooks, ARRAY_SIZE(loadpin_hooks), "loadpin");
+	return 0;
 }
 
+DEFINE_LSM(loadpin)
+	.enabled = &enabled,
+	.init = loadpin_init,
+END_LSM;
+
 /* Should not be mutable after boot, so not listed in sysfs (perm == 0). */
 module_param(enabled, int, 0);
 MODULE_PARM_DESC(enabled, "Pin module/firmware loading (default: true)");
security/security.c +0 -1
index 4db194f81419..9ffb76b7655b 100644
@@ -246,7 +246,6 @@ int __init security_init(void)
 	 */
 	capability_add_hooks();
 	yama_add_hooks();
-	loadpin_add_hooks();
 
 	/* Load LSMs in specified order. */
 	prepare_lsm_order();
Signature · 1 line
2.17.1
author
#29 lore raw

PATCH v2 22/26 Yama: Initialize as ordered LSM

In reply to Kees Cook

This converts Yama from being a direct "minor" LSM into an ordered LSM.

---
 include/linux/lsm_hooks.h | 5 -----
 security/Kconfig          | 2 +-
 security/security.c       | 1 -
 security/yama/yama_lsm.c  | 7 ++++++-
 4 files changed, 7 insertions(+), 8 deletions(-)
include/linux/lsm_hooks.h +0 -5
index 7a38ffdd690f..d75a42eb3ddd 100644
@@ -2092,10 +2092,5 @@ static inline void security_delete_hooks(struct security_hook_list *hooks,
 #endif /* CONFIG_SECURITY_WRITABLE_HOOKS */
 
 extern void __init capability_add_hooks(void);
-#ifdef CONFIG_SECURITY_YAMA
-extern void __init yama_add_hooks(void);
-#else
-static inline void __init yama_add_hooks(void) { }
-#endif
 
 #endif /* ! __LINUX_LSM_HOOKS_H */
security/Kconfig +1 -1
index f2003bd03ef6..33c9ac3cb759 100644
@@ -278,7 +278,7 @@ config DEFAULT_SECURITY
 
 config LSM_ORDER
 	string "Default initialization order of builtin LSMs"
-	default "loadpin,integrity"
+	default "yama,loadpin,integrity"
 	help
 	  A comma-separated list of LSMs, in initialization order.
 	  Any LSMs left off this list will be link-order initialized
security/security.c +0 -1
index 9ffb76b7655b..3fba28de789b 100644
@@ -245,7 +245,6 @@ int __init security_init(void)
 	 * Load minor LSMs, with the capability module always first.
 	 */
 	capability_add_hooks();
-	yama_add_hooks();
 
 	/* Load LSMs in specified order. */
 	prepare_lsm_order();
security/yama/yama_lsm.c +6 -1
index ffda91a4a1aa..f2b1f47f98e8 100644
@@ -477,9 +477,14 @@ static void __init yama_init_sysctl(void)
 static inline void yama_init_sysctl(void) { }
 #endif /* CONFIG_SYSCTL */
 
-void __init yama_add_hooks(void)
+static int __init yama_init(void)
 {
 	pr_info("Yama: becoming mindful.\n");
 	security_add_hooks(yama_hooks, ARRAY_SIZE(yama_hooks), "yama");
 	yama_init_sysctl();
+	return 0;
 }
+
+DEFINE_LSM(yama)
+	.init = yama_init,
+END_LSM;
Signature · 1 line
2.17.1
author
#30 lore raw

PATCH v2 23/26 LSM: Introduce enum lsm_order

In reply to Kees Cook

In preparation for distinguishing the "capability" LSM from other LSMs, it must be ordered first. This introduces LSM_ORDER_MUTABLE for the general LSMs, LSM_ORDER_FIRST for capabilities, and LSM_ORDER_LAST for anything that must run last (e.g. Landlock may use this in the future).

---
 include/linux/lsm_hooks.h |  7 +++++++
 security/security.c       | 22 ++++++++++++++++++++--
 2 files changed, 27 insertions(+), 2 deletions(-)
include/linux/lsm_hooks.h +7 -0
index d75a42eb3ddd..bf29851baf47 100644
@@ -2041,8 +2041,15 @@ extern void security_add_hooks(struct security_hook_list *hooks, int count,
 
 #define LSM_FLAG_LEGACY_MAJOR	(1 << 0)
 
+enum lsm_order {
+	LSM_ORDER_FIRST = -1,	/* This is only for capabilities. */
+	LSM_ORDER_MUTABLE = 0,
+	LSM_ORDER_LAST,
+};
+
 struct lsm_info {
 	const char *name;	/* Populated automatically. */
+	enum lsm_order order;	/* Optional: default is LSM_ORDER_MUTABLE */
 	unsigned long flags;	/* Optional: flags describing LSM */
 	int *enabled;		/* Optional: NULL means enabled. */
 	int (*init)(void);
security/security.c +20 -2
index 3fba28de789b..d649e7dea4c4 100644
@@ -62,6 +62,10 @@ static int lsm_enabled_true __initdata = 1;
 static int lsm_enabled_false __initdata = 0;
 static void __init set_enabled(struct lsm_info *lsm, bool enabled)
 {
+	/* First LSM cannot have enablement changed. */
+	if (lsm->order == LSM_ORDER_FIRST)
+		return;
+
 	if (!lsm->enabled) {
 		/*
 		 * If the LSM hasn't configured an enable flag, we
@@ -124,7 +128,8 @@ static void __init parse_lsm_order(const char *order, const char *origin)
 		bool found = false;
 
 		for (lsm = __start_lsm_info; lsm < __end_lsm_info; lsm++) {
-			if ((lsm->flags & LSM_FLAG_LEGACY_MAJOR) == 0 &&
+			if (lsm->order == LSM_ORDER_MUTABLE &&
+			    (lsm->flags & LSM_FLAG_LEGACY_MAJOR) == 0 &&
 			    strcmp(lsm->name, name) == 0) {
 				append_ordered_lsm(lsm, origin);
 				found = true;
@@ -142,6 +147,12 @@ static void __init prepare_lsm_order(void)
 {
 	struct lsm_info *lsm;
 
+	/* LSM_ORDER_FIRST is always first. */
+	for (lsm = __start_lsm_info; lsm < __end_lsm_info; lsm++) {
+		if (lsm->order == LSM_ORDER_FIRST)
+			append_ordered_lsm(lsm, "first");
+	}
+
 	/* Parse order from commandline, if present. */
 	if (chosen_lsm_order)
 		parse_lsm_order(chosen_lsm_order, "cmdline");
@@ -151,9 +162,16 @@ static void __init prepare_lsm_order(void)
 
 	/* Add any missing LSMs, in link order. */
 	for (lsm = __start_lsm_info; lsm < __end_lsm_info; lsm++) {
-		if ((lsm->flags & LSM_FLAG_LEGACY_MAJOR) == 0)
+		if (lsm->order == LSM_ORDER_MUTABLE &&
+		    (lsm->flags & LSM_FLAG_LEGACY_MAJOR) == 0)
 			append_ordered_lsm(lsm, "link-time");
 	}
+
+	/* LSM_ORDER_LAST is always last. */
+	for (lsm = __start_lsm_info; lsm < __end_lsm_info; lsm++) {
+		if (lsm->order == LSM_ORDER_LAST)
+			append_ordered_lsm(lsm, "last");
+	}
 }
 
 /* Is an LSM allowed to be enabled? */
Signature · 1 line
2.17.1
author
#31 lore raw

PATCH v2 24/26 capability: Mark as LSM_ORDER_FIRST

In reply to Kees Cook

This converts capabilities to use the new LSM_ORDER_FIRST position.

---
 include/linux/lsm_hooks.h | 2 --
 security/commoncap.c      | 8 +++++++-
 security/security.c       | 5 -----
 3 files changed, 7 insertions(+), 8 deletions(-)
include/linux/lsm_hooks.h +0 -2
index bf29851baf47..8e843eaacffb 100644
@@ -2098,6 +2098,4 @@ static inline void security_delete_hooks(struct security_hook_list *hooks,
 #define __lsm_ro_after_init	__ro_after_init
 #endif /* CONFIG_SECURITY_WRITABLE_HOOKS */
 
-extern void __init capability_add_hooks(void);
-
 #endif /* ! __LINUX_LSM_HOOKS_H */
security/commoncap.c +7 -1
index 2e489d6a3ac8..7a6abaec65de 100644
@@ -1366,10 +1366,16 @@ struct security_hook_list capability_hooks[] __lsm_ro_after_init = {
 	LSM_HOOK_INIT(vm_enough_memory, cap_vm_enough_memory),
 };
 
-void __init capability_add_hooks(void)
+static int __init capability_init(void)
 {
 	security_add_hooks(capability_hooks, ARRAY_SIZE(capability_hooks),
 				"capability");
+	return 0;
 }
 
+DEFINE_LSM(capability)
+	.order = LSM_ORDER_FIRST,
+	.init = capability_init,
+END_LSM;
+
 #endif /* CONFIG_SECURITY */
security/security.c +0 -5
index d649e7dea4c4..a40e938db1b0 100644
@@ -259,11 +259,6 @@ int __init security_init(void)
 		}
 	}
 
-	/*
-	 * Load minor LSMs, with the capability module always first.
-	 */
-	capability_add_hooks();
-
 	/* Load LSMs in specified order. */
 	prepare_lsm_order();
 	ordered_lsm_init();
Signature · 1 line
2.17.1
author
#32 lore raw

PATCH v2 25/26 LSM: Separate idea of "major" LSM from "exclusive" LSM

In reply to Kees Cook

In order to both support old "security=" Legacy Major LSM selection, and handling real exclusivity, this creates LSM_FLAG_EXCLUSIVE and updates the selection logic to handle them.

---
 include/linux/lsm_hooks.h  |  1 +
 security/apparmor/lsm.c    |  2 +-
 security/security.c        | 12 ++++++++++++
 security/selinux/hooks.c   |  2 +-
 security/smack/smack_lsm.c |  2 +-
 security/tomoyo/tomoyo.c   |  2 +-
 6 files changed, 17 insertions(+), 4 deletions(-)
include/linux/lsm_hooks.h +1 -0
index 8e843eaacffb..7d9c94d31279 100644
@@ -2040,6 +2040,7 @@ extern void security_add_hooks(struct security_hook_list *hooks, int count,
 				char *lsm);
 
 #define LSM_FLAG_LEGACY_MAJOR	(1 << 0)
+#define LSM_FLAG_EXCLUSIVE	(2 << 0)
 
 enum lsm_order {
 	LSM_ORDER_FIRST = -1,	/* This is only for capabilities. */
security/apparmor/lsm.c +1 -1
index 5399c2f03536..d68bc931d388 100644
@@ -1601,7 +1601,7 @@ static int __init apparmor_init(void)
 }
 
 DEFINE_LSM(apparmor)
-	.flags = LSM_FLAG_LEGACY_MAJOR,
+	.flags = LSM_FLAG_LEGACY_MAJOR | LSM_FLAG_EXCLUSIVE,
 	.enabled = &apparmor_enabled,
 	.init = apparmor_init,
 END_LSM;
security/security.c +12 -0
index a40e938db1b0..f076fdc6b451 100644
@@ -49,6 +49,7 @@ static __initconst const char * const builtin_lsm_order = CONFIG_LSM_ORDER;
 
 /* Ordered list of LSMs to initialize. */
 static __initdata struct lsm_info **ordered_lsms;
+static __initdata struct lsm_info *exclusive;
 
 static bool debug __initdata;
 #define init_debug(...)						\
@@ -181,6 +182,12 @@ static bool __init lsm_allowed(struct lsm_info *lsm)
 	if (lsm->enabled && !*lsm->enabled)
 		return false;
 
+	/* Not allowed if another exclusive LSM already initialized. */
+	if ((lsm->flags & LSM_FLAG_EXCLUSIVE) && exclusive) {
+		init_debug("exclusive disabled: %s\n", lsm->name);
+		return false;
+	}
+
 	return true;
 }
 
@@ -196,6 +203,11 @@ static void __init maybe_initialize_lsm(struct lsm_info *lsm)
 	if (enabled) {
 		int ret;
 
+		if ((lsm->flags & LSM_FLAG_EXCLUSIVE) && !exclusive) {
+			exclusive = lsm;
+			init_debug("exclusive: %s\n", lsm->name);
+		}
+
 		init_debug("initializing %s\n", lsm->name);
 		ret = lsm->init();
 		WARN(ret, "%s failed to initialize: %d\n", lsm->name, ret);
security/selinux/hooks.c +1 -1
index 409a9252aeb6..5461d54fcd99 100644
@@ -7193,7 +7193,7 @@ void selinux_complete_init(void)
 /* SELinux requires early initialization in order to label
    all processes and objects when they are created. */
 DEFINE_LSM(selinux)
-	.flags = LSM_FLAG_LEGACY_MAJOR,
+	.flags = LSM_FLAG_LEGACY_MAJOR | LSM_FLAG_EXCLUSIVE,
 	.enabled = &selinux_enabled,
 	.init = selinux_init,
 END_LSM;
security/smack/smack_lsm.c +1 -1
index e79fad43a8e3..e46c1ea8cf84 100644
@@ -4880,6 +4880,6 @@ static __init int smack_init(void)
  * all processes and objects when they are created.
  */
 DEFINE_LSM(smack)
-	.flags = LSM_FLAG_LEGACY_MAJOR,
+	.flags = LSM_FLAG_LEGACY_MAJOR | LSM_FLAG_EXCLUSIVE,
 	.init = smack_init,
 END_LSM;
security/tomoyo/tomoyo.c +1 -1
index 39bb994ebe09..cc39eb8df61a 100644
@@ -549,6 +549,6 @@ static int __init tomoyo_init(void)
 }
 
 DEFINE_LSM(tomoyo)
-	.flags = LSM_FLAG_LEGACY_MAJOR,
+	.flags = LSM_FLAG_LEGACY_MAJOR | LSM_FLAG_EXCLUSIVE,
 	.init = tomoyo_init,
 END_LSM;
Signature · 1 line
2.17.1
author
#33 lore raw

PATCH v2 26/26 LSM: Add all exclusive LSMs to ordered initialization

In reply to Kees Cook

This removes CONFIG_DEFAULT_SECURITY in favor of the explicit build-time ordering offered by CONFIG_LSM_ORDER, and adds all the exclusive LSMs to the ordered LSM initialization.

---
 security/Kconfig    | 39 +--------------------------------------
 security/security.c | 23 +----------------------
 2 files changed, 2 insertions(+), 60 deletions(-)
security/Kconfig +1 -38
index 33c9ac3cb759..a2e365420919 100644
@@ -239,46 +239,9 @@ source security/yama/Kconfig
 
 source security/integrity/Kconfig
 
-choice
-	prompt "Default security module"
-	default DEFAULT_SECURITY_SELINUX if SECURITY_SELINUX
-	default DEFAULT_SECURITY_SMACK if SECURITY_SMACK
-	default DEFAULT_SECURITY_TOMOYO if SECURITY_TOMOYO
-	default DEFAULT_SECURITY_APPARMOR if SECURITY_APPARMOR
-	default DEFAULT_SECURITY_DAC
-
-	help
-	  Select the security module that will be used by default if the
-	  kernel parameter security= is not specified.
-
-	config DEFAULT_SECURITY_SELINUX
-		bool "SELinux" if SECURITY_SELINUX=y
-
-	config DEFAULT_SECURITY_SMACK
-		bool "Simplified Mandatory Access Control" if SECURITY_SMACK=y
-
-	config DEFAULT_SECURITY_TOMOYO
-		bool "TOMOYO" if SECURITY_TOMOYO=y
-
-	config DEFAULT_SECURITY_APPARMOR
-		bool "AppArmor" if SECURITY_APPARMOR=y
-
-	config DEFAULT_SECURITY_DAC
-		bool "Unix Discretionary Access Controls"
-
-endchoice
-
-config DEFAULT_SECURITY
-	string
-	default "selinux" if DEFAULT_SECURITY_SELINUX
-	default "smack" if DEFAULT_SECURITY_SMACK
-	default "tomoyo" if DEFAULT_SECURITY_TOMOYO
-	default "apparmor" if DEFAULT_SECURITY_APPARMOR
-	default "" if DEFAULT_SECURITY_DAC
-
 config LSM_ORDER
 	string "Default initialization order of builtin LSMs"
-	default "yama,loadpin,integrity"
+	default "yama,loadpin,integrity,selinux,smack,tomoyo,apparmor"
 	help
 	  A comma-separated list of LSMs, in initialization order.
 	  Any LSMs left off this list will be link-order initialized
security/security.c +1 -22
index f076fdc6b451..628e62fda5fe 100644
@@ -130,7 +130,6 @@ static void __init parse_lsm_order(const char *order, const char *origin)
 
 		for (lsm = __start_lsm_info; lsm < __end_lsm_info; lsm++) {
 			if (lsm->order == LSM_ORDER_MUTABLE &&
-			    (lsm->flags & LSM_FLAG_LEGACY_MAJOR) == 0 &&
 			    strcmp(lsm->name, name) == 0) {
 				append_ordered_lsm(lsm, origin);
 				found = true;
@@ -163,8 +162,7 @@ static void __init prepare_lsm_order(void)
 
 	/* Add any missing LSMs, in link order. */
 	for (lsm = __start_lsm_info; lsm < __end_lsm_info; lsm++) {
-		if (lsm->order == LSM_ORDER_MUTABLE &&
-		    (lsm->flags & LSM_FLAG_LEGACY_MAJOR) == 0)
+		if (lsm->order == LSM_ORDER_MUTABLE)
 			append_ordered_lsm(lsm, "link-time");
 	}
 
@@ -222,18 +220,6 @@ static void __init ordered_lsm_init(void)
 		maybe_initialize_lsm(*lsm);
 }
 
-static void __init major_lsm_init(void)
-{
-	struct lsm_info *lsm;
-
-	for (lsm = __start_lsm_info; lsm < __end_lsm_info; lsm++) {
-		if ((lsm->flags & LSM_FLAG_LEGACY_MAJOR) == 0)
-			continue;
-
-		maybe_initialize_lsm(lsm);
-	}
-}
-
 /**
  * security_init - initializes the security framework
  *
@@ -253,8 +239,6 @@ int __init security_init(void)
 				GFP_KERNEL);
 
 	/* Process "security=", if given. */
-	if (!chosen_major_lsm)
-		chosen_major_lsm = CONFIG_DEFAULT_SECURITY;
 	if (chosen_major_lsm) {
 		struct lsm_info *lsm;
 
@@ -275,11 +259,6 @@ int __init security_init(void)
 	prepare_lsm_order();
 	ordered_lsm_init();
 
-	/*
-	 * Load all the remaining security modules.
-	 */
-	major_lsm_init();
-
 	kfree(ordered_lsms);
 	return 0;
 }
Signature · 1 line
2.17.1
maintainer
#34 lore raw

Re: [PATCH security-next v2 26/26] LSM: Add all exclusive LSMs to ordered initialization

Quoted 49 lines · Kees Cook

This removes CONFIG_DEFAULT_SECURITY in favor of the explicit build-time ordering offered by CONFIG_LSM_ORDER, and adds all the exclusive LSMs to the ordered LSM initialization.

---
 security/Kconfig    | 39 +--------------------------------------
 security/security.c | 23 +----------------------
 2 files changed, 2 insertions(+), 60 deletions(-)
security/Kconfig +0 -31
index 33c9ac3cb759..a2e365420919 100644
@@ -239,46 +239,9 @@ source security/yama/Kconfig
 
 source security/integrity/Kconfig
 
-choice
-	prompt "Default security module"
-	default DEFAULT_SECURITY_SELINUX if SECURITY_SELINUX
-	default DEFAULT_SECURITY_SMACK if SECURITY_SMACK
-	default DEFAULT_SECURITY_TOMOYO if SECURITY_TOMOYO
-	default DEFAULT_SECURITY_APPARMOR if SECURITY_APPARMOR
-	default DEFAULT_SECURITY_DAC
-
-	help
-	  Select the security module that will be used by default if the
-	  kernel parameter security= is not specified.
-
-	config DEFAULT_SECURITY_SELINUX
-		bool "SELinux" if SECURITY_SELINUX=y
-
-	config DEFAULT_SECURITY_SMACK
-		bool "Simplified Mandatory Access Control" if SECURITY_SMACK=y
-
-	config DEFAULT_SECURITY_TOMOYO
-		bool "TOMOYO" if SECURITY_TOMOYO=y
-
-	config DEFAULT_SECURITY_APPARMOR
-		bool "AppArmor" if SECURITY_APPARMOR=y
-
-	config DEFAULT_SECURITY_DAC
-		bool "Unix Discretionary Access Controls"
-
-endchoice
-
-config DEFAULT_SECURITY
-	string

security/Kconfig source security/yama/Kconfig · line 244

Quoted 10 lines
security/Kconfig +1 -7
-	default "selinux" if DEFAULT_SECURITY_SELINUX
-	default "smack" if DEFAULT_SECURITY_SMACK
-	default "tomoyo" if DEFAULT_SECURITY_TOMOYO
-	default "apparmor" if DEFAULT_SECURITY_APPARMOR
-	default "" if DEFAULT_SECURITY_DAC
-
 config LSM_ORDER
 	string "Default initialization order of builtin LSMs"
-	default "yama,loadpin,integrity"
+	default "yama,loadpin,integrity,selinux,smack,tomoyo,apparmor"

If I want to compile all the major modules into my kernel and use AppArmor by default would I use

default "yama,loadpin,integrity,apparmor,selinux,smack,tomoyo"

or

default "yama,loadpin,integrity,apparmor"

When we have "blob-sharing" how could I compile in tomoyo, but exclude it without a boot line option?

When we have full stacking, how could I compile in selinux but exclude it?

Quoted 65 lines
security/Kconfig +0 -0
 	help
 	  A comma-separated list of LSMs, in initialization order.
 	  Any LSMs left off this list will be link-order initialized
security/security.c +1 -22
index f076fdc6b451..628e62fda5fe 100644
@@ -130,7 +130,6 @@ static void __init parse_lsm_order(const char *order, const char *origin)
 
 		for (lsm = __start_lsm_info; lsm < __end_lsm_info; lsm++) {
 			if (lsm->order == LSM_ORDER_MUTABLE &&
-			    (lsm->flags & LSM_FLAG_LEGACY_MAJOR) == 0 &&
 			    strcmp(lsm->name, name) == 0) {
 				append_ordered_lsm(lsm, origin);
 				found = true;
@@ -163,8 +162,7 @@ static void __init prepare_lsm_order(void)
 
 	/* Add any missing LSMs, in link order. */
 	for (lsm = __start_lsm_info; lsm < __end_lsm_info; lsm++) {
-		if (lsm->order == LSM_ORDER_MUTABLE &&
-		    (lsm->flags & LSM_FLAG_LEGACY_MAJOR) == 0)
+		if (lsm->order == LSM_ORDER_MUTABLE)
 			append_ordered_lsm(lsm, "link-time");
 	}
 
@@ -222,18 +220,6 @@ static void __init ordered_lsm_init(void)
 		maybe_initialize_lsm(*lsm);
 }
 
-static void __init major_lsm_init(void)
-{
-	struct lsm_info *lsm;
-
-	for (lsm = __start_lsm_info; lsm < __end_lsm_info; lsm++) {
-		if ((lsm->flags & LSM_FLAG_LEGACY_MAJOR) == 0)
-			continue;
-
-		maybe_initialize_lsm(lsm);
-	}
-}
-
 /**
  * security_init - initializes the security framework
  *
@@ -253,8 +239,6 @@ int __init security_init(void)
 				GFP_KERNEL);
 
 	/* Process "security=", if given. */
-	if (!chosen_major_lsm)
-		chosen_major_lsm = CONFIG_DEFAULT_SECURITY;
 	if (chosen_major_lsm) {
 		struct lsm_info *lsm;
 
@@ -275,11 +259,6 @@ int __init security_init(void)
 	prepare_lsm_order();
 	ordered_lsm_init();
 
-	/*
-	 * Load all the remaining security modules.
-	 */
-	major_lsm_init();
-
 	kfree(ordered_lsms);
 	return 0;
 }
author
#35 lore raw

Re: [PATCH security-next v2 26/26] LSM: Add all exclusive LSMs to ordered initialization

Quoted 6 lines · Casey Schaufler

security/Kconfig source security/yama/Kconfig · line 244

Quoted 4 lines · Kees Cook

config LSM_ORDER
string "Default initialization order of builtin LSMs"

security/Kconfig +1 -1
-     default "yama,loadpin,integrity"
+     default "yama,loadpin,integrity,selinux,smack,tomoyo,apparmor"
Quoted 8 lines

If I want to compile all the major modules into my kernel and use AppArmor by default would I use

default "yama,loadpin,integrity,apparmor,selinux,smack,tomoyo"

or

default "yama,loadpin,integrity,apparmor"

I was expecting the former, but the latter will have the same result.

Quoted 2 lines

When we have "blob-sharing" how could I compile in tomoyo, but exclude it without a boot line option?

Ooh, yes, this series has no way to do that. Perhaps CONFIG_LSM_DISABLE in the same form as CONFIG_LSM_ORDER? I would totally remove LoadPin's CONFIG for this in favor it.

Quoted 2 lines

When we have full stacking, how could I compile in selinux but exclude it?

Yup, same problem. Same suggested solution?

Should lsm.enable/disable= also become a comma-separated list, or should I leave it as a multi-instance thing like I have it?

-Kees

Signature · 2 lines
Kees Cook
Pixel Security
maintainer
#36 lore raw

Re: [PATCH security-next v2 26/26] LSM: Add all exclusive LSMs to ordered initialization

Quoted 13 lines · Kees Cook
Quoted 12 lines · Casey Schaufler

security/Kconfig source security/yama/Kconfig · line 244

Quoted 4 lines · Kees Cook

config LSM_ORDER
string "Default initialization order of builtin LSMs"

security/Kconfig +1 -1
-     default "yama,loadpin,integrity"
+     default "yama,loadpin,integrity,selinux,smack,tomoyo,apparmor"

If I want to compile all the major modules into my kernel and use AppArmor by default would I use

default "yama,loadpin,integrity,apparmor,selinux,smack,tomoyo"

or

Quoted 8 lines
Quoted 1 line

default "yama,loadpin,integrity,apparmor"

I was expecting the former, but the latter will have the same result.

Quoted 2 lines

When we have "blob-sharing" how could I compile in tomoyo, but exclude it without a boot line option?

Ooh, yes, this series has no way to do that. Perhaps CONFIG_LSM_DISABLE in the same form as CONFIG_LSM_ORDER? I would totally remove LoadPin's CONFIG for this in favor it.

I would generally prefer an optional CONFIG_LSM_ENABLE to CONFIG_LSM_DISABLE, but I understand the logic behind your approach. I would be looking for something like

CONFIG LSM_ENABLE
string "Default set of enabled LSMs"
default ""

as opposed to

CONFIG LSM_DISABLE
string "Default set of disabled LSMs"
default ""

where an empty string is interpreted as "use 'em all" in either case.

Quoted 6 lines
Quoted 2 lines

When we have full stacking, how could I compile in selinux but exclude it?

Yup, same problem. Same suggested solution?

Should lsm.enable/disable= also become a comma-separated list, or should I leave it as a multi-instance thing like I have it?

I prefer the multi-instance
lsm.disable=selinux lsm.disable=yama
to the list
lsm.disable=selinux,yama

but at this point I don't really care all that much.

maintainer
#37 lore raw

Re: [PATCH security-next v2 26/26] LSM: Add all exclusive LSMs to ordered initialization

Quoted 10 lines · Casey Schaufler
Quoted 9 lines · Kees Cook
Quoted 8 lines · Casey Schaufler

security/Kconfig source security/yama/Kconfig · line 244

Quoted 4 lines · Kees Cook

config LSM_ORDER
string "Default initialization order of builtin LSMs"

security/Kconfig +1 -1
-     default "yama,loadpin,integrity"
+     default "yama,loadpin,integrity,selinux,smack,tomoyo,apparmor"

If I want to compile all the major modules into my kernel and use AppArmor by default would I use

Quoted 6 lines
Quoted 6 lines
Quoted 5 lines

default "yama,loadpin,integrity,apparmor,selinux,smack,tomoyo"

or

default "yama,loadpin,integrity,apparmor"

I was expecting the former, but the latter will have the same result.

t find having the two be equivalent violates expectations. At least when considering the end goal of full/extreme stacking, its trivially the same with current major lsms being exclusive

Quoted 11 lines
Quoted 6 lines
Quoted 3 lines

When we have "blob-sharing" how could I compile in tomoyo, but exclude it without a boot line option?

Ooh, yes, this series has no way to do that. Perhaps CONFIG_LSM_DISABLE in the same form as CONFIG_LSM_ORDER? I would totally remove LoadPin's CONFIG for this in favor it.

I would generally prefer an optional CONFIG_LSM_ENABLE to CONFIG_LSM_DISABLE, but I understand the logic behind your approach. I would be looking for something like

+1 on the CONFIG_LSM_ENABLE ove DISABLE

Quoted 20 lines

CONFIG LSM_ENABLE
string "Default set of enabled LSMs"
default ""

as opposed to

CONFIG LSM_DISABLE
string "Default set of disabled LSMs"
default ""

where an empty string is interpreted as "use 'em all" in either case.

Quoted 6 lines
Quoted 2 lines

When we have full stacking, how could I compile in selinux but exclude it?

Yup, same problem. Same suggested solution?

Should lsm.enable/disable= also become a comma-separated list, or should I leave it as a multi-instance thing like I have it?

Quoted 7 lines

I prefer the multi-instance
lsm.disable=selinux lsm.disable=yama
to the list
lsm.disable=selinux,yama

but at this point I don't really care all that much.

the comma separated list however is consistent with what is being done for default order

author
#38 lore raw

Re: [PATCH security-next v2 26/26] LSM: Add all exclusive LSMs to ordered initialization

Quoted 13 lines · John Johansen
Quoted 12 lines · Casey Schaufler
Quoted 11 lines · Kees Cook
Quoted 10 lines · Casey Schaufler

security/Kconfig source security/yama/Kconfig · line 244

Quoted 4 lines · Kees Cook

config LSM_ORDER
string "Default initialization order of builtin LSMs"

security/Kconfig +1 -1
-     default "yama,loadpin,integrity"
+     default "yama,loadpin,integrity,selinux,smack,tomoyo,apparmor"

If I want to compile all the major modules into my kernel and use AppArmor by default would I use

default "yama,loadpin,integrity,apparmor,selinux,smack,tomoyo"

Quoted 8 lines
Quoted 4 lines
Quoted 4 lines
Quoted 3 lines

or

default "yama,loadpin,integrity,apparmor"

I was expecting the former, but the latter will have the same result.

t find having the two be equivalent violates expectations. At least when considering the end goal of full/extreme stacking, its trivially the same with current major lsms being exclusive

This mixes "enablement" with "ordering", though, and I think the past threads have shown this to be largely problematic.

However, with CONFIG_LSM_ENABLED, we get the effect you're looking for, IIUC.

Quoted 6 lines
Quoted 6 lines
Quoted 5 lines
Quoted 2 lines

When we have "blob-sharing" how could I compile in tomoyo, but exclude it without a boot line option?

Ooh, yes, this series has no way to do that. Perhaps CONFIG_LSM_DISABLE in the same form as CONFIG_LSM_ORDER? I would totally remove LoadPin's CONFIG for this in favor it.

Quoted 18 lines
Quoted 4 lines

I would generally prefer an optional CONFIG_LSM_ENABLE to CONFIG_LSM_DISABLE, but I understand the logic behind your approach. I would be looking for something like

+1 on the CONFIG_LSM_ENABLE ove DISABLE

Quoted 12 lines

CONFIG LSM_ENABLE
string "Default set of enabled LSMs"
default ""

as opposed to

CONFIG LSM_DISABLE
string "Default set of disabled LSMs"
default ""

where an empty string is interpreted as "use 'em all" in either case.

Yes, I like CONFIG_LSM_ENABLE if "empty" means "enable all". Should CONFIG_LSM_ENABLE replace all the other CONFIG-based LSM enabling/disabling?

Quoted 12 lines
Quoted 12 lines
Quoted 6 lines
Quoted 2 lines

When we have full stacking, how could I compile in selinux but exclude it?

Yup, same problem. Same suggested solution?

Should lsm.enable/disable= also become a comma-separated list, or should I leave it as a multi-instance thing like I have it?

I prefer the multi-instance
lsm.disable=selinux lsm.disable=yama
to the list
lsm.disable=selinux,yama

Quoted 4 lines
Quoted 1 line

but at this point I don't really care all that much.

the comma separated list however is consistent with what is being done for default order

Yeah, and it would match the new CONFIG_LSM_ENABLE.

FWIW, it was tedious to type "lsm.enable" and "lsm.disable" over and over when doing testing, so I almost prefer the comma separated list at the end of the day. I'll ponder this a bit.

-Kees

Signature · 2 lines
Kees Cook
Pixel Security
maintainer
#39 lore raw

Re: [PATCH security-next v2 26/26] LSM: Add all exclusive LSMs to ordered initialization

Quoted 20 lines · Kees Cook
Quoted 18 lines · John Johansen
Quoted 16 lines · Casey Schaufler
Quoted 15 lines · Kees Cook
Quoted 5 lines · Casey Schaufler

security/Kconfig source security/yama/Kconfig · line 244

Quoted 4 lines · Kees Cook

config LSM_ORDER
string "Default initialization order of builtin LSMs"

security/Kconfig +1 -1
-     default "yama,loadpin,integrity"
+     default "yama,loadpin,integrity,selinux,smack,tomoyo,apparmor"
Quoted 8 lines

If I want to compile all the major modules into my kernel and use AppArmor by default would I use

default "yama,loadpin,integrity,apparmor,selinux,smack,tomoyo"

or

default "yama,loadpin,integrity,apparmor"

I was expecting the former, but the latter will have the same result.

Quoted 8 lines
Quoted 3 lines

t find having the two be equivalent violates expectations. At least when considering the end goal of full/extreme stacking, its trivially the same with current major lsms being exclusive

This mixes "enablement" with "ordering", though, and I think the past threads have shown this to be largely problematic.

However, with CONFIG_LSM_ENABLED, we get the effect you're looking for, IIUC.

no, I was just stating in a world where we have full stacking those two are not equivalent, as I would assume the order of any lsm not listed may end up being different.

Quoted 23 lines
Quoted 23 lines
Quoted 11 lines
Quoted 6 lines
Quoted 3 lines

When we have "blob-sharing" how could I compile in tomoyo, but exclude it without a boot line option?

Ooh, yes, this series has no way to do that. Perhaps CONFIG_LSM_DISABLE in the same form as CONFIG_LSM_ORDER? I would totally remove LoadPin's CONFIG for this in favor it.

I would generally prefer an optional CONFIG_LSM_ENABLE to CONFIG_LSM_DISABLE, but I understand the logic behind your approach. I would be looking for something like

+1 on the CONFIG_LSM_ENABLE ove DISABLE

Quoted 10 lines

CONFIG LSM_ENABLE
string "Default set of enabled LSMs"
default ""

as opposed to

CONFIG LSM_DISABLE
string "Default set of disabled LSMs"
default ""

Quoted 6 lines
Quoted 2 lines
Quoted 2 lines

where an empty string is interpreted as "use 'em all" in either case.

Yes, I like CONFIG_LSM_ENABLE if "empty" means "enable all". Should CONFIG_LSM_ENABLE replace all the other CONFIG-based LSM enabling/disabling?

I don't particularly like "empty" being "enable all". With that how would I disable all builtin lsms so that I just boot with capability.

An option of all or even * is more explicit and leaves the empty set to mean disable everything

Quoted 26 lines
Quoted 13 lines
Quoted 13 lines
Quoted 7 lines
Quoted 3 lines

When we have full stacking, how could I compile in selinux but exclude it?

Yup, same problem. Same suggested solution?

Should lsm.enable/disable= also become a comma-separated list, or should I leave it as a multi-instance thing like I have it?

I prefer the multi-instance
lsm.disable=selinux lsm.disable=yama
to the list
lsm.disable=selinux,yama

Quoted 4 lines
Quoted 1 line

but at this point I don't really care all that much.

the comma separated list however is consistent with what is being done for default order

Yeah, and it would match the new CONFIG_LSM_ENABLE.

FWIW, it was tedious to type "lsm.enable" and "lsm.disable" over and over when doing testing, so I almost prefer the comma separated list at the end of the day. I'll ponder this a bit.

-Kees

author
#40 lore raw

Re: [PATCH security-next v2 26/26] LSM: Add all exclusive LSMs to ordered initialization

Quoted 25 lines · John Johansen
Quoted 24 lines · Kees Cook
Quoted 21 lines · John Johansen
Quoted 10 lines · Casey Schaufler
Quoted 9 lines · Kees Cook
Quoted 8 lines · Casey Schaufler

Review

Quoted 4 lines · Kees Cook

config LSM_ORDER
string "Default initialization order of builtin LSMs"

(quoted diff) +1 -1
-     default "yama,loadpin,integrity"
+     default "yama,loadpin,integrity,selinux,smack,tomoyo,apparmor"

If I want to compile all the major modules into my kernel and use AppArmor by default would I use

Quoted 6 lines
Quoted 6 lines
Quoted 5 lines

default "yama,loadpin,integrity,apparmor,selinux,smack,tomoyo"

or

default "yama,loadpin,integrity,apparmor"

I was expecting the former, but the latter will have the same result.

t find having the two be equivalent violates expectations. At least when considering the end goal of full/extreme stacking, its trivially the same with current major lsms being exclusive

Quoted 8 lines
Quoted 4 lines

This mixes "enablement" with "ordering", though, and I think the past threads have shown this to be largely problematic.

However, with CONFIG_LSM_ENABLED, we get the effect you're looking for, IIUC.

no, I was just stating in a world where we have full stacking those two are not equivalent, as I would assume the order of any lsm not listed may end up being different.

Right, the ordering would be defined first by runtime (lsm.order=) followed any missing LSMs then ordered by their order in CONFIG_LSM_ORDER=, followed by any still missing LSMs then ordered by their order at link-time (which *may* be Makefile order, but could change with LTO, etc).

Quoted 29 lines
Quoted 22 lines
Quoted 22 lines
Quoted 10 lines
Quoted 5 lines
Quoted 2 lines

When we have "blob-sharing" how could I compile in tomoyo, but exclude it without a boot line option?

Ooh, yes, this series has no way to do that. Perhaps CONFIG_LSM_DISABLE in the same form as CONFIG_LSM_ORDER? I would totally remove LoadPin's CONFIG for this in favor it.

I would generally prefer an optional CONFIG_LSM_ENABLE to CONFIG_LSM_DISABLE, but I understand the logic behind your approach. I would be looking for something like

+1 on the CONFIG_LSM_ENABLE ove DISABLE

Quoted 10 lines

CONFIG LSM_ENABLE
string "Default set of enabled LSMs"
default ""

as opposed to

CONFIG LSM_DISABLE
string "Default set of disabled LSMs"
default ""

Quoted 6 lines
Quoted 2 lines
Quoted 2 lines

where an empty string is interpreted as "use 'em all" in either case.

Yes, I like CONFIG_LSM_ENABLE if "empty" means "enable all". Should CONFIG_LSM_ENABLE replace all the other CONFIG-based LSM enabling/disabling?

Quoted 6 lines

I don't particularly like "empty" being "enable all". With that how would I disable all builtin lsms so that I just boot with capability.

An option of all or even * is more explicit and leaves the empty set to mean disable everything

Okay, that works. I prefer "all" FWIW.

-Kees

Signature · 2 lines
Kees Cook
Pixel Security
maintainer
#41 lore raw

Re: [PATCH security-next v2 26/26] LSM: Add all exclusive LSMs to ordered initialization

Quoted 71 lines · Kees Cook
Quoted 25 lines · John Johansen
Quoted 24 lines · Kees Cook
Quoted 21 lines · John Johansen
Quoted 10 lines · Casey Schaufler
Quoted 9 lines · Kees Cook
Quoted 8 lines · Casey Schaufler

Review

Quoted 4 lines · Kees Cook

config LSM_ORDER
string "Default initialization order of builtin LSMs"

(quoted diff) +1 -1
-     default "yama,loadpin,integrity"
+     default "yama,loadpin,integrity,selinux,smack,tomoyo,apparmor"

If I want to compile all the major modules into my kernel and use AppArmor by default would I use

Quoted 6 lines
Quoted 6 lines
Quoted 5 lines

default "yama,loadpin,integrity,apparmor,selinux,smack,tomoyo"

or

default "yama,loadpin,integrity,apparmor"

I was expecting the former, but the latter will have the same result.

t find having the two be equivalent violates expectations. At least when considering the end goal of full/extreme stacking, its trivially the same with current major lsms being exclusive

Quoted 8 lines
Quoted 4 lines

This mixes "enablement" with "ordering", though, and I think the past threads have shown this to be largely problematic.

However, with CONFIG_LSM_ENABLED, we get the effect you're looking for, IIUC.

no, I was just stating in a world where we have full stacking those two are not equivalent, as I would assume the order of any lsm not listed may end up being different.

Right, the ordering would be defined first by runtime (lsm.order=) followed any missing LSMs then ordered by their order in CONFIG_LSM_ORDER=, followed by any still missing LSMs then ordered by their order at link-time (which *may* be Makefile order, but could change with LTO, etc).

Quoted 29 lines
Quoted 28 lines
Quoted 6 lines
Quoted 6 lines
Quoted 5 lines
Quoted 2 lines

When we have "blob-sharing" how could I compile in tomoyo, but exclude it without a boot line option?

Ooh, yes, this series has no way to do that. Perhaps CONFIG_LSM_DISABLE in the same form as CONFIG_LSM_ORDER? I would totally remove LoadPin's CONFIG for this in favor it.

Quoted 18 lines
Quoted 4 lines

I would generally prefer an optional CONFIG_LSM_ENABLE to CONFIG_LSM_DISABLE, but I understand the logic behind your approach. I would be looking for something like

+1 on the CONFIG_LSM_ENABLE ove DISABLE

Quoted 12 lines

CONFIG LSM_ENABLE
string "Default set of enabled LSMs"
default ""

as opposed to

CONFIG LSM_DISABLE
string "Default set of disabled LSMs"
default ""

where an empty string is interpreted as "use 'em all" in either case.

Yes, I like CONFIG_LSM_ENABLE if "empty" means "enable all". Should CONFIG_LSM_ENABLE replace all the other CONFIG-based LSM enabling/disabling?

Quoted 9 lines
Quoted 6 lines

I don't particularly like "empty" being "enable all". With that how would I disable all builtin lsms so that I just boot with capability.

An option of all or even * is more explicit and leaves the empty set to mean disable everything

Okay, that works. I prefer "all" FWIW.

me too, I was just trying to throw out options.

maintainer
#42 lore raw

Re: [PATCH security-next v2 26/26] LSM: Add all exclusive LSMs to ordered initialization

Quoted 14 lines · John Johansen
Quoted 13 lines · Kees Cook
Quoted 11 lines · John Johansen
Quoted 6 lines · Kees Cook

On Thu, Sep 20, 2018 at 6:39 PM, John Johansen
<[email protected]> wrote:

Yes, I like CONFIG_LSM_ENABLE if "empty" means "enable all". Should CONFIG_LSM_ENABLE replace all the other CONFIG-based LSM enabling/disabling?

I don't particularly like "empty" being "enable all". With that how would I disable all builtin lsms so that I just boot with capability.

Quoted 5 lines
Quoted 4 lines
Quoted 2 lines

An option of all or even * is more explicit and leaves the empty set to mean disable everything

Okay, that works. I prefer "all" FWIW.

me too, I was just trying to throw out options.

I'll buy that. "all" is fine by me, although it means we can't have an LSM named "all". :) We should also allow "none" to mean no LSMs. I know lots of people who love using security=none.

#43 lore raw
In reply to Kees Cook

Kees Cook - 20.09.18, 18:23:

Quoted 13 lines

v2:
- add "lsm.order=" and CONFIG_LSM_ORDER instead of overloading "security=" - reorganize introduction of ordering logic code

Updated cover letter:

This refactors the LSM registration and initialization infrastructure to more centrally support different LSM types. What was considered a "major" LSM is kept for legacy use of the "security=" boot parameter, and now overlaps with the new class of "exclusive" LSMs for the future blob sharing (to be added later). The "minor" LSMs become more well defined as a result of the refactoring.

Quoted 6 lines

Instead of continuing to (somewhat improperly) overload the kernel's initcall system, this changes the LSM infrastructure to store a registration structure (struct lsm_info) table instead, where metadata about each LSM can be recorded (name, flags, order, enable flag, init function). This can be extended in the future to include things like required blob size for the coming "blob sharing" LSMs.

I read the cover letter and still don´t know what this is about. Now I am certainly not engaged deeply with LSM. I bet my main missing piece
is: What is a "blob sharing" LSM.

I think it would improve the cover letter greatly if it explains briefly what is a major LSM, what is a minor LSM and what is a "blob sharing" LSM.

Why those are all needed? What is the actual security or end user benefit of this work? The questions are not to question your work. I bet it makes all perfect sense. I just did not understand its sense from reading the cover letter.

Quoted 83 lines

The "major" LSMs had to individually negotiate which of them should be enabled. This didn't provide a way to negotiate combinations of other LSMs (as will be needed for "blob sharing" LSMs). This is solved by providing the LSM infrastructure with all the details needed to make the choice (exposing the per-LSM "enabled" flag, if used, the LSM characteristics, and ordering expectations).

As a result of the refactoring, the "minor" LSMs are able to remove the open-coded security_add_hooks() calls for "capability", "yama", and "loadpin", and to redefine "integrity" properly as a general LSM. (Note that "integrity" actually defined _no_ hooks, but needs the early initialization).

With all LSMs being proessed centrally, it was possible to implement a new boot parameter "lsm.order=" to provide explicit ordering, which is helpful for the future "blob sharing" LSMs. Matching this is the new CONFIG_LSM_ORDER, which replaces CONFIG_DEFAULT_SECURITY, as it provides a higher granularity of control.

To better show LSMs activation some debug reporting was added (enabled with the "lsm.debug" boot commandline option).

Finally, I added a WARN() around LSM initialization failures, which appear to have always been silently ignored. (Realistically any LSM init failures would have only been due to catastrophic kernel issues that would render a system unworkable anyway, but it'd be better to expose the problem as early as possible.)

-Kees

Kees Cook (26):
LSM: Correctly announce start of LSM initialization vmlinux.lds.h: Avoid copy/paste of security_init section
LSM: Rename .security_initcall section to .lsm_info
LSM: Remove initcall tracing
LSM: Convert from initcall to struct lsm_info vmlinux.lds.h: Move LSM_TABLE into INIT_DATA
LSM: Convert security_initcall() into DEFINE_LSM()
LSM: Record LSM name in struct lsm_info
LSM: Provide init debugging infrastructure
LSM: Don't ignore initialization failures
LSM: Introduce LSM_FLAG_LEGACY_MAJOR
LSM: Provide separate ordered initialization
LSM: Plumb visibility into optional "enabled" state
LSM: Lift LSM selection out of individual LSMs
LSM: Introduce lsm.enable= and lsm.disable=
LSM: Prepare for reorganizing "security=" logic
LSM: Refactor "security=" in terms of enable/disable
LSM: Build ordered list of ordered LSMs for init
LSM: Introduce CONFIG_LSM_ORDER
LSM: Introduce "lsm.order=" for boottime ordering
LoadPin: Initialize as ordered LSM
Yama: Initialize as ordered LSM
LSM: Introduce enum lsm_order
capability: Mark as LSM_ORDER_FIRST
LSM: Separate idea of "major" LSM from "exclusive" LSM
LSM: Add all exclusive LSMs to ordered initialization

 .../admin-guide/kernel-parameters.txt         |   7 +
 arch/arc/kernel/vmlinux.lds.S                 |   1 -
 arch/arm/kernel/vmlinux-xip.lds.S             |   1 -
 arch/arm64/kernel/vmlinux.lds.S               |   1 -
 arch/h8300/kernel/vmlinux.lds.S               |   1 -
 arch/microblaze/kernel/vmlinux.lds.S          |   2 -
 arch/powerpc/kernel/vmlinux.lds.S             |   2 -
 arch/um/include/asm/common.lds.S              |   2 -
 arch/xtensa/kernel/vmlinux.lds.S              |   1 -
 include/asm-generic/vmlinux.lds.h             |  25 +-
 include/linux/init.h                          |   2 -
 include/linux/lsm_hooks.h                     |  43 ++-
 include/linux/module.h                        |   1 -
 security/Kconfig                              |  42 +--
 security/apparmor/lsm.c                       |  16 +-
 security/commoncap.c                          |   8 +-
 security/integrity/iint.c                     |   5 +-
 security/loadpin/loadpin.c                    |  10 +-
 security/security.c                           | 304
++++++++++++++---- security/selinux/hooks.c                      | 
16 +-
 security/smack/smack_lsm.c                    |   8 +-
 security/tomoyo/tomoyo.c                      |   7 +-
 security/yama/yama_lsm.c                      |   7 +-
 23 files changed, 348 insertions(+), 164 deletions(-)
Signature · 1 line
Martin
author
#44 lore raw
Quoted 25 lines · Martin Steigerwald

Kees Cook - 20.09.18, 18:23:

Quoted 13 lines

v2:
- add "lsm.order=" and CONFIG_LSM_ORDER instead of overloading "security=" - reorganize introduction of ordering logic code

Updated cover letter:

This refactors the LSM registration and initialization infrastructure to more centrally support different LSM types. What was considered a "major" LSM is kept for legacy use of the "security=" boot parameter, and now overlaps with the new class of "exclusive" LSMs for the future blob sharing (to be added later). The "minor" LSMs become more well defined as a result of the refactoring.

Quoted 6 lines

Instead of continuing to (somewhat improperly) overload the kernel's initcall system, this changes the LSM infrastructure to store a registration structure (struct lsm_info) table instead, where metadata about each LSM can be recorded (name, flags, order, enable flag, init function). This can be extended in the future to include things like required blob size for the coming "blob sharing" LSMs.

I read the cover letter and still don´t know what this is about. Now I am certainly not engaged deeply with LSM. I bet my main missing piece
is: What is a "blob sharing" LSM.

Quoted 8 lines

I think it would improve the cover letter greatly if it explains briefly what is a major LSM, what is a minor LSM and what is a "blob sharing" LSM.

Why those are all needed? What is the actual security or end user benefit of this work? The questions are not to question your work. I bet it makes all perfect sense. I just did not understand its sense from reading the cover letter.

Sure, thanks! I'll include more details for any later versions. This is mainly related to some internal refactoring the LSM is doing to support additional LSM that need more extensive "stacking" of the kernel internals. I aimed this at linux-doc@ and linux-arch@ to get feedback on the Documentation/ and linker script changes, respectively. In theory, users don't need to know anything about minor/major nor blob-sharing, as that should normally be all an internal issue.

Thanks!

-Kees

Signature · 2 lines
Kees Cook
Pixel Security