* [PATCH 1/3] drivers: char: mem: Make /dev/mem an optional device
2014-12-07 15:40 [PATCH 0/3] /dev/mem as optional device + associated tidy up robert.ward114
@ 2014-12-07 15:40 ` robert.ward114
2014-12-07 15:40 ` [PATCH 2/3] drivers: char: mem: Simplify DEVKMEM configuration robert.ward114
` (2 subsequent siblings)
3 siblings, 0 replies; 5+ messages in thread
From: robert.ward114 @ 2014-12-07 15:40 UTC (permalink / raw)
To: arnd, gregkh, linux-kernel; +Cc: Rob Ward
From: Rob Ward <robert.ward114@googlemail.com>
Adds Kconfig option CONFIG_DEVMEM that allows the
/dev/mem device to be disabled.
Option defaults to /dev/mem enabled.
Signed-off-by: Rob Ward <robert.ward114@googlemail.com>
---
drivers/char/Kconfig | 9 +++++++++
drivers/char/mem.c | 4 +++-
2 files changed, 12 insertions(+), 1 deletion(-)
diff --git a/drivers/char/Kconfig b/drivers/char/Kconfig
index efefd12..a4af822 100644
--- a/drivers/char/Kconfig
+++ b/drivers/char/Kconfig
@@ -6,6 +6,15 @@ menu "Character devices"
source "drivers/tty/Kconfig"
+config DEVMEM
+ bool "/dev/mem virtual device support"
+ default y
+ help
+ Say Y here if you want to support the /dev/mem device.
+ The /dev/mem device is used to access areas of physical
+ memory.
+ When in doubt, say "Y".
+
config DEVKMEM
bool "/dev/kmem virtual device support"
default y
diff --git a/drivers/char/mem.c b/drivers/char/mem.c
index 524b707..b2ca476 100644
--- a/drivers/char/mem.c
+++ b/drivers/char/mem.c
@@ -712,7 +712,7 @@ static int open_port(struct inode *inode, struct file *filp)
#define open_mem open_port
#define open_kmem open_mem
-static const struct file_operations mem_fops = {
+static const struct file_operations __maybe_unused mem_fops = {
.llseek = memory_lseek,
.read = read_mem,
.write = write_mem,
@@ -782,7 +782,9 @@ static const struct memdev {
const struct file_operations *fops;
struct backing_dev_info *dev_info;
} devlist[] = {
+#ifdef CONFIG_DEVMEM
[1] = { "mem", 0, &mem_fops, &directly_mappable_cdev_bdi },
+#endif
#ifdef CONFIG_DEVKMEM
[2] = { "kmem", 0, &kmem_fops, &directly_mappable_cdev_bdi },
#endif
--
2.0.2
^ permalink raw reply related [flat|nested] 5+ messages in thread* [PATCH 2/3] drivers: char: mem: Simplify DEVKMEM configuration
2014-12-07 15:40 [PATCH 0/3] /dev/mem as optional device + associated tidy up robert.ward114
2014-12-07 15:40 ` [PATCH 1/3] drivers: char: mem: Make /dev/mem an optional device robert.ward114
@ 2014-12-07 15:40 ` robert.ward114
2014-12-07 15:40 ` [PATCH 3/3] drivers: char: mem: Simplify DEVPORT configuration robert.ward114
2014-12-07 19:35 ` [PATCH 0/3] /dev/mem as optional device + associated tidy up Arnd Bergmann
3 siblings, 0 replies; 5+ messages in thread
From: robert.ward114 @ 2014-12-07 15:40 UTC (permalink / raw)
To: arnd, gregkh, linux-kernel; +Cc: Rob Ward
From: Rob Ward <robert.ward114@googlemail.com>
Simplify the use of CONFIG_DEVKMEM by making the kmem_fops
so that it is __maybe_unused.
This enabled the multiple #ifdef's used for this structure
to be removed and brings it in line with the use of CONFIG_DEVMEM
This change should introduce no functional changes.
Signed-off-by: Rob Ward <robert.ward114@googlemail.com>
---
drivers/char/mem.c | 8 +-------
1 file changed, 1 insertion(+), 7 deletions(-)
diff --git a/drivers/char/mem.c b/drivers/char/mem.c
index b2ca476..4521fea 100644
--- a/drivers/char/mem.c
+++ b/drivers/char/mem.c
@@ -338,7 +338,6 @@ static int mmap_mem(struct file *file, struct vm_area_struct *vma)
return 0;
}
-#ifdef CONFIG_DEVKMEM
static int mmap_kmem(struct file *file, struct vm_area_struct *vma)
{
unsigned long pfn;
@@ -359,9 +358,7 @@ static int mmap_kmem(struct file *file, struct vm_area_struct *vma)
vma->vm_pgoff = pfn;
return mmap_mem(file, vma);
}
-#endif
-#ifdef CONFIG_DEVKMEM
/*
* This function reads the *virtual* memory as seen by the kernel.
*/
@@ -541,7 +538,6 @@ static ssize_t write_kmem(struct file *file, const char __user *buf,
*ppos = p;
return virtr + wrote ? : err;
}
-#endif
#ifdef CONFIG_DEVPORT
static ssize_t read_port(struct file *file, char __user *buf,
@@ -721,8 +717,7 @@ static const struct file_operations __maybe_unused mem_fops = {
.get_unmapped_area = get_unmapped_area_mem,
};
-#ifdef CONFIG_DEVKMEM
-static const struct file_operations kmem_fops = {
+static const struct file_operations __maybe_unused kmem_fops = {
.llseek = memory_lseek,
.read = read_kmem,
.write = write_kmem,
@@ -730,7 +725,6 @@ static const struct file_operations kmem_fops = {
.open = open_kmem,
.get_unmapped_area = get_unmapped_area_mem,
};
-#endif
static const struct file_operations null_fops = {
.llseek = null_lseek,
--
2.0.2
^ permalink raw reply related [flat|nested] 5+ messages in thread* [PATCH 3/3] drivers: char: mem: Simplify DEVPORT configuration
2014-12-07 15:40 [PATCH 0/3] /dev/mem as optional device + associated tidy up robert.ward114
2014-12-07 15:40 ` [PATCH 1/3] drivers: char: mem: Make /dev/mem an optional device robert.ward114
2014-12-07 15:40 ` [PATCH 2/3] drivers: char: mem: Simplify DEVKMEM configuration robert.ward114
@ 2014-12-07 15:40 ` robert.ward114
2014-12-07 19:35 ` [PATCH 0/3] /dev/mem as optional device + associated tidy up Arnd Bergmann
3 siblings, 0 replies; 5+ messages in thread
From: robert.ward114 @ 2014-12-07 15:40 UTC (permalink / raw)
To: arnd, gregkh, linux-kernel; +Cc: Rob Ward
From: Rob Ward <robert.ward114@googlemail.com>
Simplify the use of CONFIG_DEVPORT by making the port_fops
so that it includes __maybe_unused.
This enabled the multiple #ifdef's used for this structure
to be removed and brings it in line with the use of CONFIG_DEVMEM
This change should introduce no functional changes.
Signed-off-by: Rob Ward <robert.ward114@googlemail.com>
---
drivers/char/mem.c | 6 +-----
1 file changed, 1 insertion(+), 5 deletions(-)
diff --git a/drivers/char/mem.c b/drivers/char/mem.c
index 4521fea..39315fe 100644
--- a/drivers/char/mem.c
+++ b/drivers/char/mem.c
@@ -539,7 +539,6 @@ static ssize_t write_kmem(struct file *file, const char __user *buf,
return virtr + wrote ? : err;
}
-#ifdef CONFIG_DEVPORT
static ssize_t read_port(struct file *file, char __user *buf,
size_t count, loff_t *ppos)
{
@@ -580,7 +579,6 @@ static ssize_t write_port(struct file *file, const char __user *buf,
*ppos = i;
return tmp-buf;
}
-#endif
static ssize_t read_null(struct file *file, char __user *buf,
size_t count, loff_t *ppos)
@@ -735,14 +733,12 @@ static const struct file_operations null_fops = {
.splice_write = splice_write_null,
};
-#ifdef CONFIG_DEVPORT
-static const struct file_operations port_fops = {
+static const struct file_operations __maybe_unused port_fops = {
.llseek = memory_lseek,
.read = read_port,
.write = write_port,
.open = open_port,
};
-#endif
static const struct file_operations zero_fops = {
.llseek = zero_lseek,
--
2.0.2
^ permalink raw reply related [flat|nested] 5+ messages in thread* Re: [PATCH 0/3] /dev/mem as optional device + associated tidy up
2014-12-07 15:40 [PATCH 0/3] /dev/mem as optional device + associated tidy up robert.ward114
` (2 preceding siblings ...)
2014-12-07 15:40 ` [PATCH 3/3] drivers: char: mem: Simplify DEVPORT configuration robert.ward114
@ 2014-12-07 19:35 ` Arnd Bergmann
3 siblings, 0 replies; 5+ messages in thread
From: Arnd Bergmann @ 2014-12-07 19:35 UTC (permalink / raw)
To: robert.ward114; +Cc: gregkh, linux-kernel
On Sunday 07 December 2014 15:40:32 robert.ward114@googlemail.com wrote:
> From: Rob Ward <robert.ward114@googlemail.com>
>
> Makes the /dev/mem device optional using the CONFIG_DEVMEM option.
>
> This brings /dev/mem in line with /dev/kmem so it can de disabled.
> Disabling /dev/mem is preferable on devices that do not require
> direct access to memory in order to improve security. This is especially
> true on platforms where no restiction is placed on the areas of memory
> that can be accessed(for example mips) without custom modifcations to
> the kernel source.
>
> The implementation of this functionality declares the mem_fops structure
> as __maybe_unused to eliminate the need for #ifdefs throughout the
> file.
>
> Follow up changes are present to change CONFIG_DEVKMEM and CONFIG_DEVPORT
> to use __maybe_unused. This simplifies the code and make the
> implementations consistent.
>
Acked-by: Arnd Bergmann <arnd@arndb.de>
^ permalink raw reply [flat|nested] 5+ messages in thread