Received: by 2002:a05:6a10:22f:0:0:0:0 with SMTP id 15csp660456pxk; Wed, 23 Sep 2020 12:34:56 -0700 (PDT) X-Google-Smtp-Source: ABdhPJy10FEygV3YqH/rFRrKbw2OHikk4MvYutYge2PaXJ4DR4qLOJUEuzfe7m9e7//u2uljDqZz X-Received: by 2002:a05:6402:6c9:: with SMTP id n9mr889226edy.297.1600889696447; Wed, 23 Sep 2020 12:34:56 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1600889696; cv=none; d=google.com; s=arc-20160816; b=Wg6s1300E2+nSKvNtiUkhRWxJN/0Gca/dZtVFcZSZ6s9dylzgnLuu0FFlxiaVJ7XX9 aqCYaS7/d5qsRlcxQM7LFsRiZUscsmqZN1UmbQyc2rOFSeKoqN4tSxzbiYD+Aghr5pOL wUl9fSkOjrpqIak4n1Y6uyqabODNqYfsHDQkoa7HapSNeptaXS/kphzZ9+7q6Rj0a5Kp 4/+Un3wEtGkeakLFmhUvpgfP/uuSLUpostmNjsKeiVJNVAgv5C+5ct+UidIuMfz6FcS8 qwRUymXf0QbX2I9wVvs4aC4L7cWEX72qkZ3+YQ6KCgqt5AQVhIH1yswcTkSyGX+ANU3E shrQ== 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=WVSvTUrYOLntpcfEv21un6OtJaYezAF3iVaHLu7hkAE=; b=qHAQWIQLaLuKSkQJLj+/r1+Stug1PdzO8cNsp79ljqBoHbTPSg6VxBMLhBd3rqTXAh GiB5FyNYmwxjOMrjO1nJvYHZMbHPBWAgSarIBMYgbvNS8tgi5xgnOoiJpeOswxPNRGxl PmaYW6Cl6TtsNYYy+PTv4UPa1YV6UtNqy1gNkAtLK+UUAJ/DCBp0u4cKif8fMQFQoEpX LJdNghD3C/ZTCZFGCXNcqqNbo8LVKAwpTtCYm6HExr1UCAJ0iLZR1F0OOObMEwZLyzFH ub/4B53Y/RgBhe+2TdSrH5fbn7zFIxItLKf2vhyl1iZAKua1RT3GLM/D6opci693PcgY IbOg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=ArKXeABL; 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 l11si549253ejd.105.2020.09.23.12.34.31; Wed, 23 Sep 2020 12:34:56 -0700 (PDT) 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=ArKXeABL; 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 S1726613AbgIWTd3 (ORCPT + 99 others); Wed, 23 Sep 2020 15:33:29 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52242 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726424AbgIWTd3 (ORCPT ); Wed, 23 Sep 2020 15:33:29 -0400 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 48400C0613D2 for ; Wed, 23 Sep 2020 12:33:29 -0700 (PDT) Received: by mail-yb1-xb49.google.com with SMTP id n2so683231ybg.8 for ; Wed, 23 Sep 2020 12:33:29 -0700 (PDT) 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=WVSvTUrYOLntpcfEv21un6OtJaYezAF3iVaHLu7hkAE=; b=ArKXeABL055dP9UaAHA02G3C5k50VagybqYti7opUKzF6LQsQaVxD/h8N2sNItDgDp OHUaKhz9LSLg+YtA+c+ZTJUIs4uXRIN19skiynV6k3oxFeub8TU9UmYcGOqfR1X46ms/ v/XOqLRTnY5rTaEuS9iRqMJu+Y4Bb+j+ejblZdFt8TzjW2i8rwY/nogh8o41FBCauhR9 ZRkh5efI5RaAWXVhsEwTjdCNCs4kbCUPg6oGwBFfPFfjasSbiEY1jKM9VAJnyrVNvudF rAmisW6mZUGAbLlCQo/PSlpoR/3N4FPTPOT/oWLnQEpCf/uM4mpee1MTLbWbNSb1T+WQ wKcA== 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=WVSvTUrYOLntpcfEv21un6OtJaYezAF3iVaHLu7hkAE=; b=RINcHkhVVPdrhHUxvk/YE1SMGL7gun3/nXTKxN/AhPmlDnaK9VC4b5L7TXn5Gao5A0 VwMr3xyt8lfS7TaBofAOgXF49dF0g1qzZdTDTUdfDFDc11I+d8xRNXP9PWUuFnRJoEqz XjtU9Cs+0hFVeAp9b2pvHstf4zpkjRiw/s1N8kJmFbL+dQ6/73zFxutkiulm0TTHAIyj bAl+2aa4e0l13iQ4iWW28w1EpkwhhNSnh4F56a9OQqATiSX71jwk9aS+ATTple9Pw1V+ TitBlRloAZnp8VMPc5cr5INbZSAiO3rzV01kxconb40GDHI838XyU0AKZp5oeVqRuI3F 7wnQ== X-Gm-Message-State: AOAM530jyzbzGmQqYG2umn/f9NdmgOC/eOFooWFy6opFxFrKTCHhQRTc sqN4wniYIe5/ZYMzZFKS7x2wjcZBI6jEw32xig== 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:ae90:: with SMTP id b16mr2522880ybj.128.1600889608275; Wed, 23 Sep 2020 12:33:28 -0700 (PDT) Date: Wed, 23 Sep 2020 12:33:21 -0700 Message-Id: <20200923193324.3090160-1-lokeshgidra@google.com> Mime-Version: 1.0 X-Mailer: git-send-email 2.28.0.681.g6f77f65b4e-goog Subject: [PATCH v9 0/3] SELinux support for anonymous inodes and UFFD From: Lokesh Gidra To: Alexander Viro , James Morris , Stephen Smalley , Casey Schaufler , Eric Biggers Cc: "Serge E. Hallyn" , Paul Moore , Eric Paris , Lokesh Gidra , Daniel Colascione , Kees Cook , "Eric W. Biederman" , KP Singh , David Howells , Thomas Cedeno , 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, nnk@google.com, jeffv@google.com, kernel-team@android.com 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 [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): Add a new LSM-supporting anonymous inode interface Teach SELinux about anonymous inodes Wire UFFD up to SELinux fs/anon_inodes.c | 147 ++++++++++++++++++++-------- fs/userfaultfd.c | 19 ++-- include/linux/anon_inodes.h | 8 ++ 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 | 53 ++++++++++ security/selinux/include/classmap.h | 2 + 9 files changed, 209 insertions(+), 49 deletions(-) -- 2.28.0.681.g6f77f65b4e-goog