From patchwork Tue Jan 9 20:55:55 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kees Cook X-Patchwork-Id: 10153453 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 AE9BC60223 for ; Tue, 9 Jan 2018 21:05:52 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id A59D31FFE4 for ; Tue, 9 Jan 2018 21:05:52 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 9A397203B9; Tue, 9 Jan 2018 21:05:52 +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 3D9D01FFE4 for ; Tue, 9 Jan 2018 21:05:52 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1759366AbeAIVET (ORCPT ); Tue, 9 Jan 2018 16:04:19 -0500 Received: from mail-pg0-f65.google.com ([74.125.83.65]:44983 "EHLO mail-pg0-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1758713AbeAIU5J (ORCPT ); Tue, 9 Jan 2018 15:57:09 -0500 Received: by mail-pg0-f65.google.com with SMTP id i5so8812405pgq.11 for ; Tue, 09 Jan 2018 12:57:09 -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=FZoJICJotuAzGqQDFJ5azsrb47mSKcdNyj5ozJokbJk=; b=NihXLg332ISZM0lhF4xB2DYmL6lNjF+cgoGZ0ZEpYrXy0pxV0XjGZj3miq6tIok1mR 565YyIuW2YmqVeF/ZENcD9/jFWHP0fd7Et8cNUc8/M9MhTKBZxFyO5yHYQSOxXgz6ZH5 1zBCun4cDvVWcdhIcUVCXfuCmtbMp878oYchY= 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=FZoJICJotuAzGqQDFJ5azsrb47mSKcdNyj5ozJokbJk=; b=dUJUrxvPYKM79sc5sAl7geyf1R3wXzNonPf/oI3X5xRCcmmJe1Mt/OdY2OeIe8qE0f EIpjNXxsaRUny+iyWpQdkjom2THE4dae+Ii7rCHHrSkT5ZWc9FIcRfLZh1UdopD0sYxB SNyPaHWD2wZbG1VLQbiEK6xN2lsc4MrrvFJEK05lWw1ldHy7Y3g/Y/VkXvFjNtfYrwzJ LsR3/VVtF1nCofOmsToGacbkZUAwhHs3PKzu7mkAC+JvAxHEc9806gHTGmjy39mgCR/S kcZbe+KyWvGCddTjLuSHv/NUshJdmZraIuRbICWH6jfi8j/0+/keTNY16cL1ei1riJ3F xOLA== X-Gm-Message-State: AKGB3mIONP/WU6CamsO4qme57EBuMhIDimOW0xawb4TNReWzIe9iyhSk drvK/PwliGv3ZpgJst/4tg0Urg== X-Google-Smtp-Source: ACJfBosDYrhMAB6q/J8kKXgR9ih0iXsMLnjv+nz2KGjOBgcEdUAO1pvg+X1KhdNkWj6OJVFUxzWJRQ== X-Received: by 10.84.128.71 with SMTP id 65mr16979867pla.282.1515531428833; Tue, 09 Jan 2018 12:57:08 -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 k62sm28724314pga.42.2018.01.09.12.57.05 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 09 Jan 2018 12:57:05 -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 26/36] fork: Define usercopy region in mm_struct slab caches Date: Tue, 9 Jan 2018 12:55:55 -0800 Message-Id: <1515531365-37423-27-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> 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 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 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 | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/kernel/fork.c b/kernel/fork.c index 432eadf6b58c..82f2a0441d3b 100644 --- a/kernel/fork.c +++ b/kernel/fork.c @@ -2225,9 +2225,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_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();