Skip to content
Snippets Groups Projects
  1. Apr 10, 2019
  2. Apr 08, 2019
  3. Mar 29, 2019
  4. Mar 28, 2019
  5. Mar 18, 2019
  6. Mar 12, 2019
    • Kent Overstreet's avatar
      selinux: convert to kvmalloc · acdf52d9
      Kent Overstreet authored
      The flex arrays were being used for constant sized arrays, so there's no
      benefit to using flex_arrays over something simpler.
      
      Link: http://lkml.kernel.org/r/20181217131929.11727-4-kent.overstreet@gmail.com
      
      
      Signed-off-by: default avatarKent Overstreet <kent.overstreet@gmail.com>
      Cc: Paul Moore <paul@paul-moore.com>
      Cc: Stephen Smalley <sds@tycho.nsa.gov>
      Cc: Eric Paris <eparis@parisplace.org>
      Cc: Alexey Dobriyan <adobriyan@gmail.com>
      Cc: Al Viro <viro@zeniv.linux.org.uk>
      Cc: Dave Hansen <dave.hansen@intel.com>
      Cc: Marcelo Ricardo Leitner <marcelo.leitner@gmail.com>
      Cc: Matthew Wilcox <willy@infradead.org>
      Cc: Neil Horman <nhorman@tuxdriver.com>
      Cc: Pravin B Shelar <pshelar@ovn.org>
      Cc: Shaohua Li <shli@kernel.org>
      Cc: Vlad Yasevich <vyasevich@gmail.com>
      Signed-off-by: default avatarAndrew Morton <akpm@linux-foundation.org>
      Signed-off-by: default avatarLinus Torvalds <torvalds@linux-foundation.org>
      acdf52d9
    • John Johansen's avatar
      apparmor: fix double free when unpack of secmark rules fails · d8dbb581
      John Johansen authored
      
      if secmark rules fail to unpack a double free happens resulting in
      the following oops
      
      [ 1295.584074] audit: type=1400 audit(1549970525.256:51): apparmor="STATUS" info="failed to unpack profile secmark rules" error=-71 profile="unconfined" name="/root/test" pid=29882 comm="apparmor_parser" name="/root/test" offset=120
      [ 1374.042334] ------------[ cut here ]------------
      [ 1374.042336] kernel BUG at mm/slub.c:294!
      [ 1374.042404] invalid opcode: 0000 [#1] SMP PTI
      [ 1374.042436] CPU: 0 PID: 29921 Comm: apparmor_parser Not tainted 4.20.7-042007-generic #201902061234
      [ 1374.042461] Hardware name: QEMU Standard PC (i440FX + PIIX, 1996), BIOS 1.10.2-1ubuntu1 04/01/2014
      [ 1374.042489] RIP: 0010:kfree+0x164/0x180
      [ 1374.042502] Code: 74 05 41 0f b6 72 51 4c 89 d7 e8 37 cd f8 ff eb 8b 41 b8 01 00 00 00 48 89 d9 48 89 da 4c 89 d6 e8 11 f6 ff ff e9 72 ff ff ff <0f> 0b 49 8b 42 08 a8 01 75 c2 0f 0b 48 8b 3d a9 f4 19 01 e9 c5 fe
      [ 1374.042552] RSP: 0018:ffffaf7b812d7b90 EFLAGS: 00010246
      [ 1374.042568] RAX: ffff91e437679200 RBX: ffff91e437679200 RCX: ffff91e437679200
      [ 1374.042589] RDX: 00000000000088b6 RSI: ffff91e43da27060 RDI: ffff91e43d401a80
      [ 1374.042609] RBP: ffffaf7b812d7ba8 R08: 0000000000027080 R09: ffffffffa6627a6d
      [ 1374.042629] R10: ffffd3af41dd9e40 R11: ffff91e43a1740dc R12: ffff91e3f52e8000
      [ 1374.042650] R13: ffffffffa6627a6d R14: ffffffffffffffb9 R15: 0000000000000001
      [ 1374.042675] FS:  00007f928df77740(0000) GS:ffff91e43da00000(0000) knlGS:0000000000000000
      [ 1374.042697] CS:  0010 DS: 0000 ES: 0000 CR0: 0000000080050033
      [ 1374.042714] CR2: 000055a0c3ab6b50 CR3: 0000000079ed8004 CR4: 0000000000360ef0
      [ 1374.042737] Call Trace:
      [ 1374.042750]  kzfree+0x2d/0x40
      [ 1374.042763]  aa_free_profile+0x12b/0x270
      [ 1374.042776]  unpack_profile+0xc1/0xf10
      [ 1374.042790]  aa_unpack+0x115/0x4e0
      [ 1374.042802]  aa_replace_profiles+0x8e/0xcc0
      [ 1374.042817]  ? kvmalloc_node+0x6d/0x80
      [ 1374.042831]  ? __check_object_size+0x166/0x192
      [ 1374.042845]  policy_update+0xcf/0x1b0
      [ 1374.042858]  profile_load+0x7d/0xa0
      [ 1374.042871]  __vfs_write+0x3a/0x190
      [ 1374.042883]  ? apparmor_file_permission+0x1a/0x20
      [ 1374.042899]  ? security_file_permission+0x31/0xc0
      [ 1374.042918]  ? _cond_resched+0x19/0x30
      [ 1374.042931]  vfs_write+0xab/0x1b0
      [ 1374.042963]  ksys_write+0x55/0xc0
      [ 1374.043004]  __x64_sys_write+0x1a/0x20
      [ 1374.043046]  do_syscall_64+0x5a/0x110
      [ 1374.043087]  entry_SYSCALL_64_after_hwframe+0x44/0xa9
      
      Fixes: 9caafbe2 ("apparmor: Parse secmark policy")
      Reported-by: default avatarAlex Murray <alex.murray@canonical.com>
      Signed-off-by: default avatarJohn Johansen <john.johansen@canonical.com>
      d8dbb581
    • Chris Coulson's avatar
      apparmor: delete the dentry in aafs_remove() to avoid a leak · 201218e4
      Chris Coulson authored
      
      Although the apparmorfs dentries are always dropped from the dentry cache
      when the usage count drops to zero, there is no guarantee that this will
      happen in aafs_remove(), as another thread might still be using it. In
      this scenario, this means that the dentry will temporarily continue to
      appear in the results of lookups, even after the call to aafs_remove().
      
      In the case of removal of a profile - it also causes simple_rmdir()
      on the profile directory to fail, as the directory won't be empty until
      the usage counts of all child dentries have decreased to zero. This
      results in the dentry for the profile directory leaking and appearing
      empty in the file system tree forever.
      
      Signed-off-by: default avatarChris Coulson <chris.coulson@canonical.com>
      Signed-off-by: default avatarJohn Johansen <john.johansen@canonical.com>
      201218e4
  7. Mar 11, 2019
    • J. Bruce Fields's avatar
      security/selinux: fix SECURITY_LSM_NATIVE_LABELS on reused superblock · 3815a245
      J. Bruce Fields authored
      
      In the case when we're reusing a superblock, selinux_sb_clone_mnt_opts()
      fails to set set_kern_flags, with the result that
      nfs_clone_sb_security() incorrectly clears NFS_CAP_SECURITY_LABEL.
      
      The result is that if you mount the same NFS filesystem twice, NFS
      security labels are turned off, even if they would work fine if you
      mounted the filesystem only once.
      
      ("fixes" may be not exactly the right tag, it may be more like
      "fixed-other-cases-but-missed-this-one".)
      
      Cc: Scott Mayhew <smayhew@redhat.com>
      Cc: stable@vger.kernel.org
      Fixes: 0b4d3452 "security/selinux: allow security_sb_clone_mnt_opts..."
      Signed-off-by: default avatarJ. Bruce Fields <bfields@redhat.com>
      Acked-by: default avatarStephen Smalley <sds@tycho.nsa.gov>
      Signed-off-by: default avatarPaul Moore <paul@paul-moore.com>
      3815a245
    • Xin Long's avatar
      selinux: add the missing walk_size + len check in selinux_sctp_bind_connect · 292c997a
      Xin Long authored
      
      As does in __sctp_connect(), when checking addrs in a while loop, after
      get the addr len according to sa_family, it's necessary to do the check
      walk_size + af->sockaddr_len > addrs_size to make sure it won't access
      an out-of-bounds addr.
      
      The same thing is needed in selinux_sctp_bind_connect(), otherwise an
      out-of-bounds issue can be triggered:
      
        [14548.772313] BUG: KASAN: slab-out-of-bounds in selinux_sctp_bind_connect+0x1aa/0x1f0
        [14548.927083] Call Trace:
        [14548.938072]  dump_stack+0x9a/0xe9
        [14548.953015]  print_address_description+0x65/0x22e
        [14548.996524]  kasan_report.cold.6+0x92/0x1a6
        [14549.015335]  selinux_sctp_bind_connect+0x1aa/0x1f0
        [14549.036947]  security_sctp_bind_connect+0x58/0x90
        [14549.058142]  __sctp_setsockopt_connectx+0x5a/0x150 [sctp]
        [14549.081650]  sctp_setsockopt.part.24+0x1322/0x3ce0 [sctp]
      
      Cc: stable@vger.kernel.org
      Fixes: d452930f ("selinux: Add SCTP support")
      Reported-by: default avatarChunyu Hu <chuhu@redhat.com>
      Signed-off-by: default avatarXin Long <lucien.xin@gmail.com>
      Reviewed-by: default avatarMarcelo Ricardo Leitner <marcelo.leitner@gmail.com>
      Signed-off-by: default avatarPaul Moore <paul@paul-moore.com>
      292c997a
  8. Mar 04, 2019
    • Ben Dooks's avatar
      keys: fix missing __user in KEYCTL_PKEY_QUERY · 468e91ce
      Ben Dooks authored
      
      The arg5 of KEYCTL_PKEY_QUERY should have a __user pointer tag on
      it as it is a user pointer. This clears the following sparse warning
      for this:
      
      security/keys/keyctl.c:1755:43: warning: incorrect type in argument 3 (different address spaces)
      security/keys/keyctl.c:1755:43:    expected struct keyctl_pkey_query [noderef] <asn:1>*<noident>
      security/keys/keyctl.c:1755:43:    got struct keyctl_pkey_query *<noident>
      
      Signed-off-by: default avatarBen Dooks <ben.dooks@codethink.co.uk>
      Acked-by: default avatarSerge Hallyn <serge@hallyn.com>
      Signed-off-by: default avatarJames Morris <james.morris@microsoft.com>
      468e91ce
    • Linus Torvalds's avatar
      get rid of legacy 'get_ds()' function · 736706be
      Linus Torvalds authored
      
      Every in-kernel use of this function defined it to KERNEL_DS (either as
      an actual define, or as an inline function).  It's an entirely
      historical artifact, and long long long ago used to actually read the
      segment selector valueof '%ds' on x86.
      
      Which in the kernel is always KERNEL_DS.
      
      Inspired by a patch from Jann Horn that just did this for a very small
      subset of users (the ones in fs/), along with Al who suggested a script.
      I then just took it to the logical extreme and removed all the remaining
      gunk.
      
      Roughly scripted with
      
         git grep -l '(get_ds())' -- :^tools/ | xargs sed -i 's/(get_ds())/(KERNEL_DS)/'
         git grep -lw 'get_ds' -- :^tools/ | xargs sed -i '/^#define get_ds()/d'
      
      plus manual fixups to remove a few unusual usage patterns, the couple of
      inline function cases and to fix up a comment that had become stale.
      
      The 'get_ds()' function remains in an x86 kvm selftest, since in user
      space it actually does something relevant.
      
      Inspired-by: default avatarJann Horn <jannh@google.com>
      Inspired-by: default avatarAl Viro <viro@zeniv.linux.org.uk>
      Signed-off-by: default avatarLinus Torvalds <torvalds@linux-foundation.org>
      736706be
  9. Mar 01, 2019
  10. Feb 28, 2019
    • Al Viro's avatar
      introduce cloning of fs_context · 0b52075e
      Al Viro authored
      
      new primitive: vfs_dup_fs_context().  Comes with fs_context
      method (->dup()) for copying the filesystem-specific parts
      of fs_context, along with LSM one (->fs_context_dup()) for
      doing the same to LSM parts.
      
      [needs better commit message, and change of Author:, anyway]
      
      Signed-off-by: default avatarAl Viro <viro@zeniv.linux.org.uk>
      0b52075e
    • David Howells's avatar
      smack: Implement filesystem context security hooks · 2febd254
      David Howells authored
      
      Implement filesystem context security hooks for the smack LSM.
      
      Signed-off-by: default avatarDavid Howells <dhowells@redhat.com>
      cc: Casey Schaufler <casey@schaufler-ca.com>
      cc: linux-security-module@vger.kernel.org
      Signed-off-by: default avatarAl Viro <viro@zeniv.linux.org.uk>
      2febd254
    • David Howells's avatar
      selinux: Implement the new mount API LSM hooks · 442155c1
      David Howells authored
      
      Implement the new mount API LSM hooks for SELinux.  At some point the old
      hooks will need to be removed.
      
      Signed-off-by: default avatarDavid Howells <dhowells@redhat.com>
      cc: Paul Moore <paul@paul-moore.com>
      cc: Stephen Smalley <sds@tycho.nsa.gov>
      cc: selinux@tycho.nsa.gov
      cc: linux-security-module@vger.kernel.org
      Signed-off-by: default avatarAl Viro <viro@zeniv.linux.org.uk>
      442155c1
    • David Howells's avatar
      vfs: Add LSM hooks for the new mount API · da2441fd
      David Howells authored
      
      Add LSM hooks for use by the new mount API and filesystem context code.
      This includes:
      
       (1) Hooks to handle allocation, duplication and freeing of the security
           record attached to a filesystem context.
      
       (2) A hook to snoop source specifications.  There may be multiple of these
           if the filesystem supports it.  They will to be local files/devices if
           fs_context::source_is_dev is true and will be something else, possibly
           remote server specifications, if false.
      
       (3) A hook to snoop superblock configuration options in key[=val] form.
           If the LSM decides it wants to handle it, it can suppress the option
           being passed to the filesystem.  Note that 'val' may include commas
           and binary data with the fsopen patch.
      
       (4) A hook to perform validation and allocation after the configuration
           has been done but before the superblock is allocated and set up.
      
       (5) A hook to transfer the security from the context to a newly created
           superblock.
      
       (6) A hook to rule on whether a path point can be used as a mountpoint.
      
      These are intended to replace:
      
      	security_sb_copy_data
      	security_sb_kern_mount
      	security_sb_mount
      	security_sb_set_mnt_opts
      	security_sb_clone_mnt_opts
      	security_sb_parse_opts_str
      
      [AV -- some of the methods being replaced are already gone, some of the
      methods are not added for the lack of need]
      
      Signed-off-by: default avatarDavid Howells <dhowells@redhat.com>
      cc: linux-security-module@vger.kernel.org
      Signed-off-by: default avatarAl Viro <viro@zeniv.linux.org.uk>
      da2441fd
  11. Feb 25, 2019
  12. Feb 22, 2019
    • Eric Biggers's avatar
      KEYS: always initialize keyring_index_key::desc_len · ede0fa98
      Eric Biggers authored
      
      syzbot hit the 'BUG_ON(index_key->desc_len == 0);' in __key_link_begin()
      called from construct_alloc_key() during sys_request_key(), because the
      length of the key description was never calculated.
      
      The problem is that we rely on ->desc_len being initialized by
      search_process_keyrings(), specifically by search_nested_keyrings().
      But, if the process isn't subscribed to any keyrings that never happens.
      
      Fix it by always initializing keyring_index_key::desc_len as soon as the
      description is set, like we already do in some places.
      
      The following program reproduces the BUG_ON() when it's run as root and
      no session keyring has been installed.  If it doesn't work, try removing
      pam_keyinit.so from /etc/pam.d/login and rebooting.
      
          #include <stdlib.h>
          #include <unistd.h>
          #include <keyutils.h>
      
          int main(void)
          {
                  int id = add_key("keyring", "syz", NULL, 0, KEY_SPEC_USER_KEYRING);
      
                  keyctl_setperm(id, KEY_OTH_WRITE);
                  setreuid(5000, 5000);
                  request_key("user", "desc", "", id);
          }
      
      Reported-by: default avatar <syzbot+ec24e95ea483de0a24da@syzkaller.appspotmail.com>
      Fixes: b2a4df20 ("KEYS: Expand the capacity of a keyring")
      Signed-off-by: default avatarEric Biggers <ebiggers@google.com>
      Signed-off-by: default avatarDavid Howells <dhowells@redhat.com>
      Cc: stable@vger.kernel.org
      Signed-off-by: default avatarJames Morris <james.morris@microsoft.com>
      ede0fa98
    • Gustavo A. R. Silva's avatar
      security: mark expected switch fall-throughs and add a missing break · 09186e50
      Gustavo A. R. Silva authored
      
      In preparation to enabling -Wimplicit-fallthrough, mark switch
      cases where we are expecting to fall through.
      
      This patch fixes the following warnings:
      
      security/integrity/ima/ima_template_lib.c:85:10: warning: this statement may fall through [-Wimplicit-fallthrough=]
      security/integrity/ima/ima_policy.c:940:18: warning: this statement may fall through [-Wimplicit-fallthrough=]
      security/integrity/ima/ima_policy.c:943:7: warning: this statement may fall through [-Wimplicit-fallthrough=]
      security/integrity/ima/ima_policy.c:972:21: warning: this statement may fall through [-Wimplicit-fallthrough=]
      security/integrity/ima/ima_policy.c:974:7: warning: this statement may fall through [-Wimplicit-fallthrough=]
      security/smack/smack_lsm.c:3391:9: warning: this statement may fall through [-Wimplicit-fallthrough=]
      security/apparmor/domain.c:569:6: warning: this statement may fall through [-Wimplicit-fallthrough=]
      
      Warning level 3 was used: -Wimplicit-fallthrough=3
      
      Also, add a missing break statement to fix the following warning:
      
      security/integrity/ima/ima_appraise.c:116:26: warning: this statement may fall through [-Wimplicit-fallthrough=]
      
      Acked-by: default avatarJohn Johansen <john.johansen@canonical.com>
      Acked-by: default avatarCasey Schaufler <casey@schaufler-ca.com>
      Signed-off-by: default avatarGustavo A. R. Silva <gustavo@embeddedor.com>
      Acked-by: default avatarMimi Zohar <zohar@linux.ibm.com>
      Signed-off-by: default avatarJames Morris <james.morris@microsoft.com>
      09186e50
    • Kees Cook's avatar
      doc: sctp: Merge and clean up rst files · d61330c6
      Kees Cook authored
      
      The SCTP sections were ending up at the top-level table of contents
      under the security section when they should have be sections with the
      SCTP chapters. In addition to correcting the section and subsection
      headings, this merges the SCTP documents into a single file to organize
      the chapters more clearly, internally linkifies them, and adds the
      missing SPDX header.
      
      Signed-off-by: default avatarKees Cook <keescook@chromium.org>
      Acked-by: default avatarPaul Moore <paul@paul-moore.com>
      Signed-off-by: default avatarJonathan Corbet <corbet@lwn.net>
      d61330c6
  13. Feb 21, 2019
    • Al Viro's avatar
      missing barriers in some of unix_sock ->addr and ->path accesses · ae3b5641
      Al Viro authored
      
      Several u->addr and u->path users are not holding any locks in
      common with unix_bind().  unix_state_lock() is useless for those
      purposes.
      
      u->addr is assign-once and *(u->addr) is fully set up by the time
      we set u->addr (all under unix_table_lock).  u->path is also
      set in the same critical area, also before setting u->addr, and
      any unix_sock with ->path filled will have non-NULL ->addr.
      
      So setting ->addr with smp_store_release() is all we need for those
      "lockless" users - just have them fetch ->addr with smp_load_acquire()
      and don't even bother looking at ->path if they see NULL ->addr.
      
      Users of ->addr and ->path fall into several classes now:
          1) ones that do smp_load_acquire(u->addr) and access *(u->addr)
      and u->path only if smp_load_acquire() has returned non-NULL.
          2) places holding unix_table_lock.  These are guaranteed that
      *(u->addr) is seen fully initialized.  If unix_sock is in one of the
      "bound" chains, so's ->path.
          3) unix_sock_destructor() using ->addr is safe.  All places
      that set u->addr are guaranteed to have seen all stores *(u->addr)
      while holding a reference to u and unix_sock_destructor() is called
      when (atomic) refcount hits zero.
          4) unix_release_sock() using ->path is safe.  unix_bind()
      is serialized wrt unix_release() (normally - by struct file
      refcount), and for the instances that had ->path set by unix_bind()
      unix_release_sock() comes from unix_release(), so they are fine.
      Instances that had it set in unix_stream_connect() either end up
      attached to a socket (in unix_accept()), in which case the call
      chain to unix_release_sock() and serialization are the same as in
      the previous case, or they never get accept'ed and unix_release_sock()
      is called when the listener is shut down and its queue gets purged.
      In that case the listener's queue lock provides the barriers needed -
      unix_stream_connect() shoves our unix_sock into listener's queue
      under that lock right after having set ->path and eventual
      unix_release_sock() caller picks them from that queue under the
      same lock right before calling unix_release_sock().
          5) unix_find_other() use of ->path is pointless, but safe -
      it happens with successful lookup by (abstract) name, so ->path.dentry
      is guaranteed to be NULL there.
      
      earlier-variant-reviewed-by: default avatar"Paul E. McKenney" <paulmck@linux.ibm.com>
      Signed-off-by: default avatarAl Viro <viro@zeniv.linux.org.uk>
      Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
      ae3b5641
  14. Feb 19, 2019
  15. Feb 15, 2019
    • David Howells's avatar
      keys: Timestamp new keys · 7c1857bd
      David Howells authored
      
      Set the timestamp on new keys rather than leaving it unset.
      
      Fixes: 31d5a79d ("KEYS: Do LRU discard in full keyrings")
      Signed-off-by: default avatarDavid Howells <dhowells@redhat.com>
      Signed-off-by: default avatarJames Morris <james.morris@microsoft.com>
      7c1857bd
    • David Howells's avatar
      keys: Fix dependency loop between construction record and auth key · 822ad64d
      David Howells authored
      
      In the request_key() upcall mechanism there's a dependency loop by which if
      a key type driver overrides the ->request_key hook and the userspace side
      manages to lose the authorisation key, the auth key and the internal
      construction record (struct key_construction) can keep each other pinned.
      
      Fix this by the following changes:
      
       (1) Killing off the construction record and using the auth key instead.
      
       (2) Including the operation name in the auth key payload and making the
           payload available outside of security/keys/.
      
       (3) The ->request_key hook is given the authkey instead of the cons
           record and operation name.
      
      Changes (2) and (3) allow the auth key to naturally be cleaned up if the
      keyring it is in is destroyed or cleared or the auth key is unlinked.
      
      Fixes: 7ee02a316600 ("keys: Fix dependency loop between construction record and auth key")
      Signed-off-by: default avatarDavid Howells <dhowells@redhat.com>
      Signed-off-by: default avatarJames Morris <james.morris@microsoft.com>
      822ad64d
    • Eric Biggers's avatar
      KEYS: allow reaching the keys quotas exactly · a08bf91c
      Eric Biggers authored
      
      If the sysctl 'kernel.keys.maxkeys' is set to some number n, then
      actually users can only add up to 'n - 1' keys.  Likewise for
      'kernel.keys.maxbytes' and the root_* versions of these sysctls.  But
      these sysctls are apparently supposed to be *maximums*, as per their
      names and all documentation I could find -- the keyrings(7) man page,
      Documentation/security/keys/core.rst, and all the mentions of EDQUOT
      meaning that the key quota was *exceeded* (as opposed to reached).
      
      Thus, fix the code to allow reaching the quotas exactly.
      
      Fixes: 0b77f5bf ("keys: make the keyring quotas controllable through /proc/sys")
      Cc: stable@vger.kernel.org
      Signed-off-by: default avatarEric Biggers <ebiggers@google.com>
      Signed-off-by: default avatarDavid Howells <dhowells@redhat.com>
      Signed-off-by: default avatarJames Morris <james.morris@microsoft.com>
      a08bf91c
  16. Feb 13, 2019
  17. Feb 12, 2019
  18. Feb 05, 2019
  19. Feb 04, 2019
  20. Feb 01, 2019
Loading