1. 23 3月, 2021 3 次提交
    • P
      selinux: clarify task subjective and objective credentials · eb1231f7
      Paul Moore 提交于
      SELinux has a function, task_sid(), which returns the task's
      objective credentials, but unfortunately is used in a few places
      where the subjective task credentials should be used.  Most notably
      in the new security_task_getsecid_subj() LSM hook.
      
      This patch fixes this and attempts to make things more obvious by
      introducing a new function, task_sid_subj(), and renaming the
      existing task_sid() function to task_sid_obj().
      
      This patch also adds an interesting function in task_sid_binder().
      The task_sid_binder() function has a comment which hopefully
      describes it's reason for being, but it basically boils down to the
      simple fact that we can't safely access another task's subjective
      credentials so in the case of binder we need to stick with the
      objective credentials regardless.
      Reviewed-by: NRichard Guy Briggs <rgb@redhat.com>
      Signed-off-by: NPaul Moore <paul@paul-moore.com>
      eb1231f7
    • P
      lsm: separate security_task_getsecid() into subjective and objective variants · 4ebd7651
      Paul Moore 提交于
      Of the three LSMs that implement the security_task_getsecid() LSM
      hook, all three LSMs provide the task's objective security
      credentials.  This turns out to be unfortunate as most of the hook's
      callers seem to expect the task's subjective credentials, although
      a small handful of callers do correctly expect the objective
      credentials.
      
      This patch is the first step towards fixing the problem: it splits
      the existing security_task_getsecid() hook into two variants, one
      for the subjective creds, one for the objective creds.
      
        void security_task_getsecid_subj(struct task_struct *p,
      				   u32 *secid);
        void security_task_getsecid_obj(struct task_struct *p,
      				  u32 *secid);
      
      While this patch does fix all of the callers to use the correct
      variant, in order to keep this patch focused on the callers and to
      ease review, the LSMs continue to use the same implementation for
      both hooks.  The net effect is that this patch should not change
      the behavior of the kernel in any way, it will be up to the latter
      LSM specific patches in this series to change the hook
      implementations and return the correct credentials.
      
      Acked-by: Mimi Zohar <zohar@linux.ibm.com> (IMA)
      Acked-by: NCasey Schaufler <casey@schaufler-ca.com>
      Reviewed-by: NRichard Guy Briggs <rgb@redhat.com>
      Signed-off-by: NPaul Moore <paul@paul-moore.com>
      4ebd7651
    • O
      lsm,selinux: add new hook to compare new mount to an existing mount · 69c4a42d
      Olga Kornievskaia 提交于
      Add a new hook that takes an existing super block and a new mount
      with new options and determines if new options confict with an
      existing mount or not.
      
      A filesystem can use this new hook to determine if it can share
      the an existing superblock with a new superblock for the new mount.
      Signed-off-by: NOlga Kornievskaia <kolga@netapp.com>
      Acked-by: NAnna Schumaker <Anna.Schumaker@Netapp.com>
      [PM: tweak the subject line, fix tab/space problems]
      Signed-off-by: NPaul Moore <paul@paul-moore.com>
      69c4a42d
  2. 09 3月, 2021 1 次提交
    • V
      selinux: Allow context mounts for unpriviliged overlayfs · 7fa2e79a
      Vivek Goyal 提交于
      Now overlayfs allow unpriviliged mounts. That is root inside a non-init
      user namespace can mount overlayfs. This is being added in 5.11 kernel.
      
      Giuseppe tried to mount overlayfs with option "context" and it failed
      with error -EACCESS.
      
      $ su test
      $ unshare -rm
      $ mkdir -p lower upper work merged
      $ mount -t overlay -o lowerdir=lower,workdir=work,upperdir=upper,userxattr,context='system_u:object_r:container_file_t:s0' none merged
      
      This fails with -EACCESS. It works if option "-o context" is not specified.
      
      Little debugging showed that selinux_set_mnt_opts() returns -EACCESS.
      
      So this patch adds "overlay" to the list, where it is fine to specific
      context from non init_user_ns.
      Reported-by: NGiuseppe Scrivano <gscrivan@redhat.com>
      Signed-off-by: NVivek Goyal <vgoyal@redhat.com>
      [PM: trimmed the changelog from the description]
      Signed-off-by: NPaul Moore <paul@paul-moore.com>
      7fa2e79a
  3. 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
  4. 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
  5. 13 1月, 2021 1 次提交
  6. 05 1月, 2021 2 次提交
  7. 04 12月, 2020 1 次提交
  8. 24 11月, 2020 2 次提交
  9. 13 11月, 2020 1 次提交
  10. 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
  11. 28 10月, 2020 1 次提交
  12. 05 10月, 2020 3 次提交
  13. 16 9月, 2020 1 次提交
  14. 27 8月, 2020 1 次提交
  15. 25 8月, 2020 1 次提交
  16. 24 8月, 2020 2 次提交
  17. 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
  18. 24 6月, 2020 1 次提交
  19. 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
  20. 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
  21. 01 5月, 2020 1 次提交
  22. 23 2月, 2020 1 次提交
  23. 12 2月, 2020 1 次提交
  24. 10 2月, 2020 3 次提交
  25. 08 2月, 2020 2 次提交
  26. 06 2月, 2020 1 次提交
  27. 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