From patchwork Tue Jan 9 20:55:37 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kees Cook X-Patchwork-Id: 10153433 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 AC30360596 for ; Tue, 9 Jan 2018 21:04:46 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id A3DA02040D for ; Tue, 9 Jan 2018 21:04:46 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 984E72434C; Tue, 9 Jan 2018 21:04:46 +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 959B7204BA for ; Tue, 9 Jan 2018 21:04:45 +0000 (UTC) Received: (qmail 11269 invoked by uid 550); 9 Jan 2018 20:57:55 -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 9543 invoked from network); 9 Jan 2018 20:57:32 -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=dHVNXQ6l5G+RsHH0Msr3+DNZZebZt6wJXxrtvxpaUjs=; b=jW/un8Lj3PoEX09F9QHuZ+tJCeIXKdO0OGBW4AcKmH+pSDI32x7bkmff0W+3JwQBPk YNgpCi2oST7lKCXS9Pe9w5iin9fkdNysM0xOCBQS7ynTsFbOl6K3c6J3p1vEKm/LSV+A JIBrhcycEzPL4OjX8zFdqC+v7/XN76LeOaQro= 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=dHVNXQ6l5G+RsHH0Msr3+DNZZebZt6wJXxrtvxpaUjs=; b=CT1ZbAHlQyGLXNQ0+iHlp0Cl2QDKXsp2Et+s56e8zT+v2O2mI2uTfKrDa84d3theW4 /Y2dzsEcGxhTw4dGI79k16eKEjyOdwIARhTm7LgSTKZQUg8YFxGYThqLrU4polLNusgP PtvCG2E61Y3Alou+/z9Gxwa/22c1ngpeY3bH7ChINyx+abMZZ9IrSiDF3DvecOYDUetb KWWzsRlmRhAt06OB1ZpeCBxggU4aZ0qQgaIk03mDp+Q0WfNURztA9SWMPCPnELXP6mnd /Y61pEd1SHWnY2+7vgaPGuK3veAzuvjwNO/bKI4w1gENBSFXQiCxM2u2ZT/+kbX67vI3 9kbw== X-Gm-Message-State: AKGB3mJF1ACniSYHPgJTc8jZRaBjmK4Bhf67OddzfFsCZf5LwE5SBkg2 HyHuDOSqmPgYBKMdV5e92aphvQ== X-Google-Smtp-Source: ACJfBovoZ7cjHkemojOFWfheI0kzFZvRfiJOJmuPjYyXA6q0VIAUOlOhhCWwelKnfMOCFlu5iDq3Mw== X-Received: by 10.101.73.204 with SMTP id t12mr13373540pgs.48.1515531440561; Tue, 09 Jan 2018 12:57:20 -0800 (PST) From: Kees Cook To: linux-kernel@vger.kernel.org Cc: Kees Cook , David Windsor , Alexander Viro , linux-fsdevel@vger.kernel.org, Linus Torvalds , Andrew Morton , Andy Lutomirski , 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-arch@vger.kernel.org, netdev@vger.kernel.org, linux-mm@kvack.org, kernel-hardening@lists.openwall.com Date: Tue, 9 Jan 2018 12:55:37 -0800 Message-Id: <1515531365-37423-9-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 08/36] vfs: Define usercopy region in names_cache slab caches X-Virus-Scanned: ClamAV using ClamSMTP From: David Windsor VFS pathnames are stored in the names_cache slab cache, either inline or across an entire allocation entry (when approaching PATH_MAX). These are copied to/from userspace, so they must be entirely whitelisted. cache object allocation: include/linux/fs.h: #define __getname() kmem_cache_alloc(names_cachep, GFP_KERNEL) example usage trace: strncpy_from_user+0x4d/0x170 getname_flags+0x6f/0x1f0 user_path_at_empty+0x23/0x40 do_mount+0x69/0xda0 SyS_mount+0x83/0xd0 fs/namei.c: getname_flags(...): ... result = __getname(); ... kname = (char *)result->iname; result->name = kname; len = strncpy_from_user(kname, filename, EMBEDDED_NAME_MAX); ... if (unlikely(len == EMBEDDED_NAME_MAX)) { const size_t size = offsetof(struct filename, iname[1]); kname = (char *)result; result = kzalloc(size, GFP_KERNEL); ... result->name = kname; len = strncpy_from_user(kname, filename, PATH_MAX); In support of usercopy hardening, this patch defines the entire cache object in the names_cache slab cache as whitelisted, since it may entirely hold name strings to be copied to/from userspace. This patch is verbatim 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, add usage trace] Cc: Alexander Viro Cc: linux-fsdevel@vger.kernel.org Signed-off-by: Kees Cook --- fs/dcache.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/fs/dcache.c b/fs/dcache.c index 92ad7a2168e1..9d7ee2de682c 100644 --- a/fs/dcache.c +++ b/fs/dcache.c @@ -3640,8 +3640,8 @@ void __init vfs_caches_init_early(void) void __init vfs_caches_init(void) { - names_cachep = kmem_cache_create("names_cache", PATH_MAX, 0, - SLAB_HWCACHE_ALIGN|SLAB_PANIC, NULL); + names_cachep = kmem_cache_create_usercopy("names_cache", PATH_MAX, 0, + SLAB_HWCACHE_ALIGN|SLAB_PANIC, 0, PATH_MAX, NULL); dcache_init(); inode_init();