Received: by 2002:a05:6a10:16a7:0:0:0:0 with SMTP id gp39csp103058pxb; Wed, 11 Nov 2020 21:40:01 -0800 (PST) X-Google-Smtp-Source: ABdhPJwxwkILXUCvo5U4BL4F/OBDxnS4hTZWqr7ymYtVprVsgNfzaowCElOowPNGYY0bjBG5JfdJ X-Received: by 2002:a05:6402:142c:: with SMTP id c12mr3478574edx.41.1605159601350; Wed, 11 Nov 2020 21:40:01 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1605159601; cv=none; d=google.com; s=arc-20160816; b=odyIUXsPE3RsuNRJHFcKHJ8axp0QkP9aXqGQvkwEntttsfsPZy4bkqGd3u2ztff+JV C4Tb0Ed83ysdxSVgM+BKwAvE6wBFfnIP9quX9GYodh3lZEcAlAs3YY9U4XSzAtV/tudq CXb15NeOQbFXvA/3inlY0ch4V+Kt+8V6vHYjZImaYeO20gcDfkqE2fSv2CyxkYSoZEiA eHG9jFrYVb6HE5rq0fFs4C87k7gpNq9uGGMRBlVXmxoKYPl8X8hsfb9w0GSnrIzFmXNp uLB5vFtU2XYSB5rEKJgvgFIyaWlt9RZW1cz+pxPeA8uausC4usYplPZ+nkD3wIZcWsUp GE8w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:from:subject:mime-version:message-id:date :sender:dkim-signature; bh=jTdS5qD6Cs9spAbYdY/Y3qiyvOeoxSwh4Xr7vha7mcg=; b=mZLRFKAQnn9g80+OnT2wrQ0IHQk1lZm69IxJvjpMrnHOWVju5Eh7wYiUbIvR5ie584 /A3A39REGlhU4av5PVnvsLZOPG1Cl7CDCKDL289hOLHExUzYkNL7lLSx/zP6QZYBGiKV DSfNm0pkW1cvNX6DLDCmCM5ChNpc43iMlWJ3Bvubyvqw9genEZhLwdhAgE5gzCd6vPQ+ z20W8DucO9awlj3RNbmYUrtH8L7CWvoZvqA4gqBE2EGftf5HcuMlHK6su7+BSzVVYvFL +dWHutdTO7T6Q2N89Drr8O3ZPPiyBJXLznZRla+ch8gzgISbPXW0CJwLspkCUD1/xJxg Clwg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=dpamQo0R; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id r24si3287051edq.456.2020.11.11.21.39.38; Wed, 11 Nov 2020 21:40:01 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=dpamQo0R; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728580AbgKLFd4 (ORCPT + 99 others); Thu, 12 Nov 2020 00:33:56 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55466 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728977AbgKLByE (ORCPT ); Wed, 11 Nov 2020 20:54:04 -0500 Received: from mail-yb1-xb49.google.com (mail-yb1-xb49.google.com [IPv6:2607:f8b0:4864:20::b49]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6DFFDC061A4F for ; Wed, 11 Nov 2020 17:54:04 -0800 (PST) Received: by mail-yb1-xb49.google.com with SMTP id v13so8661ybe.18 for ; Wed, 11 Nov 2020 17:54:04 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=sender:date:message-id:mime-version:subject:from:to:cc; bh=jTdS5qD6Cs9spAbYdY/Y3qiyvOeoxSwh4Xr7vha7mcg=; b=dpamQo0R6nrhSTmxCkRKiC1S89iAq3sss5Kiv2a6XarKjuK3+EubjqCft+NNU1H7IC x2gBDgyR5iTp4mXOzjYVMKH0rxAdd6zdG6XrlKFe1dzrvlpu2Y9ujzE3nnP7YKKf6LMV UrELwuRxw4AyprYz+CJODn4usi8UFJr/uXAYYX6jla+Aob5qkEECdtBJWWY/0a1Lt1UW PKHCuDhtQlbL10Nh1y5MBK3U7oGj0/+r2AKZwWwTIZgr+4G3BQnhQsFjOX43FiQxyc6F X/f/BGPh2byzOAI+h8HtktaCiFDrdBDMXgZ4CW+II/WvSC3vaz/sUizCHC65B/ngJOAz fg2g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:date:message-id:mime-version:subject:from :to:cc; bh=jTdS5qD6Cs9spAbYdY/Y3qiyvOeoxSwh4Xr7vha7mcg=; b=BhrrN4Ayy1TT2P/q0qSFNsoR8LkcGFVUfLZgfA+2OcJ8X8h1kBQ5rgWKVQ3Zay/B9x P9hAQjOe5uIHaM7t2HkBQpx/zFErCsUTtQOvJLIDjAbTgO0KD8Y+JugUSXoooG4KYh2z nKoX2fPSdLMjvY43GbehDRlRo5l73tGLC7AxSwef2a0zjVjfRmwSoQbgCKEBFjkK9g5M pburFB8FK7la5tjfcBpzLFnZ6UgJtlrQwxsUwLPxyAlBCuewT5Zz8skK0ZYastwz2wLO 4BzD8w47X7K+SG38lIkH0FCs7Qv9JeAPutdjdkC2zWOY13n4p+Zdhog9es7xaqA3sEfl 3UKA== X-Gm-Message-State: AOAM532EX1Gcd6rPbraaalyTq+wNkB0ckNL0r14TPEXWZ5K8CQ7854t5 I+qgNQpZqQJOPMX/WoEoubEMZkcSEeH/IVxG6A== Sender: "lokeshgidra via sendgmr" X-Received: from lg.mtv.corp.google.com ([2620:15c:211:202:f693:9fff:fef4:29dd]) (user=lokeshgidra job=sendgmr) by 2002:a25:4cc7:: with SMTP id z190mr38493734yba.405.1605146043522; Wed, 11 Nov 2020 17:54:03 -0800 (PST) Date: Wed, 11 Nov 2020 17:53:55 -0800 Message-Id: <20201112015359.1103333-1-lokeshgidra@google.com> Mime-Version: 1.0 X-Mailer: git-send-email 2.29.2.299.gdc1121823c-goog Subject: [PATCH v13 0/4] SELinux support for anonymous inodes and UFFD From: Lokesh Gidra To: Andrea Arcangeli , Alexander Viro , James Morris , Stephen Smalley , Casey Schaufler , Eric Biggers , Paul Moore Cc: "Serge E. Hallyn" , Eric Paris , Lokesh Gidra , Daniel Colascione , Kees Cook , "Eric W. Biederman" , KP Singh , David Howells , Anders Roxell , Sami Tolvanen , Matthew Garrett , Aaron Goidel , Randy Dunlap , "Joel Fernandes (Google)" , YueHaibing , Christian Brauner , Alexei Starovoitov , Alexey Budankov , Adrian Reber , Aleksa Sarai , linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org, linux-security-module@vger.kernel.org, selinux@vger.kernel.org, kaleshsingh@google.com, calin@google.com, surenb@google.com, jeffv@google.com, kernel-team@android.com, linux-mm@kvack.org, Andrew Morton , hch@infradead.org Content-Type: text/plain; charset="UTF-8" Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Userfaultfd in unprivileged contexts could be potentially very useful. We'd like to harden userfaultfd to make such unprivileged use less risky. This patch series allows SELinux to manage userfaultfd file descriptors and in the future, other kinds of anonymous-inode-based file descriptor. SELinux policy authors can apply policy types to anonymous inodes by providing name-based transition rules keyed off the anonymous inode internal name ( "[userfaultfd]" in the case of userfaultfd(2) file descriptors) and applying policy to the new SIDs thus produced. With SELinux managed userfaultfd, an admin can control creation and movement of the file descriptors. In particular, handling of a userfaultfd descriptor by a different process is essentially a ptrace access into the process, without any of the corresponding security_ptrace_access_check() checks. For privacy, the admin may want to deny such accesses, which is possible with SELinux support. Inside the kernel, a new anon_inode interface, anon_inode_getfd_secure, allows callers to opt into this SELinux management. In this new "secure" mode, anon_inodes create new ephemeral inodes for anonymous file objects instead of reusing the normal anon_inodes singleton dummy inode. A new LSM hook gives security modules an opportunity to configure and veto these ephemeral inodes. This patch series is one of two fork of [1] and is an alternative to [2]. The primary difference between the two patch series is that this partch series creates a unique inode for each "secure" anonymous inode, while the other patch series ([2]) continues using the singleton dummy anonymous inode and adds a way to attach SELinux security information directly to file objects. I prefer the approach in this patch series because 1) it's a smaller patch than [2], and 2) it produces a more regular security architecture: in this patch series, secure anonymous inodes aren't S_PRIVATE and they maintain the SELinux property that the label for a file is in its inode. We do need an additional inode per anonymous file, but per-struct-file inode creation doesn't seem to be a problem for pipes and sockets. The previous version of this feature ([1]) created a new SELinux security class for userfaultfd file descriptors. This version adopts the generic transition-based approach of [2]. This patch series also differs from [2] in that it doesn't affect all anonymous inodes right away --- instead requiring anon_inodes callers to opt in --- but this difference isn't one of basic approach. The important question to resolve is whether we should be creating new inodes or enhancing per-file data. Changes from the first version of the patch: - Removed some error checks - Defined a new anon_inode SELinux class to resolve the ambiguity in [3] - Inherit sclass as well as descriptor from context inode Changes from the second version of the patch: - Fixed example policy in the commit message to reflect the use of the new anon_inode class. Changes from the third version of the patch: - Dropped the fops parameter to the LSM hook - Documented hook parameters - Fixed incorrect class used for SELinux transition - Removed stray UFFD changed early in the series - Removed a redundant ERR_PTR(PTR_ERR()) Changes from the fourth version of the patch: - Removed an unused parameter from an internal function - Fixed function documentation Changes from the fifth version of the patch: - Fixed function documentation in fs/anon_inodes.c and include/linux/lsm_hooks.h - Used anon_inode_getfd_secure() in userfaultfd() syscall and removed owner from userfaultfd_ctx. Changes from the sixth version of the patch: - Removed definition of anon_inode_getfile_secure() as there are no callers. - Simplified function description of anon_inode_getfd_secure(). - Elaborated more on the purpose of 'context_inode' in commit message. Changes from the seventh version of the patch: - Fixed error handling in _anon_inode_getfile(). - Fixed minor comment and indentation related issues. Changes from the eighth version of the patch: - Replaced selinux_state.initialized with selinux_state.initialized Changes from the ninth version of the patch: - Fixed function names in fs/anon_inodes.c - Fixed comment of anon_inode_getfd_secure() - Fixed name of the patch wherein userfaultfd code uses anon_inode_getfd_secure() Changes from the tenth version of the patch: - Split first patch into VFS and LSM specific patches - Fixed comments in fs/anon_inodes.c - Fixed comment of alloc_anon_inode() Changes from the eleventh version of the patch: - Removed comment of alloc_anon_inode() for consistency with the code - Fixed explanation of LSM hook in the commit message Changes from the twelfth version of the patch: - Replaced FILE__CREATE with ANON_INODE__CREATE while initializing anon-inode's SELinux security struct. - Check context_inode's SELinux label and return -EACCES if it's invalid. [1] https://lore.kernel.org/lkml/20200211225547.235083-1-dancol@google.com/ [2] https://lore.kernel.org/linux-fsdevel/20200213194157.5877-1-sds@tycho.nsa.gov/ [3] https://lore.kernel.org/lkml/23f725ca-5b5a-5938-fcc8-5bbbfc9ba9bc@tycho.nsa.gov/ Daniel Colascione (3): fs: add LSM-supporting anon-inode interface selinux: teach SELinux about anonymous inodes userfaultfd: use secure anon inodes for userfaultfd Lokesh Gidra (1): security: add inode_init_security_anon() LSM hook fs/anon_inodes.c | 150 ++++++++++++++++++++-------- fs/libfs.c | 5 - fs/userfaultfd.c | 19 ++-- include/linux/anon_inodes.h | 5 + include/linux/lsm_hook_defs.h | 2 + include/linux/lsm_hooks.h | 9 ++ include/linux/security.h | 10 ++ security/security.c | 8 ++ security/selinux/hooks.c | 56 +++++++++++ security/selinux/include/classmap.h | 2 + 10 files changed, 212 insertions(+), 54 deletions(-) -- 2.29.2.299.gdc1121823c-goog