• David Windsor's avatar
    fork: Define usercopy region in mm_struct slab caches · 07dcd7fe
    David Windsor authored
    In support of usercopy hardening, this patch defines a region in the
    mm_struct slab caches in which userspace copy operations are allowed.
    Only the auxv field is copied to userspace.
    
    cache object allocation:
        kernel/fork.c:
            #define allocate_mm()     (kmem_cache_alloc(mm_cachep, GFP_KERNEL))
    
            dup_mm():
                ...
                mm = allocate_mm();
    
            copy_mm(...):
                ...
                dup_mm();
    
            copy_process(...):
                ...
                copy_mm(...)
    
            _do_fork(...):
                ...
                copy_process(...)
    
    example usage trace:
    
        fs/binfmt_elf.c:
            create_elf_tables(...):
                ...
                elf_info = (elf_addr_t *)current->mm->saved_auxv;
                ...
                copy_to_user(..., elf_info, ei_index * sizeof(elf_addr_t))
    
            load_elf_binary(...):
                ...
                create_elf_tables(...);
    
    This region is known as the slab cache's usercopy region. Slab caches
    can now check that each dynamically sized copy operation involving
    cache-managed memory falls entirely within the slab's usercopy region.
    
    This patch is modified from Brad Spengler/PaX Team's PAX_USERCOPY
    whitelisting code in the last public patch of grsecurity/PaX based on my
    understanding of the code. Changes or omissions from the original code are
    mine and don't reflect the original grsecurity/PaX code.
    Signed-off-by: default avatarDavid Windsor <dave@nullcore.net>
    [kees: adjust commit log, split patch, provide usage trace]
    Cc: Ingo Molnar <mingo@kernel.org>
    Cc: Andrew Morton <akpm@linux-foundation.org>
    Cc: Thomas Gleixner <tglx@linutronix.de>
    Cc: Andy Lutomirski <luto@kernel.org>
    Signed-off-by: default avatarKees Cook <keescook@chromium.org>
    Acked-by: default avatarRik van Riel <riel@redhat.com>
    07dcd7fe
fork.c 59.1 KB