Skip to contentSkip to conversation

LSM: LoadPin for module and firmware loading restrictions

PATCH In review Kees Cook 2 participants 5 messages Jul 24, 2015 – Jul 28, 2015

Subsystems (2)
lore
Share & tools
lore

Kees Cook

author
#0 lore raw

PATCH 1/1 LSM: LoadPin for module and firmware loading restrictions

This LSM enforces that kernel-loaded modules and firmware must all come from the same filesystem, with the expectation that such a filesystem is backed by a read-only device such as dm-verity or CDROM. This allows systems that have a verified and/or unchangeable filesystem to enforce module and firmware loading restrictions without needing to sign the files individually.

---
 MAINTAINERS                |   6 +
 include/linux/lsm_hooks.h  |   5 +
 security/Kconfig           |   1 +
 security/Makefile          |   2 +
 security/loadpin/Kconfig   |   9 ++
 security/loadpin/Makefile  |   1 +
 security/loadpin/loadpin.c | 279 +++++++++++++++++++++++++++++++++++++++++++++
 security/security.c        |   2 +
 8 files changed, 305 insertions(+)
 create mode 100644 security/loadpin/Kconfig
 create mode 100644 security/loadpin/Makefile
 create mode 100644 security/loadpin/loadpin.c
MAINTAINERS +6 -0
index 2d3d55c8f5be..671e760cbe85 100644
@@ -9101,6 +9101,12 @@ T:	git git://git.kernel.org/pub/scm/linux/kernel/git/jj/apparmor-dev.git
 S:	Supported
 F:	security/apparmor/
 
+LOADPIN SECURITY MODULE
+M:	Kees Cook <[email protected]>
+T:	git git://git.kernel.org/pub/scm/linux/kernel/git/kees/linux.git lsm/loadpin
+S:	Supported
+F:	security/loadpin/
+
 SENSABLE PHANTOM
 M:	Jiri Slaby <[email protected]>
 S:	Maintained
include/linux/lsm_hooks.h +5 -0
index 9429f054c323..d8ceb8099bc0 100644
@@ -1884,5 +1884,10 @@ extern void __init capability_add_hooks(void);
 #ifdef CONFIG_SECURITY_YAMA_STACKED
 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 -0
index bf4ec46474b6..f09b58ef43af 100644
@@ -122,6 +122,7 @@ source security/selinux/Kconfig
 source security/smack/Kconfig
 source security/tomoyo/Kconfig
 source security/apparmor/Kconfig
+source security/loadpin/Kconfig
 source security/yama/Kconfig
 
 source security/integrity/Kconfig
security/Makefile +2 -0
index c9bfbc84ff50..f2d71cdb8e19 100644
@@ -8,6 +8,7 @@ subdir-$(CONFIG_SECURITY_SMACK)		+= smack
 subdir-$(CONFIG_SECURITY_TOMOYO)        += tomoyo
 subdir-$(CONFIG_SECURITY_APPARMOR)	+= apparmor
 subdir-$(CONFIG_SECURITY_YAMA)		+= yama
+subdir-$(CONFIG_SECURITY_LOADPIN)	+= loadpin
 
 # always enable default capabilities
 obj-y					+= commoncap.o
@@ -22,6 +23,7 @@ obj-$(CONFIG_AUDIT)			+= lsm_audit.o
 obj-$(CONFIG_SECURITY_TOMOYO)		+= tomoyo/
 obj-$(CONFIG_SECURITY_APPARMOR)		+= apparmor/
 obj-$(CONFIG_SECURITY_YAMA)		+= yama/
+obj-$(CONFIG_SECURITY_LOADPIN)		+= loadpin/
 obj-$(CONFIG_CGROUP_DEVICE)		+= device_cgroup.o
 
 # Object integrity file lists
security/loadpin/Kconfig new file +9 -0
new file mode 100644
index 000000000000..8efb8458a9a2
@@ -0,0 +1,9 @@
+config SECURITY_LOADPIN
+	bool "Pin loading of kernel modules and firmware to one filesystem"
+	depends on SECURITY && BLOCK
+	help
+	  Kernel module and firmware loading will be pinned to the first
+	  filesystem used for loading. Any files that come from other
+	  filesystems will be rejected. This is best used on systems
+	  without an initrd that have a root filesystem backed by a
+	  read-only device such as dm-verity or a CDROM.
security/loadpin/Makefile new file +1 -0
new file mode 100644
index 000000000000..c2d77f83037b
@@ -0,0 +1 @@
+obj-$(CONFIG_SECURITY_LOADPIN) += loadpin.o
security/loadpin/loadpin.c new file +279 -0

279 lines not on this page · raw message

security/security.c +2 -0
index 595fffab48b0..45557e200ac5 100644
@@ -65,6 +65,8 @@ int __init security_init(void)
 	 */
 	yama_add_hooks();
 #endif
+	loadpin_add_hooks();
+
 	/*
 	 * Load the chosen module if there is one.
 	 * This will also find yama if it is stacking
Signature · 6 lines
1.9.1


-- 
Kees Cook
Chrome OS Security
maintainer
#1 lore raw

security/loadpin/loadpin.c line 35

Quoted 7 lines · Kees Cook
security/loadpin/loadpin.c new file +7 -0
+
+/*
+ * Return an allocated string that has been escaped of special characters
+ * and double quotes, making it safe to log in quotes.
+ */
+static char *kstrdup_quotable(char *src)
+{

Do you think these should go into a library?

Signature · 2 lines
James Morris
<[email protected]>
author
#2 lore raw
Quoted 11 lines · James Morris

security/loadpin/loadpin.c line 35

Quoted 7 lines · Kees Cook
security/loadpin/loadpin.c new file +7 -0
+
+/*
+ * Return an allocated string that has been escaped of special characters
+ * and double quotes, making it safe to log in quotes.
+ */
+static char *kstrdup_quotable(char *src)
+{

Do you think these should go into a library?

Possibly. There are some other areas of code that almost do the same thing, but not exactly. Perhaps I'll first change Yama around to use it, then send these again.

-Kees

Signature · 2 lines
Kees Cook
Chrome OS Security
maintainer
#3 lore raw
Quoted 13 lines · Kees Cook
Quoted 11 lines · James Morris

security/loadpin/loadpin.c line 35

Quoted 7 lines · Kees Cook
security/loadpin/loadpin.c new file +7 -0
+
+/*
+ * Return an allocated string that has been escaped of special characters
+ * and double quotes, making it safe to log in quotes.
+ */
+static char *kstrdup_quotable(char *src)
+{

Do you think these should go into a library?

Quoted 3 lines

Possibly. There are some other areas of code that almost do the same thing, but not exactly. Perhaps I'll first change Yama around to use it, then send these again.

Ok. Is this the same code being used in ChromeOS?

Signature · 2 lines
James Morris
<[email protected]>
author
#4 lore raw
Quoted 15 lines · James Morris
Quoted 13 lines · Kees Cook
Quoted 11 lines · James Morris

security/loadpin/loadpin.c line 35

Quoted 7 lines · Kees Cook
security/loadpin/loadpin.c new file +7 -0
+
+/*
+ * Return an allocated string that has been escaped of special characters
+ * and double quotes, making it safe to log in quotes.
+ */
+static char *kstrdup_quotable(char *src)
+{

Do you think these should go into a library?

Quoted 5 lines
Quoted 3 lines

Possibly. There are some other areas of code that almost do the same thing, but not exactly. Perhaps I'll first change Yama around to use it, then send these again.

Ok. Is this the same code being used in ChromeOS?

Essentially, yes. As the kernels used by Chrome OS don't have LSM stacking, we merged a bunch of functionality into a single LSM. LoadPin is a logical subset of that LSM.

-Kees

Signature · 2 lines
Kees Cook
Chrome OS Security