1. 23 5月, 2022 1 次提交
  2. 14 5月, 2022 1 次提交
  3. 16 2月, 2022 1 次提交
  4. 07 12月, 2021 1 次提交
  5. 23 11月, 2021 1 次提交
  6. 14 11月, 2021 1 次提交
    • P
      net,lsm,selinux: revert the security_sctp_assoc_established() hook · 1aa3b220
      Paul Moore 提交于
      This patch reverts two prior patches, e7310c94
      ("security: implement sctp_assoc_established hook in selinux") and
      7c2ef024 ("security: add sctp_assoc_established hook"), which
      create the security_sctp_assoc_established() LSM hook and provide a
      SELinux implementation.  Unfortunately these two patches were merged
      without proper review (the Reviewed-by and Tested-by tags from
      Richard Haines were for previous revisions of these patches that
      were significantly different) and there are outstanding objections
      from the SELinux maintainers regarding these patches.
      
      Work is currently ongoing to correct the problems identified in the
      reverted patches, as well as others that have come up during review,
      but it is unclear at this point in time when that work will be ready
      for inclusion in the mainline kernel.  In the interest of not keeping
      objectionable code in the kernel for multiple weeks, and potentially
      a kernel release, we are reverting the two problematic patches.
      Signed-off-by: NPaul Moore <paul@paul-moore.com>
      Signed-off-by: NDavid S. Miller <davem@davemloft.net>
      1aa3b220
  7. 13 11月, 2021 1 次提交
    • P
      net,lsm,selinux: revert the security_sctp_assoc_established() hook · 32a370ab
      Paul Moore 提交于
      This patch reverts two prior patches, e7310c94
      ("security: implement sctp_assoc_established hook in selinux") and
      7c2ef024 ("security: add sctp_assoc_established hook"), which
      create the security_sctp_assoc_established() LSM hook and provide a
      SELinux implementation.  Unfortunately these two patches were merged
      without proper review (the Reviewed-by and Tested-by tags from
      Richard Haines were for previous revisions of these patches that
      were significantly different) and there are outstanding objections
      from the SELinux maintainers regarding these patches.
      
      Work is currently ongoing to correct the problems identified in the
      reverted patches, as well as others that have come up during review,
      but it is unclear at this point in time when that work will be ready
      for inclusion in the mainline kernel.  In the interest of not keeping
      objectionable code in the kernel for multiple weeks, and potentially
      a kernel release, we are reverting the two problematic patches.
      Signed-off-by: NPaul Moore <paul@paul-moore.com>
      32a370ab
  8. 03 11月, 2021 2 次提交
  9. 20 10月, 2021 1 次提交
  10. 15 10月, 2021 1 次提交
  11. 20 9月, 2021 1 次提交
    • P
      lsm,io_uring: add LSM hooks to io_uring · cdc1404a
      Paul Moore 提交于
      A full expalantion of io_uring is beyond the scope of this commit
      description, but in summary it is an asynchronous I/O mechanism
      which allows for I/O requests and the resulting data to be queued
      in memory mapped "rings" which are shared between the kernel and
      userspace.  Optionally, io_uring offers the ability for applications
      to spawn kernel threads to dequeue I/O requests from the ring and
      submit the requests in the kernel, helping to minimize the syscall
      overhead.  Rings are accessed in userspace by memory mapping a file
      descriptor provided by the io_uring_setup(2), and can be shared
      between applications as one might do with any open file descriptor.
      Finally, process credentials can be registered with a given ring
      and any process with access to that ring can submit I/O requests
      using any of the registered credentials.
      
      While the io_uring functionality is widely recognized as offering a
      vastly improved, and high performing asynchronous I/O mechanism, its
      ability to allow processes to submit I/O requests with credentials
      other than its own presents a challenge to LSMs.  When a process
      creates a new io_uring ring the ring's credentials are inhertied
      from the calling process; if this ring is shared with another
      process operating with different credentials there is the potential
      to bypass the LSMs security policy.  Similarly, registering
      credentials with a given ring allows any process with access to that
      ring to submit I/O requests with those credentials.
      
      In an effort to allow LSMs to apply security policy to io_uring I/O
      operations, this patch adds two new LSM hooks.  These hooks, in
      conjunction with the LSM anonymous inode support previously
      submitted, allow an LSM to apply access control policy to the
      sharing of io_uring rings as well as any io_uring credential changes
      requested by a process.
      
      The new LSM hooks are described below:
      
       * int security_uring_override_creds(cred)
         Controls if the current task, executing an io_uring operation,
         is allowed to override it's credentials with @cred.  In cases
         where the current task is a user application, the current
         credentials will be those of the user application.  In cases
         where the current task is a kernel thread servicing io_uring
         requests the current credentials will be those of the io_uring
         ring (inherited from the process that created the ring).
      
       * int security_uring_sqpoll(void)
         Controls if the current task is allowed to create an io_uring
         polling thread (IORING_SETUP_SQPOLL).  Without a SQPOLL thread
         in the kernel processes must submit I/O requests via
         io_uring_enter(2) which allows us to compare any requested
         credential changes against the application making the request.
         With a SQPOLL thread, we can no longer compare requested
         credential changes against the application making the request,
         the comparison is made against the ring's credentials.
      Signed-off-by: NPaul Moore <paul@paul-moore.com>
      cdc1404a
  12. 23 4月, 2021 2 次提交
  13. 23 3月, 2021 2 次提交
    • 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
  14. 24 1月, 2021 1 次提交
    • 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
  15. 15 1月, 2021 1 次提交
    • L
      security: add inode_init_security_anon() LSM hook · 215b674b
      Lokesh Gidra 提交于
      This change adds a new LSM hook, inode_init_security_anon(), that will
      be used while creating secure anonymous inodes. The hook allows/denies
      its creation and assigns a security context to the inode.
      
      The new hook accepts an optional context_inode parameter that callers
      can use to provide additional contextual information to security modules
      for granting/denying permission to create an anon-inode of the same type.
      This context_inode's security_context can also be used to initialize the
      newly created anon-inode's security_context.
      Signed-off-by: NLokesh Gidra <lokeshgidra@google.com>
      Reviewed-by: NEric Biggers <ebiggers@google.com>
      Signed-off-by: NPaul Moore <paul@paul-moore.com>
      215b674b
  16. 24 11月, 2020 1 次提交
  17. 26 10月, 2020 1 次提交
  18. 05 10月, 2020 2 次提交
    • K
      LSM: Add "contents" flag to kernel_read_file hook · 2039bda1
      Kees Cook 提交于
      As with the kernel_load_data LSM hook, add a "contents" flag to the
      kernel_read_file LSM hook that indicates whether the LSM can expect
      a matching call to the kernel_post_read_file LSM hook with the full
      contents of the file. With the coming addition of partial file read
      support for kernel_read_file*() API, the LSM will no longer be able
      to always see the entire contents of a file during the read calls.
      
      For cases where the LSM must read examine the complete file contents,
      it will need to do so on its own every time the kernel_read_file
      hook is called with contents=false (or reject such cases). Adjust all
      existing LSMs to retain existing behavior.
      Signed-off-by: NKees Cook <keescook@chromium.org>
      Reviewed-by: NMimi Zohar <zohar@linux.ibm.com>
      Link: https://lore.kernel.org/r/20201002173828.2099543-12-keescook@chromium.orgSigned-off-by: NGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      2039bda1
    • K
      LSM: Introduce kernel_post_load_data() hook · b64fcae7
      Kees Cook 提交于
      There are a few places in the kernel where LSMs would like to have
      visibility into the contents of a kernel buffer that has been loaded or
      read. While security_kernel_post_read_file() (which includes the
      buffer) exists as a pairing for security_kernel_read_file(), no such
      hook exists to pair with security_kernel_load_data().
      
      Earlier proposals for just using security_kernel_post_read_file() with a
      NULL file argument were rejected (i.e. "file" should always be valid for
      the security_..._file hooks, but it appears at least one case was
      left in the kernel during earlier refactoring. (This will be fixed in
      a subsequent patch.)
      
      Since not all cases of security_kernel_load_data() can have a single
      contiguous buffer made available to the LSM hook (e.g. kexec image
      segments are separately loaded), there needs to be a way for the LSM to
      reason about its expectations of the hook coverage. In order to handle
      this, add a "contents" argument to the "kernel_load_data" hook that
      indicates if the newly added "kernel_post_load_data" hook will be called
      with the full contents once loaded. That way, LSMs requiring full contents
      can choose to unilaterally reject "kernel_load_data" with contents=false
      (which is effectively the existing hook coverage), but when contents=true
      they can allow it and later evaluate the "kernel_post_load_data" hook
      once the buffer is loaded.
      
      With this change, LSMs can gain coverage over non-file-backed data loads
      (e.g. init_module(2) and firmware userspace helper), which will happen
      in subsequent patches.
      
      Additionally prepare IMA to start processing these cases.
      Signed-off-by: NKees Cook <keescook@chromium.org>
      Reviewed-by: NKP Singh <kpsingh@google.com>
      Link: https://lore.kernel.org/r/20201002173828.2099543-9-keescook@chromium.orgSigned-off-by: NGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      b64fcae7
  19. 07 8月, 2020 1 次提交
  20. 15 6月, 2020 1 次提交
  21. 30 5月, 2020 2 次提交
    • E
      exec: Compute file based creds only once · 56305aa9
      Eric W. Biederman 提交于
      Move the computation of creds from prepare_binfmt into begin_new_exec
      so that the creds need only be computed once.  This is just code
      reorganization no semantic changes of any kind are made.
      
      Moving the computation is safe.  I have looked through the kernel and
      verified none of the binfmts look at bprm->cred directly, and that
      there are no helpers that look at bprm->cred indirectly.  Which means
      that it is not a problem to compute the bprm->cred later in the
      execution flow as it is not used until it becomes current->cred.
      
      A new function bprm_creds_from_file is added to contain the work that
      needs to be done.  bprm_creds_from_file first computes which file
      bprm->executable or most likely bprm->file that the bprm->creds
      will be computed from.
      
      The funciton bprm_fill_uid is updated to receive the file instead of
      accessing bprm->file.  The now unnecessary work needed to reset the
      bprm->cred->euid, and bprm->cred->egid is removed from brpm_fill_uid.
      A small comment to document that bprm_fill_uid now only deals with the
      work to handle suid and sgid files.  The default case is already
      heandled by prepare_exec_creds.
      
      The function security_bprm_repopulate_creds is renamed
      security_bprm_creds_from_file and now is explicitly passed the file
      from which to compute the creds.  The documentation of the
      bprm_creds_from_file security hook is updated to explain when the hook
      is called and what it needs to do.  The file is passed from
      cap_bprm_creds_from_file into get_file_caps so that the caps are
      computed for the appropriate file.  The now unnecessary work in
      cap_bprm_creds_from_file to reset the ambient capabilites has been
      removed.  A small comment to document that the work of
      cap_bprm_creds_from_file is to read capabilities from the files
      secureity attribute and derive capabilities from the fact the
      user had uid 0 has been added.
      Reviewed-by: NKees Cook <keescook@chromium.org>
      Signed-off-by: N"Eric W. Biederman" <ebiederm@xmission.com>
      56305aa9
    • E
      exec: Add a per bprm->file version of per_clear · a7868323
      Eric W. Biederman 提交于
      There is a small bug in the code that recomputes parts of bprm->cred
      for every bprm->file.  The code never recomputes the part of
      clear_dangerous_personality_flags it is responsible for.
      
      Which means that in practice if someone creates a sgid script
      the interpreter will not be able to use any of:
      	READ_IMPLIES_EXEC
      	ADDR_NO_RANDOMIZE
      	ADDR_COMPAT_LAYOUT
      	MMAP_PAGE_ZERO.
      
      This accentially clearing of personality flags probably does
      not matter in practice because no one has complained
      but it does make the code more difficult to understand.
      
      Further remaining bug compatible prevents the recomputation from being
      removed and replaced by simply computing bprm->cred once from the
      final bprm->file.
      
      Making this change removes the last behavior difference between
      computing bprm->creds from the final file and recomputing
      bprm->cred several times.  Which allows this behavior change
      to be justified for it's own reasons, and for any but hunts
      looking into why the behavior changed to wind up here instead
      of in the code that will follow that computes bprm->cred
      from the final bprm->file.
      
      This small logic bug appears to have existed since the code
      started clearing dangerous personality bits.
      
      History Tree: git://git.kernel.org/pub/scm/linux/kernel/git/tglx/history.git
      Fixes: 1bb0fa189c6a ("[PATCH] NX: clean up legacy binary support")
      Reviewed-by: NKees Cook <keescook@chromium.org>
      Signed-off-by: N"Eric W. Biederman" <ebiederm@xmission.com>
      a7868323
  22. 21 5月, 2020 2 次提交
  23. 19 5月, 2020 2 次提交
  24. 05 5月, 2020 1 次提交
  25. 30 3月, 2020 1 次提交
  26. 20 2月, 2020 1 次提交
    • R
      security: <linux/lsm_hooks.h>: fix all kernel-doc warnings · bd1a5a53
      Randy Dunlap 提交于
      Fix all kernel-doc warnings in <linux/lsm_hooks.h>.
      Fixes the following warnings:
      
      ../include/linux/lsm_hooks.h:1830: warning: Function parameter or member 'quotactl' not described in 'security_list_options'
      ../include/linux/lsm_hooks.h:1830: warning: Function parameter or member 'quota_on' not described in 'security_list_options'
      ../include/linux/lsm_hooks.h:1830: warning: Function parameter or member 'sb_free_mnt_opts' not described in 'security_list_options'
      ../include/linux/lsm_hooks.h:1830: warning: Function parameter or member 'sb_eat_lsm_opts' not described in 'security_list_options'
      ../include/linux/lsm_hooks.h:1830: warning: Function parameter or member 'sb_kern_mount' not described in 'security_list_options'
      ../include/linux/lsm_hooks.h:1830: warning: Function parameter or member 'sb_show_options' not described in 'security_list_options'
      ../include/linux/lsm_hooks.h:1830: warning: Function parameter or member 'sb_add_mnt_opt' not described in 'security_list_options'
      ../include/linux/lsm_hooks.h:1830: warning: Function parameter or member 'd_instantiate' not described in 'security_list_options'
      ../include/linux/lsm_hooks.h:1830: warning: Function parameter or member 'getprocattr' not described in 'security_list_options'
      ../include/linux/lsm_hooks.h:1830: warning: Function parameter or member 'setprocattr' not described in 'security_list_options'
      ../include/linux/lsm_hooks.h:1830: warning: Function parameter or member 'locked_down' not described in 'security_list_options'
      ../include/linux/lsm_hooks.h:1830: warning: Function parameter or member 'perf_event_open' not described in 'security_list_options'
      ../include/linux/lsm_hooks.h:1830: warning: Function parameter or member 'perf_event_alloc' not described in 'security_list_options'
      ../include/linux/lsm_hooks.h:1830: warning: Function parameter or member 'perf_event_free' not described in 'security_list_options'
      ../include/linux/lsm_hooks.h:1830: warning: Function parameter or member 'perf_event_read' not described in 'security_list_options'
      ../include/linux/lsm_hooks.h:1830: warning: Function parameter or member 'perf_event_write' not described in 'security_list_options'
      Signed-off-by: NRandy Dunlap <rdunlap@infradead.org>
      Cc: John Johansen <john.johansen@canonical.com>
      Cc: Kees Cook <keescook@chromium.org>
      Cc: Micah Morton <mortonm@chromium.org>
      Cc: James Morris <jmorris@namei.org>
      Cc: "Serge E. Hallyn" <serge@hallyn.com>
      Cc: linux-security-module@vger.kernel.org
      Cc: Paul Moore <paul@paul-moore.com>
      Cc: Stephen Smalley <sds@tycho.nsa.gov>
      Cc: Eric Paris <eparis@parisplace.org>
      Cc: Casey Schaufler <casey@schaufler-ca.com>
      Cc: Kentaro Takeda <takedakn@nttdata.co.jp>
      Cc: Tetsuo Handa <penguin-kernel@I-love.SAKURA.ne.jp>
      Acked-by: NCasey Schaufler <casey@schaufler-ca.com>
      Acked-by: NKees Cook <keescook@chromium.org>
      Signed-off-by: NJames Morris <jmorris@namei.org>
      bd1a5a53
  27. 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
  28. 20 8月, 2019 2 次提交
  29. 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
  30. 09 6月, 2019 1 次提交
  31. 27 3月, 2019 2 次提交