Forum | Documentation | Website | Blog

Skip to content
Snippets Groups Projects
  1. Mar 03, 2022
  2. Mar 01, 2022
    • Roopa Prabhu's avatar
      rtnetlink: add new rtm tunnel api for tunnel id filtering · 7b8135f4
      Roopa Prabhu authored
      
      This patch adds new rtm tunnel msg and api for tunnel id
      filtering in dst_metadata devices. First dst_metadata
      device to use the api is vxlan driver with AF_BRIDGE
      family.
      
      This and later changes add ability in vxlan driver to do
      tunnel id filtering (or vni filtering) on dst_metadata
      devices. This is similar to vlan api in the vlan filtering bridge.
      
      this patch includes selinux nlmsg_route_perms support for RTM_*TUNNEL
      api from Benjamin Poirier.
      
      Signed-off-by: default avatarRoopa Prabhu <roopa@nvidia.com>
      Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
      7b8135f4
  3. Feb 22, 2022
  4. Feb 02, 2022
  5. Jan 28, 2022
    • Vivek Goyal's avatar
      security, lsm: dentry_init_security() Handle multi LSM registration · 7f5056b9
      Vivek Goyal authored
      
      A ceph user has reported that ceph is crashing with kernel NULL pointer
      dereference. Following is the backtrace.
      
      /proc/version: Linux version 5.16.2-arch1-1 (linux@archlinux) (gcc (GCC)
      11.1.0, GNU ld (GNU Binutils) 2.36.1) #1 SMP PREEMPT Thu, 20 Jan 2022
      16:18:29 +0000
      distro / arch: Arch Linux / x86_64
      SELinux is not enabled
      ceph cluster version: 16.2.7 (dd0603118f56ab514f133c8d2e3adfc983942503)
      
      relevant dmesg output:
      [   30.947129] BUG: kernel NULL pointer dereference, address:
      0000000000000000
      [   30.947206] #PF: supervisor read access in kernel mode
      [   30.947258] #PF: error_code(0x0000) - not-present page
      [   30.947310] PGD 0 P4D 0
      [   30.947342] Oops: 0000 [#1] PREEMPT SMP PTI
      [   30.947388] CPU: 5 PID: 778 Comm: touch Not tainted 5.16.2-arch1-1 #1
      86fbf2c313cc37a553d65deb81d98e9dcc2a3659
      [   30.947486] Hardware name: Gigabyte Technology Co., Ltd. B365M
      DS3H/B365M DS3H, BIOS F5 08/13/2019
      [   30.947569] RIP: 0010:strlen+0x0/0x20
      [   30.947616] Code: b6 07 38 d0 74 16 48 83 c7 01 84 c0 74 05 48 39 f7 75
      ec 31 c0 31 d2 89 d6 89 d7 c3 48 89 f8 31 d2 89 d6 89 d7 c3 0
      f 1f 40 00 <80> 3f 00 74 12 48 89 f8 48 83 c0 01 80 38 00 75 f7 48 29 f8 31
      ff
      [   30.947782] RSP: 0018:ffffa4ed80ffbbb8 EFLAGS: 00010246
      [   30.947836] RAX: 0000000000000000 RBX: ffffa4ed80ffbc60 RCX:
      0000000000000000
      [   30.947904] RDX: 0000000000000000 RSI: 0000000000000000 RDI:
      0000000000000000
      [   30.947971] RBP: ffff94b0d15c0ae0 R08: 0000000000000000 R09:
      0000000000000000
      [   30.948040] R10: 0000000000000000 R11: 0000000000000000 R12:
      0000000000000000
      [   30.948106] R13: 0000000000000001 R14: ffffa4ed80ffbc60 R15:
      0000000000000000
      [   30.948174] FS:  00007fc7520f0740(0000) GS:ffff94b7ced40000(0000)
      knlGS:0000000000000000
      [   30.948252] CS:  0010 DS: 0000 ES: 0000 CR0: 0000000080050033
      [   30.948308] CR2: 0000000000000000 CR3: 0000000104a40001 CR4:
      00000000003706e0
      [   30.948376] Call Trace:
      [   30.948404]  <TASK>
      [   30.948431]  ceph_security_init_secctx+0x7b/0x240 [ceph
      49f9c4b9bf5be8760f19f1747e26da33920bce4b]
      [   30.948582]  ceph_atomic_open+0x51e/0x8a0 [ceph
      49f9c4b9bf5be8760f19f1747e26da33920bce4b]
      [   30.948708]  ? get_cached_acl+0x4d/0xa0
      [   30.948759]  path_openat+0x60d/0x1030
      [   30.948809]  do_filp_open+0xa5/0x150
      [   30.948859]  do_sys_openat2+0xc4/0x190
      [   30.948904]  __x64_sys_openat+0x53/0xa0
      [   30.948948]  do_syscall_64+0x5c/0x90
      [   30.948989]  ? exc_page_fault+0x72/0x180
      [   30.949034]  entry_SYSCALL_64_after_hwframe+0x44/0xae
      [   30.949091] RIP: 0033:0x7fc7521e25bb
      [   30.950849] Code: 25 00 00 41 00 3d 00 00 41 00 74 4b 64 8b 04 25 18 00
      00 00 85 c0 75 67 44 89 e2 48 89 ee bf 9c ff ff ff b8 01 01 0
      0 00 0f 05 <48> 3d 00 f0 ff ff 0f 87 91 00 00 00 48 8b 54 24 28 64 48 2b 14
      25
      
      Core of the problem is that ceph checks for return code from
      security_dentry_init_security() and if return code is 0, it assumes
      everything is fine and continues to call strlen(name), which crashes.
      
      Typically SELinux LSM returns 0 and sets name to "security.selinux" and
      it is not a problem. Or if selinux is not compiled in or disabled, it
      returns -EOPNOTSUP and ceph deals with it.
      
      But somehow in this configuration, 0 is being returned and "name" is
      not being initialized and that's creating the problem.
      
      Our suspicion is that BPF LSM is registering a hook for
      dentry_init_security() and returns hook default of 0.
      
      LSM_HOOK(int, 0, dentry_init_security, struct dentry *dentry,...)
      
      I have not been able to reproduce it just by doing CONFIG_BPF_LSM=y.
      Stephen has tested the patch though and confirms it solves the problem
      for him.
      
      dentry_init_security() is written in such a way that it expects only one
      LSM to register the hook. Atleast that's the expectation with current code.
      
      If another LSM returns a hook and returns default, it will simply return
      0 as of now and that will break ceph.
      
      Hence, suggestion is that change semantics of this hook a bit. If there
      are no LSMs or no LSM is taking ownership and initializing security context,
      then return -EOPNOTSUP. Also allow at max one LSM to initialize security
      context. This hook can't deal with multiple LSMs trying to init security
      context. This patch implements this new behavior.
      
      Reported-by: default avatarStephen Muth <smuth4@gmail.com>
      Tested-by: default avatarStephen Muth <smuth4@gmail.com>
      Suggested-by: default avatarCasey Schaufler <casey@schaufler-ca.com>
      Acked-by: default avatarCasey Schaufler <casey@schaufler-ca.com>
      Reviewed-by: default avatarSerge Hallyn <serge@hallyn.com>
      Cc: Jeff Layton <jlayton@kernel.org>
      Cc: Christian Brauner <brauner@kernel.org>
      Cc: Paul Moore <paul@paul-moore.com>
      Cc: <stable@vger.kernel.org> # 5.16.0
      Signed-off-by: default avatarVivek Goyal <vgoyal@redhat.com>
      Reviewed-by: default avatarJeff Layton <jlayton@kernel.org>
      Acked-by: default avatarPaul Moore <paul@paul-moore.com>
      Acked-by: default avatarChristian Brauner <brauner@kernel.org>
      Signed-off-by: default avatarJames Morris <jmorris@namei.org>
      7f5056b9
  6. Jan 24, 2022
  7. Jan 19, 2022
  8. Jan 05, 2022
    • Bruno Meneguele's avatar
      ima: silence measurement list hexdump during kexec · 520451e9
      Bruno Meneguele authored
      
      Directly calling print_hex_dump() dumps the IMA measurement list on soft
      resets (kexec) straight to the syslog (kmsg/dmesg) without considering the
      DEBUG flag or the dynamic debug state, causing the output to be always
      printed, including during boot time.
      
      Since this output is only valid for IMA debugging, but not necessary on
      normal kexec operation, print_hex_dump_debug() adheres to the pr_debug()
      behavior: the dump is only printed to syslog when DEBUG is defined or when
      explicitly requested by the user through dynamic debugging.
      
      Signed-off-by: default avatarBruno Meneguele <bmeneg@redhat.com>
      Signed-off-by: default avatarMimi Zohar <zohar@linux.ibm.com>
      520451e9
  9. 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
  10. Dec 24, 2021
  11. Dec 21, 2021
  12. Dec 16, 2021
    • Jakub Kicinski's avatar
      add missing bpf-cgroup.h includes · aef2feda
      Jakub Kicinski authored
      
      We're about to break the cgroup-defs.h -> bpf-cgroup.h dependency,
      make sure those who actually need more than the definition of
      struct cgroup_bpf include bpf-cgroup.h explicitly.
      
      Signed-off-by: default avatarJakub Kicinski <kuba@kernel.org>
      Signed-off-by: default avatarAlexei Starovoitov <ast@kernel.org>
      Acked-by: default avatarTejun Heo <tj@kernel.org>
      Link: https://lore.kernel.org/bpf/20211216025538.1649516-3-kuba@kernel.org
      aef2feda
    • 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
  13. Dec 15, 2021
    • Tetsuo Handa's avatar
      tomoyo: use hwight16() in tomoyo_domain_quota_is_ok() · f702e110
      Tetsuo Handa authored
      
      hwight16() is much faster. While we are at it, no need to include
      "perm =" part into data_race() macro, for perm is a local variable
      that cannot be accessed by other threads.
      
      Signed-off-by: default avatarTetsuo Handa <penguin-kernel@I-love.SAKURA.ne.jp>
      f702e110
    • Dmitry Vyukov's avatar
      tomoyo: Check exceeded quota early in tomoyo_domain_quota_is_ok(). · 04e57a2d
      Dmitry Vyukov authored
      
      If tomoyo is used in a testing/fuzzing environment in learning mode,
      for lots of domains the quota will be exceeded and stay exceeded
      for prolonged periods of time. In such cases it's pointless (and slow)
      to walk the whole acl list again and again just to rediscover that
      the quota is exceeded. We already have the TOMOYO_DIF_QUOTA_WARNED flag
      that notes the overflow condition. Check it early to avoid the slowdown.
      
      [penguin-kernel]
      This patch causes a user visible change that the learning mode will not be
      automatically resumed after the quota is increased. To resume the learning
      mode, administrator will need to explicitly clear TOMOYO_DIF_QUOTA_WARNED
      flag after increasing the quota. But I think that this change is generally
      preferable, for administrator likely wants to optimize the acl list for
      that domain before increasing the quota, or that domain likely hits the
      quota again. Therefore, don't try to care to clear TOMOYO_DIF_QUOTA_WARNED
      flag automatically when the quota for that domain changed.
      
      Signed-off-by: default avatarDmitry Vyukov <dvyukov@google.com>
      Signed-off-by: default avatarTetsuo Handa <penguin-kernel@I-love.SAKURA.ne.jp>
      04e57a2d
  14. Dec 06, 2021
  15. Dec 05, 2021
    • Xiu Jianfeng's avatar
      selinux: Use struct_size() helper in kmalloc() · 5fe37572
      Xiu Jianfeng authored
      Make use of struct_size() helper instead of an open-coded calculation.
      
      Link: https://github.com/KSPP/linux/issues/160
      
      
      Signed-off-by: default avatarXiu Jianfeng <xiujianfeng@huawei.com>
      Signed-off-by: default avatarPaul Moore <paul@paul-moore.com>
      5fe37572
    • Christian Brauner's avatar
      fs: support mapped mounts of mapped filesystems · bd303368
      Christian Brauner authored
      In previous patches we added new and modified existing helpers to handle
      idmapped mounts of filesystems mounted with an idmapping. In this final
      patch we convert all relevant places in the vfs to actually pass the
      filesystem's idmapping into these helpers.
      
      With this the vfs is in shape to handle idmapped mounts of filesystems
      mounted with an idmapping. Note that this is just the generic
      infrastructure. Actually adding support for idmapped mounts to a
      filesystem mountable with an idmapping is follow-up work.
      
      In this patch we extend the definition of an idmapped mount from a mount
      that that has the initial idmapping attached to it to a mount that has
      an idmapping attached to it which is not the same as the idmapping the
      filesystem was mounted with.
      
      As before we do not allow the initial idmapping to be attached to a
      mount. In addition this patch prevents that the idmapping the filesystem
      was mounted with can be attached to a mount created based on this
      files...
      bd303368
  16. Dec 03, 2021
  17. Nov 26, 2021
  18. Nov 22, 2021
  19. 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
  20. 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
  21. 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
  22. Nov 06, 2021
  23. Nov 03, 2021