1. 09 1月, 2019 12 次提交
  2. 22 12月, 2018 13 次提交
  3. 21 12月, 2018 2 次提交
  4. 20 12月, 2018 1 次提交
  5. 06 12月, 2018 2 次提交
    • O
      selinux: overhaul sidtab to fix bug and improve performance · ee1a84fd
      Ondrej Mosnacek 提交于
      Before this patch, during a policy reload the sidtab would become frozen
      and trying to map a new context to SID would be unable to add a new
      entry to sidtab and fail with -ENOMEM.
      
      Such failures are usually propagated into userspace, which has no way of
      distignuishing them from actual allocation failures and thus doesn't
      handle them gracefully. Such situation can be triggered e.g. by the
      following reproducer:
      
          while true; do load_policy; echo -n .; sleep 0.1; done &
          for (( i = 0; i < 1024; i++ )); do
              runcon -l s0:c$i echo -n x || break
              # or:
              # chcon -l s0:c$i <some_file> || break
          done
      
      This patch overhauls the sidtab so it doesn't need to be frozen during
      policy reload, thus solving the above problem.
      
      The new SID table leverages the fact that SIDs are allocated
      sequentially and are never invalidated and stores them in linear buckets
      indexed by a tree structure. This brings several advantages:
        1. Fast SID -> context lookup - this lookup can now be done in
           logarithmic time complexity (usually in less than 4 array lookups)
           and can still be done safely without locking.
        2. No need to re-search the whole table on reverse lookup miss - after
           acquiring the spinlock only the newly added entries need to be
           searched, which means that reverse lookups that end up inserting a
           new entry are now about twice as fast.
        3. No need to freeze sidtab during policy reload - it is now possible
           to handle insertion of new entries even during sidtab conversion.
      
      The tree structure of the new sidtab is able to grow automatically to up
      to about 2^31 entries (at which point it should not have more than about
      4 tree levels). The old sidtab had a theoretical capacity of almost 2^32
      entries, but half of that is still more than enough since by that point
      the reverse table lookups would become unusably slow anyway...
      
      The number of entries per tree node is selected automatically so that
      each node fits into a single page, which should be the easiest size for
      kmalloc() to handle.
      
      Note that the cache for reverse lookup is preserved with equivalent
      logic. The only difference is that instead of storing pointers to the
      hash table nodes it stores just the indices of the cached entries.
      
      The new cache ensures that the indices are loaded/stored atomically, but
      it still has the drawback that concurrent cache updates may mess up the
      contents of the cache. Such situation however only reduces its
      effectivity, not the correctness of lookups.
      
      Tested by selinux-testsuite and thoroughly tortured by this simple
      stress test:
      ```
      function rand_cat() {
      	echo $(( $RANDOM % 1024 ))
      }
      
      function do_work() {
      	while true; do
      		echo -n "system_u:system_r:kernel_t:s0:c$(rand_cat),c$(rand_cat)" \
      			>/sys/fs/selinux/context 2>/dev/null || true
      	done
      }
      
      do_work >/dev/null &
      do_work >/dev/null &
      do_work >/dev/null &
      
      while load_policy; do echo -n .; sleep 0.1; done
      
      kill %1
      kill %2
      kill %3
      ```
      
      Link: https://github.com/SELinuxProject/selinux-kernel/issues/38Reported-by: NOrion Poplawski <orion@nwra.com>
      Reported-by: NLi Kun <hw.likun@huawei.com>
      Signed-off-by: NOndrej Mosnacek <omosnace@redhat.com>
      Reviewed-by: NStephen Smalley <sds@tycho.nsa.gov>
      [PM: most of sidtab.c merged by hand due to conflicts]
      [PM: checkpatch fixes in mls.c, services.c, sidtab.c]
      Signed-off-by: NPaul Moore <paul@paul-moore.com>
      ee1a84fd
    • O
      selinux: use separate table for initial SID lookup · 24ed7fda
      Ondrej Mosnacek 提交于
      This moves handling of initial SIDs into a separate table. Note that the
      SIDs stored in the main table are now shifted by SECINITSID_NUM and
      converted to/from the actual SIDs transparently by helper functions.
      
      This change doesn't make much sense on its own, but it simplifies
      further sidtab overhaul in a succeeding patch.
      Signed-off-by: NOndrej Mosnacek <omosnace@redhat.com>
      Reviewed-by: NStephen Smalley <sds@tycho.nsa.gov>
      [PM: fixed some checkpatch warnings on line length, whitespace]
      Signed-off-by: NPaul Moore <paul@paul-moore.com>
      24ed7fda
  6. 30 11月, 2018 1 次提交
  7. 27 11月, 2018 2 次提交
    • A
      selinux: make "selinux_policycap_names[]" const char * · 89f5bebc
      Alexey Dobriyan 提交于
      Those strings aren't written.
      Signed-off-by: NAlexey Dobriyan <adobriyan@gmail.com>
      Signed-off-by: NPaul Moore <paul@paul-moore.com>
      89f5bebc
    • O
      selinux: always allow mounting submounts · 2cbdcb88
      Ondrej Mosnacek 提交于
      If a superblock has the MS_SUBMOUNT flag set, we should always allow
      mounting it. These mounts are done automatically by the kernel either as
      part of mounting some parent mount (e.g. debugfs always mounts tracefs
      under "tracing" for compatibility) or they are mounted automatically as
      needed on subdirectory accesses (e.g. NFS crossmnt mounts). Since such
      automounts are either an implicit consequence of the parent mount (which
      is already checked) or they can happen during regular accesses (where it
      doesn't make sense to check against the current task's context), the
      mount permission check should be skipped for them.
      
      Without this patch, attempts to access contents of an automounted
      directory can cause unexpected SELinux denials.
      
      In the current kernel tree, the MS_SUBMOUNT flag is set only via
      vfs_submount(), which is called only from the following places:
       - AFS, when automounting special "symlinks" referencing other cells
       - CIFS, when automounting "referrals"
       - NFS, when automounting subtrees
       - debugfs, when automounting tracefs
      
      In all cases the submounts are meant to be transparent to the user and
      it makes sense that if mounting the master is allowed, then so should be
      the automounts. Note that CAP_SYS_ADMIN capability checking is already
      skipped for (SB_KERNMOUNT|SB_SUBMOUNT) in:
       - sget_userns() in fs/super.c:
      	if (!(flags & (SB_KERNMOUNT|SB_SUBMOUNT)) &&
      	    !(type->fs_flags & FS_USERNS_MOUNT) &&
      	    !capable(CAP_SYS_ADMIN))
      		return ERR_PTR(-EPERM);
       - sget() in fs/super.c:
              /* Ensure the requestor has permissions over the target filesystem */
              if (!(flags & (SB_KERNMOUNT|SB_SUBMOUNT)) && !ns_capable(user_ns, CAP_SYS_ADMIN))
                      return ERR_PTR(-EPERM);
      
      Verified internally on patched RHEL 7.6 with a reproducer using
      NFS+httpd and selinux-tesuite.
      
      Fixes: 93faccbb ("fs: Better permission checking for submounts")
      Signed-off-by: NOndrej Mosnacek <omosnace@redhat.com>
      Signed-off-by: NPaul Moore <paul@paul-moore.com>
      2cbdcb88
  8. 21 11月, 2018 1 次提交
  9. 14 11月, 2018 2 次提交
  10. 06 11月, 2018 1 次提交
    • O
      selinux: policydb - fix byte order and alignment issues · 5df275cd
      Ondrej Mosnacek 提交于
      Do the LE conversions before doing the Infiniband-related range checks.
      The incorrect checks are otherwise causing a failure to load any policy
      with an ibendportcon rule on BE systems. This can be reproduced by
      running (on e.g. ppc64):
      
      cat >my_module.cil <<EOF
      (type test_ibendport_t)
      (roletype object_r test_ibendport_t)
      (ibendportcon mlx4_0 1 (system_u object_r test_ibendport_t ((s0) (s0))))
      EOF
      semodule -i my_module.cil
      
      Also, fix loading/storing the 64-bit subnet prefix for OCON_IBPKEY to
      use a correctly aligned buffer.
      
      Finally, do not use the 'nodebuf' (u32) buffer where 'buf' (__le32)
      should be used instead.
      
      Tested internally on a ppc64 machine with a RHEL 7 kernel with this
      patch applied.
      
      Cc: Daniel Jurgens <danielj@mellanox.com>
      Cc: Eli Cohen <eli@mellanox.com>
      Cc: James Morris <jmorris@namei.org>
      Cc: Doug Ledford <dledford@redhat.com>
      Cc: <stable@vger.kernel.org> # 4.13+
      Fixes: a806f7a1 ("selinux: Create policydb version for Infiniband support")
      Signed-off-by: NOndrej Mosnacek <omosnace@redhat.com>
      Acked-by: NStephen Smalley <sds@tycho.nsa.gov>
      Signed-off-by: NPaul Moore <paul@paul-moore.com>
      5df275cd
  11. 11 10月, 2018 2 次提交
  12. 03 10月, 2018 1 次提交
    • E
      signal: Distinguish between kernel_siginfo and siginfo · ae7795bc
      Eric W. Biederman 提交于
      Linus recently observed that if we did not worry about the padding
      member in struct siginfo it is only about 48 bytes, and 48 bytes is
      much nicer than 128 bytes for allocating on the stack and copying
      around in the kernel.
      
      The obvious thing of only adding the padding when userspace is
      including siginfo.h won't work as there are sigframe definitions in
      the kernel that embed struct siginfo.
      
      So split siginfo in two; kernel_siginfo and siginfo.  Keeping the
      traditional name for the userspace definition.  While the version that
      is used internally to the kernel and ultimately will not be padded to
      128 bytes is called kernel_siginfo.
      
      The definition of struct kernel_siginfo I have put in include/signal_types.h
      
      A set of buildtime checks has been added to verify the two structures have
      the same field offsets.
      
      To make it easy to verify the change kernel_siginfo retains the same
      size as siginfo.  The reduction in size comes in a following change.
      Signed-off-by: N"Eric W. Biederman" <ebiederm@xmission.com>
      ae7795bc