1. 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
  2. 03 11月, 2021 2 次提交
  3. 20 10月, 2021 1 次提交
  4. 15 10月, 2021 2 次提交
    • T
      binder: use cred instead of task for selinux checks · 52f88693
      Todd Kjos 提交于
      Since binder was integrated with selinux, it has passed
      'struct task_struct' associated with the binder_proc
      to represent the source and target of transactions.
      The conversion of task to SID was then done in the hook
      implementations. It turns out that there are race conditions
      which can result in an incorrect security context being used.
      
      Fix by using the 'struct cred' saved during binder_open and pass
      it to the selinux subsystem.
      
      Cc: stable@vger.kernel.org # 5.14 (need backport for earlier stables)
      Fixes: 79af7307 ("Add security hooks to binder and implement the hooks for SELinux.")
      Suggested-by: NJann Horn <jannh@google.com>
      Signed-off-by: NTodd Kjos <tkjos@google.com>
      Acked-by: NCasey Schaufler <casey@schaufler-ca.com>
      Signed-off-by: NPaul Moore <paul@paul-moore.com>
      52f88693
    • K
      LSM: Avoid warnings about potentially unused hook variables · 86dd9fd5
      Kees Cook 提交于
      Building with W=1 shows many unused const variable warnings. These can
      be silenced, as we're well aware of their being potentially unused:
      
      ./include/linux/lsm_hook_defs.h:36:18: error: 'ptrace_access_check_default' defined but not used [-Werror=unused-const-variable=]
         36 | LSM_HOOK(int, 0, ptrace_access_check, struct task_struct *child,
            |                  ^~~~~~~~~~~~~~~~~~~
      security/security.c:706:32: note: in definition of macro 'LSM_RET_DEFAULT'
        706 | #define LSM_RET_DEFAULT(NAME) (NAME##_default)
            |                                ^~~~
      security/security.c:711:9: note: in expansion of macro 'DECLARE_LSM_RET_DEFAULT_int'
        711 |         DECLARE_LSM_RET_DEFAULT_##RET(DEFAULT, NAME)
            |         ^~~~~~~~~~~~~~~~~~~~~~~~
      ./include/linux/lsm_hook_defs.h:36:1: note: in expansion of macro 'LSM_HOOK'
         36 | LSM_HOOK(int, 0, ptrace_access_check, struct task_struct *child,
            | ^~~~~~~~
      
      Cc: James Morris <jmorris@namei.org>
      Cc: "Serge E. Hallyn" <serge@hallyn.com>
      Cc: Paul Moore <paul@paul-moore.com>
      Cc: Casey Schaufler <casey@schaufler-ca.com>
      Cc: KP Singh <kpsingh@chromium.org>
      Cc: linux-security-module@vger.kernel.org
      Reported-by: Nkernel test robot <lkp@intel.com>
      Link: https://lore.kernel.org/linux-mm/202110131608.zms53FPR-lkp@intel.com/
      Fixes: 98e828a0 ("security: Refactor declaration of LSM hooks")
      Signed-off-by: NKees Cook <keescook@chromium.org>
      Acked-by: NJames Morris <jamorris@linux.microsoft.com>
      Signed-off-by: NPaul Moore <paul@paul-moore.com>
      86dd9fd5
  5. 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
  6. 10 8月, 2021 2 次提交
    • D
      bpf: Add lockdown check for probe_write_user helper · 51e1bb9e
      Daniel Borkmann 提交于
      Back then, commit 96ae5227 ("bpf: Add bpf_probe_write_user BPF helper
      to be called in tracers") added the bpf_probe_write_user() helper in order
      to allow to override user space memory. Its original goal was to have a
      facility to "debug, divert, and manipulate execution of semi-cooperative
      processes" under CAP_SYS_ADMIN. Write to kernel was explicitly disallowed
      since it would otherwise tamper with its integrity.
      
      One use case was shown in cf9b1199 ("samples/bpf: Add test/example of
      using bpf_probe_write_user bpf helper") where the program DNATs traffic
      at the time of connect(2) syscall, meaning, it rewrites the arguments to
      a syscall while they're still in userspace, and before the syscall has a
      chance to copy the argument into kernel space. These days we have better
      mechanisms in BPF for achieving the same (e.g. for load-balancers), but
      without having to write to userspace memory.
      
      Of course the bpf_probe_write_user() helper can also be used to abuse
      many other things for both good or bad purpose. Outside of BPF, there is
      a similar mechanism for ptrace(2) such as PTRACE_PEEK{TEXT,DATA} and
      PTRACE_POKE{TEXT,DATA}, but would likely require some more effort.
      Commit 96ae5227 explicitly dedicated the helper for experimentation
      purpose only. Thus, move the helper's availability behind a newly added
      LOCKDOWN_BPF_WRITE_USER lockdown knob so that the helper is disabled under
      the "integrity" mode. More fine-grained control can be implemented also
      from LSM side with this change.
      
      Fixes: 96ae5227 ("bpf: Add bpf_probe_write_user BPF helper to be called in tracers")
      Signed-off-by: NDaniel Borkmann <daniel@iogearbox.net>
      Acked-by: NAndrii Nakryiko <andrii@kernel.org>
      51e1bb9e
    • D
      bpf: Add _kernel suffix to internal lockdown_bpf_read · 71330842
      Daniel Borkmann 提交于
      Rename LOCKDOWN_BPF_READ into LOCKDOWN_BPF_READ_KERNEL so we have naming
      more consistent with a LOCKDOWN_BPF_WRITE_USER option that we are adding.
      Signed-off-by: NDaniel Borkmann <daniel@iogearbox.net>
      Acked-by: NAndrii Nakryiko <andrii@kernel.org>
      71330842
  7. 22 5月, 2021 1 次提交
  8. 11 5月, 2021 1 次提交
  9. 23 4月, 2021 2 次提交
  10. 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
  11. 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
  12. 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
  13. 04 12月, 2020 1 次提交
  14. 27 11月, 2020 1 次提交
    • A
      xfrm: redact SA secret with lockdown confidentiality · c7a5899e
      Antony Antony 提交于
      redact XFRM SA secret in the netlink response to xfrm_get_sa()
      or dumpall sa.
      Enable lockdown, confidentiality mode, at boot or at run time.
      
      e.g. when enabled:
      cat /sys/kernel/security/lockdown
      none integrity [confidentiality]
      
      ip xfrm state
      src 172.16.1.200 dst 172.16.1.100
      	proto esp spi 0x00000002 reqid 2 mode tunnel
      	replay-window 0
      	aead rfc4106(gcm(aes)) 0x0000000000000000000000000000000000000000 96
      
      note: the aead secret is redacted.
      Redacting secret is also a FIPS 140-2 requirement.
      
      v1->v2
       - add size checks before memset calls
      v2->v3
       - replace spaces with tabs for consistency
      v3->v4
       - use kernel lockdown instead of a /proc setting
      v4->v5
       - remove kconfig option
      Reviewed-by: NStephan Mueller <smueller@chronox.de>
      Signed-off-by: NAntony Antony <antony.antony@secunet.com>
      Signed-off-by: NSteffen Klassert <steffen.klassert@secunet.com>
      c7a5899e
  15. 24 11月, 2020 1 次提交
  16. 05 10月, 2020 3 次提交
  17. 24 6月, 2020 1 次提交
    • K
      security: Fix hook iteration and default value for inode_copy_up_xattr · 23e390cd
      KP Singh 提交于
      inode_copy_up_xattr returns 0 to indicate the acceptance of the xattr
      and 1 to reject it. If the LSM does not know about the xattr, it's
      expected to return -EOPNOTSUPP, which is the correct default value for
      this hook. BPF LSM, currently, uses 0 as the default value and thereby
      falsely allows all overlay fs xattributes to be copied up.
      
      The iteration logic is also updated from the "bail-on-fail"
      call_int_hook to continue on the non-decisive -EOPNOTSUPP and bail out
      on other values.
      
      Fixes: 98e828a0 ("security: Refactor declaration of LSM hooks")
      Signed-off-by: NKP Singh <kpsingh@google.com>
      Signed-off-by: NJames Morris <jmorris@namei.org>
      23e390cd
  18. 15 6月, 2020 1 次提交
  19. 03 6月, 2020 1 次提交
  20. 30 5月, 2020 1 次提交
    • 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
  21. 23 5月, 2020 1 次提交
  22. 21 5月, 2020 3 次提交
  23. 19 5月, 2020 3 次提交
    • 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
    • D
      security: Add hooks to rule on setting a watch · 998f5040
      David Howells 提交于
      Add security hooks that will allow an LSM to rule on whether or not a watch
      may be set.  More than one hook is required as the watches watch different
      types of object.
      Signed-off-by: NDavid Howells <dhowells@redhat.com>
      Acked-by: NJames Morris <jamorris@linux.microsoft.com>
      cc: Casey Schaufler <casey@schaufler-ca.com>
      cc: Stephen Smalley <sds@tycho.nsa.gov>
      cc: linux-security-module@vger.kernel.org
      998f5040
    • D
      security: Add a hook for the point of notification insertion · 344fa64e
      David Howells 提交于
      Add a security hook that allows an LSM to rule on whether a notification
      message is allowed to be inserted into a particular watch queue.
      
      The hook is given the following information:
      
       (1) The credentials of the triggerer (which may be init_cred for a system
           notification, eg. a hardware error).
      
       (2) The credentials of the whoever set the watch.
      
       (3) The notification message.
      Signed-off-by: NDavid Howells <dhowells@redhat.com>
      Acked-by: NJames Morris <jamorris@linux.microsoft.com>
      cc: Casey Schaufler <casey@schaufler-ca.com>
      cc: Stephen Smalley <sds@tycho.nsa.gov>
      cc: linux-security-module@vger.kernel.org
      344fa64e
  24. 30 3月, 2020 1 次提交
  25. 28 1月, 2020 1 次提交
  26. 10 12月, 2019 1 次提交
    • 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
  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 次提交