From patchwork Mon Aug 28 21:35:05 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kees Cook X-Patchwork-Id: 9926341 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 1CE3B60375 for ; Mon, 28 Aug 2017 21:45:24 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 102BF287D6 for ; Mon, 28 Aug 2017 21:45:24 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 04B98287DA; Mon, 28 Aug 2017 21:45:24 +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 084E5287D6 for ; Mon, 28 Aug 2017 21:45:22 +0000 (UTC) Received: (qmail 9665 invoked by uid 550); 28 Aug 2017 21:44:13 -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 9496 invoked from network); 28 Aug 2017 21:44:07 -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=o8Vs6+IKK8UyU/ijoSm1PUI7yTRTacqtEku2GPWRsPU=; b=Uo9oLiaBHYKkhAwTUUN9d7nXquZC9joBPekm5eD78ucpxn052NMJVMK0Hy5zEx2hLK gwKgDj78bI8XmhwMnv9u6yZ7xdNpYUJLHLaY26fNg6MLOuf74qBT/lLCv/XJVXg92Kfi OwPSXFEodWRG2wgfkz0lt+gL7zAr0Rx6YAgSc= 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=o8Vs6+IKK8UyU/ijoSm1PUI7yTRTacqtEku2GPWRsPU=; b=t+vV3DW0/QqjUkyC1h49qsItp6QwTUdO0zUCR1gYnWsprGYXrGVhEeR4AW8MPbae4j tgeWosZumTxF6OGNutY1OWNMLUPNrZ3awUG9Lc4Ha/j9X0oLyKxBY15fqXs4Cz3KJoNr opcCsqqruLF6SVdfy/inoOrv+5UzZHcBYAxP04WDqFnHL79Z3WPzT7Qd0mpbinyJjSyu We8iNY5I4D9XGvCrGOwNCfIgJex0ns5WLH5xYze9XoxFC6HIycL+DPQRKbk8rIDA7Eaq RBevcLlBihC128657I3leB0xgMN8j/EQqiLlAJAz0fwd4t4jbr7ziBwABjhudM8lRnRm StOA== X-Gm-Message-State: AHYfb5j7ixmdp9Ws1+ojETuC4wW8glj8DkDQJDlVWI/KrRXh0PjNWJPw NIypBB+zPjYaV89p X-Received: by 10.99.186.86 with SMTP id l22mr1851013pgu.244.1503956636294; 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:05 -0700 Message-Id: <1503956111-36652-25-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 24/30] fork: Define usercopy region in mm_struct slab caches X-Virus-Scanned: ClamAV using ClamSMTP From: David Windsor In support of usercopy hardening, this patch defines a region in the mm_struct slab caches in which userspace copy operations are allowed. Only the auxv field is copied to userspace. cache object allocation: kernel/fork.c: #define allocate_mm() (kmem_cache_alloc(mm_cachep, GFP_KERNEL)) dup_mm(): ... mm = allocate_mm(); copy_mm(...): ... dup_mm(); copy_process(...): ... copy_mm(...) _do_fork(...): ... copy_process(...) example usage trace: fs/binfmt_elf.c: create_elf_tables(...): ... elf_info = (elf_addr_t *)current->mm->saved_auxv; ... copy_to_user(..., elf_info, ei_index * sizeof(elf_addr_t)) load_elf_binary(...): ... create_elf_tables(...); 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 | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/kernel/fork.c b/kernel/fork.c index 17921b0390b4..d8ebf755a47b 100644 --- a/kernel/fork.c +++ b/kernel/fork.c @@ -2206,9 +2206,11 @@ void __init proc_caches_init(void) * maximum number of CPU's we can ever have. The cpumask_allocation * is at the end of the structure, exactly for that reason. */ - mm_cachep = kmem_cache_create("mm_struct", + mm_cachep = kmem_cache_create_usercopy("mm_struct", sizeof(struct mm_struct), ARCH_MIN_MMSTRUCT_ALIGN, SLAB_HWCACHE_ALIGN|SLAB_PANIC|SLAB_NOTRACK|SLAB_ACCOUNT, + offsetof(struct mm_struct, saved_auxv), + sizeof_field(struct mm_struct, saved_auxv), NULL); vm_area_cachep = KMEM_CACHE(vm_area_struct, SLAB_PANIC|SLAB_ACCOUNT); mmap_init();