2016-10-27 14:49:53 +00:00
|
|
|
From 9f31204f829da97f99f7aacf30f0ddc26e456df7 Mon Sep 17 00:00:00 2001
|
2014-08-20 17:22:24 +00:00
|
|
|
From: Matthew Garrett <matthew.garrett@nebula.com>
|
|
|
|
Date: Fri, 9 Mar 2012 09:28:15 -0500
|
2016-10-27 14:49:53 +00:00
|
|
|
Subject: [PATCH 06/20] Restrict /dev/mem and /dev/kmem when module loading is
|
2014-08-20 17:22:24 +00:00
|
|
|
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
|
2016-10-27 14:49:53 +00:00
|
|
|
index 7f1a7ab5850d..d6a6f05fbc1c 100644
|
2014-08-20 17:22:24 +00:00
|
|
|
--- a/drivers/char/mem.c
|
|
|
|
+++ b/drivers/char/mem.c
|
2016-10-27 14:49:53 +00:00
|
|
|
@@ -164,6 +164,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;
|
|
|
|
|
2016-10-27 14:49:53 +00:00
|
|
|
@@ -516,6 +519,9 @@ static ssize_t write_kmem(struct file *file, const char __user *buf,
|
2016-10-04 16:00:00 +00:00
|
|
|
if (!pfn_valid(PFN_DOWN(p)))
|
|
|
|
return -EIO;
|
2014-08-20 17:22:24 +00:00
|
|
|
|
|
|
|
+ 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);
|
2015-09-09 15:10:06 +00:00
|
|
|
--
|
2016-10-27 14:49:53 +00:00
|
|
|
2.9.3
|
2015-09-09 15:10:06 +00:00
|
|
|
|