1. 05 2月, 2015 3 次提交
  2. 02 12月, 2014 1 次提交
  3. 13 11月, 2014 1 次提交
  4. 04 11月, 2014 1 次提交
  5. 15 10月, 2014 1 次提交
    • S
      selinux: fix inode security list corruption · 923190d3
      Stephen Smalley 提交于
      sb_finish_set_opts() can race with inode_free_security()
      when initializing inode security structures for inodes
      created prior to initial policy load or by the filesystem
      during ->mount().   This appears to have always been
      a possible race, but commit 3dc91d43 ("SELinux:  Fix possible
      NULL pointer dereference in selinux_inode_permission()")
      made it more evident by immediately reusing the unioned
      list/rcu element  of the inode security structure for call_rcu()
      upon an inode_free_security().  But the underlying issue
      was already present before that commit as a possible use-after-free
      of isec.
      
      Shivnandan Kumar reported the list corruption and proposed
      a patch to split the list and rcu elements out of the union
      as separate fields of the inode_security_struct so that setting
      the rcu element would not affect the list element.  However,
      this would merely hide the issue and not truly fix the code.
      
      This patch instead moves up the deletion of the list entry
      prior to dropping the sbsec->isec_lock initially.  Then,
      if the inode is dropped subsequently, there will be no further
      references to the isec.
      Reported-by: NShivnandan Kumar <shivnandan.k@samsung.com>
      Signed-off-by: NStephen Smalley <sds@tycho.nsa.gov>
      Cc: stable@vger.kernel.org
      Signed-off-by: NPaul Moore <pmoore@redhat.com>
      923190d3
  6. 23 9月, 2014 2 次提交
  7. 11 9月, 2014 1 次提交
    • P
      selinux: make the netif cache namespace aware · cbe0d6e8
      Paul Moore 提交于
      While SELinux largely ignores namespaces, for good reason, there are
      some places where it needs to at least be aware of namespaces in order
      to function correctly.  Network namespaces are one example.  Basic
      awareness of network namespaces are necessary in order to match a
      network interface's index number to an actual network device.
      
      This patch corrects a problem with network interfaces added to a
      non-init namespace, and can be reproduced with the following commands:
      
       [NOTE: the NetLabel configuration is here only to active the dynamic
              networking controls ]
      
       # netlabelctl unlbl add default address:0.0.0.0/0 \
         label:system_u:object_r:unlabeled_t:s0
       # netlabelctl unlbl add default address:::/0 \
         label:system_u:object_r:unlabeled_t:s0
       # netlabelctl cipsov4 add pass doi:100 tags:1
       # netlabelctl map add domain:lspp_test_netlabel_t \
         protocol:cipsov4,100
      
       # ip link add type veth
       # ip netns add myns
       # ip link set veth1 netns myns
       # ip a add dev veth0 10.250.13.100/24
       # ip netns exec myns ip a add dev veth1 10.250.13.101/24
       # ip l set veth0 up
       # ip netns exec myns ip l set veth1 up
      
       # ping -c 1 10.250.13.101
       # ip netns exec myns ping -c 1 10.250.13.100
      Reported-by: NJiri Jaburek <jjaburek@redhat.com>
      Signed-off-by: NPaul Moore <pmoore@redhat.com>
      cbe0d6e8
  8. 10 9月, 2014 1 次提交
  9. 09 9月, 2014 1 次提交
  10. 03 9月, 2014 1 次提交
  11. 28 8月, 2014 1 次提交
  12. 08 8月, 2014 1 次提交
  13. 01 8月, 2014 2 次提交
    • P
      netlabel: shorter names for the NetLabel catmap funcs/structs · 4fbe63d1
      Paul Moore 提交于
      Historically the NetLabel LSM secattr catmap functions and data
      structures have had very long names which makes a mess of the NetLabel
      code and anyone who uses NetLabel.  This patch renames the catmap
      functions and structures from "*_secattr_catmap_*" to just "*_catmap_*"
      which improves things greatly.
      
      There are no substantial code or logic changes in this patch.
      Signed-off-by: NPaul Moore <pmoore@redhat.com>
      Tested-by: NCasey Schaufler <casey@schaufler-ca.com>
      4fbe63d1
    • P
      netlabel: fix the horribly broken catmap functions · 4b8feff2
      Paul Moore 提交于
      The NetLabel secattr catmap functions, and the SELinux import/export
      glue routines, were broken in many horrible ways and the SELinux glue
      code fiddled with the NetLabel catmap structures in ways that we
      probably shouldn't allow.  At some point this "worked", but that was
      likely due to a bit of dumb luck and sub-par testing (both inflicted
      by yours truly).  This patch corrects these problems by basically
      gutting the code in favor of something less obtuse and restoring the
      NetLabel abstractions in the SELinux catmap glue code.
      
      Everything is working now, and if it decides to break itself in the
      future this code will be much easier to debug than the code it
      replaces.
      
      One noteworthy side effect of the changes is that it is no longer
      necessary to allocate a NetLabel catmap before calling one of the
      NetLabel APIs to set a bit in the catmap.  NetLabel will automatically
      allocate the catmap nodes when needed, resulting in less allocations
      when the lowest bit is greater than 255 and less code in the LSMs.
      
      Cc: stable@vger.kernel.org
      Reported-by: NChristian Evans <frodox@zoho.com>
      Signed-off-by: NPaul Moore <pmoore@redhat.com>
      Tested-by: NCasey Schaufler <casey@schaufler-ca.com>
      4b8feff2
  14. 28 7月, 2014 1 次提交
  15. 10 7月, 2014 1 次提交
    • P
      selinux: fix the default socket labeling in sock_graft() · 4da6daf4
      Paul Moore 提交于
      The sock_graft() hook has special handling for AF_INET, AF_INET, and
      AF_UNIX sockets as those address families have special hooks which
      label the sock before it is attached its associated socket.
      Unfortunately, the sock_graft() hook was missing a default approach
      to labeling sockets which meant that any other address family which
      made use of connections or the accept() syscall would find the
      returned socket to be in an "unlabeled" state.  This was recently
      demonstrated by the kcrypto/AF_ALG subsystem and the newly released
      cryptsetup package (cryptsetup v1.6.5 and later).
      
      This patch preserves the special handling in selinux_sock_graft(),
      but adds a default behavior - setting the sock's label equal to the
      associated socket - which resolves the problem with AF_ALG and
      presumably any other address family which makes use of accept().
      
      Cc: stable@vger.kernel.org
      Signed-off-by: NPaul Moore <pmoore@redhat.com>
      Tested-by: NMilan Broz <gmazyland@gmail.com>
      4da6daf4
  16. 27 6月, 2014 1 次提交
  17. 24 6月, 2014 1 次提交
    • W
      selinux: no recursive read_lock of policy_rwlock in security_genfs_sid() · f31e7994
      Waiman Long 提交于
      With the introduction of fair queued rwlock, recursive read_lock()
      may hang the offending process if there is a write_lock() somewhere
      in between.
      
      With recursive read_lock checking enabled, the following error was
      reported:
      
      =============================================
      [ INFO: possible recursive locking detected ]
      3.16.0-rc1 #2 Tainted: G            E
      ---------------------------------------------
      load_policy/708 is trying to acquire lock:
       (policy_rwlock){.+.+..}, at: [<ffffffff8125b32a>]
      security_genfs_sid+0x3a/0x170
      
      but task is already holding lock:
       (policy_rwlock){.+.+..}, at: [<ffffffff8125b48c>]
      security_fs_use+0x2c/0x110
      
      other info that might help us debug this:
       Possible unsafe locking scenario:
      
             CPU0
             ----
        lock(policy_rwlock);
        lock(policy_rwlock);
      
      This patch fixes the occurrence of recursive read_lock() of
      policy_rwlock by adding a helper function __security_genfs_sid()
      which requires caller to take the lock before calling it. The
      security_fs_use() was then modified to call the new helper function.
      Signed-off-by: NWaiman Long <Waiman.Long@hp.com>
      Acked-by: NStephen Smalley <sds@tycho.nsa.gov>
      Signed-off-by: NPaul Moore <pmoore@redhat.com>
      f31e7994
  18. 20 6月, 2014 2 次提交
  19. 19 6月, 2014 2 次提交
  20. 18 6月, 2014 1 次提交
  21. 04 6月, 2014 4 次提交
    • D
      selinux: conditionally reschedule in hashtab_insert while loading selinux policy · ed1c9642
      Dave Jones 提交于
      After silencing the sleeping warning in mls_convert_context() I started
      seeing similar traces from hashtab_insert. Do a cond_resched there too.
      Signed-off-by: NDave Jones <davej@redhat.com>
      Acked-by: NStephen Smalley <sds@tycho.nsa.gov>
      Signed-off-by: NPaul Moore <pmoore@redhat.com>
      ed1c9642
    • D
      selinux: conditionally reschedule in mls_convert_context while loading selinux policy · 9a591f39
      Dave Jones 提交于
      On a slow machine (with debugging enabled), upgrading selinux policy may take
      a considerable amount of time. Long enough that the softlockup detector
      gets triggered.
      
      The backtrace looks like this..
      
       > BUG: soft lockup - CPU#2 stuck for 23s! [load_policy:19045]
       > Call Trace:
       >  [<ffffffff81221ddf>] symcmp+0xf/0x20
       >  [<ffffffff81221c27>] hashtab_search+0x47/0x80
       >  [<ffffffff8122e96c>] mls_convert_context+0xdc/0x1c0
       >  [<ffffffff812294e8>] convert_context+0x378/0x460
       >  [<ffffffff81229170>] ? security_context_to_sid_core+0x240/0x240
       >  [<ffffffff812221b5>] sidtab_map+0x45/0x80
       >  [<ffffffff8122bb9f>] security_load_policy+0x3ff/0x580
       >  [<ffffffff810788a8>] ? sched_clock_cpu+0xa8/0x100
       >  [<ffffffff810786dd>] ? sched_clock_local+0x1d/0x80
       >  [<ffffffff810788a8>] ? sched_clock_cpu+0xa8/0x100
       >  [<ffffffff8103096a>] ? __change_page_attr_set_clr+0x82a/0xa50
       >  [<ffffffff810786dd>] ? sched_clock_local+0x1d/0x80
       >  [<ffffffff810788a8>] ? sched_clock_cpu+0xa8/0x100
       >  [<ffffffff8103096a>] ? __change_page_attr_set_clr+0x82a/0xa50
       >  [<ffffffff810788a8>] ? sched_clock_cpu+0xa8/0x100
       >  [<ffffffff81534ddc>] ? retint_restore_args+0xe/0xe
       >  [<ffffffff8109c82d>] ? trace_hardirqs_on_caller+0xfd/0x1c0
       >  [<ffffffff81279a2e>] ? trace_hardirqs_on_thunk+0x3a/0x3f
       >  [<ffffffff810d28a8>] ? rcu_irq_exit+0x68/0xb0
       >  [<ffffffff81534ddc>] ? retint_restore_args+0xe/0xe
       >  [<ffffffff8121e947>] sel_write_load+0xa7/0x770
       >  [<ffffffff81139633>] ? vfs_write+0x1c3/0x200
       >  [<ffffffff81210e8e>] ? security_file_permission+0x1e/0xa0
       >  [<ffffffff8113952b>] vfs_write+0xbb/0x200
       >  [<ffffffff811581c7>] ? fget_light+0x397/0x4b0
       >  [<ffffffff81139c27>] SyS_write+0x47/0xa0
       >  [<ffffffff8153bde4>] tracesys+0xdd/0xe2
      
      Stephen Smalley suggested:
      
       > Maybe put a cond_resched() within the ebitmap_for_each_positive_bit()
       > loop in mls_convert_context()?
      
      That seems to do the trick. Tested by downgrading and re-upgrading selinux-policy-targeted.
      Signed-off-by: NDave Jones <davej@redhat.com>
      Acked-by: NStephen Smalley <sds@tycho.nsa.gov>
      Signed-off-by: NPaul Moore <pmoore@redhat.com>
      9a591f39
    • P
      selinux: reject setexeccon() on MNT_NOSUID applications with -EACCES · 5b589d44
      Paul Moore 提交于
      We presently prevent processes from using setexecon() to set the
      security label of exec()'d processes when NO_NEW_PRIVS is enabled by
      returning an error; however, we silently ignore setexeccon() when
      exec()'ing from a nosuid mounted filesystem.  This patch makes things
      a bit more consistent by returning an error in the setexeccon()/nosuid
      case.
      Signed-off-by: NPaul Moore <pmoore@redhat.com>
      Acked-by: NAndy Lutomirski <luto@amacapital.net>
      Acked-by: NStephen Smalley <sds@tycho.nsa.gov>
      5b589d44
    • S
      selinux: Report permissive mode in avc: denied messages. · ca7786a2
      Stephen Smalley 提交于
      We cannot presently tell from an avc: denied message whether access was in
      fact denied or was allowed due to global or per-domain permissive mode.
      Add a permissive= field to the avc message to reflect this information.
      Signed-off-by: NStephen Smalley <sds@tycho.nsa.gov>
      Acked-by: NEric Paris <eparis@redhat.com>
      Signed-off-by: NPaul Moore <pmoore@redhat.com>
      ca7786a2
  22. 16 5月, 2014 2 次提交
    • D
      selinux: conditionally reschedule in hashtab_insert while loading selinux policy · 47dd0b76
      Dave Jones 提交于
      After silencing the sleeping warning in mls_convert_context() I started
      seeing similar traces from hashtab_insert. Do a cond_resched there too.
      Signed-off-by: NDave Jones <davej@redhat.com>
      Acked-by: NStephen Smalley <sds@tycho.nsa.gov>
      Signed-off-by: NPaul Moore <pmoore@redhat.com>
      47dd0b76
    • D
      selinux: conditionally reschedule in mls_convert_context while loading selinux policy · 612c3531
      Dave Jones 提交于
      On a slow machine (with debugging enabled), upgrading selinux policy may take
      a considerable amount of time. Long enough that the softlockup detector
      gets triggered.
      
      The backtrace looks like this..
      
       > BUG: soft lockup - CPU#2 stuck for 23s! [load_policy:19045]
       > Call Trace:
       >  [<ffffffff81221ddf>] symcmp+0xf/0x20
       >  [<ffffffff81221c27>] hashtab_search+0x47/0x80
       >  [<ffffffff8122e96c>] mls_convert_context+0xdc/0x1c0
       >  [<ffffffff812294e8>] convert_context+0x378/0x460
       >  [<ffffffff81229170>] ? security_context_to_sid_core+0x240/0x240
       >  [<ffffffff812221b5>] sidtab_map+0x45/0x80
       >  [<ffffffff8122bb9f>] security_load_policy+0x3ff/0x580
       >  [<ffffffff810788a8>] ? sched_clock_cpu+0xa8/0x100
       >  [<ffffffff810786dd>] ? sched_clock_local+0x1d/0x80
       >  [<ffffffff810788a8>] ? sched_clock_cpu+0xa8/0x100
       >  [<ffffffff8103096a>] ? __change_page_attr_set_clr+0x82a/0xa50
       >  [<ffffffff810786dd>] ? sched_clock_local+0x1d/0x80
       >  [<ffffffff810788a8>] ? sched_clock_cpu+0xa8/0x100
       >  [<ffffffff8103096a>] ? __change_page_attr_set_clr+0x82a/0xa50
       >  [<ffffffff810788a8>] ? sched_clock_cpu+0xa8/0x100
       >  [<ffffffff81534ddc>] ? retint_restore_args+0xe/0xe
       >  [<ffffffff8109c82d>] ? trace_hardirqs_on_caller+0xfd/0x1c0
       >  [<ffffffff81279a2e>] ? trace_hardirqs_on_thunk+0x3a/0x3f
       >  [<ffffffff810d28a8>] ? rcu_irq_exit+0x68/0xb0
       >  [<ffffffff81534ddc>] ? retint_restore_args+0xe/0xe
       >  [<ffffffff8121e947>] sel_write_load+0xa7/0x770
       >  [<ffffffff81139633>] ? vfs_write+0x1c3/0x200
       >  [<ffffffff81210e8e>] ? security_file_permission+0x1e/0xa0
       >  [<ffffffff8113952b>] vfs_write+0xbb/0x200
       >  [<ffffffff811581c7>] ? fget_light+0x397/0x4b0
       >  [<ffffffff81139c27>] SyS_write+0x47/0xa0
       >  [<ffffffff8153bde4>] tracesys+0xdd/0xe2
      
      Stephen Smalley suggested:
      
       > Maybe put a cond_resched() within the ebitmap_for_each_positive_bit()
       > loop in mls_convert_context()?
      
      That seems to do the trick. Tested by downgrading and re-upgrading selinux-policy-targeted.
      Signed-off-by: NDave Jones <davej@redhat.com>
      Acked-by: NStephen Smalley <sds@tycho.nsa.gov>
      Signed-off-by: NPaul Moore <pmoore@redhat.com>
      612c3531
  23. 15 5月, 2014 1 次提交
  24. 02 5月, 2014 1 次提交
  25. 23 4月, 2014 1 次提交
  26. 22 4月, 2014 1 次提交
    • J
      locks: rename file-private locks to "open file description locks" · 0d3f7a2d
      Jeff Layton 提交于
      File-private locks have been merged into Linux for v3.15, and *now*
      people are commenting that the name and macro definitions for the new
      file-private locks suck.
      
      ...and I can't even disagree. The names and command macros do suck.
      
      We're going to have to live with these for a long time, so it's
      important that we be happy with the names before we're stuck with them.
      The consensus on the lists so far is that they should be rechristened as
      "open file description locks".
      
      The name isn't a big deal for the kernel, but the command macros are not
      visually distinct enough from the traditional POSIX lock macros. The
      glibc and documentation folks are recommending that we change them to
      look like F_OFD_{GETLK|SETLK|SETLKW}. That lessens the chance that a
      programmer will typo one of the commands wrong, and also makes it easier
      to spot this difference when reading code.
      
      This patch makes the following changes that I think are necessary before
      v3.15 ships:
      
      1) rename the command macros to their new names. These end up in the uapi
         headers and so are part of the external-facing API. It turns out that
         glibc doesn't actually use the fcntl.h uapi header, but it's hard to
         be sure that something else won't. Changing it now is safest.
      
      2) make the the /proc/locks output display these as type "OFDLCK"
      
      Cc: Michael Kerrisk <mtk.manpages@gmail.com>
      Cc: Christoph Hellwig <hch@infradead.org>
      Cc: Carlos O'Donell <carlos@redhat.com>
      Cc: Stefan Metzmacher <metze@samba.org>
      Cc: Andy Lutomirski <luto@amacapital.net>
      Cc: Frank Filz <ffilzlnx@mindspring.com>
      Cc: Theodore Ts'o <tytso@mit.edu>
      Signed-off-by: NJeff Layton <jlayton@redhat.com>
      0d3f7a2d
  27. 31 3月, 2014 1 次提交
    • J
      locks: add new fcntl cmd values for handling file private locks · 5d50ffd7
      Jeff Layton 提交于
      Due to some unfortunate history, POSIX locks have very strange and
      unhelpful semantics. The thing that usually catches people by surprise
      is that they are dropped whenever the process closes any file descriptor
      associated with the inode.
      
      This is extremely problematic for people developing file servers that
      need to implement byte-range locks. Developers often need a "lock
      management" facility to ensure that file descriptors are not closed
      until all of the locks associated with the inode are finished.
      
      Additionally, "classic" POSIX locks are owned by the process. Locks
      taken between threads within the same process won't conflict with one
      another, which renders them useless for synchronization between threads.
      
      This patchset adds a new type of lock that attempts to address these
      issues. These locks conflict with classic POSIX read/write locks, but
      have semantics that are more like BSD locks with respect to inheritance
      and behavior on close.
      
      This is implemented primarily by changing how fl_owner field is set for
      these locks. Instead of having them owned by the files_struct of the
      process, they are instead owned by the filp on which they were acquired.
      Thus, they are inherited across fork() and are only released when the
      last reference to a filp is put.
      
      These new semantics prevent them from being merged with classic POSIX
      locks, even if they are acquired by the same process. These locks will
      also conflict with classic POSIX locks even if they are acquired by
      the same process or on the same file descriptor.
      
      The new locks are managed using a new set of cmd values to the fcntl()
      syscall. The initial implementation of this converts these values to
      "classic" cmd values at a fairly high level, and the details are not
      exposed to the underlying filesystem. We may eventually want to push
      this handing out to the lower filesystem code but for now I don't
      see any need for it.
      
      Also, note that with this implementation the new cmd values are only
      available via fcntl64() on 32-bit arches. There's little need to
      add support for legacy apps on a new interface like this.
      Signed-off-by: NJeff Layton <jlayton@redhat.com>
      5d50ffd7
  28. 20 3月, 2014 2 次提交
    • P
      selinux: correctly label /proc inodes in use before the policy is loaded · f64410ec
      Paul Moore 提交于
      This patch is based on an earlier patch by Eric Paris, he describes
      the problem below:
      
        "If an inode is accessed before policy load it will get placed on a
         list of inodes to be initialized after policy load.  After policy
         load we call inode_doinit() which calls inode_doinit_with_dentry()
         on all inodes accessed before policy load.  In the case of inodes
         in procfs that means we'll end up at the bottom where it does:
      
           /* Default to the fs superblock SID. */
           isec->sid = sbsec->sid;
      
           if ((sbsec->flags & SE_SBPROC) && !S_ISLNK(inode->i_mode)) {
                   if (opt_dentry) {
                           isec->sclass = inode_mode_to_security_class(...)
                           rc = selinux_proc_get_sid(opt_dentry,
                                                     isec->sclass,
                                                     &sid);
                           if (rc)
                                   goto out_unlock;
                           isec->sid = sid;
                   }
           }
      
         Since opt_dentry is null, we'll never call selinux_proc_get_sid()
         and will leave the inode labeled with the label on the superblock.
         I believe a fix would be to mimic the behavior of xattrs.  Look
         for an alias of the inode.  If it can't be found, just leave the
         inode uninitialized (and pick it up later) if it can be found, we
         should be able to call selinux_proc_get_sid() ..."
      
      On a system exhibiting this problem, you will notice a lot of files in
      /proc with the generic "proc_t" type (at least the ones that were
      accessed early in the boot), for example:
      
         # ls -Z /proc/sys/kernel/shmmax | awk '{ print $4 " " $5 }'
         system_u:object_r:proc_t:s0 /proc/sys/kernel/shmmax
      
      However, with this patch in place we see the expected result:
      
         # ls -Z /proc/sys/kernel/shmmax | awk '{ print $4 " " $5 }'
         system_u:object_r:sysctl_kernel_t:s0 /proc/sys/kernel/shmmax
      
      Cc: Eric Paris <eparis@redhat.com>
      Signed-off-by: NPaul Moore <pmoore@redhat.com>
      Acked-by: NEric Paris <eparis@redhat.com>
      f64410ec
    • P
      selinux: put the mmap() DAC controls before the MAC controls · 98883bfd
      Paul Moore 提交于
      It turns out that doing the SELinux MAC checks for mmap() before the
      DAC checks was causing users and the SELinux policy folks headaches
      as users were seeing a lot of SELinux AVC denials for the
      memprotect:mmap_zero permission that would have also been denied by
      the normal DAC capability checks (CAP_SYS_RAWIO).
      
      Example:
      
       # cat mmap_test.c
        #include <stdlib.h>
        #include <stdio.h>
        #include <errno.h>
        #include <sys/mman.h>
      
        int main(int argc, char *argv[])
        {
              int rc;
              void *mem;
      
              mem = mmap(0x0, 4096,
                         PROT_READ | PROT_WRITE,
                         MAP_PRIVATE | MAP_ANONYMOUS | MAP_FIXED, -1, 0);
              if (mem == MAP_FAILED)
                      return errno;
              printf("mem = %p\n", mem);
              munmap(mem, 4096);
      
              return 0;
        }
       # gcc -g -O0 -o mmap_test mmap_test.c
       # ./mmap_test
       mem = (nil)
       # ausearch -m AVC | grep mmap_zero
       type=AVC msg=audit(...): avc:  denied  { mmap_zero }
         for pid=1025 comm="mmap_test"
         scontext=unconfined_u:unconfined_r:unconfined_t:s0-s0:c0.c1023
         tcontext=unconfined_u:unconfined_r:unconfined_t:s0-s0:c0.c1023
         tclass=memprotect
      
      This patch corrects things so that when the above example is run by a
      user without CAP_SYS_RAWIO the SELinux AVC is no longer generated as
      the DAC capability check fails before the SELinux permission check.
      Signed-off-by: NPaul Moore <pmoore@redhat.com>
      Acked-by: NStephen Smalley <sds@tycho.nsa.gov>
      98883bfd
  29. 15 3月, 2014 1 次提交