2014-08-20 17:22:24 +00:00
|
|
|
From: Matthew Garrett <matthew.garrett@nebula.com>
|
|
|
|
Date: Fri, 9 Mar 2012 09:28:15 -0500
|
|
|
|
Subject: [PATCH] Restrict /dev/mem and /dev/kmem when module loading is
|
|
|
|
restricted
|
|
|
|
|
|
|
|
Allowing users to write to address space makes it possible for the kernel
|
|
|
|
to be subverted, avoiding module loading restrictions. Prevent this when
|
|
|
|
any restrictions have been imposed on loading modules.
|
|
|
|
|
|
|
|
Signed-off-by: Matthew Garrett <matthew.garrett@nebula.com>
|
|
|
|
---
|
|
|
|
drivers/char/mem.c | 6 ++++++
|
|
|
|
1 file changed, 6 insertions(+)
|
|
|
|
|
|
|
|
diff --git a/drivers/char/mem.c b/drivers/char/mem.c
|
2015-04-16 14:55:18 +00:00
|
|
|
index 53fe675f9bd7..b52c88860532 100644
|
2014-08-20 17:22:24 +00:00
|
|
|
--- a/drivers/char/mem.c
|
|
|
|
+++ b/drivers/char/mem.c
|
2015-01-05 21:09:49 +00:00
|
|
|
@@ -167,6 +167,9 @@ static ssize_t write_mem(struct file *file, const char __user *buf,
|
2014-08-20 17:22:24 +00:00
|
|
|
if (p != *ppos)
|
|
|
|
return -EFBIG;
|
|
|
|
|
|
|
|
+ if (secure_modules())
|
|
|
|
+ return -EPERM;
|
|
|
|
+
|
|
|
|
if (!valid_phys_addr_range(p, count))
|
|
|
|
return -EFAULT;
|
|
|
|
|
2015-02-16 15:01:09 +00:00
|
|
|
@@ -513,6 +516,9 @@ static ssize_t write_kmem(struct file *file, const char __user *buf,
|
2014-08-20 17:22:24 +00:00
|
|
|
char *kbuf; /* k-addr because vwrite() takes vmlist_lock rwlock */
|
|
|
|
int err = 0;
|
|
|
|
|
|
|
|
+ if (secure_modules())
|
|
|
|
+ return -EPERM;
|
|
|
|
+
|
|
|
|
if (p < (unsigned long) high_memory) {
|
|
|
|
unsigned long to_write = min_t(unsigned long, count,
|
|
|
|
(unsigned long)high_memory - p);
|