Skip to content
Snippets Groups Projects
  1. Dec 27, 2021
    • Tom Rix's avatar
      selinux: initialize proto variable in selinux_ip_postroute_compat() · 732bc2ff
      Tom Rix authored
      
      Clang static analysis reports this warning
      
      hooks.c:5765:6: warning: 4th function call argument is an uninitialized
                      value
              if (selinux_xfrm_postroute_last(sksec->sid, skb, &ad, proto))
                  ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
      
      selinux_parse_skb() can return ok without setting proto.  The later call
      to selinux_xfrm_postroute_last() does an early check of proto and can
      return ok if the garbage proto value matches.  So initialize proto.
      
      Cc: stable@vger.kernel.org
      Fixes: eef9b416 ("selinux: cleanup selinux_xfrm_sock_rcv_skb() and selinux_xfrm_postroute_last()")
      Signed-off-by: default avatarTom Rix <trix@redhat.com>
      [PM: typo/spelling and checkpatch.pl description fixes]
      Signed-off-by: default avatarPaul Moore <paul@paul-moore.com>
      732bc2ff
  2. Dec 16, 2021
    • Scott Mayhew's avatar
      selinux: fix sleeping function called from invalid context · cc274ae7
      Scott Mayhew authored
      
      selinux_sb_mnt_opts_compat() is called via sget_fc() under the sb_lock
      spinlock, so it can't use GFP_KERNEL allocations:
      
      [  868.565200] BUG: sleeping function called from invalid context at
                     include/linux/sched/mm.h:230
      [  868.568246] in_atomic(): 1, irqs_disabled(): 0,
                     non_block: 0, pid: 4914, name: mount.nfs
      [  868.569626] preempt_count: 1, expected: 0
      [  868.570215] RCU nest depth: 0, expected: 0
      [  868.570809] Preemption disabled at:
      [  868.570810] [<0000000000000000>] 0x0
      [  868.571848] CPU: 1 PID: 4914 Comm: mount.nfs Kdump: loaded
                     Tainted: G        W         5.16.0-rc5.2585cf9d #1
      [  868.573273] Hardware name: QEMU Standard PC (Q35 + ICH9, 2009),
                     BIOS 1.14.0-4.fc34 04/01/2014
      [  868.574478] Call Trace:
      [  868.574844]  <TASK>
      [  868.575156]  dump_stack_lvl+0x34/0x44
      [  868.575692]  __might_resched.cold+0xd6/0x10f
      [  868.576308]  slab_pre_alloc_hook.constprop.0+0x89/0xf0
      [  868.577046]  __kmalloc_track_caller+0x72/0x420
      [  868.577684]  ? security_context_to_sid_core+0x48/0x2b0
      [  868.578569]  kmemdup_nul+0x22/0x50
      [  868.579108]  security_context_to_sid_core+0x48/0x2b0
      [  868.579854]  ? _nfs4_proc_pathconf+0xff/0x110 [nfsv4]
      [  868.580742]  ? nfs_reconfigure+0x80/0x80 [nfs]
      [  868.581355]  security_context_str_to_sid+0x36/0x40
      [  868.581960]  selinux_sb_mnt_opts_compat+0xb5/0x1e0
      [  868.582550]  ? nfs_reconfigure+0x80/0x80 [nfs]
      [  868.583098]  security_sb_mnt_opts_compat+0x2a/0x40
      [  868.583676]  nfs_compare_super+0x113/0x220 [nfs]
      [  868.584249]  ? nfs_try_mount_request+0x210/0x210 [nfs]
      [  868.584879]  sget_fc+0xb5/0x2f0
      [  868.585267]  nfs_get_tree_common+0x91/0x4a0 [nfs]
      [  868.585834]  vfs_get_tree+0x25/0xb0
      [  868.586241]  fc_mount+0xe/0x30
      [  868.586605]  do_nfs4_mount+0x130/0x380 [nfsv4]
      [  868.587160]  nfs4_try_get_tree+0x47/0xb0 [nfsv4]
      [  868.587724]  vfs_get_tree+0x25/0xb0
      [  868.588193]  do_new_mount+0x176/0x310
      [  868.588782]  __x64_sys_mount+0x103/0x140
      [  868.589388]  do_syscall_64+0x3b/0x90
      [  868.589935]  entry_SYSCALL_64_after_hwframe+0x44/0xae
      [  868.590699] RIP: 0033:0x7f2b371c6c4e
      [  868.591239] Code: 48 8b 0d dd 71 0e 00 f7 d8 64 89 01 48 83 c8 ff c3 66 2e
                           0f 1f 84 00 00 00 00 00 90 f3 0f 1e fa 49 89 ca b8 a5 00
                           00 00 0f 05 <48> 3d 01 f0 ff ff 73 01 c3 48 8b 0d aa 71
                           0e 00 f7 d8 64 89 01 48
      [  868.593810] RSP: 002b:00007ffc83775d88 EFLAGS: 00000246
                     ORIG_RAX: 00000000000000a5
      [  868.594691] RAX: ffffffffffffffda RBX: 00007ffc83775f10 RCX: 00007f2b371c6c4e
      [  868.595504] RDX: 0000555d517247a0 RSI: 0000555d51724700 RDI: 0000555d51724540
      [  868.596317] RBP: 00007ffc83775f10 R08: 0000555d51726890 R09: 0000555d51726890
      [  868.597162] R10: 0000000000000000 R11: 0000000000000246 R12: 0000555d51726890
      [  868.598005] R13: 0000000000000003 R14: 0000555d517246e0 R15: 0000555d511ac925
      [  868.598826]  </TASK>
      
      Cc: stable@vger.kernel.org
      Fixes: 69c4a42d ("lsm,selinux: add new hook to compare new mount to an existing mount")
      Signed-off-by: default avatarScott Mayhew <smayhew@redhat.com>
      [PM: cleanup/line-wrap the backtrace]
      Signed-off-by: default avatarPaul Moore <paul@paul-moore.com>
      cc274ae7
  3. Nov 19, 2021
    • Ondrej Mosnacek's avatar
      selinux: fix NULL-pointer dereference when hashtab allocation fails · dc27f3c5
      Ondrej Mosnacek authored
      
      When the hash table slot array allocation fails in hashtab_init(),
      h->size is left initialized with a non-zero value, but the h->htable
      pointer is NULL. This may then cause a NULL pointer dereference, since
      the policydb code relies on the assumption that even after a failed
      hashtab_init(), hashtab_map() and hashtab_destroy() can be safely called
      on it. Yet, these detect an empty hashtab only by looking at the size.
      
      Fix this by making sure that hashtab_init() always leaves behind a valid
      empty hashtab when the allocation fails.
      
      Cc: stable@vger.kernel.org
      Fixes: 03414a49 ("selinux: do not allocate hashtabs dynamically")
      Signed-off-by: default avatarOndrej Mosnacek <omosnace@redhat.com>
      Signed-off-by: default avatarPaul Moore <paul@paul-moore.com>
      dc27f3c5
  4. Nov 14, 2021
    • Paul Moore's avatar
      net,lsm,selinux: revert the security_sctp_assoc_established() hook · 1aa3b220
      Paul Moore authored
      
      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: default avatarPaul Moore <paul@paul-moore.com>
      Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
      1aa3b220
  5. Nov 12, 2021
    • Paul Moore's avatar
      net,lsm,selinux: revert the security_sctp_assoc_established() hook · 32a370ab
      Paul Moore authored
      
      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: default avatarPaul Moore <paul@paul-moore.com>
      32a370ab
  6. Nov 03, 2021
  7. Oct 20, 2021
  8. Oct 19, 2021
  9. Oct 15, 2021
  10. Oct 13, 2021
  11. Oct 11, 2021
    • Ondrej Mosnacek's avatar
      selinux: fix race condition when computing ocontext SIDs · cbfcd13b
      Ondrej Mosnacek authored
      Current code contains a lot of racy patterns when converting an
      ocontext's context structure to an SID. This is being done in a "lazy"
      fashion, such that the SID is looked up in the SID table only when it's
      first needed and then cached in the "sid" field of the ocontext
      structure. However, this is done without any locking or memory barriers
      and is thus unsafe.
      
      Between commits 24ed7fda ("selinux: use separate table for initial
      SID lookup") and 66f8e2f0 ("selinux: sidtab reverse lookup hash
      table"), this race condition lead to an actual observable bug, because a
      pointer to the shared sid field was passed directly to
      sidtab_context_to_sid(), which was using this location to also store an
      intermediate value, which could have been read by other threads and
      interpreted as an SID. In practice this caused e.g. new mounts to get a
      wrong (seemingly random) filesystem context, leading to strange denials.
      This bug has been spotted in the wild at least twice, see [1] and [2].
      
      Fix the race condition by making all the racy functions use a common
      helper that ensures the ocontext::sid accesses are made safely using the
      appropriate SMP constructs.
      
      Note that security_netif_sid() was populating the sid field of both
      contexts stored in the ocontext, but only the first one was actually
      used. The SELinux wiki's documentation on the "netifcon" policy
      statement [3] suggests that using only the first context is intentional.
      I kept only the handling of the first context here, as there is really
      no point in doing the SID lookup for the unused one.
      
      I wasn't able to reproduce the bug mentioned above on any kernel that
      includes commit 66f8e2f0, even though it has been reported that the
      issue occurs with that commit, too, just less frequently. Thus, I wasn't
      able to verify that this patch fixes the issue, but it makes sense to
      avoid the race condition regardless.
      
      [1] https://github.com/containers/container-selinux/issues/89
      [2] https://lists.fedoraproject.org/archives/list/selinux@lists.fedoraproject.org/thread/6DMTAMHIOAOEMUAVTULJD45JZU7IBAFM/
      [3] https://selinuxproject.org/page/NetworkStatements#netifcon
      
      
      
      Cc: stable@vger.kernel.org
      Cc: Xinjie Zheng <xinjie@google.com>
      Reported-by: default avatarSujithra Periasamy <sujithra@google.com>
      Fixes: 1da177e4 ("Linux-2.6.12-rc2")
      Signed-off-by: default avatarOndrej Mosnacek <omosnace@redhat.com>
      Signed-off-by: default avatarPaul Moore <paul@paul-moore.com>
      cbfcd13b
    • Florian Westphal's avatar
      selinux: remove unneeded ipv6 hook wrappers · 4342f705
      Florian Westphal authored
      
      Netfilter places the protocol number the hook function is getting called
      from in state->pf, so we can use that instead of an extra wrapper.
      
      While at it, remove one-line wrappers too and make
      selinux_ip_{out,forward,postroute} useable as hook function.
      
      Signed-off-by: default avatarFlorian Westphal <fw@strlen.de>
      Message-Id: <20211011202229.28289-1-fw@strlen.de>
      Signed-off-by: default avatarPaul Moore <paul@paul-moore.com>
      4342f705
  12. Sep 30, 2021
    • Paul Moore's avatar
      selinux: remove the SELinux lockdown implementation · f5d0e5e9
      Paul Moore authored
      
      NOTE: This patch intentionally omits any "Fixes:" metadata or stable
      tagging since it removes a SELinux access control check; while
      removing the control point is the right thing to do moving forward,
      removing it in stable kernels could be seen as a regression.
      
      The original SELinux lockdown implementation in 59438b46
      ("security,lockdown,selinux: implement SELinux lockdown") used the
      current task's credentials as both the subject and object in the
      SELinux lockdown hook, selinux_lockdown().  Unfortunately that
      proved to be incorrect in a number of cases as the core kernel was
      calling the LSM lockdown hook in places where the credentials from
      the "current" task_struct were not the correct credentials to use
      in the SELinux access check.
      
      Attempts were made to resolve this by adding a credential pointer
      to the LSM lockdown hook as well as suggesting that the single hook
      be split into two: one for user tasks, one for kernel tasks; however
      neither approach was deemed acceptable by Linus.  Faced with the
      prospect of either changing the subj/obj in the access check to a
      constant context (likely the kernel's label) or removing the SELinux
      lockdown check entirely, the SELinux community decided that removing
      the lockdown check was preferable.
      
      The supporting changes to the general LSM layer are left intact, this
      patch only removes the SELinux implementation.
      
      Acked-by: default avatarOndrej Mosnacek <omosnace@redhat.com>
      Signed-off-by: default avatarPaul Moore <paul@paul-moore.com>
      f5d0e5e9
  13. Sep 28, 2021
    • Christian Göttsche's avatar
      selinux: enable genfscon labeling for securityfs · 8a764ef1
      Christian Göttsche authored
      
      Add support for genfscon per-file labeling of securityfs files.
      This allows for separate labels and thereby access control for
      different files. For example a genfscon statement
      
          genfscon securityfs /integrity/ima/policy \
      	system_u:object_r:ima_policy_t:s0
      
      will set a private label to the IMA policy file and thus allow to
      control the ability to set the IMA policy. Setting labels directly
      with setxattr(2), e.g. by chcon(1) or setfiles(8), is still not
      supported.
      
      Signed-off-by: default avatarChristian Göttsche <cgzones@googlemail.com>
      [PM: line width fixes in the commit description]
      Signed-off-by: default avatarPaul Moore <paul@paul-moore.com>
      8a764ef1
  14. Sep 23, 2021
    • Paul Moore's avatar
      selinux,smack: fix subjective/objective credential use mixups · a3727a8b
      Paul Moore authored
      
      Jann Horn reported a problem with commit eb1231f7 ("selinux:
      clarify task subjective and objective credentials") where some LSM
      hooks were attempting to access the subjective credentials of a task
      other than the current task.  Generally speaking, it is not safe to
      access another task's subjective credentials and doing so can cause
      a number of problems.
      
      Further, while looking into the problem, I realized that Smack was
      suffering from a similar problem brought about by a similar commit
      1fb057dc ("smack: differentiate between subjective and objective
      task credentials").
      
      This patch addresses this problem by restoring the use of the task's
      objective credentials in those cases where the task is other than the
      current executing task.  Not only does this resolve the problem
      reported by Jann, it is arguably the correct thing to do in these
      cases.
      
      Cc: stable@vger.kernel.org
      Fixes: eb1231f7 ("selinux: clarify task subjective and objective credentials")
      Fixes: 1fb057dc ("smack: differentiate between subjective and objective task credentials")
      Reported-by: default avatarJann Horn <jannh@google.com>
      Acked-by: default avatarEric W. Biederman <ebiederm@xmission.com>
      Acked-by: default avatarCasey Schaufler <casey@schaufler-ca.com>
      Signed-off-by: default avatarPaul Moore <paul@paul-moore.com>
      a3727a8b
  15. Sep 20, 2021
    • Paul Moore's avatar
      selinux: add support for the io_uring access controls · 740b0341
      Paul Moore authored
      
      This patch implements two new io_uring access controls, specifically
      support for controlling the io_uring "personalities" and
      IORING_SETUP_SQPOLL.  Controlling the sharing of io_urings themselves
      is handled via the normal file/inode labeling and sharing mechanisms.
      
      The io_uring { override_creds } permission restricts which domains
      the subject domain can use to override it's own credentials.
      Granting a domain the io_uring { override_creds } permission allows
      it to impersonate another domain in io_uring operations.
      
      The io_uring { sqpoll } permission restricts which domains can create
      asynchronous io_uring polling threads.  This is important from a
      security perspective as operations queued by this asynchronous thread
      inherit the credentials of the thread creator by default; if an
      io_uring is shared across process/domain boundaries this could result
      in one domain impersonating another.  Controlling the creation of
      sqpoll threads, and the sharing of io_urings across processes, allow
      policy authors to restrict the ability of one domain to impersonate
      another via io_uring.
      
      As a quick summary, this patch adds a new object class with two
      permissions:
      
       io_uring { override_creds sqpoll }
      
      These permissions can be seen in the two simple policy statements
      below:
      
        allow domA_t domB_t : io_uring { override_creds };
        allow domA_t self : io_uring { sqpoll };
      
      Signed-off-by: default avatarPaul Moore <paul@paul-moore.com>
      740b0341
  16. Sep 14, 2021
  17. Aug 02, 2021
  18. Jul 29, 2021
  19. Jul 23, 2021
  20. Jul 14, 2021
    • Austin Kim's avatar
      selinux: return early for possible NULL audit buffers · 893c47d1
      Austin Kim authored
      
      audit_log_start() may return NULL in below cases:
      
        - when audit is not initialized.
        - when audit backlog limit exceeds.
      
      After the call to audit_log_start() is made and then possible NULL audit
      buffer argument is passed to audit_log_*() functions,
      audit_log_*() functions return immediately in case of a NULL audit buffer
      argument.
      
      But it is optimal to return early when audit_log_start() returns NULL,
      because it is not necessary for audit_log_*() functions to be called with
      NULL audit buffer argument.
      
      So add exception handling for possible NULL audit buffers where
      return value can be handled from callers.
      
      Signed-off-by: default avatarAustin Kim <austin.kim@lge.com>
      [PM: tweak subject line]
      Signed-off-by: default avatarPaul Moore <paul@paul-moore.com>
      893c47d1
  21. Jun 11, 2021
    • Al Viro's avatar
      selinux: kill 'flags' argument in avc_has_perm_flags() and avc_audit() · d99cf13f
      Al Viro authored
      
      ... along with avc_has_perm_flags() itself, since now it's identical
      to avc_has_perm() (as pointed out by Paul Moore)
      
      Signed-off-by: default avatarAl Viro <viro@zeniv.linux.org.uk>
      [PM: add "selinux:" prefix to subj and tweak for length]
      Signed-off-by: default avatarPaul Moore <paul@paul-moore.com>
      d99cf13f
    • Al Viro's avatar
      selinux: slow_avc_audit has become non-blocking · b17ec22f
      Al Viro authored
      
      dump_common_audit_data() is safe to use under rcu_read_lock() now;
      no need for AVC_NONBLOCKING and games around it
      
      Signed-off-by: default avatarAl Viro <viro@zeniv.linux.org.uk>
      Signed-off-by: default avatarPaul Moore <paul@paul-moore.com>
      b17ec22f
    • Yang Li's avatar
      selinux: Fix kernel-doc · d0a83314
      Yang Li authored
      
      Fix function name and add comment for parameter state in ss/services.c 
      kernel-doc to remove some warnings found by running make W=1 LLVM=1.
      
      Reported-by: default avatarAbaci Robot <abaci@linux.alibaba.com>
      Signed-off-by: default avatarYang Li <yang.lee@linux.alibaba.com>
      Signed-off-by: default avatarPaul Moore <paul@paul-moore.com>
      d0a83314
    • Minchan Kim's avatar
      selinux: use __GFP_NOWARN with GFP_NOWAIT in the AVC · 648f2c61
      Minchan Kim authored
      
      In the field, we have seen lots of allocation failure from the call
      path below.
      
      06-03 13:29:12.999 1010315 31557 31557 W Binder  : 31542_2: page allocation failure: order:0, mode:0x800(GFP_NOWAIT), nodemask=(null),cpuset=background,mems_allowed=0
      ...
      ...
      06-03 13:29:12.999 1010315 31557 31557 W Call trace:
      06-03 13:29:12.999 1010315 31557 31557 W         : dump_backtrace.cfi_jt+0x0/0x8
      06-03 13:29:12.999 1010315 31557 31557 W         : dump_stack+0xc8/0x14c
      06-03 13:29:12.999 1010315 31557 31557 W         : warn_alloc+0x158/0x1c8
      06-03 13:29:12.999 1010315 31557 31557 W         : __alloc_pages_slowpath+0x9d8/0xb80
      06-03 13:29:12.999 1010315 31557 31557 W         : __alloc_pages_nodemask+0x1c4/0x430
      06-03 13:29:12.999 1010315 31557 31557 W         : allocate_slab+0xb4/0x390
      06-03 13:29:12.999 1010315 31557 31557 W         : ___slab_alloc+0x12c/0x3a4
      06-03 13:29:12.999 1010315 31557 31557 W         : kmem_cache_alloc+0x358/0x5e4
      06-03 13:29:12.999 1010315 31557 31557 W         : avc_alloc_node+0x30/0x184
      06-03 13:29:12.999 1010315 31557 31557 W         : avc_update_node+0x54/0x4f0
      06-03 13:29:12.999 1010315 31557 31557 W         : avc_has_extended_perms+0x1a4/0x460
      06-03 13:29:12.999 1010315 31557 31557 W         : selinux_file_ioctl+0x320/0x3d0
      06-03 13:29:12.999 1010315 31557 31557 W         : __arm64_sys_ioctl+0xec/0x1fc
      06-03 13:29:12.999 1010315 31557 31557 W         : el0_svc_common+0xc0/0x24c
      06-03 13:29:12.999 1010315 31557 31557 W         : el0_svc+0x28/0x88
      06-03 13:29:12.999 1010315 31557 31557 W         : el0_sync_handler+0x8c/0xf0
      06-03 13:29:12.999 1010315 31557 31557 W         : el0_sync+0x1a4/0x1c0
      ..
      ..
      06-03 13:29:12.999 1010315 31557 31557 W SLUB    : Unable to allocate memory on node -1, gfp=0x900(GFP_NOWAIT|__GFP_ZERO)
      06-03 13:29:12.999 1010315 31557 31557 W cache   : avc_node, object size: 72, buffer size: 80, default order: 0, min order: 0
      06-03 13:29:12.999 1010315 31557 31557 W node 0  : slabs: 57, objs: 2907, free: 0
      06-03 13:29:12.999 1010161 10686 10686 W SLUB    : Unable to allocate memory on node -1, gfp=0x900(GFP_NOWAIT|__GFP_ZERO)
      06-03 13:29:12.999 1010161 10686 10686 W cache   : avc_node, object size: 72, buffer size: 80, default order: 0, min order: 0
      06-03 13:29:12.999 1010161 10686 10686 W node 0  : slabs: 57, objs: 2907, free: 0
      06-03 13:29:12.999 1010161 10686 10686 W SLUB    : Unable to allocate memory on node -1, gfp=0x900(GFP_NOWAIT|__GFP_ZERO)
      06-03 13:29:12.999 1010161 10686 10686 W cache   : avc_node, object size: 72, buffer size: 80, default order: 0, min order: 0
      06-03 13:29:12.999 1010161 10686 10686 W node 0  : slabs: 57, objs: 2907, free: 0
      06-03 13:29:12.999 1010161 10686 10686 W SLUB    : Unable to allocate memory on node -1, gfp=0x900(GFP_NOWAIT|__GFP_ZERO)
      06-03 13:29:12.999 1010161 10686 10686 W cache   : avc_node, object size: 72, buffer size: 80, default order: 0, min order: 0
      06-03 13:29:12.999 1010161 10686 10686 W node 0  : slabs: 57, objs: 2907, free: 0
      06-03 13:29:13.000 1010161 10686 10686 W SLUB    : Unable to allocate memory on node -1, gfp=0x900(GFP_NOWAIT|__GFP_ZERO)
      06-03 13:29:13.000 1010161 10686 10686 W cache   : avc_node, object size: 72, buffer size: 80, default order: 0, min order: 0
      06-03 13:29:13.000 1010161 10686 10686 W node 0  : slabs: 57, objs: 2907, free: 0
      06-03 13:29:13.000 1010161 10686 10686 W SLUB    : Unable to allocate memory on node -1, gfp=0x900(GFP_NOWAIT|__GFP_ZERO)
      06-03 13:29:13.000 1010161 10686 10686 W cache   : avc_node, object size: 72, buffer size: 80, default order: 0, min order: 0
      06-03 13:29:13.000 1010161 10686 10686 W node 0  : slabs: 57, objs: 2907, free: 0
      06-03 13:29:13.000 1010161 10686 10686 W SLUB    : Unable to allocate memory on node -1, gfp=0x900(GFP_NOWAIT|__GFP_ZERO)
      06-03 13:29:13.000 1010161 10686 10686 W cache   : avc_node, object size: 72, buffer size: 80, default order: 0, min order: 0
      06-03 13:29:13.000 1010161 10686 10686 W node 0  : slabs: 57, objs: 2907, free: 0
      06-03 13:29:13.000 10230 30892 30892 W SLUB    : Unable to allocate memory on node -1, gfp=0x900(GFP_NOWAIT|__GFP_ZERO)
      06-03 13:29:13.000 10230 30892 30892 W cache   : avc_node, object size: 72, buffer size: 80, default order: 0, min order: 0
      06-03 13:29:13.000 10230 30892 30892 W node 0  : slabs: 57, objs: 2907, free: 0
      06-03 13:29:13.000 10230 30892 30892 W SLUB    : Unable to allocate memory on node -1, gfp=0x900(GFP_NOWAIT|__GFP_ZERO)
      06-03 13:29:13.000 10230 30892 30892 W cache   : avc_node, object size: 72, buffer size: 80, default order: 0, min order: 0
      
      Based on [1], selinux is tolerate for failure of memory allocation.
      Then, use __GFP_NOWARN together.
      
      [1] 476accbe ("selinux: use GFP_NOWAIT in the AVC kmem_caches")
      
      Signed-off-by: default avatarMinchan Kim <minchan@kernel.org>
      [PM: subj fix, line wraps, normalized commit refs]
      Signed-off-by: default avatarPaul Moore <paul@paul-moore.com>
      648f2c61
  22. May 14, 2021
  23. May 11, 2021
  24. Apr 22, 2021
  25. Apr 08, 2021
    • Ondrej Mosnacek's avatar
      selinux: fix race between old and new sidtab · 9ad6e9cb
      Ondrej Mosnacek authored
      Since commit 1b8b31a2 ("selinux: convert policy read-write lock to
      RCU"), there is a small window during policy load where the new policy
      pointer has already been installed, but some threads may still be
      holding the old policy pointer in their read-side RCU critical sections.
      This means that there may be conflicting attempts to add a new SID entry
      to both tables via sidtab_context_to_sid().
      
      See also (and the rest of the thread):
      https://lore.kernel.org/selinux/CAFqZXNvfux46_f8gnvVvRYMKoes24nwm2n3sPbMjrB8vKTW00g@mail.gmail.com/
      
      
      
      Fix this by installing the new policy pointer under the old sidtab's
      spinlock along with marking the old sidtab as "frozen". Then, if an
      attempt to add new entry to a "frozen" sidtab is detected, make
      sidtab_context_to_sid() return -ESTALE to indicate that a new policy
      has been installed and that the caller will have to abort the policy
      transaction and try again after re-taking the policy pointer (which is
      guaranteed to be a newer policy). This requires adding a retry-on-ESTALE
      logic to all callers of sidtab_context_to_sid(), but fortunately these
      are easy to determine and aren't that many.
      
      This seems to be the simplest solution for this problem, even if it
      looks somewhat ugly. Note that other places in the kernel (e.g.
      do_mknodat() in fs/namei.c) use similar stale-retry patterns, so I think
      it's reasonable.
      
      Cc: stable@vger.kernel.org
      Fixes: 1b8b31a2 ("selinux: convert policy read-write lock to RCU")
      Signed-off-by: default avatarOndrej Mosnacek <omosnace@redhat.com>
      Signed-off-by: default avatarPaul Moore <paul@paul-moore.com>
      9ad6e9cb
  26. Apr 02, 2021
    • Ondrej Mosnacek's avatar
      selinux: fix cond_list corruption when changing booleans · d8f5f0ea
      Ondrej Mosnacek authored
      
      Currently, duplicate_policydb_cond_list() first copies the whole
      conditional avtab and then tries to link to the correct entries in
      cond_dup_av_list() using avtab_search(). However, since the conditional
      avtab may contain multiple entries with the same key, this approach
      often fails to find the right entry, potentially leading to wrong rules
      being activated/deactivated when booleans are changed.
      
      To fix this, instead start with an empty conditional avtab and add the
      individual entries one-by-one while building the new av_lists. This
      approach leads to the correct result, since each entry is present in the
      av_lists exactly once.
      
      The issue can be reproduced with Fedora policy as follows:
      
          # sesearch -s ftpd_t -t public_content_rw_t -c dir -p create -A
          allow ftpd_t non_security_file_type:dir { add_name create getattr ioctl link lock open read remove_name rename reparent rmdir search setattr unlink watch watch_reads write }; [ ftpd_full_access ]:True
          allow ftpd_t public_content_rw_t:dir { add_name create link remove_name rename reparent rmdir setattr unlink watch watch_reads write }; [ ftpd_anon_write ]:True
          # setsebool ftpd_anon_write=off ftpd_connect_all_unreserved=off ftpd_connect_db=off ftpd_full_access=off
      
      On fixed kernels, the sesearch output is the same after the setsebool
      command:
      
          # sesearch -s ftpd_t -t public_content_rw_t -c dir -p create -A
          allow ftpd_t non_security_file_type:dir { add_name create getattr ioctl link lock open read remove_name rename reparent rmdir search setattr unlink watch watch_reads write }; [ ftpd_full_access ]:True
          allow ftpd_t public_content_rw_t:dir { add_name create link remove_name rename reparent rmdir setattr unlink watch watch_reads write }; [ ftpd_anon_write ]:True
      
      While on the broken kernels, it will be different:
      
          # sesearch -s ftpd_t -t public_content_rw_t -c dir -p create -A
          allow ftpd_t non_security_file_type:dir { add_name create getattr ioctl link lock open read remove_name rename reparent rmdir search setattr unlink watch watch_reads write }; [ ftpd_full_access ]:True
          allow ftpd_t non_security_file_type:dir { add_name create getattr ioctl link lock open read remove_name rename reparent rmdir search setattr unlink watch watch_reads write }; [ ftpd_full_access ]:True
          allow ftpd_t non_security_file_type:dir { add_name create getattr ioctl link lock open read remove_name rename reparent rmdir search setattr unlink watch watch_reads write }; [ ftpd_full_access ]:True
      
      While there, also simplify the computation of nslots. This changes the
      nslots values for nrules 2 or 3 to just two slots instead of 4, which
      makes the sequence more consistent.
      
      Cc: stable@vger.kernel.org
      Fixes: c7c556f1 ("selinux: refactor changing booleans")
      Signed-off-by: default avatarOndrej Mosnacek <omosnace@redhat.com>
      Signed-off-by: default avatarPaul Moore <paul@paul-moore.com>
      d8f5f0ea
    • Ondrej Mosnacek's avatar
      selinux: make nslot handling in avtab more robust · 442dc00f
      Ondrej Mosnacek authored
      
      1. Make sure all fileds are initialized in avtab_init().
      2. Slightly refactor avtab_alloc() to use the above fact.
      3. Use h->nslot == 0 as a sentinel in the access functions to prevent
         dereferencing h->htable when it's not allocated.
      
      Cc: stable@vger.kernel.org
      Signed-off-by: default avatarOndrej Mosnacek <omosnace@redhat.com>
      Signed-off-by: default avatarPaul Moore <paul@paul-moore.com>
      442dc00f
  27. Mar 22, 2021
    • Paul Moore's avatar
      selinux: clarify task subjective and objective credentials · eb1231f7
      Paul Moore authored
      
      SELinux has a function, task_sid(), which returns the task's
      objective credentials, but unfortunately is used in a few places
      where the subjective task credentials should be used.  Most notably
      in the new security_task_getsecid_subj() LSM hook.
      
      This patch fixes this and attempts to make things more obvious by
      introducing a new function, task_sid_subj(), and renaming the
      existing task_sid() function to task_sid_obj().
      
      This patch also adds an interesting function in task_sid_binder().
      The task_sid_binder() function has a comment which hopefully
      describes it's reason for being, but it basically boils down to the
      simple fact that we can't safely access another task's subjective
      credentials so in the case of binder we need to stick with the
      objective credentials regardless.
      
      Reviewed-by: default avatarRichard Guy Briggs <rgb@redhat.com>
      Signed-off-by: default avatarPaul Moore <paul@paul-moore.com>
      eb1231f7
    • Paul Moore's avatar
      lsm: separate security_task_getsecid() into subjective and objective variants · 4ebd7651
      Paul Moore authored
      
      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: default avatarCasey Schaufler <casey@schaufler-ca.com>
      Reviewed-by: default avatarRichard Guy Briggs <rgb@redhat.com>
      Signed-off-by: default avatarPaul Moore <paul@paul-moore.com>
      4ebd7651
Loading