From patchwork Thu Jan 11 02:03:02 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kees Cook X-Patchwork-Id: 10156563 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 BD22C605BA for ; Thu, 11 Jan 2018 02:11:04 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id ABFE62873F for ; Thu, 11 Jan 2018 02:11:04 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id A09082874A; Thu, 11 Jan 2018 02:11:04 +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=-5.3 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, RCVD_IN_DNSWL_HI, URIBL_BLACK autolearn=unavailable version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 2C8292873F for ; Thu, 11 Jan 2018 02:11:04 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754262AbeAKCKA (ORCPT ); Wed, 10 Jan 2018 21:10:00 -0500 Received: from mail-pg0-f66.google.com ([74.125.83.66]:42211 "EHLO mail-pg0-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754345AbeAKCJt (ORCPT ); Wed, 10 Jan 2018 21:09:49 -0500 Received: by mail-pg0-f66.google.com with SMTP id q67so1620922pga.9 for ; Wed, 10 Jan 2018 18:09:49 -0800 (PST) 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=AH3i3QMBjHcV2eWAKdVrtVkeKv43MCWAP/zxJk/u6HQTp0K+1qOMN0kPy+RN2sW3J6 HLdI2KA7TLYIvbAHHc+J2jxctr1LjoTKXfJN/FCosNksQXyUL+e5D4TU7gAwVYJDoSIx FhQ3MCCaU60GEPDi5sKHoJkpxAGAlw6gtd2xY= 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=fiA2VK7uNV9eKpntIj/KfJJawZxu44PYOK/QHSoj5ldWYowpgnrL0XxFPgx7x1xwxu rP98LEK6fjW4ejL3YAiQ6it8H7E18P0Hf+mTySu4/gN4T9IqpIgca+HsaHkigz3I27BI AebmB75jdeQKFit36a1EO5mrpfAILRbDBRNAHQ6l/64naHwZXGhXsZ7nxvsq8r+C3tmd SdqWEXMfkikjn6rjIHOybxh5TH7/yoZKzGiLEq5vuOFKQRIxCMtGh2vNvEG7fnZF/HKu pKUzPxU0MrHz+kSZtz3GECGHds2KTIWvkjVADW48qZlnjNYHCKA//q1/84qNC6lIMQFg RokQ== X-Gm-Message-State: AKwxytfqAflUdhUpHBQQUMmSH/tS2UDAAUvY49ybg4FrLS7KeoqQ53fo 2exzop0BLS7kfYxGtAWs0g3EuA== X-Google-Smtp-Source: ACJfBoseWnDVuxTg4dNT6NF5LzfiNKdzZ4ADIgpVLkvwF4igOadVdgpinLrcYSK6+E6oyPW2MlBFCQ== X-Received: by 10.98.160.25 with SMTP id r25mr3267241pfe.218.1515636588626; Wed, 10 Jan 2018 18:09:48 -0800 (PST) Received: from www.outflux.net (173-164-112-133-Oregon.hfc.comcastbusiness.net. [173.164.112.133]) by smtp.gmail.com with ESMTPSA id n186sm29961643pgn.11.2018.01.10.18.09.39 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 10 Jan 2018 18:09:45 -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 Subject: [PATCH 30/38] fork: Define usercopy region in thread_stack slab caches Date: Wed, 10 Jan 2018 18:03:02 -0800 Message-Id: <1515636190-24061-31-git-send-email-keescook@chromium.org> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1515636190-24061-1-git-send-email-keescook@chromium.org> References: <1515636190-24061-1-git-send-email-keescook@chromium.org> Sender: linux-fsdevel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-fsdevel@vger.kernel.org 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