0f09adf
From: Matthew Garrett <matthew.garrett@nebula.com>
0f09adf
Date: Fri, 9 Mar 2012 09:28:15 -0500
0f09adf
Subject: [PATCH] Restrict /dev/mem and /dev/kmem when module loading is
0f09adf
 restricted
0f09adf
0f09adf
Allowing users to write to address space makes it possible for the kernel
0f09adf
to be subverted, avoiding module loading restrictions. Prevent this when
0f09adf
any restrictions have been imposed on loading modules.
0f09adf
0f09adf
Signed-off-by: Matthew Garrett <matthew.garrett@nebula.com>
0f09adf
---
0f09adf
 drivers/char/mem.c | 6 ++++++
0f09adf
 1 file changed, 6 insertions(+)
0f09adf
0f09adf
diff --git a/drivers/char/mem.c b/drivers/char/mem.c
0f09adf
index cdf839f9defe..c63cf93b00eb 100644
0f09adf
--- a/drivers/char/mem.c
0f09adf
+++ b/drivers/char/mem.c
0f09adf
@@ -164,6 +164,9 @@ static ssize_t write_mem(struct file *file, const char __user *buf,
0f09adf
 	if (p != *ppos)
0f09adf
 		return -EFBIG;
0f09adf
 
0f09adf
+	if (secure_modules())
0f09adf
+		return -EPERM;
0f09adf
+
0f09adf
 	if (!valid_phys_addr_range(p, count))
0f09adf
 		return -EFAULT;
0f09adf
 
0f09adf
@@ -502,6 +505,9 @@ static ssize_t write_kmem(struct file *file, const char __user *buf,
0f09adf
 	char *kbuf; /* k-addr because vwrite() takes vmlist_lock rwlock */
0f09adf
 	int err = 0;
0f09adf
 
0f09adf
+	if (secure_modules())
0f09adf
+		return -EPERM;
0f09adf
+
0f09adf
 	if (p < (unsigned long) high_memory) {
0f09adf
 		unsigned long to_write = min_t(unsigned long, count,
0f09adf
 					       (unsigned long)high_memory - p);
0f09adf
-- 
0f09adf
1.9.3
0f09adf