From patchwork Mon Jun 19 23:36:31 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kees Cook X-Patchwork-Id: 9798109 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 6189460381 for ; Mon, 19 Jun 2017 23:44:15 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 5E9461FFB9 for ; Mon, 19 Jun 2017 23:44:15 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 52F0627DCD; Mon, 19 Jun 2017 23:44:15 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-2.4 required=2.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_MED, T_DKIM_INVALID, URIBL_BLACK autolearn=ham version=3.3.1 Received: from mother.openwall.net (mother.openwall.net [195.42.179.200]) by mail.wl.linuxfoundation.org (Postfix) with SMTP id 1390E26C9B for ; Mon, 19 Jun 2017 23:44:10 +0000 (UTC) Received: (qmail 6046 invoked by uid 550); 19 Jun 2017 23:43:39 -0000 Mailing-List: contact kernel-hardening-help@lists.openwall.com; run by ezmlm Precedence: bulk List-Post: List-Help: List-Unsubscribe: List-Subscribe: List-ID: Delivered-To: mailing list kernel-hardening@lists.openwall.com Received: (qmail 5485 invoked from network); 19 Jun 2017 23:43:31 -0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=cP34J2BkQHv/qRxPtU67X0JNuKJdxSdXHaIoZfAz8tA=; b=h4rXyI+4iJJQHgYQmuCovUD6i9H/9IriMzQld0GibormOJkrLsMfnzVgT3g/UASayq MUc9pE8/K4S73FVtHD7tDBljmX3NpRQizxWRmCHH+CXTXSBWQwR4O01np8KjeMl7A1Nh 2X3plHHjfwPchlk0K+EXE+znhp0mhM6HBbga8= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=cP34J2BkQHv/qRxPtU67X0JNuKJdxSdXHaIoZfAz8tA=; b=m8evmB8RCu2BsAM9Asd/zw68M3NSViFLNy2edWP9RgDcFwcL1QyTg7YU3l7poUAT1j CB9KWK22iEduW4sSDiiEDNmEN9/pHf47KxNO7Ph7mA4jAjhCQJaMGADJwDZV6Rw/Q3zn lN+1ow4AayXZjzQvHrvutlfXvCMrprQEKYUQpPrtcMcrngxWfNUKey2GWb9emihduJe4 QSwH7W5RRI+E+QBxi4A0SqIYK7H1uWv8ef6M9hr7gKZOyLVkdp2HPYuykDPbKdFMlU3e mALJ3P7Wpu3RYnRe5o7sZ3ktnJGBRnWQf/VVyxzR95J5PRC/Ejh7WqYYNfaC9vanr/7A l93w== X-Gm-Message-State: AKS2vOyDmWXDLgW39ucOuUXtVH0awG1karJOg8R/xSfSSEiPkvcH2DG/ 6+qOxmcfwPOI0B1y X-Received: by 10.98.43.7 with SMTP id r7mr23770865pfr.202.1497915800322; Mon, 19 Jun 2017 16:43:20 -0700 (PDT) From: Kees Cook To: kernel-hardening@lists.openwall.com Cc: Kees Cook , David Windsor , linux-mm@kvack.org, linux-kernel@vger.kernel.org Date: Mon, 19 Jun 2017 16:36:31 -0700 Message-Id: <1497915397-93805-18-git-send-email-keescook@chromium.org> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1497915397-93805-1-git-send-email-keescook@chromium.org> References: <1497915397-93805-1-git-send-email-keescook@chromium.org> Subject: [kernel-hardening] [PATCH 17/23] dcache: define usercopy region in dentry_cache slab cache X-Virus-Scanned: ClamAV using ClamSMTP From: David Windsor When a dentry name is short enough, it can be stored directly in the dentry itself. These dentry short names, stored in struct dentry.d_iname and therefore contained in the dentry_cache slab cache, need to be coped to/from userspace. 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 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: David Windsor [kees: adjust hunks for kmalloc-specific things moved later, adjust commit log] Signed-off-by: Kees Cook --- fs/dcache.c | 5 +++-- include/linux/slab.h | 5 +++++ 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/fs/dcache.c b/fs/dcache.c index f7f3c4114baa..bae2e148946c 100644 --- a/fs/dcache.c +++ b/fs/dcache.c @@ -3580,8 +3580,9 @@ static void __init dcache_init(void) * but it is probably not worth it because of the cache nature * of the dcache. */ - dentry_cache = KMEM_CACHE(dentry, - SLAB_RECLAIM_ACCOUNT|SLAB_PANIC|SLAB_MEM_SPREAD|SLAB_ACCOUNT); + dentry_cache = KMEM_CACHE_USERCOPY(dentry, + SLAB_RECLAIM_ACCOUNT|SLAB_PANIC|SLAB_MEM_SPREAD|SLAB_ACCOUNT, + d_iname); /* Hash may have been set up in dcache_init_early */ if (!hashdist) diff --git a/include/linux/slab.h b/include/linux/slab.h index a48f54238273..97f4a0117b3b 100644 --- a/include/linux/slab.h +++ b/include/linux/slab.h @@ -151,6 +151,11 @@ void memcg_destroy_kmem_caches(struct mem_cgroup *); sizeof(struct __struct), __alignof__(struct __struct),\ (__flags), NULL) +#define KMEM_CACHE_USERCOPY(__struct, __flags, __field) kmem_cache_create_usercopy(#__struct,\ + sizeof(struct __struct), __alignof__(struct __struct),\ + (__flags), offsetof(struct __struct, __field),\ + sizeof_field(struct __struct, __field), NULL) + /* * Common kmalloc functions provided by all allocators */