From patchwork Tue Jan 9 20:55:56 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kees Cook X-Patchwork-Id: 10153371 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 5921560223 for ; Tue, 9 Jan 2018 21:01:11 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 51E762521E for ; Tue, 9 Jan 2018 21:01:11 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 5088126224; Tue, 9 Jan 2018 21:01:11 +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 62C712521E for ; Tue, 9 Jan 2018 21:01:10 +0000 (UTC) Received: (qmail 9514 invoked by uid 550); 9 Jan 2018 20:57:31 -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 9242 invoked from network); 9 Jan 2018 20:57:21 -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=e9mehbylxpULwq1JxF6fYk2hZRoxnP8EylWUrDfh/Go=; b=Fzk6/qXqpyPQ2d2f+lrb9uSIjlG+z7MgBG+mbXZfFoOj7+VaIeJF249Yv8ABHyVkWg RlRd/QhCq26vaFIHfv6nyrTFGDYDaSl4WSRg7V2ajgwYhUJsrVc/m730aQz4V5ZZUPqU XaKZqmy0teFxTd/+I9Kzr+zKrcys7XZ6+51ig= 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=e9mehbylxpULwq1JxF6fYk2hZRoxnP8EylWUrDfh/Go=; b=JIN5Ez4O3MhFUEWDTBJvugx1Cl99NHi7jFwggLpLYnJLamO983bDP1GJTvgdufdYKd l9JFvrj+jhc7YNoKWxTXHALCHPLpyNREHD9sRr1dDzkC/dMJHInl/yfUktU0qD2yx4kz AXwxKCa+ic9XBBSdjgKNyGeNrp1PpMpsncU++d2c7gsOsD9aKRdtpBKtcOzNPY74w0jB NGDXbDsAXUT6B1ui9rGpZnp6dn56T3KQ32tAbAcErreeaUelOzvSKbskbYunNg0ygwiA JM3u1NHxHbXh1+fcCTLzwLSQ4CSWEsZcUwlh1YarEhlTakkOi5psoaYjiQ7iBS7YrmiT x0Vg== X-Gm-Message-State: AKGB3mKYc60wsycx/tviYk4T0tRbUKDsJrOGRrQq85iBKywxqeTRq9Ve B7y8MwWaSZpazK7Di1I/M+fvxQ== X-Google-Smtp-Source: ACJfBot9erCzswLw9cPPwWBUN7mB37XBQ/PiS7GorxJEyTrlpTmsk4yKazpQulmLs3dxfWAfLajhuA== X-Received: by 10.84.215.143 with SMTP id l15mr12505097pli.441.1515531429698; Tue, 09 Jan 2018 12:57:09 -0800 (PST) From: Kees Cook To: linux-kernel@vger.kernel.org Cc: Kees Cook , David Windsor , Ingo Molnar , Andrew Morton , Thomas Gleixner , Andy Lutomirski , Linus Torvalds , Alexander Viro , Christoph Hellwig , Christoph Lameter , "David S. Miller" , Laura Abbott , Mark Rutland , "Martin K. Petersen" , Paolo Bonzini , Christian Borntraeger , Christoffer Dall , Dave Kleikamp , Jan Kara , Luis de Bethencourt , Marc Zyngier , Rik van Riel , Matthew Garrett , linux-fsdevel@vger.kernel.org, linux-arch@vger.kernel.org, netdev@vger.kernel.org, linux-mm@kvack.org, kernel-hardening@lists.openwall.com Date: Tue, 9 Jan 2018 12:55:56 -0800 Message-Id: <1515531365-37423-28-git-send-email-keescook@chromium.org> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1515531365-37423-1-git-send-email-keescook@chromium.org> References: <1515531365-37423-1-git-send-email-keescook@chromium.org> Subject: [kernel-hardening] [PATCH 27/36] fork: Define usercopy region in thread_stack slab caches X-Virus-Scanned: ClamAV using ClamSMTP From: David Windsor In support of usercopy hardening, this patch defines a region in the thread_stack slab caches in which userspace copy operations are allowed. Since the entire thread_stack needs to be available to userspace, the entire slab contents are whitelisted. Note that the slab-based thread stack is only present on systems with THREAD_SIZE < PAGE_SIZE and !CONFIG_VMAP_STACK. cache object allocation: kernel/fork.c: alloc_thread_stack_node(...): return kmem_cache_alloc_node(thread_stack_cache, ...) dup_task_struct(...): ... stack = alloc_thread_stack_node(...) ... tsk->stack = stack; copy_process(...): ... dup_task_struct(...) _do_fork(...): ... copy_process(...) 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: David Windsor [kees: adjust commit log, split patch, provide usage trace] Cc: Ingo Molnar Cc: Andrew Morton Cc: Thomas Gleixner Cc: Andy Lutomirski Signed-off-by: Kees Cook Acked-by: Rik van Riel --- kernel/fork.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/kernel/fork.c b/kernel/fork.c index 82f2a0441d3b..0e086af148f2 100644 --- a/kernel/fork.c +++ b/kernel/fork.c @@ -282,8 +282,9 @@ static void free_thread_stack(struct task_struct *tsk) void thread_stack_cache_init(void) { - thread_stack_cache = kmem_cache_create("thread_stack", THREAD_SIZE, - THREAD_SIZE, 0, NULL); + thread_stack_cache = kmem_cache_create_usercopy("thread_stack", + THREAD_SIZE, THREAD_SIZE, 0, 0, + THREAD_SIZE, NULL); BUG_ON(thread_stack_cache == NULL); } # endif