From: Ben Hutchings Date: Thu, 2 Jun 2016 23:48:39 +0000 (+0100) Subject: mtd: Disable slram and phram when securelevel is enabled X-Git-Tag: archive/raspbian/4.9.82-1+deb9u3+rpi1_jessie~8^2~32 X-Git-Url: https://dgit.raspbian.org/?a=commitdiff_plain;h=dfb6aadd30ee107cb6f7768a4f0cf739f8ef9432;p=linux-4.9.git mtd: Disable slram and phram when securelevel is enabled 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 Gbp-Pq: Topic features/all/securelevel Gbp-Pq: Name mtd-disable-slram-and-phram-when-securelevel-is-enabled.patch --- diff --git a/drivers/mtd/devices/phram.c b/drivers/mtd/devices/phram.c index 8b66e52ca3cc..df136924a4b3 100644 --- a/drivers/mtd/devices/phram.c +++ b/drivers/mtd/devices/phram.c @@ -25,6 +25,7 @@ #include #include #include +#include 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"); diff --git a/drivers/mtd/devices/slram.c b/drivers/mtd/devices/slram.c index a70eb83e68f1..f6ce816080d1 100644 --- a/drivers/mtd/devices/slram.c +++ b/drivers/mtd/devices/slram.c @@ -42,6 +42,7 @@ #include #include #include +#include #include @@ -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);