mtd: Disable slram and phram when securelevel is enabled
authorBen Hutchings <ben@decadent.org.uk>
Thu, 2 Jun 2016 23:48:39 +0000 (00:48 +0100)
committerAurelien Jarno <aurel32@debian.org>
Fri, 2 Mar 2018 07:52:22 +0000 (07:52 +0000)
The slram and phram drivers both allow mapping regions of physical
address space such that they can then be read and written by userland
through the MTD interface.  This is probably usable to manipulate
hardware into overwriting kernel code on many systems.  Prevent that
if securelevel is set.

Signed-off-by: Ben Hutchings <ben@decadent.org.uk>
Gbp-Pq: Topic features/all/securelevel
Gbp-Pq: Name mtd-disable-slram-and-phram-when-securelevel-is-enabled.patch

drivers/mtd/devices/phram.c
drivers/mtd/devices/slram.c

index 8b66e52ca3ccb811e818dce496ca6e0fcc7c9ecb..df136924a4b39d5d7c63da5500c4b96afb56b486 100644 (file)
@@ -25,6 +25,7 @@
 #include <linux/moduleparam.h>
 #include <linux/slab.h>
 #include <linux/mtd/mtd.h>
+#include <linux/security.h>
 
 struct phram_mtd_list {
        struct mtd_info mtd;
@@ -226,6 +227,9 @@ static int phram_setup(const char *val)
        uint64_t len;
        int i, ret;
 
+       if (get_securelevel() > 0)
+               return -EPERM;
+
        if (strnlen(val, sizeof(buf)) >= sizeof(buf))
                parse_err("parameter too long\n");
 
index a70eb83e68f12cb82fc6d30f55261883191ce196..f6ce816080d1d8c816867814ba2a37c2162bf06c 100644 (file)
@@ -42,6 +42,7 @@
 #include <linux/ioctl.h>
 #include <linux/init.h>
 #include <linux/io.h>
+#include <linux/security.h>
 
 #include <linux/mtd/mtd.h>
 
@@ -230,6 +231,9 @@ static int parse_cmdline(char *devname, char *szstart, char *szlength)
        unsigned long devstart;
        unsigned long devlength;
 
+       if (get_securelevel() > 0)
+               return -EPERM;
+
        if ((!devname) || (!szstart) || (!szlength)) {
                unregister_devices();
                return(-EINVAL);