1 From 4003b9a2c05f4d0d37535c3dffbf4a7b47d5c36c Mon Sep 17 00:00:00 2001
2 From: Maarten ter Huurne <maarten@treewalker.org>
3 Date: Wed, 8 Sep 2010 02:31:19 +0200
4 Subject: [PATCH 09/21] /dev/mem: Add kernel config option to omit this
7 Omitting this device prevents software from accessing the hardware directly, which can cause trouble if the kernel accesses the same hardware.
8 It also saves some space on embedded systems.
10 arch/x86/Kconfig.debug | 1 +
11 drivers/char/Kconfig | 10 ++++++++++
12 drivers/char/mem.c | 17 +++++++++++++++++
13 3 files changed, 28 insertions(+), 0 deletions(-)
15 --- a/arch/x86/Kconfig.debug
16 +++ b/arch/x86/Kconfig.debug
17 @@ -7,6 +7,7 @@ source "lib/Kconfig.debug"
20 bool "Filter access to /dev/mem"
23 If this option is disabled, you allow userspace (root) access to all
24 of memory, including kernel and userspace memory. Accidental
25 --- a/drivers/char/Kconfig
26 +++ b/drivers/char/Kconfig
27 @@ -6,6 +6,16 @@ menu "Character devices"
29 source "drivers/tty/Kconfig"
32 + bool "/dev/mem virtual device support"
35 + Say Y here if you want to support the /dev/mem device.
36 + Some X server drivers access the video hardware using this device.
37 + Accessing hardware directly from user space can be useful in some
38 + cases, but it is not without risks.
39 + When in doubt, say "N".
42 bool "/dev/kmem virtual device support"
44 --- a/drivers/char/mem.c
45 +++ b/drivers/char/mem.c
46 @@ -89,6 +89,8 @@ void __weak unxlate_dev_mem_ptr(unsigned
53 * This funcion reads the *physical* memory. The f_pos points directly to the
55 @@ -212,6 +214,10 @@ static ssize_t write_mem(struct file *fi
61 +#if defined(CONFIG_DEVMEM) || defined(CONFIG_DEVKMEM)
63 int __weak phys_mem_access_prot_allowed(struct file *file,
64 unsigned long pfn, unsigned long size, pgprot_t *vma_prot)
66 @@ -333,6 +339,8 @@ static int mmap_mem(struct file *file, s
73 static int mmap_kmem(struct file *file, struct vm_area_struct *vma)
75 @@ -696,6 +704,7 @@ static loff_t null_lseek(struct file *fi
76 return file->f_pos = 0;
79 +#if defined(CONFIG_DEVMEM) || defined(CONFIG_DEVKMEM) || defined(CONFIG_DEVPORT)
81 * The memory devices use the full 32/64 bits of the offset, and so we cannot
82 * check against negative addresses: they are ok. The return value is weird,
83 @@ -728,11 +737,15 @@ static loff_t memory_lseek(struct file *
84 mutex_unlock(&file->f_path.dentry->d_inode->i_mutex);
89 +#if defined(CONFIG_DEVMEM) || defined(CONFIG_DEVKMEM) || \
90 + defined(CONFIG_DEVPORT) || defined(CONFIG_CRASH_DUMP)
91 static int open_port(struct inode * inode, struct file * filp)
93 return capable(CAP_SYS_RAWIO) ? 0 : -EPERM;
97 #define zero_lseek null_lseek
98 #define full_lseek null_lseek
99 @@ -742,6 +755,7 @@ static int open_port(struct inode * inod
100 #define open_kmem open_mem
101 #define open_oldmem open_mem
103 +#ifdef CONFIG_DEVMEM
104 static const struct file_operations mem_fops = {
105 .llseek = memory_lseek,
107 @@ -750,6 +764,7 @@ static const struct file_operations mem_
109 .get_unmapped_area = get_unmapped_area_mem,
113 #ifdef CONFIG_DEVKMEM
114 static const struct file_operations kmem_fops = {
115 @@ -815,7 +830,9 @@ static const struct memdev {
116 const struct file_operations *fops;
117 struct backing_dev_info *dev_info;
119 +#ifdef CONFIG_DEVMEM
120 [1] = { "mem", 0, &mem_fops, &directly_mappable_cdev_bdi },
122 #ifdef CONFIG_DEVKMEM
123 [2] = { "kmem", 0, &kmem_fops, &directly_mappable_cdev_bdi },