Skip to content

SELinux support for anonymous inodes and UFFD

Daniel Colascione kvm linux-api linux-fsdevel linux-security-module lkml oe-kbuild-all selinux 5 versions – In review

Get series with b4
b4 am [email protected]

Versions newest first · linked by author and title

  1. v5 Latest3 patches 16 repliesIn review
  2. v43 patches 2 repliesSuperseded
  3. v33 patches 2 repliesSuperseded
Earlier versions · 2
VersionPostedPatchesRepliesStatus
v23 patches5 repliesSuperseded
v13 patches5 repliesSuperseded

Patches in v5 No applies recorded yet

#Subject and filesSizeRepliesApplied
1/3Add a new LSM-supporting anonymous inode interfacefs/anon_inodes.c include/linux/anon_inodes.h include/linux/lsm_hooks.h +2 more+186 -412 replies
2/3Teach SELinux about anonymous inodessecurity/selinux/hooks.c security/selinux/include/classmap.h+55 -00 replies
3/3Wire UFFD up to SELinuxfs/userfaultfd.c+26 -41 reply

Reviews trailers per patch

None of the 3 patches has a Reviewed-by or Acked-by of their own; the series has one for all of them.

PatchCasey SchauflerStephen Smalley
SeriesA-b A-b
1/3
2/3
3/3

Trailers given in replies are filled; those carried in the patches from earlier versions are outlined with dashes.

Read the v5 thread

Cover letter [PATCH v5 0/3] SELinux support for anonymous inodes and UFFD

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.

Inside the kernel, a pair of new anon_inodes interface, anon_inode_getfile_secure and anon_inode_getfd_secure, allow callers to opt into this SELinux management. In this new "secure" mode, anon_inodes creates 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

[1] https://lore.kernel.org/lkml/[email protected]/
[2] https://lore.kernel.org/linux-fsdevel/[email protected]/
[3] https://lore.kernel.org/lkml/[email protected]/

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                    | 191 ++++++++++++++++++++++------
 fs/userfaultfd.c                    |  30 ++++-
 include/linux/anon_inodes.h         |  13 ++
 include/linux/lsm_hooks.h           |  11 ++
 include/linux/security.h            |   3 +
 security/security.c                 |   9 ++
 security/selinux/hooks.c            |  53 ++++++++
 security/selinux/include/classmap.h |   2 +
 8 files changed, 267 insertions(+), 45 deletions(-)
Signature · 1 line
2.26.0.rc2.310.g2932bb562d-goog