1. 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
  2. 28 10月, 2020 1 次提交
  3. 05 10月, 2020 3 次提交
  4. 16 9月, 2020 1 次提交
  5. 27 8月, 2020 1 次提交
  6. 25 8月, 2020 1 次提交
  7. 24 8月, 2020 2 次提交
  8. 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
  9. 24 6月, 2020 1 次提交
  10. 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
  11. 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
  12. 01 5月, 2020 1 次提交
  13. 23 2月, 2020 1 次提交
  14. 12 2月, 2020 1 次提交
  15. 10 2月, 2020 3 次提交
  16. 08 2月, 2020 2 次提交
  17. 06 2月, 2020 1 次提交
  18. 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
  19. 17 1月, 2020 2 次提交
  20. 11 1月, 2020 4 次提交
    • 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
    • O
      selinux: treat atomic flags more carefully · 65cddd50
      Ondrej Mosnacek 提交于
      The disabled/enforcing/initialized flags are all accessed concurrently
      by threads so use the appropriate accessors that ensure atomicity and
      document that it is expected.
      
      Use smp_load/acquire...() helpers (with memory barriers) for the
      initialized flag, since it gates access to the rest of the state
      structures.
      
      Note that the disabled flag is currently not used for anything other
      than avoiding double disable, but it will be used for bailing out of
      hooks once security_delete_hooks() is removed.
      Signed-off-by: NOndrej Mosnacek <omosnace@redhat.com>
      Acked-by: NStephen Smalley <sds@tycho.nsa.gov>
      Reviewed-by: NKees Cook <keescook@chromium.org>
      Reviewed-by: NJames Morris <jamorris@linux.microsoft.com>
      Signed-off-by: NPaul Moore <paul@paul-moore.com>
      65cddd50
    • S
      selinux: make default_noexec read-only after init · b78b7d59
      Stephen Smalley 提交于
      SELinux checks whether VM_EXEC is set in the VM_DATA_DEFAULT_FLAGS
      during initialization and saves the result in default_noexec for use
      in its mmap and mprotect hook function implementations to decide
      whether to apply EXECMEM, EXECHEAP, EXECSTACK, and EXECMOD checks.
      Mark default_noexec as ro_after_init to prevent later clearing it
      and thereby disabling these checks.  It is only set legitimately from
      init code.
      Signed-off-by: NStephen Smalley <sds@tycho.nsa.gov>
      Signed-off-by: NPaul Moore <paul@paul-moore.com>
      b78b7d59
    • H
      selinux: remove redundant msg_msg_alloc_security · b82f3f68
      Huaisheng Ye 提交于
      selinux_msg_msg_alloc_security only calls msg_msg_alloc_security but
      do nothing else. And also msg_msg_alloc_security is just used by the
      former.
      
      Remove the redundant function to simplify the code.
      Signed-off-by: NHuaisheng Ye <yehs1@lenovo.com>
      Acked-by: NStephen Smalley <sds@tycho.nsa.gov>
      Signed-off-by: NPaul Moore <paul@paul-moore.com>
      b82f3f68
  21. 07 1月, 2020 1 次提交
  22. 19 12月, 2019 1 次提交
    • S
      selinux: clean up selinux_enabled/disabled/enforcing_boot · 6c5a682e
      Stephen Smalley 提交于
      Rename selinux_enabled to selinux_enabled_boot to make it clear that
      it only reflects whether SELinux was enabled at boot.  Replace the
      references to it in the MAC_STATUS audit log in sel_write_enforce()
      with hardcoded "1" values because this code is only reachable if SELinux
      is enabled and does not change its value, and update the corresponding
      MAC_STATUS audit log in sel_write_disable().  Stop clearing
      selinux_enabled in selinux_disable() since it is not used outside of
      initialization code that runs before selinux_disable() can be reached.
      Mark both selinux_enabled_boot and selinux_enforcing_boot as __initdata
      since they are only used in initialization code.
      
      Wrap the disabled field in the struct selinux_state with
      CONFIG_SECURITY_SELINUX_DISABLE since it is only used for
      runtime disable.
      Signed-off-by: NStephen Smalley <sds@tycho.nsa.gov>
      Signed-off-by: NPaul Moore <paul@paul-moore.com>
      6c5a682e
  23. 12 12月, 2019 1 次提交
  24. 10 12月, 2019 4 次提交
    • S
      selinux: clean up selinux_inode_permission MAY_NOT_BLOCK tests · 5298d0b9
      Stephen Smalley 提交于
      Through a somewhat convoluted series of changes, we have ended up
      with multiple unnecessary occurrences of (flags & MAY_NOT_BLOCK)
      tests in selinux_inode_permission().  Clean it up and simplify.
      No functional change.
      Signed-off-by: NStephen Smalley <sds@tycho.nsa.gov>
      Signed-off-by: NPaul Moore <paul@paul-moore.com>
      5298d0b9
    • S
      selinux: fall back to ref-walk if audit is required · 0188d5c0
      Stephen Smalley 提交于
      commit bda0be7a ("security: make inode_follow_link RCU-walk aware")
      passed down the rcu flag to the SELinux AVC, but failed to adjust the
      test in slow_avc_audit() to also return -ECHILD on LSM_AUDIT_DATA_DENTRY.
      Previously, we only returned -ECHILD if generating an audit record with
      LSM_AUDIT_DATA_INODE since this was only relevant from inode_permission.
      Move the handling of MAY_NOT_BLOCK to avc_audit() and its inlined
      equivalent in selinux_inode_permission() immediately after we determine
      that audit is required, and always fall back to ref-walk in this case.
      
      Fixes: bda0be7a ("security: make inode_follow_link RCU-walk aware")
      Reported-by: NWill Deacon <will@kernel.org>
      Suggested-by: NAl Viro <viro@zeniv.linux.org.uk>
      Signed-off-by: NStephen Smalley <sds@tycho.nsa.gov>
      Signed-off-by: NPaul Moore <paul@paul-moore.com>
      0188d5c0
    • S
      selinux: revert "stop passing MAY_NOT_BLOCK to the AVC upon follow_link" · 1a37079c
      Stephen Smalley 提交于
      This reverts commit e46e01ee ("selinux: stop passing MAY_NOT_BLOCK
      to the AVC upon follow_link"). The correct fix is to instead fall
      back to ref-walk if audit is required irrespective of the specific
      audit data type.  This is done in the next commit.
      
      Fixes: e46e01ee ("selinux: stop passing MAY_NOT_BLOCK to the AVC upon follow_link")
      Reported-by: NWill Deacon <will@kernel.org>
      Signed-off-by: NStephen Smalley <sds@tycho.nsa.gov>
      Signed-off-by: NPaul Moore <paul@paul-moore.com>
      1a37079c
    • S
      security,lockdown,selinux: implement SELinux lockdown · 59438b46
      Stephen Smalley 提交于
      Implement a SELinux hook for lockdown.  If the lockdown module is also
      enabled, then a denial by the lockdown module will take precedence over
      SELinux, so SELinux can only further restrict lockdown decisions.
      The SELinux hook only distinguishes at the granularity of integrity
      versus confidentiality similar to the lockdown module, but includes the
      full lockdown reason as part of the audit record as a hint in diagnosing
      what triggered the denial.  To support this auditing, move the
      lockdown_reasons[] string array from being private to the lockdown
      module to the security framework so that it can be used by the lsm audit
      code and so that it is always available even when the lockdown module
      is disabled.
      
      Note that the SELinux implementation allows the integrity and
      confidentiality reasons to be controlled independently from one another.
      Thus, in an SELinux policy, one could allow operations that specify
      an integrity reason while blocking operations that specify a
      confidentiality reason. The SELinux hook implementation is
      stricter than the lockdown module in validating the provided reason value.
      
      Sample AVC audit output from denials:
      avc:  denied  { integrity } for pid=3402 comm="fwupd"
       lockdown_reason="/dev/mem,kmem,port" scontext=system_u:system_r:fwupd_t:s0
       tcontext=system_u:system_r:fwupd_t:s0 tclass=lockdown permissive=0
      
      avc:  denied  { confidentiality } for pid=4628 comm="cp"
       lockdown_reason="/proc/kcore access"
       scontext=unconfined_u:unconfined_r:test_lockdown_integrity_t:s0-s0:c0.c1023
       tcontext=unconfined_u:unconfined_r:test_lockdown_integrity_t:s0-s0:c0.c1023
       tclass=lockdown permissive=0
      Signed-off-by: NStephen Smalley <sds@tycho.nsa.gov>
      Reviewed-by: NJames Morris <jamorris@linux.microsoft.com>
      [PM: some merge fuzz do the the perf hooks]
      Signed-off-by: NPaul Moore <paul@paul-moore.com>
      59438b46
  25. 27 11月, 2019 1 次提交
    • M
      net: port < inet_prot_sock(net) --> inet_port_requires_bind_service(net, port) · 82f31ebf
      Maciej Żenczykowski 提交于
      Note that the sysctl write accessor functions guarantee that:
        net->ipv4.sysctl_ip_prot_sock <= net->ipv4.ip_local_ports.range[0]
      invariant is maintained, and as such the max() in selinux hooks is actually spurious.
      
      ie. even though
        if (snum < max(inet_prot_sock(sock_net(sk)), low) || snum > high) {
      per logic is the same as
        if ((snum < inet_prot_sock(sock_net(sk)) && snum < low) || snum > high) {
      it is actually functionally equivalent to:
        if (snum < low || snum > high) {
      which is equivalent to:
        if (snum < inet_prot_sock(sock_net(sk)) || snum < low || snum > high) {
      even though the first clause is spurious.
      
      But we want to hold on to it in case we ever want to change what what
      inet_port_requires_bind_service() means (for example by changing
      it from a, by default, [0..1024) range to some sort of set).
      
      Test: builds, git 'grep inet_prot_sock' finds no other references
      Cc: Eric Dumazet <edumazet@google.com>
      Signed-off-by: NMaciej Żenczykowski <maze@google.com>
      Signed-off-by: NDavid S. Miller <davem@davemloft.net>
      82f31ebf
  26. 15 11月, 2019 1 次提交