• David Windsor's avatar
    dcache: Define usercopy region in dentry_cache slab cache · 80344266
    David Windsor authored
    When a dentry name is short enough, it can be stored directly in the
    dentry itself (instead in a separate kmalloc allocation). These dentry
    short names, stored in struct dentry.d_iname and therefore contained in
    the dentry_cache slab cache, need to be coped to userspace.
    
    cache object allocation:
        fs/dcache.c:
            __d_alloc(...):
                ...
                dentry = kmem_cache_alloc(dentry_cache, ...);
                ...
                dentry->d_name.name = dentry->d_iname;
    
    example usage trace:
        filldir+0xb0/0x140
        dcache_readdir+0x82/0x170
        iterate_dir+0x142/0x1b0
        SyS_getdents+0xb5/0x160
    
        fs/readdir.c:
            (called via ctx.actor by dir_emit)
            filldir(..., const char *name, ...):
                ...
                copy_to_user(..., name, namlen)
    
        fs/libfs.c:
            dcache_readdir(...):
                ...
                next = next_positive(dentry, p, 1)
                ...
                dir_emit(..., next->d_name.name, ...)
    
    In support of usercopy hardening, this patch defines a region in the
    dentry_cache slab cache in which userspace copy operations are allowed.
    
    This region is known as the slab cache's usercopy region. Slab caches can
    now check that each dynamic 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 hunks for kmalloc-specific things moved later]
    [kees: adjust commit log, provide usage trace]
    Cc: Alexander Viro <viro@zeniv.linux.org.uk>
    Cc: linux-fsdevel@vger.kernel.org
    Signed-off-by: default avatarKees Cook <keescook@chromium.org>
    80344266
dcache.c 94.5 KB