cifs: Define usercopy region in cifs_request slab cache
authorDavid Windsor <dave@nullcore.net>
Sun, 11 Jun 2017 02:50:33 +0000 (22:50 -0400)
committerKees Cook <keescook@chromium.org>
Mon, 15 Jan 2018 20:07:57 +0000 (12:07 -0800)
commitde046449045a329bae5c9256e55b58a685a22532
tree7aa94c2a5f9506ad2ac0391f64211658ac3f92bb
parente9a0561b7c8ef964078fa340fc1983f1f6d30544
cifs: Define usercopy region in cifs_request slab cache

CIFS request buffers, stored in the cifs_request slab cache, need to be
copied to/from userspace.

cache object allocation:
    fs/cifs/cifsfs.c:
        cifs_init_request_bufs():
            ...
            cifs_req_poolp = mempool_create_slab_pool(cifs_min_rcv,
                                                      cifs_req_cachep);

    fs/cifs/misc.c:
        cifs_buf_get():
            ...
            ret_buf = mempool_alloc(cifs_req_poolp, GFP_NOFS);
            ...
            return ret_buf;

In support of usercopy hardening, this patch defines a region in the
cifs_request 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 dynamically sized copy operation involving
cache-managed memory falls entirely within the slab's usercopy region.

This patch is verbatim 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: David Windsor <dave@nullcore.net>
[kees: adjust commit log, provide usage trace]
Cc: Steve French <sfrench@samba.org>
Cc: linux-cifs@vger.kernel.org
Signed-off-by: Kees Cook <keescook@chromium.org>
fs/cifs/cifsfs.c