aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorsukadev@linux.vnet.ibm.com <sukadev@linux.vnet.ibm.com>2011-08-30 05:19:17 -0400
committerBenjamin Herrenschmidt <benh@kernel.crashing.org>2011-11-27 19:42:08 -0500
commit1d54cf2b973a6265789b382b7d305771321b9b57 (patch)
tree8103c4c2accf96fd40cb1fb32ee9797aa97d17ed
parent56368797d6c2d093bb0e7a7e5fe7b267274b6c58 (diff)
powerpc: Implement CONFIG_STRICT_DEVMEM
As described in the help text in the patch, this token restricts general access to /dev/mem as a way of increasing the security. Specifically, access to exclusive IOMEM and kernel RAM is denied unless CONFIG_STRICT_DEVMEM is set to 'n'. Implement the 'devmem_is_allowed()' interface for Powerpc. It will be called from range_is_allowed() when userpsace attempts to access /dev/mem. This patch is based on an earlier patch from Steve Best and with input from Paul Mackerras and Scott Wood. [BenH] Fixed a typo or two and removed the generic change which should be submitted as a separate patch Signed-off-by: Sukadev Bhattiprolu <sukadev@linux.vnet.ibm.com> Signed-off-by: Benjamin Herrenschmidt <benh@kernel.crashing.org>
-rw-r--r--arch/powerpc/Kconfig.debug12
-rw-r--r--arch/powerpc/include/asm/page.h1
-rw-r--r--arch/powerpc/mm/mem.c18
3 files changed, 31 insertions, 0 deletions
diff --git a/arch/powerpc/Kconfig.debug b/arch/powerpc/Kconfig.debug
index 1b8a9c905cf..4ccb2a009f7 100644
--- a/arch/powerpc/Kconfig.debug
+++ b/arch/powerpc/Kconfig.debug
@@ -336,4 +336,16 @@ config PPC_EARLY_DEBUG_CPM_ADDR
336 platform probing is done, all platforms selected must 336 platform probing is done, all platforms selected must
337 share the same address. 337 share the same address.
338 338
339config STRICT_DEVMEM
340 def_bool y
341 prompt "Filter access to /dev/mem"
342 help
343 This option restricts access to /dev/mem. If this option is
344 disabled, you allow userspace access to all memory, including
345 kernel and userspace memory. Accidental memory access is likely
346 to be disastrous.
347 Memory access is required for experts who want to debug the kernel.
348
349 If you are unsure, say Y.
350
339endmenu 351endmenu
diff --git a/arch/powerpc/include/asm/page.h b/arch/powerpc/include/asm/page.h
index dd9c4fd038e..9d7485c7e6f 100644
--- a/arch/powerpc/include/asm/page.h
+++ b/arch/powerpc/include/asm/page.h
@@ -290,6 +290,7 @@ extern void clear_user_page(void *page, unsigned long vaddr, struct page *pg);
290extern void copy_user_page(void *to, void *from, unsigned long vaddr, 290extern void copy_user_page(void *to, void *from, unsigned long vaddr,
291 struct page *p); 291 struct page *p);
292extern int page_is_ram(unsigned long pfn); 292extern int page_is_ram(unsigned long pfn);
293extern int devmem_is_allowed(unsigned long pfn);
293 294
294#ifdef CONFIG_PPC_SMLPAR 295#ifdef CONFIG_PPC_SMLPAR
295void arch_free_page(struct page *page, int order); 296void arch_free_page(struct page *page, int order);
diff --git a/arch/powerpc/mm/mem.c b/arch/powerpc/mm/mem.c
index 2dd6bdd31fe..22563b9664c 100644
--- a/arch/powerpc/mm/mem.c
+++ b/arch/powerpc/mm/mem.c
@@ -585,3 +585,21 @@ static int add_system_ram_resources(void)
585 return 0; 585 return 0;
586} 586}
587subsys_initcall(add_system_ram_resources); 587subsys_initcall(add_system_ram_resources);
588
589#ifdef CONFIG_STRICT_DEVMEM
590/*
591 * devmem_is_allowed(): check to see if /dev/mem access to a certain address
592 * is valid. The argument is a physical page number.
593 *
594 * Access has to be given to non-kernel-ram areas as well, these contain the
595 * PCI mmio resources as well as potential bios/acpi data regions.
596 */
597int devmem_is_allowed(unsigned long pfn)
598{
599 if (iomem_is_exclusive(pfn << PAGE_SHIFT))
600 return 0;
601 if (!page_is_ram(pfn))
602 return 1;
603 return 0;
604}
605#endif /* CONFIG_STRICT_DEVMEM */