All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] sparc64 - strict devmem
@ 2014-03-03 17:00 Bob Picco
  2014-03-04 20:46 ` David Miller
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: Bob Picco @ 2014-03-03 17:00 UTC (permalink / raw)
  To: sparclinux

From: bob picco <bpicco@meloft.net>

This patch adds support to enable STRICT_DEVMEM for sparc64. By selecting the
new config option you enable this feature.

CC: Sam Ravnborg <sam@ravnborg.org>
Signed-off-by: Bob Picco <bob.picco@oracle.com>
---
 arch/sparc/Kconfig.debug         |    8 ++++++++
 arch/sparc/include/asm/page_64.h |    1 +
 arch/sparc/mm/init_64.c          |   11 +++++++++++
 3 files changed, 20 insertions(+), 0 deletions(-)

diff --git a/arch/sparc/Kconfig.debug b/arch/sparc/Kconfig.debug
index 6db35fb..92f2388 100644
--- a/arch/sparc/Kconfig.debug
+++ b/arch/sparc/Kconfig.debug
@@ -6,6 +6,14 @@ config TRACE_IRQFLAGS_SUPPORT
 
 source "lib/Kconfig.debug"
 
+config STRICT_DEVMEM
+	bool "Filter access to /dev/mem"
+	---help---
+	  If this option is disabled, you allow userspace (root) access to all
+	  of memory, including kernel and userspace memory. Accidental
+	  access to this is obviously disastrous, but specific access can
+	  be used by people debugging the kernel.
+
 config DEBUG_DCFLUSH
 	bool "D-cache flush debugging"
 	depends on SPARC64 && DEBUG_KERNEL
diff --git a/arch/sparc/include/asm/page_64.h b/arch/sparc/include/asm/page_64.h
index aac53fc..e54ee50 100644
--- a/arch/sparc/include/asm/page_64.h
+++ b/arch/sparc/include/asm/page_64.h
@@ -36,6 +36,7 @@ extern void hugetlb_setup(struct pt_regs *regs);
 
 #define WANT_PAGE_VIRTUAL
 
+extern int devmem_is_allowed(unsigned long pagenr);
 extern void _clear_page(void *page);
 #define clear_page(X)	_clear_page((void *)(X))
 struct page;
diff --git a/arch/sparc/mm/init_64.c b/arch/sparc/mm/init_64.c
index a4a9b69..0a38a42 100644
--- a/arch/sparc/mm/init_64.c
+++ b/arch/sparc/mm/init_64.c
@@ -2759,3 +2759,14 @@ static int __init report_memory(void)
 	return 0;
 }
 device_initcall(report_memory);
+
+#ifdef CONFIG_STRICT_DEVMEM
+int devmem_is_allowed(unsigned long pagenr)
+{
+	unsigned long phys_addr = pagenr << PAGE_SHIFT;
+	unsigned long virt_addr = (unsigned long) __va(phys_addr);
+	int rc = kern_addr_valid(virt_addr);
+
+	return rc;
+}
+#endif /* CONFIG_STRICT_DEVMEM */
-- 
1.7.1


^ permalink raw reply related	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2014-03-05 20:18 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2014-03-03 17:00 [PATCH] sparc64 - strict devmem Bob Picco
2014-03-04 20:46 ` David Miller
2014-03-05 13:11 ` Bob Picco
2014-03-05 20:18 ` Bob Picco

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.