ea38f2f
From 9f31204f829da97f99f7aacf30f0ddc26e456df7 Mon Sep 17 00:00:00 2001
6a91557
From: Matthew Garrett <matthew.garrett@nebula.com>
6a91557
Date: Fri, 9 Mar 2012 09:28:15 -0500
ea38f2f
Subject: [PATCH 06/20] Restrict /dev/mem and /dev/kmem when module loading is
6a91557
 restricted
6a91557
6a91557
Allowing users to write to address space makes it possible for the kernel
6a91557
to be subverted, avoiding module loading restrictions. Prevent this when
6a91557
any restrictions have been imposed on loading modules.
6a91557
6a91557
Signed-off-by: Matthew Garrett <matthew.garrett@nebula.com>
6a91557
---
6a91557
 drivers/char/mem.c | 6 ++++++
6a91557
 1 file changed, 6 insertions(+)
6a91557
6a91557
diff --git a/drivers/char/mem.c b/drivers/char/mem.c
ea38f2f
index 7f1a7ab5850d..d6a6f05fbc1c 100644
6a91557
--- a/drivers/char/mem.c
6a91557
+++ b/drivers/char/mem.c
ea38f2f
@@ -164,6 +164,9 @@ static ssize_t write_mem(struct file *file, const char __user *buf,
6a91557
 	if (p != *ppos)
6a91557
 		return -EFBIG;
6a91557
 
6a91557
+	if (secure_modules())
6a91557
+		return -EPERM;
6a91557
+
6a91557
 	if (!valid_phys_addr_range(p, count))
6a91557
 		return -EFAULT;
6a91557
 
ea38f2f
@@ -516,6 +519,9 @@ static ssize_t write_kmem(struct file *file, const char __user *buf,
b92ba30
 	if (!pfn_valid(PFN_DOWN(p)))
b92ba30
 		return -EIO;
6a91557
 
6a91557
+	if (secure_modules())
6a91557
+		return -EPERM;
6a91557
+
6a91557
 	if (p < (unsigned long) high_memory) {
6a91557
 		unsigned long to_write = min_t(unsigned long, count,
6a91557
 					       (unsigned long)high_memory - p);
18c8249
-- 
ea38f2f
2.9.3
18c8249