1. 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
  2. 01 5月, 2020 1 次提交
  3. 23 2月, 2020 1 次提交
  4. 12 2月, 2020 1 次提交
  5. 10 2月, 2020 3 次提交
  6. 08 2月, 2020 2 次提交
  7. 06 2月, 2020 1 次提交
  8. 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
  9. 17 1月, 2020 2 次提交
  10. 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
  11. 07 1月, 2020 1 次提交
  12. 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
  13. 12 12月, 2019 1 次提交
  14. 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
  15. 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
  16. 15 11月, 2019 1 次提交
  17. 18 10月, 2019 1 次提交
    • J
      perf_event: Add support for LSM and SELinux checks · da97e184
      Joel Fernandes (Google) 提交于
      In current mainline, the degree of access to perf_event_open(2) system
      call depends on the perf_event_paranoid sysctl.  This has a number of
      limitations:
      
      1. The sysctl is only a single value. Many types of accesses are controlled
         based on the single value thus making the control very limited and
         coarse grained.
      2. The sysctl is global, so if the sysctl is changed, then that means
         all processes get access to perf_event_open(2) opening the door to
         security issues.
      
      This patch adds LSM and SELinux access checking which will be used in
      Android to access perf_event_open(2) for the purposes of attaching BPF
      programs to tracepoints, perf profiling and other operations from
      userspace. These operations are intended for production systems.
      
      5 new LSM hooks are added:
      1. perf_event_open: This controls access during the perf_event_open(2)
         syscall itself. The hook is called from all the places that the
         perf_event_paranoid sysctl is checked to keep it consistent with the
         systctl. The hook gets passed a 'type' argument which controls CPU,
         kernel and tracepoint accesses (in this context, CPU, kernel and
         tracepoint have the same semantics as the perf_event_paranoid sysctl).
         Additionally, I added an 'open' type which is similar to
         perf_event_paranoid sysctl == 3 patch carried in Android and several other
         distros but was rejected in mainline [1] in 2016.
      
      2. perf_event_alloc: This allocates a new security object for the event
         which stores the current SID within the event. It will be useful when
         the perf event's FD is passed through IPC to another process which may
         try to read the FD. Appropriate security checks will limit access.
      
      3. perf_event_free: Called when the event is closed.
      
      4. perf_event_read: Called from the read(2) and mmap(2) syscalls for the event.
      
      5. perf_event_write: Called from the ioctl(2) syscalls for the event.
      
      [1] https://lwn.net/Articles/696240/
      
      Since Peter had suggest LSM hooks in 2016 [1], I am adding his
      Suggested-by tag below.
      
      To use this patch, we set the perf_event_paranoid sysctl to -1 and then
      apply selinux checking as appropriate (default deny everything, and then
      add policy rules to give access to domains that need it). In the future
      we can remove the perf_event_paranoid sysctl altogether.
      Suggested-by: NPeter Zijlstra <peterz@infradead.org>
      Co-developed-by: NPeter Zijlstra <peterz@infradead.org>
      Signed-off-by: NJoel Fernandes (Google) <joel@joelfernandes.org>
      Signed-off-by: NPeter Zijlstra (Intel) <peterz@infradead.org>
      Acked-by: NJames Morris <jmorris@namei.org>
      Cc: Arnaldo Carvalho de Melo <acme@kernel.org>
      Cc: rostedt@goodmis.org
      Cc: Yonghong Song <yhs@fb.com>
      Cc: Kees Cook <keescook@chromium.org>
      Cc: Ingo Molnar <mingo@redhat.com>
      Cc: Alexei Starovoitov <ast@kernel.org>
      Cc: jeffv@google.com
      Cc: Jiri Olsa <jolsa@redhat.com>
      Cc: Daniel Borkmann <daniel@iogearbox.net>
      Cc: primiano@google.com
      Cc: Song Liu <songliubraving@fb.com>
      Cc: rsavitski@google.com
      Cc: Namhyung Kim <namhyung@kernel.org>
      Cc: Matthew Garrett <matthewgarrett@google.com>
      Link: https://lkml.kernel.org/r/20191014170308.70668-1-joel@joelfernandes.org
      da97e184
  18. 01 10月, 2019 1 次提交
    • J
      selinux: allow labeling before policy is loaded · 3e3e24b4
      Jonathan Lebon 提交于
      Currently, the SELinux LSM prevents one from setting the
      `security.selinux` xattr on an inode without a policy first being
      loaded. However, this restriction is problematic: it makes it impossible
      to have newly created files with the correct label before actually
      loading the policy.
      
      This is relevant in distributions like Fedora, where the policy is
      loaded by systemd shortly after pivoting out of the initrd. In such
      instances, all files created prior to pivoting will be unlabeled. One
      then has to relabel them after pivoting, an operation which inherently
      races with other processes trying to access those same files.
      
      Going further, there are use cases for creating the entire root
      filesystem on first boot from the initrd (e.g. Container Linux supports
      this today[1], and we'd like to support it in Fedora CoreOS as well[2]).
      One can imagine doing this in two ways: at the block device level (e.g.
      laying down a disk image), or at the filesystem level. In the former,
      labeling can simply be part of the image. But even in the latter
      scenario, one still really wants to be able to set the right labels when
      populating the new filesystem.
      
      This patch enables this by changing behaviour in the following two ways:
      1. allow `setxattr` if we're not initialized
      2. don't try to set the in-core inode SID if we're not initialized;
         instead leave it as `LABEL_INVALID` so that revalidation may be
         attempted at a later time
      
      Note the first hunk of this patch is mostly the same as a previously
      discussed one[3], though it was part of a larger series which wasn't
      accepted.
      
      [1] https://coreos.com/os/docs/latest/root-filesystem-placement.html
      [2] https://github.com/coreos/fedora-coreos-tracker/issues/94
      [3] https://www.spinics.net/lists/linux-initramfs/msg04593.htmlCo-developed-by: NVictor Kamensky <kamensky@cisco.com>
      Signed-off-by: NVictor Kamensky <kamensky@cisco.com>
      Signed-off-by: NJonathan Lebon <jlebon@redhat.com>
      Signed-off-by: NPaul Moore <paul@paul-moore.com>
      3e3e24b4
  19. 05 9月, 2019 1 次提交
  20. 13 8月, 2019 1 次提交
    • A
      fanotify, inotify, dnotify, security: add security hook for fs notifications · ac5656d8
      Aaron Goidel 提交于
      As of now, setting watches on filesystem objects has, at most, applied a
      check for read access to the inode, and in the case of fanotify, requires
      CAP_SYS_ADMIN. No specific security hook or permission check has been
      provided to control the setting of watches. Using any of inotify, dnotify,
      or fanotify, it is possible to observe, not only write-like operations, but
      even read access to a file. Modeling the watch as being merely a read from
      the file is insufficient for the needs of SELinux. This is due to the fact
      that read access should not necessarily imply access to information about
      when another process reads from a file. Furthermore, fanotify watches grant
      more power to an application in the form of permission events. While
      notification events are solely, unidirectional (i.e. they only pass
      information to the receiving application), permission events are blocking.
      Permission events make a request to the receiving application which will
      then reply with a decision as to whether or not that action may be
      completed. This causes the issue of the watching application having the
      ability to exercise control over the triggering process. Without drawing a
      distinction within the permission check, the ability to read would imply
      the greater ability to control an application. Additionally, mount and
      superblock watches apply to all files within the same mount or superblock.
      Read access to one file should not necessarily imply the ability to watch
      all files accessed within a given mount or superblock.
      
      In order to solve these issues, a new LSM hook is implemented and has been
      placed within the system calls for marking filesystem objects with inotify,
      fanotify, and dnotify watches. These calls to the hook are placed at the
      point at which the target path has been resolved and are provided with the
      path struct, the mask of requested notification events, and the type of
      object on which the mark is being set (inode, superblock, or mount). The
      mask and obj_type have already been translated into common FS_* values
      shared by the entirety of the fs notification infrastructure. The path
      struct is passed rather than just the inode so that the mount is available,
      particularly for mount watches. This also allows for use of the hook by
      pathname-based security modules. However, since the hook is intended for
      use even by inode based security modules, it is not placed under the
      CONFIG_SECURITY_PATH conditional. Otherwise, the inode-based security
      modules would need to enable all of the path hooks, even though they do not
      use any of them.
      
      This only provides a hook at the point of setting a watch, and presumes
      that permission to set a particular watch implies the ability to receive
      all notification about that object which match the mask. This is all that
      is required for SELinux. If other security modules require additional hooks
      or infrastructure to control delivery of notification, these can be added
      by them. It does not make sense for us to propose hooks for which we have
      no implementation. The understanding that all notifications received by the
      requesting application are all strictly of a type for which the application
      has been granted permission shows that this implementation is sufficient in
      its coverage.
      
      Security modules wishing to provide complete control over fanotify must
      also implement a security_file_open hook that validates that the access
      requested by the watching application is authorized. Fanotify has the issue
      that it returns a file descriptor with the file mode specified during
      fanotify_init() to the watching process on event. This is already covered
      by the LSM security_file_open hook if the security module implements
      checking of the requested file mode there. Otherwise, a watching process
      can obtain escalated access to a file for which it has not been authorized.
      
      The selinux_path_notify hook implementation works by adding five new file
      permissions: watch, watch_mount, watch_sb, watch_reads, and watch_with_perm
      (descriptions about which will follow), and one new filesystem permission:
      watch (which is applied to superblock checks). The hook then decides which
      subset of these permissions must be held by the requesting application
      based on the contents of the provided mask and the obj_type. The
      selinux_file_open hook already checks the requested file mode and therefore
      ensures that a watching process cannot escalate its access through
      fanotify.
      
      The watch, watch_mount, and watch_sb permissions are the baseline
      permissions for setting a watch on an object and each are a requirement for
      any watch to be set on a file, mount, or superblock respectively. It should
      be noted that having either of the other two permissions (watch_reads and
      watch_with_perm) does not imply the watch, watch_mount, or watch_sb
      permission. Superblock watches further require the filesystem watch
      permission to the superblock. As there is no labeled object in view for
      mounts, there is no specific check for mount watches beyond watch_mount to
      the inode. Such a check could be added in the future, if a suitable labeled
      object existed representing the mount.
      
      The watch_reads permission is required to receive notifications from
      read-exclusive events on filesystem objects. These events include accessing
      a file for the purpose of reading and closing a file which has been opened
      read-only. This distinction has been drawn in order to provide a direct
      indication in the policy for this otherwise not obvious capability. Read
      access to a file should not necessarily imply the ability to observe read
      events on a file.
      
      Finally, watch_with_perm only applies to fanotify masks since it is the
      only way to set a mask which allows for the blocking, permission event.
      This permission is needed for any watch which is of this type. Though
      fanotify requires CAP_SYS_ADMIN, this is insufficient as it gives implicit
      trust to root, which we do not do, and does not support least privilege.
      Signed-off-by: NAaron Goidel <acgoide@tycho.nsa.gov>
      Acked-by: NCasey Schaufler <casey@schaufler-ca.com>
      Acked-by: NJan Kara <jack@suse.cz>
      Signed-off-by: NPaul Moore <paul@paul-moore.com>
      ac5656d8
  21. 11 7月, 2019 1 次提交
  22. 28 6月, 2019 1 次提交
    • D
      keys: Replace uid/gid/perm permissions checking with an ACL · 2e12256b
      David Howells 提交于
      Replace the uid/gid/perm permissions checking on a key with an ACL to allow
      the SETATTR and SEARCH permissions to be split.  This will also allow a
      greater range of subjects to represented.
      
      ============
      WHY DO THIS?
      ============
      
      The problem is that SETATTR and SEARCH cover a slew of actions, not all of
      which should be grouped together.
      
      For SETATTR, this includes actions that are about controlling access to a
      key:
      
       (1) Changing a key's ownership.
      
       (2) Changing a key's security information.
      
       (3) Setting a keyring's restriction.
      
      And actions that are about managing a key's lifetime:
      
       (4) Setting an expiry time.
      
       (5) Revoking a key.
      
      and (proposed) managing a key as part of a cache:
      
       (6) Invalidating a key.
      
      Managing a key's lifetime doesn't really have anything to do with
      controlling access to that key.
      
      Expiry time is awkward since it's more about the lifetime of the content
      and so, in some ways goes better with WRITE permission.  It can, however,
      be set unconditionally by a process with an appropriate authorisation token
      for instantiating a key, and can also be set by the key type driver when a
      key is instantiated, so lumping it with the access-controlling actions is
      probably okay.
      
      As for SEARCH permission, that currently covers:
      
       (1) Finding keys in a keyring tree during a search.
      
       (2) Permitting keyrings to be joined.
      
       (3) Invalidation.
      
      But these don't really belong together either, since these actions really
      need to be controlled separately.
      
      Finally, there are number of special cases to do with granting the
      administrator special rights to invalidate or clear keys that I would like
      to handle with the ACL rather than key flags and special checks.
      
      
      ===============
      WHAT IS CHANGED
      ===============
      
      The SETATTR permission is split to create two new permissions:
      
       (1) SET_SECURITY - which allows the key's owner, group and ACL to be
           changed and a restriction to be placed on a keyring.
      
       (2) REVOKE - which allows a key to be revoked.
      
      The SEARCH permission is split to create:
      
       (1) SEARCH - which allows a keyring to be search and a key to be found.
      
       (2) JOIN - which allows a keyring to be joined as a session keyring.
      
       (3) INVAL - which allows a key to be invalidated.
      
      The WRITE permission is also split to create:
      
       (1) WRITE - which allows a key's content to be altered and links to be
           added, removed and replaced in a keyring.
      
       (2) CLEAR - which allows a keyring to be cleared completely.  This is
           split out to make it possible to give just this to an administrator.
      
       (3) REVOKE - see above.
      
      
      Keys acquire ACLs which consist of a series of ACEs, and all that apply are
      unioned together.  An ACE specifies a subject, such as:
      
       (*) Possessor - permitted to anyone who 'possesses' a key
       (*) Owner - permitted to the key owner
       (*) Group - permitted to the key group
       (*) Everyone - permitted to everyone
      
      Note that 'Other' has been replaced with 'Everyone' on the assumption that
      you wouldn't grant a permit to 'Other' that you wouldn't also grant to
      everyone else.
      
      Further subjects may be made available by later patches.
      
      The ACE also specifies a permissions mask.  The set of permissions is now:
      
      	VIEW		Can view the key metadata
      	READ		Can read the key content
      	WRITE		Can update/modify the key content
      	SEARCH		Can find the key by searching/requesting
      	LINK		Can make a link to the key
      	SET_SECURITY	Can change owner, ACL, expiry
      	INVAL		Can invalidate
      	REVOKE		Can revoke
      	JOIN		Can join this keyring
      	CLEAR		Can clear this keyring
      
      
      The KEYCTL_SETPERM function is then deprecated.
      
      The KEYCTL_SET_TIMEOUT function then is permitted if SET_SECURITY is set,
      or if the caller has a valid instantiation auth token.
      
      The KEYCTL_INVALIDATE function then requires INVAL.
      
      The KEYCTL_REVOKE function then requires REVOKE.
      
      The KEYCTL_JOIN_SESSION_KEYRING function then requires JOIN to join an
      existing keyring.
      
      The JOIN permission is enabled by default for session keyrings and manually
      created keyrings only.
      
      
      ======================
      BACKWARD COMPATIBILITY
      ======================
      
      To maintain backward compatibility, KEYCTL_SETPERM will translate the
      permissions mask it is given into a new ACL for a key - unless
      KEYCTL_SET_ACL has been called on that key, in which case an error will be
      returned.
      
      It will convert possessor, owner, group and other permissions into separate
      ACEs, if each portion of the mask is non-zero.
      
      SETATTR permission turns on all of INVAL, REVOKE and SET_SECURITY.  WRITE
      permission turns on WRITE, REVOKE and, if a keyring, CLEAR.  JOIN is turned
      on if a keyring is being altered.
      
      The KEYCTL_DESCRIBE function translates the ACL back into a permissions
      mask to return depending on possessor, owner, group and everyone ACEs.
      
      It will make the following mappings:
      
       (1) INVAL, JOIN -> SEARCH
      
       (2) SET_SECURITY -> SETATTR
      
       (3) REVOKE -> WRITE if SETATTR isn't already set
      
       (4) CLEAR -> WRITE
      
      Note that the value subsequently returned by KEYCTL_DESCRIBE may not match
      the value set with KEYCTL_SETATTR.
      
      
      =======
      TESTING
      =======
      
      This passes the keyutils testsuite for all but a couple of tests:
      
       (1) tests/keyctl/dh_compute/badargs: The first wrong-key-type test now
           returns EOPNOTSUPP rather than ENOKEY as READ permission isn't removed
           if the type doesn't have ->read().  You still can't actually read the
           key.
      
       (2) tests/keyctl/permitting/valid: The view-other-permissions test doesn't
           work as Other has been replaced with Everyone in the ACL.
      Signed-off-by: NDavid Howells <dhowells@redhat.com>
      2e12256b
  23. 19 6月, 2019 1 次提交
  24. 14 6月, 2019 1 次提交
  25. 13 6月, 2019 2 次提交
  26. 12 6月, 2019 1 次提交
  27. 21 5月, 2019 1 次提交
  28. 11 5月, 2019 1 次提交
  29. 09 5月, 2019 1 次提交