From patchwork Thu Jan 11 02:02:43 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kees Cook X-Patchwork-Id: 10156461 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 44944605BA for ; Thu, 11 Jan 2018 02:04:16 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 35103286D3 for ; Thu, 11 Jan 2018 02:04:16 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 29407286D5; Thu, 11 Jan 2018 02:04:16 +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=-7.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, RCVD_IN_DNSWL_HI 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 A405B286D3 for ; Thu, 11 Jan 2018 02:04:15 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753860AbeAKCDj (ORCPT ); Wed, 10 Jan 2018 21:03:39 -0500 Received: from mail-pg0-f67.google.com ([74.125.83.67]:34013 "EHLO mail-pg0-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753762AbeAKCDb (ORCPT ); Wed, 10 Jan 2018 21:03:31 -0500 Received: by mail-pg0-f67.google.com with SMTP id j4so1622931pgp.1 for ; Wed, 10 Jan 2018 18:03:31 -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=dHVNXQ6l5G+RsHH0Msr3+DNZZebZt6wJXxrtvxpaUjs=; b=Oixsvs5ABruzTXDfW3zIKj5Wm+eOzshNb2soc1klMv5SLwxQ/oyl+AuSo/uENHaynd /zlCEPoP3ONDbZJh7b4viJ9jEIE7d8uYvyH1vMMP9UmnZ5y1EsxihVpHdzJttKLnwpEY 0FqRN5k1AbKGJftap/cRtkMgakPpR5IY5oluk= 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=pfmUpr6aicSf//7ehNIZ72fEW7oYYqi2c3cwjhVAK8O02tlWJ3I1IfcMCnQqdg9T3H GGyGHUiUx5hxu07cJucCOPWvkOCNzu232SI5eMaTrPvZK9mWlVGkhSexFD0IU1cSaXuw ldIWcT75eqUQDM0h4hqiHGqJT77x4EdVAtppCs2NkLShV8lLpsGDzh0slV8KEvlQzzVx nZ6ZAt2ZXYzTJsDT8qvHDHmF9n7jh5JekHGPtZcf4ggUSKNznfnuVqUp+apGwSa0O2NX 5y2oXKWMehzq7rqx9koMW6W+QKB6wXHQQ1jvEq8bi0mUmfXRiTuN97Qk7grgOIHB4wzk Hi6w== X-Gm-Message-State: AKGB3mIosinP2xtcZwHN0F2kMSGzFjxcSYvOKGN71lMZdh03BKFlkd6V z1pMRHtB16BO+X76Bzl4uorLFQ== X-Google-Smtp-Source: ACJfBosxjp7GHm8kQ8qFVf+Pa01EP4/tlMuPwl72QEs+zLeHr6OFye7NJbPH1EMLIR0BPWH0t4m3qg== X-Received: by 10.99.65.70 with SMTP id o67mr16818435pga.125.1515636210961; Wed, 10 Jan 2018 18:03:30 -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 r13sm31776857pgq.25.2018.01.10.18.03.23 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 10 Jan 2018 18:03:24 -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 Subject: [PATCH 11/38] vfs: Define usercopy region in names_cache slab caches Date: Wed, 10 Jan 2018 18:02:43 -0800 Message-Id: <1515636190-24061-12-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 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();