From patchwork Mon Jun 19 23:36:34 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kees Cook X-Patchwork-Id: 9798095 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 9BA4560381 for ; Mon, 19 Jun 2017 23:43:40 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 96D221FFB9 for ; Mon, 19 Jun 2017 23:43:40 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 8B92127DCD; Mon, 19 Jun 2017 23:43:40 +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 0E2E81FFB9 for ; Mon, 19 Jun 2017 23:43:34 +0000 (UTC) Received: (qmail 5494 invoked by uid 550); 19 Jun 2017 23:43:32 -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 5393 invoked from network); 19 Jun 2017 23:43:28 -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=e5MshN/6WTNE3ZliL8iUbd9i23qMaFGq9vEw6gwz8N8=; b=il2IJBZMHZzBxB0uDrBwkjGwmgWHCxmxtD9HX9NSYmdopZacFzzFHX+SCclY9RmVOr JG9gffpAY/Dbw3xhH9LXbrd3RZ9dWun2Q3/16jWHDDpMNlCT4NSw5x3ctgnVNUrbFcAt PFPaNrq+f0apHgxtX5PIJlCWCDLh4iGwPVktY= 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=e5MshN/6WTNE3ZliL8iUbd9i23qMaFGq9vEw6gwz8N8=; b=fG0LPK/pkEiTMrbAe+bEAiTSlM1QNG3PjTQLQrbFIVhpMXbCNehzFBKN7/B5BOlC4y w2GAJ/poF729ukbBpKbmDbsNpJ5iHD7Ooso+lAIhMn9IV/0yCdj1QfQvzr+s1/wgKlh8 wNi7M3JfCZdnH1BnUeMdE29ca3WOsuXg8i8/Ef30WnaV0+zcxafOws5fYO7RnK3nmsrA 5RkdG9fMrNAX9vWxnS4TrOvg+tRBaNdhvTJhX9AGxzXuIPG3MECtBUPkNaknXfgczxdJ TlyHKn7XaA8uOtea4fyLb+pubK6C7lJDdfItvEtj+7PKJIlCUWKrlYZMtAqkvkuFWuvr ZsiQ== X-Gm-Message-State: AKS2vOx9O57kf1k3N4WaXTEelrVWxsHeWkQnMupM0irCwGj6Wcw16PTf Kj8Wl1ISESBqWPqW X-Received: by 10.84.254.11 with SMTP id b11mr32350166plm.209.1497915797225; Mon, 19 Jun 2017 16:43:17 -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:34 -0700 Message-Id: <1497915397-93805-21-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 20/23] usercopy: convert kmalloc caches to usercopy caches X-Virus-Scanned: ClamAV using ClamSMTP From: David Windsor Mark the kmalloc slab caches as entirely whitelisted. These caches are frequently used to fulfill kernel allocations that contain data to be copied to/from userspace. It is impossible to know at build time what objects will be contained in these caches, so the entire cache is whitelisted. 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: merged in moved kmalloc hunks, adjust commit log] Signed-off-by: Kees Cook --- mm/slab.c | 3 ++- mm/slab.h | 3 ++- mm/slab_common.c | 10 ++++++---- 3 files changed, 10 insertions(+), 6 deletions(-) diff --git a/mm/slab.c b/mm/slab.c index 5c78830aeea0..4cafbe13f239 100644 --- a/mm/slab.c +++ b/mm/slab.c @@ -1291,7 +1291,8 @@ void __init kmem_cache_init(void) */ kmalloc_caches[INDEX_NODE] = create_kmalloc_cache( kmalloc_info[INDEX_NODE].name, - kmalloc_size(INDEX_NODE), ARCH_KMALLOC_FLAGS); + kmalloc_size(INDEX_NODE), ARCH_KMALLOC_FLAGS, + 0, kmalloc_size(INDEX_NODE)); slab_state = PARTIAL_NODE; setup_kmalloc_cache_index_table(); diff --git a/mm/slab.h b/mm/slab.h index 92c0cedb296d..4cdc8e64fdbd 100644 --- a/mm/slab.h +++ b/mm/slab.h @@ -96,7 +96,8 @@ struct kmem_cache *kmalloc_slab(size_t, gfp_t); extern int __kmem_cache_create(struct kmem_cache *, unsigned long flags); extern struct kmem_cache *create_kmalloc_cache(const char *name, size_t size, - unsigned long flags); + unsigned long flags, size_t useroffset, + size_t usersize); extern void create_boot_cache(struct kmem_cache *, const char *name, size_t size, unsigned long flags, size_t useroffset, size_t usersize); diff --git a/mm/slab_common.c b/mm/slab_common.c index af97465b99e6..685321a0d355 100644 --- a/mm/slab_common.c +++ b/mm/slab_common.c @@ -917,14 +917,15 @@ void __init create_boot_cache(struct kmem_cache *s, const char *name, size_t siz } struct kmem_cache *__init create_kmalloc_cache(const char *name, size_t size, - unsigned long flags) + unsigned long flags, size_t useroffset, + size_t usersize) { struct kmem_cache *s = kmem_cache_zalloc(kmem_cache, GFP_NOWAIT); if (!s) panic("Out of memory when creating slab %s\n", name); - create_boot_cache(s, name, size, flags, 0, size); + create_boot_cache(s, name, size, flags, useroffset, usersize); list_add(&s->list, &slab_caches); memcg_link_cache(s); s->refcount = 1; @@ -1078,7 +1079,8 @@ void __init setup_kmalloc_cache_index_table(void) static void __init new_kmalloc_cache(int idx, unsigned long flags) { kmalloc_caches[idx] = create_kmalloc_cache(kmalloc_info[idx].name, - kmalloc_info[idx].size, flags); + kmalloc_info[idx].size, flags, 0, + kmalloc_info[idx].size); } /* @@ -1119,7 +1121,7 @@ void __init create_kmalloc_caches(unsigned long flags) BUG_ON(!n); kmalloc_dma_caches[i] = create_kmalloc_cache(n, - size, SLAB_CACHE_DMA | flags); + size, SLAB_CACHE_DMA | flags, 0, 0); } } #endif