security: use mmap_min_addr indepedently of security models
authorChristoph Lameter <cl@linux-foundation.org>
Wed, 3 Jun 2009 20:04:31 +0000 (16:04 -0400)
committerGreg Kroah-Hartman <gregkh@suse.de>
Mon, 20 Jul 2009 03:44:59 +0000 (20:44 -0700)
commit e0a94c2a63f2644826069044649669b5e7ca75d3 upstream.

This patch removes the dependency of mmap_min_addr on CONFIG_SECURITY.
It also sets a default mmap_min_addr of 4096.

mmapping of addresses below 4096 will only be possible for processes
with CAP_SYS_RAWIO.

Signed-off-by: Christoph Lameter <cl@linux-foundation.org>
Acked-by: Eric Paris <eparis@redhat.com>
Looks-ok-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: James Morris <jmorris@namei.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
include/linux/mm.h
include/linux/security.h
kernel/sysctl.c
mm/Kconfig
mm/mmap.c
security/Kconfig
security/security.c

index ae9775d7e8af1f0bcf32541fffd8b5f751b6b17a..eeb7e56b15a472c3bb4db2d2b6973dc85aa00aa5 100644 (file)
@@ -572,12 +572,10 @@ static inline void set_page_links(struct page *page, enum zone_type zone,
  */
 static inline unsigned long round_hint_to_min(unsigned long hint)
 {
-#ifdef CONFIG_SECURITY
        hint &= PAGE_MASK;
        if (((void *)hint != NULL) &&
            (hint < mmap_min_addr))
                return PAGE_ALIGN(mmap_min_addr);
-#endif
        return hint;
 }
 
index 80c4d002864cb2f3e9db8ebb575de2baeafe47c8..1638afdbe4e30a0813ea68f598a5b1f7d619b2f6 100644 (file)
@@ -2134,6 +2134,8 @@ static inline int security_file_mmap(struct file *file, unsigned long reqprot,
                                     unsigned long addr,
                                     unsigned long addr_only)
 {
+       if ((addr < mmap_min_addr) && !capable(CAP_SYS_RAWIO))
+               return -EACCES;
        return 0;
 }
 
index 6816e6db0ab0709c9029c77357bea2d0d6e4d429..1228d65903a0480d04aef460cf0715aacba980fb 100644 (file)
@@ -1132,7 +1132,6 @@ static struct ctl_table vm_table[] = {
                .strategy       = &sysctl_jiffies,
        },
 #endif
-#ifdef CONFIG_SECURITY
        {
                .ctl_name       = CTL_UNNUMBERED,
                .procname       = "mmap_min_addr",
@@ -1141,7 +1140,6 @@ static struct ctl_table vm_table[] = {
                .mode           = 0644,
                .proc_handler   = &proc_doulongvec_minmax,
        },
-#endif
 #ifdef CONFIG_NUMA
        {
                .ctl_name       = CTL_UNNUMBERED,
index 0bd9c2dbb2a0be8d184b4b9f1d75dc03ec2a14ba..07b4ec477103e5166b83df6dc53fcabcd9ea18cd 100644 (file)
@@ -208,3 +208,21 @@ config VIRT_TO_BUS
 
 config MMU_NOTIFIER
        bool
+
+config DEFAULT_MMAP_MIN_ADDR
+        int "Low address space to protect from user allocation"
+        default 4096
+        help
+         This is the portion of low virtual memory which should be protected
+         from userspace allocation.  Keeping a user from writing to low pages
+         can help reduce the impact of kernel NULL pointer bugs.
+
+         For most ia64, ppc64 and x86 users with lots of address space
+         a value of 65536 is reasonable and should cause no problems.
+         On arm and other archs it should not be higher than 32768.
+         Programs which use vm86 functionality would either need additional
+         permissions from either the LSM or the capabilities module or have
+         this protection disabled.
+
+         This value can be changed after boot using the
+         /proc/sys/vm/mmap_min_addr tunable.
index 2ae093ed2cac75f068f2dbbe47518fd2171eebfd..d330758ccfed08539069b80c6e1c44b899fb519d 100644 (file)
--- a/mm/mmap.c
+++ b/mm/mmap.c
@@ -86,6 +86,9 @@ int sysctl_overcommit_ratio = 50;     /* default is 50% */
 int sysctl_max_map_count __read_mostly = DEFAULT_MAX_MAP_COUNT;
 atomic_long_t vm_committed_space = ATOMIC_LONG_INIT(0);
 
+/* amount of vm to protect from userspace access */
+unsigned long mmap_min_addr = CONFIG_DEFAULT_MMAP_MIN_ADDR;
+
 /*
  * Check that a process has enough memory to allocate a new virtual
  * mapping. 0 means there is enough memory for the allocation to
index 559293922a479eabf188b70e963d5264f9032799..38411dddfea11c28fc8fe815d4043b1aac27e403 100644 (file)
@@ -92,28 +92,8 @@ config SECURITY_ROOTPLUG
 
          See <http://www.linuxjournal.com/article.php?sid=6279> for
          more information about this module.
-         
-         If you are unsure how to answer this question, answer N.
-
-config SECURITY_DEFAULT_MMAP_MIN_ADDR
-        int "Low address space to protect from user allocation"
-        depends on SECURITY
-        default 0
-        help
-         This is the portion of low virtual memory which should be protected
-         from userspace allocation.  Keeping a user from writing to low pages
-         can help reduce the impact of kernel NULL pointer bugs.
-
-         For most ia64, ppc64 and x86 users with lots of address space
-         a value of 65536 is reasonable and should cause no problems.
-         On arm and other archs it should not be higher than 32768.
-         Programs which use vm86 functionality would either need additional
-         permissions from either the LSM or the capabilities module or have
-         this protection disabled.
-
-         This value can be changed after boot using the
-         /proc/sys/vm/mmap_min_addr tunable.
 
+         If you are unsure how to answer this question, answer N.
 
 source security/selinux/Kconfig
 source security/smack/Kconfig
index 3a4b4f55b33f373d5a85145d61e6de95cce4bf3c..27a315db6a00b253d10ab2f0795ba4f21e19f3e2 100644 (file)
@@ -26,9 +26,6 @@ extern void security_fixup_ops(struct security_operations *ops);
 
 struct security_operations *security_ops;      /* Initialized to NULL */
 
-/* amount of vm to protect from userspace access */
-unsigned long mmap_min_addr = CONFIG_SECURITY_DEFAULT_MMAP_MIN_ADDR;
-
 static inline int verify(struct security_operations *ops)
 {
        /* verify the security_operations structure exists */