From patchwork Mon Aug 28 21:35:06 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kees Cook X-Patchwork-Id: 9926345 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 4562E60329 for ; Mon, 28 Aug 2017 21:45:35 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 38214287D6 for ; Mon, 28 Aug 2017 21:45:35 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 2B140287DA; Mon, 28 Aug 2017 21:45:35 +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 29E4B287D6 for ; Mon, 28 Aug 2017 21:45:33 +0000 (UTC) Received: (qmail 9706 invoked by uid 550); 28 Aug 2017 21:44:15 -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 9516 invoked from network); 28 Aug 2017 21:44:08 -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=NHE1W3Ms2GYKhW9cXCbjs4HzD2vI3QuNsMCz3p7uaJA=; b=R3dARKwyLwrfmoTH4DLKpsALnEvnXpN7ZTftXmG5TekSidcA+l1XIwAgKVk9udOvbZ nm6cLYwdyaLUzTTAWfkZBp0c0FEfGz41XZQawuMuFfUKwR7P0ctBD4vzRV4nU5NQIK4J hnj5EZk15lMXS/gbFm60SYfdtRqEXIPBpFm1Q= 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=NHE1W3Ms2GYKhW9cXCbjs4HzD2vI3QuNsMCz3p7uaJA=; b=VwRvpDzMspZWjtl70fnEiKtdN+EJOQSyrelWvw15v3nW7xKJchC9E+JKntznA50O/e WYcRdTdGCSkKIjAvYM2OFXB6RxSBgYPzLgwcXf6ovDjCHAvhMjMqwO+cmEFjx4Hnwkn/ HjG4yaTQVtt06ksKCPneprehYhEyncFDpLGNHFT/1yOgdmb+244ppIMsIquEyJXfPFb8 CD9uB6zo8s+vVCW54i/4k/cNMN5w3smRTuKs2dD4ZGPQW0qTyp2A5cir6JOXYvCBphW7 GfXn7Ou7FEfryZu8bwgmcxC2TEer/AV4AF2rv/MlJajIZN4DDptMLStsgXrfK0+E5LSY h28Q== X-Gm-Message-State: AHYfb5hLxU/AbcoMUO3M4r1KiqR/z2rSFD5X4a2aSOfOgNSnq5PNd+TX u9undcZJZN5bCPbc X-Received: by 10.99.170.71 with SMTP id x7mr1873976pgo.131.1503956636818; Mon, 28 Aug 2017 14:43:56 -0700 (PDT) From: Kees Cook To: linux-kernel@vger.kernel.org Cc: Kees Cook , David Windsor , Ingo Molnar , Andrew Morton , Thomas Gleixner , Andy Lutomirski , linux-mm@kvack.org, kernel-hardening@lists.openwall.com Date: Mon, 28 Aug 2017 14:35:06 -0700 Message-Id: <1503956111-36652-26-git-send-email-keescook@chromium.org> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1503956111-36652-1-git-send-email-keescook@chromium.org> References: <1503956111-36652-1-git-send-email-keescook@chromium.org> Subject: [kernel-hardening] [PATCH v2 25/30] 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 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 d8ebf755a47b..0f33fb1aabbf 100644 --- a/kernel/fork.c +++ b/kernel/fork.c @@ -276,8 +276,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