1. 16 4月, 2015 2 次提交
  2. 12 4月, 2015 1 次提交
  3. 05 4月, 2015 1 次提交
  4. 26 3月, 2015 1 次提交
  5. 21 3月, 2015 1 次提交
  6. 23 2月, 2015 2 次提交
    • D
      VFS: (Scripted) Convert S_ISLNK/DIR/REG(dentry->d_inode) to d_is_*(dentry) · e36cb0b8
      David Howells 提交于
      Convert the following where appropriate:
      
       (1) S_ISLNK(dentry->d_inode) to d_is_symlink(dentry).
      
       (2) S_ISREG(dentry->d_inode) to d_is_reg(dentry).
      
       (3) S_ISDIR(dentry->d_inode) to d_is_dir(dentry).  This is actually more
           complicated than it appears as some calls should be converted to
           d_can_lookup() instead.  The difference is whether the directory in
           question is a real dir with a ->lookup op or whether it's a fake dir with
           a ->d_automount op.
      
      In some circumstances, we can subsume checks for dentry->d_inode not being
      NULL into this, provided we the code isn't in a filesystem that expects
      d_inode to be NULL if the dirent really *is* negative (ie. if we're going to
      use d_inode() rather than d_backing_inode() to get the inode pointer).
      
      Note that the dentry type field may be set to something other than
      DCACHE_MISS_TYPE when d_inode is NULL in the case of unionmount, where the VFS
      manages the fall-through from a negative dentry to a lower layer.  In such a
      case, the dentry type of the negative union dentry is set to the same as the
      type of the lower dentry.
      
      However, if you know d_inode is not NULL at the call site, then you can use
      the d_is_xxx() functions even in a filesystem.
      
      There is one further complication: a 0,0 chardev dentry may be labelled
      DCACHE_WHITEOUT_TYPE rather than DCACHE_SPECIAL_TYPE.  Strictly, this was
      intended for special directory entry types that don't have attached inodes.
      
      The following perl+coccinelle script was used:
      
      use strict;
      
      my @callers;
      open($fd, 'git grep -l \'S_IS[A-Z].*->d_inode\' |') ||
          die "Can't grep for S_ISDIR and co. callers";
      @callers = <$fd>;
      close($fd);
      unless (@callers) {
          print "No matches\n";
          exit(0);
      }
      
      my @cocci = (
          '@@',
          'expression E;',
          '@@',
          '',
          '- S_ISLNK(E->d_inode->i_mode)',
          '+ d_is_symlink(E)',
          '',
          '@@',
          'expression E;',
          '@@',
          '',
          '- S_ISDIR(E->d_inode->i_mode)',
          '+ d_is_dir(E)',
          '',
          '@@',
          'expression E;',
          '@@',
          '',
          '- S_ISREG(E->d_inode->i_mode)',
          '+ d_is_reg(E)' );
      
      my $coccifile = "tmp.sp.cocci";
      open($fd, ">$coccifile") || die $coccifile;
      print($fd "$_\n") || die $coccifile foreach (@cocci);
      close($fd);
      
      foreach my $file (@callers) {
          chomp $file;
          print "Processing ", $file, "\n";
          system("spatch", "--sp-file", $coccifile, $file, "--in-place", "--no-show-diff") == 0 ||
      	die "spatch failed";
      }
      
      [AV: overlayfs parts skipped]
      Signed-off-by: NDavid Howells <dhowells@redhat.com>
      Signed-off-by: NAl Viro <viro@zeniv.linux.org.uk>
      e36cb0b8
    • D
      SELinux: Use d_is_positive() rather than testing dentry->d_inode · 2c616d4d
      David Howells 提交于
      Use d_is_positive() rather than testing dentry->d_inode in SELinux to get rid
      of direct references to d_inode outside of the VFS.
      Signed-off-by: NDavid Howells <dhowells@redhat.com>
      Signed-off-by: NAl Viro <viro@zeniv.linux.org.uk>
      2c616d4d
  7. 05 2月, 2015 4 次提交
  8. 26 1月, 2015 2 次提交
  9. 02 12月, 2014 1 次提交
  10. 13 11月, 2014 1 次提交
  11. 04 11月, 2014 1 次提交
  12. 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
  13. 23 9月, 2014 2 次提交
  14. 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
  15. 10 9月, 2014 1 次提交
  16. 09 9月, 2014 1 次提交
  17. 03 9月, 2014 1 次提交
  18. 28 8月, 2014 1 次提交
  19. 08 8月, 2014 1 次提交
  20. 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
  21. 28 7月, 2014 1 次提交
  22. 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
  23. 27 6月, 2014 1 次提交
  24. 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
  25. 20 6月, 2014 2 次提交
  26. 19 6月, 2014 2 次提交
  27. 18 6月, 2014 1 次提交
  28. 04 6月, 2014 3 次提交
    • 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