1. 23 4月, 2021 1 次提交
  2. 24 1月, 2021 3 次提交
    • C
      commoncap: handle idmapped mounts · 71bc356f
      Christian Brauner 提交于
      When interacting with user namespace and non-user namespace aware
      filesystem capabilities the vfs will perform various security checks to
      determine whether or not the filesystem capabilities can be used by the
      caller, whether they need to be removed and so on. The main
      infrastructure for this resides in the capability codepaths but they are
      called through the LSM security infrastructure even though they are not
      technically an LSM or optional. This extends the existing security hooks
      security_inode_removexattr(), security_inode_killpriv(),
      security_inode_getsecurity() to pass down the mount's user namespace and
      makes them aware of idmapped mounts.
      
      In order to actually get filesystem capabilities from disk the
      capability infrastructure exposes the get_vfs_caps_from_disk() helper.
      For user namespace aware filesystem capabilities a root uid is stored
      alongside the capabilities.
      
      In order to determine whether the caller can make use of the filesystem
      capability or whether it needs to be ignored it is translated according
      to the superblock's user namespace. If it can be translated to uid 0
      according to that id mapping the caller can use the filesystem
      capabilities stored on disk. If we are accessing the inode that holds
      the filesystem capabilities through an idmapped mount we map the root
      uid according to the mount's user namespace. Afterwards the checks are
      identical to non-idmapped mounts: reading filesystem caps from disk
      enforces that the root uid associated with the filesystem capability
      must have a mapping in the superblock's user namespace and that the
      caller is either in the same user namespace or is a descendant of the
      superblock's user namespace. For filesystems that are mountable inside
      user namespace the caller can just mount the filesystem and won't
      usually need to idmap it. If they do want to idmap it they can create an
      idmapped mount and mark it with a user namespace they created and which
      is thus a descendant of s_user_ns. For filesystems that are not
      mountable inside user namespaces the descendant rule is trivially true
      because the s_user_ns will be the initial user namespace.
      
      If the initial user namespace is passed nothing changes so non-idmapped
      mounts will see identical behavior as before.
      
      Link: https://lore.kernel.org/r/20210121131959.646623-11-christian.brauner@ubuntu.com
      Cc: Christoph Hellwig <hch@lst.de>
      Cc: David Howells <dhowells@redhat.com>
      Cc: Al Viro <viro@zeniv.linux.org.uk>
      Cc: linux-fsdevel@vger.kernel.org
      Reviewed-by: NChristoph Hellwig <hch@lst.de>
      Acked-by: NJames Morris <jamorris@linux.microsoft.com>
      Signed-off-by: NChristian Brauner <christian.brauner@ubuntu.com>
      71bc356f
    • T
      xattr: handle idmapped mounts · c7c7a1a1
      Tycho Andersen 提交于
      When interacting with extended attributes the vfs verifies that the
      caller is privileged over the inode with which the extended attribute is
      associated. For posix access and posix default extended attributes a uid
      or gid can be stored on-disk. Let the functions handle posix extended
      attributes on idmapped mounts. If the inode is accessed through an
      idmapped mount we need to map it according to the mount's user
      namespace. Afterwards the checks are identical to non-idmapped mounts.
      This has no effect for e.g. security xattrs since they don't store uids
      or gids and don't perform permission checks on them like posix acls do.
      
      Link: https://lore.kernel.org/r/20210121131959.646623-10-christian.brauner@ubuntu.com
      Cc: Christoph Hellwig <hch@lst.de>
      Cc: David Howells <dhowells@redhat.com>
      Cc: Al Viro <viro@zeniv.linux.org.uk>
      Cc: linux-fsdevel@vger.kernel.org
      Reviewed-by: NChristoph Hellwig <hch@lst.de>
      Reviewed-by: NJames Morris <jamorris@linux.microsoft.com>
      Signed-off-by: NTycho Andersen <tycho@tycho.pizza>
      Signed-off-by: NChristian Brauner <christian.brauner@ubuntu.com>
      c7c7a1a1
    • C
      inode: make init and permission helpers idmapped mount aware · 21cb47be
      Christian Brauner 提交于
      The inode_owner_or_capable() helper determines whether the caller is the
      owner of the inode or is capable with respect to that inode. Allow it to
      handle idmapped mounts. If the inode is accessed through an idmapped
      mount it according to the mount's user namespace. Afterwards the checks
      are identical to non-idmapped mounts. If the initial user namespace is
      passed nothing changes so non-idmapped mounts will see identical
      behavior as before.
      
      Similarly, allow the inode_init_owner() helper to handle idmapped
      mounts. It initializes a new inode on idmapped mounts by mapping the
      fsuid and fsgid of the caller from the mount's user namespace. If the
      initial user namespace is passed nothing changes so non-idmapped mounts
      will see identical behavior as before.
      
      Link: https://lore.kernel.org/r/20210121131959.646623-7-christian.brauner@ubuntu.com
      Cc: Christoph Hellwig <hch@lst.de>
      Cc: David Howells <dhowells@redhat.com>
      Cc: Al Viro <viro@zeniv.linux.org.uk>
      Cc: linux-fsdevel@vger.kernel.org
      Reviewed-by: NChristoph Hellwig <hch@lst.de>
      Reviewed-by: NJames Morris <jamorris@linux.microsoft.com>
      Signed-off-by: NChristian Brauner <christian.brauner@ubuntu.com>
      21cb47be
  3. 15 1月, 2021 1 次提交
    • D
      selinux: teach SELinux about anonymous inodes · 29cd6591
      Daniel Colascione 提交于
      This change uses the anon_inodes and LSM infrastructure introduced in
      the previous patches to give SELinux the ability to control
      anonymous-inode files that are created using the new
      anon_inode_getfd_secure() function.
      
      A SELinux policy author detects and controls these anonymous inodes by
      adding a name-based type_transition rule that assigns a new security
      type to anonymous-inode files created in some domain. The name used
      for the name-based transition is the name associated with the
      anonymous inode for file listings --- e.g., "[userfaultfd]" or
      "[perf_event]".
      
      Example:
      
      type uffd_t;
      type_transition sysadm_t sysadm_t : anon_inode uffd_t "[userfaultfd]";
      allow sysadm_t uffd_t:anon_inode { create };
      
      (The next patch in this series is necessary for making userfaultfd
      support this new interface.  The example above is just
      for exposition.)
      Signed-off-by: NDaniel Colascione <dancol@google.com>
      Signed-off-by: NLokesh Gidra <lokeshgidra@google.com>
      Signed-off-by: NPaul Moore <paul@paul-moore.com>
      29cd6591
  4. 13 1月, 2021 1 次提交
  5. 05 1月, 2021 2 次提交
  6. 04 12月, 2020 1 次提交
  7. 24 11月, 2020 2 次提交
  8. 13 11月, 2020 1 次提交
  9. 06 11月, 2020 1 次提交
    • P
      selinux: fix inode_doinit_with_dentry() LABEL_INVALID error handling · 200ea5a2
      Paul Moore 提交于
      A previous fix, commit 83370b31 ("selinux: fix error initialization
      in inode_doinit_with_dentry()"), changed how failures were handled
      before a SELinux policy was loaded.  Unfortunately that patch was
      potentially problematic for two reasons: it set the isec->initialized
      state without holding a lock, and it didn't set the inode's SELinux
      label to the "default" for the particular filesystem.  The later can
      be a problem if/when a later attempt to revalidate the inode fails
      and SELinux reverts to the existing inode label.
      
      This patch should restore the default inode labeling that existed
      before the original fix, without affecting the LABEL_INVALID marking
      such that revalidation will still be attempted in the future.
      
      Fixes: 83370b31 ("selinux: fix error initialization in inode_doinit_with_dentry()")
      Reported-by: NSven Schnelle <svens@linux.ibm.com>
      Tested-by: NSven Schnelle <svens@linux.ibm.com>
      Reviewed-by: NOndrej Mosnacek <omosnace@redhat.com>
      Signed-off-by: NPaul Moore <paul@paul-moore.com>
      200ea5a2
  10. 28 10月, 2020 1 次提交
  11. 05 10月, 2020 3 次提交
  12. 16 9月, 2020 1 次提交
  13. 27 8月, 2020 1 次提交
  14. 25 8月, 2020 1 次提交
  15. 24 8月, 2020 2 次提交
  16. 21 8月, 2020 1 次提交
    • S
      selinux: permit removing security.selinux xattr before policy load · 9530a3e0
      Stephen Smalley 提交于
      Currently SELinux denies attempts to remove the security.selinux xattr
      always, even when permissive or no policy is loaded.  This was originally
      motivated by the view that all files should be labeled, even if that label
      is unlabeled_t, and we shouldn't permit files that were once labeled to
      have their labels removed entirely.  This however prevents removing
      SELinux xattrs in the case where one "disables" SELinux by not loading
      a policy (e.g. a system where runtime disable is removed and selinux=0
      was not specified).  Allow removing the xattr before SELinux is
      initialized.  We could conceivably permit it even after initialization
      if permissive, or introduce a separate permission check here.
      Signed-off-by: NStephen Smalley <stephen.smalley.work@gmail.com>
      Signed-off-by: NPaul Moore <paul@paul-moore.com>
      9530a3e0
  17. 24 6月, 2020 1 次提交
  18. 21 5月, 2020 1 次提交
    • E
      exec: Factor security_bprm_creds_for_exec out of security_bprm_set_creds · b8bff599
      Eric W. Biederman 提交于
      Today security_bprm_set_creds has several implementations:
      apparmor_bprm_set_creds, cap_bprm_set_creds, selinux_bprm_set_creds,
      smack_bprm_set_creds, and tomoyo_bprm_set_creds.
      
      Except for cap_bprm_set_creds they all test bprm->called_set_creds and
      return immediately if it is true.  The function cap_bprm_set_creds
      ignores bprm->calld_sed_creds entirely.
      
      Create a new LSM hook security_bprm_creds_for_exec that is called just
      before prepare_binprm in __do_execve_file, resulting in a LSM hook
      that is called exactly once for the entire of exec.  Modify the bits
      of security_bprm_set_creds that only want to be called once per exec
      into security_bprm_creds_for_exec, leaving only cap_bprm_set_creds
      behind.
      
      Remove bprm->called_set_creds all of it's former users have been moved
      to security_bprm_creds_for_exec.
      
      Add or upate comments a appropriate to bring them up to date and
      to reflect this change.
      
      Link: https://lkml.kernel.org/r/87v9kszrzh.fsf_-_@x220.int.ebiederm.orgAcked-by: NLinus Torvalds <torvalds@linux-foundation.org>
      Acked-by: Casey Schaufler <casey@schaufler-ca.com> # For the LSM and Smack bits
      Reviewed-by: NKees Cook <keescook@chromium.org>
      Signed-off-by: N"Eric W. Biederman" <ebiederm@xmission.com>
      b8bff599
  19. 19 5月, 2020 2 次提交
    • D
      selinux: Implement the watch_key security hook · 3e412ccc
      David Howells 提交于
      Implement the watch_key security hook to make sure that a key grants the
      caller View permission in order to set a watch on a key.
      
      For the moment, the watch_devices security hook is left unimplemented as
      it's not obvious what the object should be since the queue is global and
      didn't previously exist.
      Signed-off-by: NDavid Howells <dhowells@redhat.com>
      Acked-by: NStephen Smalley <sds@tycho.nsa.gov>
      Reviewed-by: NJames Morris <jamorris@linux.microsoft.com>
      3e412ccc
    • D
      keys: Make the KEY_NEED_* perms an enum rather than a mask · 8c0637e9
      David Howells 提交于
      Since the meaning of combining the KEY_NEED_* constants is undefined, make
      it so that you can't do that by turning them into an enum.
      
      The enum is also given some extra values to represent special
      circumstances, such as:
      
       (1) The '0' value is reserved and causes a warning to trap the parameter
           being unset.
      
       (2) The key is to be unlinked and we require no permissions on it, only
           the keyring, (this replaces the KEY_LOOKUP_FOR_UNLINK flag).
      
       (3) An override due to CAP_SYS_ADMIN.
      
       (4) An override due to an instantiation token being present.
      
       (5) The permissions check is being deferred to later key_permission()
           calls.
      
      The extra values give the opportunity for LSMs to audit these situations.
      
      [Note: This really needs overhauling so that lookup_user_key() tells
       key_task_permission() and the LSM what operation is being done and leaves
       it to those functions to decide how to map that onto the available
       permits.  However, I don't really want to make these change in the middle
       of the notifications patchset.]
      Signed-off-by: NDavid Howells <dhowells@redhat.com>
      cc: Jarkko Sakkinen <jarkko.sakkinen@linux.intel.com>
      cc: Paul Moore <paul@paul-moore.com>
      cc: Stephen Smalley <stephen.smalley.work@gmail.com>
      cc: Casey Schaufler <casey@schaufler-ca.com>
      cc: keyrings@vger.kernel.org
      cc: selinux@vger.kernel.org
      8c0637e9
  20. 01 5月, 2020 1 次提交
  21. 23 2月, 2020 1 次提交
  22. 12 2月, 2020 1 次提交
  23. 10 2月, 2020 3 次提交
  24. 08 2月, 2020 2 次提交
  25. 06 2月, 2020 1 次提交
  26. 20 1月, 2020 1 次提交
    • S
      selinux: fix regression introduced by move_mount(2) syscall · 98aa0034
      Stephen Smalley 提交于
      commit 2db154b3 ("vfs: syscall: Add move_mount(2) to move mounts around")
      introduced a new move_mount(2) system call and a corresponding new LSM
      security_move_mount hook but did not implement this hook for any existing
      LSM.  This creates a regression for SELinux with respect to consistent
      checking of mounts; the existing selinux_mount hook checks mounton
      permission to the mount point path.  Provide a SELinux hook
      implementation for move_mount that applies this same check for
      consistency.  In the future we may wish to add a new move_mount
      filesystem permission and check as well, but this addresses
      the immediate regression.
      
      Fixes: 2db154b3 ("vfs: syscall: Add move_mount(2) to move mounts around")
      Signed-off-by: NStephen Smalley <sds@tycho.nsa.gov>
      Reviewed-by: NOndrej Mosnacek <omosnace@redhat.com>
      Signed-off-by: NPaul Moore <paul@paul-moore.com>
      98aa0034
  27. 17 1月, 2020 2 次提交
  28. 11 1月, 2020 1 次提交
    • O
      selinux: reorder hooks to make runtime disable less broken · cfff75d8
      Ondrej Mosnacek 提交于
      Commit b1d9e6b0 ("LSM: Switch to lists of hooks") switched the LSM
      infrastructure to use per-hook lists, which meant that removing the
      hooks for a given module was no longer atomic. Even though the commit
      clearly documents that modules implementing runtime revmoval of hooks
      (only SELinux attempts this madness) need to take special precautions to
      avoid race conditions, SELinux has never addressed this.
      
      By inserting an artificial delay between the loop iterations of
      security_delete_hooks() (I used 100 ms), booting to a state where
      SELinux is enabled, but policy is not yet loaded, and running these
      commands:
      
          while true; do ping -c 1 <some IP>; done &
          echo -n 1 >/sys/fs/selinux/disable
          kill %1
          wait
      
      ...I was able to trigger NULL pointer dereferences in various places. I
      also have a report of someone getting panics on a stock RHEL-8 kernel
      after setting SELINUX=disabled in /etc/selinux/config and rebooting
      (without adding "selinux=0" to kernel command-line).
      
      Reordering the SELinux hooks such that those that allocate structures
      are removed last seems to prevent these panics. It is very much possible
      that this doesn't make the runtime disable completely race-free, but at
      least it makes the operation much less fragile.
      
      Cc: stable@vger.kernel.org
      Fixes: b1d9e6b0 ("LSM: Switch to lists of hooks")
      Signed-off-by: NOndrej Mosnacek <omosnace@redhat.com>
      Reviewed-by: NStephen Smalley <sds@tycho.nsa.gov>
      Signed-off-by: NPaul Moore <paul@paul-moore.com>
      cfff75d8