Re: Security fix for remapping of page 0 (was [PATCH] Change ZERO_SIZE_PTR to point at unmapped space)

From: Eric Paris
Date: Wed Jun 03 2009 - 15:15:02 EST


On Wed, Jun 3, 2009 at 2:59 PM, Christoph Lameter
<cl@xxxxxxxxxxxxxxxxxxxx> wrote:
> We could just move the check for mmap_min_addr out from
> CONFIG_SECURITY?
>
>
> Use mmap_min_addr indepedently of security models
>
> 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@xxxxxxxxxxxxxxxxxxxx>

NAK with SELinux on you now need both the SELinux mmap_zero
permission and the CAP_SYS_RAWIO permission. Previously you only
needed one or the other, depending on which was the predominant
LSM.....

Even if you want to argue that I have to take CAP_SYS_RAWIO in the
SELinux case what about all the other places? do_mremap? do_brk?
expand_downwards?

-Eric


> ===================================================================
> --- linux-2.6.orig/mm/mmap.c    2009-06-03 13:48:01.000000000 -0500
> +++ linux-2.6/mm/mmap.c 2009-06-03 13:48:10.000000000 -0500
> @@ -87,6 +87,9 @@ int sysctl_overcommit_ratio = 50;     /* def
>  int sysctl_max_map_count __read_mostly = DEFAULT_MAX_MAP_COUNT;
>  struct percpu_counter vm_committed_as;
>
> +/* 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
> @@ -1043,6 +1046,9 @@ unsigned long do_mmap_pgoff(struct file
>                }
>        }
>
> +       if ((addr < mmap_min_addr) && !capable(CAP_SYS_RAWIO))
> +               return -EACCES;
> +
>        error = security_file_mmap(file, reqprot, prot, flags, addr, 0);
>        if (error)
>                return error;
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/