Skip to content
Snippets Groups Projects
  1. Feb 10, 2023
  2. Jan 19, 2023
    • Christian Brauner's avatar
      fs: port inode_owner_or_capable() to mnt_idmap · 01beba79
      Christian Brauner authored
      
      Convert to struct mnt_idmap.
      
      Last cycle we merged the necessary infrastructure in
      256c8aed ("fs: introduce dedicated idmap type for mounts").
      This is just the conversion to struct mnt_idmap.
      
      Currently we still pass around the plain namespace that was attached to a
      mount. This is in general pretty convenient but it makes it easy to
      conflate namespaces that are relevant on the filesystem with namespaces
      that are relevent on the mount level. Especially for non-vfs developers
      without detailed knowledge in this area this can be a potential source for
      bugs.
      
      Once the conversion to struct mnt_idmap is done all helpers down to the
      really low-level helpers will take a struct mnt_idmap argument instead of
      two namespace arguments. This way it becomes impossible to conflate the two
      eliminating the possibility of any bugs. All of the vfs and all filesystems
      only operate on struct mnt_idmap.
      
      Acked-by: default avatarDave Chinner <dchinner@redhat.com>
      Reviewed-by: default avatarChristoph Hellwig <hch@lst.de>
      Signed-off-by: default avatarChristian Brauner (Microsoft) <brauner@kernel.org>
      01beba79
    • Christian Brauner's avatar
      fs: port acl to mnt_idmap · 700b7940
      Christian Brauner authored
      
      Convert to struct mnt_idmap.
      
      Last cycle we merged the necessary infrastructure in
      256c8aed ("fs: introduce dedicated idmap type for mounts").
      This is just the conversion to struct mnt_idmap.
      
      Currently we still pass around the plain namespace that was attached to a
      mount. This is in general pretty convenient but it makes it easy to
      conflate namespaces that are relevant on the filesystem with namespaces
      that are relevent on the mount level. Especially for non-vfs developers
      without detailed knowledge in this area this can be a potential source for
      bugs.
      
      Once the conversion to struct mnt_idmap is done all helpers down to the
      really low-level helpers will take a struct mnt_idmap argument instead of
      two namespace arguments. This way it becomes impossible to conflate the two
      eliminating the possibility of any bugs. All of the vfs and all filesystems
      only operate on struct mnt_idmap.
      
      Acked-by: default avatarDave Chinner <dchinner@redhat.com>
      Reviewed-by: default avatarChristoph Hellwig <hch@lst.de>
      Signed-off-by: default avatarChristian Brauner (Microsoft) <brauner@kernel.org>
      700b7940
    • Christian Brauner's avatar
      fs: port xattr to mnt_idmap · 39f60c1c
      Christian Brauner authored
      
      Convert to struct mnt_idmap.
      
      Last cycle we merged the necessary infrastructure in
      256c8aed ("fs: introduce dedicated idmap type for mounts").
      This is just the conversion to struct mnt_idmap.
      
      Currently we still pass around the plain namespace that was attached to a
      mount. This is in general pretty convenient but it makes it easy to
      conflate namespaces that are relevant on the filesystem with namespaces
      that are relevent on the mount level. Especially for non-vfs developers
      without detailed knowledge in this area this can be a potential source for
      bugs.
      
      Once the conversion to struct mnt_idmap is done all helpers down to the
      really low-level helpers will take a struct mnt_idmap argument instead of
      two namespace arguments. This way it becomes impossible to conflate the two
      eliminating the possibility of any bugs. All of the vfs and all filesystems
      only operate on struct mnt_idmap.
      
      Acked-by: default avatarDave Chinner <dchinner@redhat.com>
      Reviewed-by: default avatarChristoph Hellwig <hch@lst.de>
      Signed-off-by: default avatarChristian Brauner (Microsoft) <brauner@kernel.org>
      39f60c1c
    • Christian Brauner's avatar
      fs: port ->permission() to pass mnt_idmap · 4609e1f1
      Christian Brauner authored
      
      Convert to struct mnt_idmap.
      
      Last cycle we merged the necessary infrastructure in
      256c8aed ("fs: introduce dedicated idmap type for mounts").
      This is just the conversion to struct mnt_idmap.
      
      Currently we still pass around the plain namespace that was attached to a
      mount. This is in general pretty convenient but it makes it easy to
      conflate namespaces that are relevant on the filesystem with namespaces
      that are relevent on the mount level. Especially for non-vfs developers
      without detailed knowledge in this area this can be a potential source for
      bugs.
      
      Once the conversion to struct mnt_idmap is done all helpers down to the
      really low-level helpers will take a struct mnt_idmap argument instead of
      two namespace arguments. This way it becomes impossible to conflate the two
      eliminating the possibility of any bugs. All of the vfs and all filesystems
      only operate on struct mnt_idmap.
      
      Acked-by: default avatarDave Chinner <dchinner@redhat.com>
      Reviewed-by: default avatarChristoph Hellwig <hch@lst.de>
      Signed-off-by: default avatarChristian Brauner (Microsoft) <brauner@kernel.org>
      4609e1f1
  3. Nov 09, 2022
  4. Nov 05, 2022
    • Paul Moore's avatar
      lsm: make security_socket_getpeersec_stream() sockptr_t safe · b10b9c34
      Paul Moore authored
      
      Commit 4ff09db1 ("bpf: net: Change sk_getsockopt() to take the
      sockptr_t argument") made it possible to call sk_getsockopt()
      with both user and kernel address space buffers through the use of
      the sockptr_t type.  Unfortunately at the time of conversion the
      security_socket_getpeersec_stream() LSM hook was written to only
      accept userspace buffers, and in a desire to avoid having to change
      the LSM hook the commit author simply passed the sockptr_t's
      userspace buffer pointer.  Since the only sk_getsockopt() callers
      at the time of conversion which used kernel sockptr_t buffers did
      not allow SO_PEERSEC, and hence the
      security_socket_getpeersec_stream() hook, this was acceptable but
      also very fragile as future changes presented the possibility of
      silently passing kernel space pointers to the LSM hook.
      
      There are several ways to protect against this, including careful
      code review of future commits, but since relying on code review to
      catch bugs is a recipe for disaster and the upstream eBPF maintainer
      is "strongly against defensive programming", this patch updates the
      LSM hook, and all of the implementations to support sockptr_t and
      safely handle both user and kernel space buffers.
      
      Acked-by: default avatarCasey Schaufler <casey@schaufler-ca.com>
      Acked-by: default avatarJohn Johansen <john.johansen@canonical.com>
      Signed-off-by: default avatarPaul Moore <paul@paul-moore.com>
      b10b9c34
  5. Oct 20, 2022
    • Christian Brauner's avatar
      selinux: implement get, set and remove acl hook · 1bdeb218
      Christian Brauner authored
      The current way of setting and getting posix acls through the generic
      xattr interface is error prone and type unsafe. The vfs needs to
      interpret and fixup posix acls before storing or reporting it to
      userspace. Various hacks exist to make this work. The code is hard to
      understand and difficult to maintain in it's current form. Instead of
      making this work by hacking posix acls through xattr handlers we are
      building a dedicated posix acl api around the get and set inode
      operations. This removes a lot of hackiness and makes the codepaths
      easier to maintain. A lot of background can be found in [1].
      
      So far posix acls were passed as a void blob to the security and
      integrity modules. Some of them like evm then proceed to interpret the
      void pointer and convert it into the kernel internal struct posix acl
      representation to perform their integrity checking magic. This is
      obviously pretty problematic as that requires knowledge that only the
      vfs is guaranteed to have and has lead to various bugs. Add a proper
      security hook for setting posix acls and pass down the posix acls in
      their appropriate vfs format instead of hacking it through a void
      pointer stored in the uapi format.
      
      I spent considerate time in the security module infrastructure and
      audited all codepaths. SELinux has no restrictions based on the posix
      acl values passed through it. The capability hook doesn't need to be
      called either because it only has restrictions on security.* xattrs. So
      these are all fairly simply hooks for SELinux.
      
      Link: https://lore.kernel.org/all/20220801145520.1532837-1-brauner@kernel.org
      
       [1]
      Acked-by: default avatarPaul Moore <paul@paul-moore.com>
      Signed-off-by: default avatarChristian Brauner (Microsoft) <brauner@kernel.org>
      1bdeb218
  6. Oct 19, 2022
    • GONG, Ruiqi's avatar
      selinux: enable use of both GFP_KERNEL and GFP_ATOMIC in convert_context() · abe3c631
      GONG, Ruiqi authored
      The following warning was triggered on a hardware environment:
      
        SELinux: Converting 162 SID table entries...
        BUG: sleeping function called from invalid context at
             __might_sleep+0x60/0x74 0x0
        in_atomic(): 1, irqs_disabled(): 128, non_block: 0, pid: 5943, name: tar
        CPU: 7 PID: 5943 Comm: tar Tainted: P O 5.10.0 #1
        Call trace:
         dump_backtrace+0x0/0x1c8
         show_stack+0x18/0x28
         dump_stack+0xe8/0x15c
         ___might_sleep+0x168/0x17c
         __might_sleep+0x60/0x74
         __kmalloc_track_caller+0xa0/0x7dc
         kstrdup+0x54/0xac
         convert_context+0x48/0x2e4
         sidtab_context_to_sid+0x1c4/0x36c
         security_context_to_sid_core+0x168/0x238
         security_context_to_sid_default+0x14/0x24
         inode_doinit_use_xattr+0x164/0x1e4
         inode_doinit_with_dentry+0x1c0/0x488
         selinux_d_instantiate+0x20/0x34
         security_d_instantiate+0x70/0xbc
         d_splice_alias+0x4c/0x3c0
         ext4_lookup+0x1d8/0x200 [ext4]
         __lookup_slow+0x12c/0x1e4
         walk_component+0x100/0x200
         path_lookupat+0x88/0x118
         filename_lookup+0x98/0x130
         user_path_at_empty+0x48/0x60
         vfs_statx+0x84/0x140
         vfs_fstatat+0x20/0x30
         __se_sys_newfstatat+0x30/0x74
         __arm64_sys_newfstatat+0x1c/0x2c
         el0_svc_common.constprop.0+0x100/0x184
         do_el0_svc+0x1c/0x2c
         el0_svc+0x20/0x34
         el0_sync_handler+0x80/0x17c
         el0_sync+0x13c/0x140
        SELinux: Context system_u:object_r:pssp_rsyslog_log_t:s0:c0 is
                 not valid (left unmapped).
      
      It was found that within a critical section of spin_lock_irqsave in
      sidtab_context_to_sid(), convert_context() (hooked by
      sidtab_convert_params.func) might cause the process to sleep via
      allocating memory with GFP_KERNEL, which is problematic.
      
      As Ondrej pointed out [1], convert_context()/sidtab_convert_params.func
      has another caller sidtab_convert_tree(), which is okay with GFP_KERNEL.
      Therefore, fix this problem by adding a gfp_t argument for
      convert_context()/sidtab_convert_params.func and pass GFP_KERNEL/_ATOMIC
      properly in individual callers.
      
      Cc: stable@vger.kernel.org
      Link: https://lore.kernel.org/all/20221018120111.1474581-1-gongruiqi1@huawei.com/
      
       [1]
      Reported-by: default avatarTan Ninghao <tanninghao1@huawei.com>
      Fixes: ee1a84fd ("selinux: overhaul sidtab to fix bug and improve performance")
      Signed-off-by: default avatarGONG, Ruiqi <gongruiqi1@huawei.com>
      Reviewed-by: default avatarOndrej Mosnacek <omosnace@redhat.com>
      [PM: wrap long BUG() output lines, tweak subject line]
      Signed-off-by: default avatarPaul Moore <paul@paul-moore.com>
      abe3c631
  7. Oct 17, 2022
  8. Sep 14, 2022
  9. Sep 01, 2022
  10. Aug 30, 2022
  11. Aug 26, 2022
    • Paul Moore's avatar
      selinux: implement the security_uring_cmd() LSM hook · f4d653dc
      Paul Moore authored
      
      Add a SELinux access control for the iouring IORING_OP_URING_CMD
      command.  This includes the addition of a new permission in the
      existing "io_uring" object class: "cmd".  The subject of the new
      permission check is the domain of the process requesting access, the
      object is the open file which points to the device/file that is the
      target of the IORING_OP_URING_CMD operation.  A sample policy rule
      is shown below:
      
        allow <domain> <file>:io_uring { cmd };
      
      Cc: stable@vger.kernel.org
      Fixes: ee692a21 ("fs,io_uring: add infrastructure for uring-cmd")
      Signed-off-by: default avatarPaul Moore <paul@paul-moore.com>
      f4d653dc
  12. Aug 16, 2022
    • Frederick Lawler's avatar
      selinux: Implement userns_create hook · ed5d44d4
      Frederick Lawler authored
      
      Unprivileged user namespace creation is an intended feature to enable
      sandboxing, however this feature is often used to as an initial step to
      perform a privilege escalation attack.
      
      This patch implements a new user_namespace { create } access control
      permission to restrict which domains allow or deny user namespace
      creation. This is necessary for system administrators to quickly protect
      their systems while waiting for vulnerability patches to be applied.
      
      This permission can be used in the following way:
      
              allow domA_t domA_t : user_namespace { create };
      
      Signed-off-by: default avatarFrederick Lawler <fred@cloudflare.com>
      Signed-off-by: default avatarPaul Moore <paul@paul-moore.com>
      ed5d44d4
  13. Jun 21, 2022
  14. Jun 16, 2022
    • Christian Göttsche's avatar
      selinux: free contexts previously transferred in selinux_add_opt() · cad140d0
      Christian Göttsche authored
      
      `selinux_add_opt()` stopped taking ownership of the passed context since
      commit 70f4169a ("selinux: parse contexts for mount options early").
      
          unreferenced object 0xffff888114dfd140 (size 64):
            comm "mount", pid 15182, jiffies 4295687028 (age 796.340s)
            hex dump (first 32 bytes):
              73 79 73 74 65 6d 5f 75 3a 6f 62 6a 65 63 74 5f  system_u:object_
              72 3a 74 65 73 74 5f 66 69 6c 65 73 79 73 74 65  r:test_filesyste
            backtrace:
              [<ffffffffa07dbef4>] kmemdup_nul+0x24/0x80
              [<ffffffffa0d34253>] selinux_sb_eat_lsm_opts+0x293/0x560
              [<ffffffffa0d13f08>] security_sb_eat_lsm_opts+0x58/0x80
              [<ffffffffa0af1eb2>] generic_parse_monolithic+0x82/0x180
              [<ffffffffa0a9c1a5>] do_new_mount+0x1f5/0x550
              [<ffffffffa0a9eccb>] path_mount+0x2ab/0x1570
              [<ffffffffa0aa019e>] __x64_sys_mount+0x20e/0x280
              [<ffffffffa1f47124>] do_syscall_64+0x34/0x80
              [<ffffffffa200007e>] entry_SYSCALL_64_after_hwframe+0x46/0xb0
      
          unreferenced object 0xffff888108e71640 (size 64):
            comm "fsmount", pid 7607, jiffies 4295044974 (age 1601.016s)
            hex dump (first 32 bytes):
              73 79 73 74 65 6d 5f 75 3a 6f 62 6a 65 63 74 5f  system_u:object_
              72 3a 74 65 73 74 5f 66 69 6c 65 73 79 73 74 65  r:test_filesyste
            backtrace:
              [<ffffffff861dc2b1>] memdup_user+0x21/0x90
              [<ffffffff861dc367>] strndup_user+0x47/0xa0
              [<ffffffff864f6965>] __do_sys_fsconfig+0x485/0x9f0
              [<ffffffff87940124>] do_syscall_64+0x34/0x80
              [<ffffffff87a0007e>] entry_SYSCALL_64_after_hwframe+0x46/0xb0
      
      Cc: stable@vger.kernel.org
      Fixes: 70f4169a ("selinux: parse contexts for mount options early")
      Signed-off-by: default avatarChristian Göttsche <cgzones@googlemail.com>
      Signed-off-by: default avatarPaul Moore <paul@paul-moore.com>
      cad140d0
  15. Jun 15, 2022
  16. Jun 14, 2022
  17. Jun 10, 2022
  18. Jun 07, 2022
  19. May 18, 2022
  20. May 03, 2022
    • Christian Göttsche's avatar
      selinux: log anon inode class name · c29722fa
      Christian Göttsche authored
      
      Log the anonymous inode class name in the security hook
      inode_init_security_anon.  This name is the key for name based type
      transitions on the anon_inode security class on creation.  Example:
      
          type=AVC msg=audit(02/16/22 22:02:50.585:216) : avc:  granted \
              { create } for  pid=2136 comm=mariadbd anonclass=[io_uring] \
              scontext=system_u:system_r:mysqld_t:s0 \
              tcontext=system_u:system_r:mysqld_iouring_t:s0 tclass=anon_inode
      
      Add a new LSM audit data type holding the inode and the class name.
      
      Signed-off-by: default avatarChristian Göttsche <cgzones@googlemail.com>
      [PM: adjusted 'anonclass' to be a trusted string, cgzones approved]
      Signed-off-by: default avatarPaul Moore <paul@paul-moore.com>
      c29722fa
    • Christian Göttsche's avatar
      selinux: declare data arrays const · ded34574
      Christian Göttsche authored
      
      The arrays for the policy capability names, the initial sid identifiers
      and the class and permission names are not changed at runtime.  Declare
      them const to avoid accidental modification.
      
      Do not override the classmap and the initial sid list in the build time
      script genheaders.
      
      Check flose(3) is successful in genheaders.c, otherwise the written data
      might be corrupted or incomplete.
      
      Signed-off-by: default avatarChristian Göttsche <cgzones@googlemail.com>
      [PM: manual merge due to fuzz, minor style tweaks]
      Signed-off-by: default avatarPaul Moore <paul@paul-moore.com>
      ded34574
    • Christian Göttsche's avatar
      selinux: fix indentation level of mls_ops block · a9029d97
      Christian Göttsche authored
      
      Add one level of indentation to the code block of the label mls_ops in
      constraint_expr_eval(), to adjust the trailing break; to the parent
      case: branch.
      
      Signed-off-by: default avatarChristian Göttsche <cgzones@googlemail.com>
      Signed-off-by: default avatarPaul Moore <paul@paul-moore.com>
      a9029d97
    • Christian Göttsche's avatar
      selinux: include necessary headers in headers · 4ad37de4
      Christian Göttsche authored
      
      Include header files required for struct or typedef declarations in
      header files.  This is for example helpful when working with an IDE, which
      needs to resolve those symbols.
      
      Signed-off-by: default avatarChristian Göttsche <cgzones@googlemail.com>
      Signed-off-by: default avatarPaul Moore <paul@paul-moore.com>
      4ad37de4
    • Christian Göttsche's avatar
      selinux: avoid extra semicolon · 1d4e8036
      Christian Göttsche authored
      Wrap macro into `do { } while (0)` to avoid Clang emitting warnings
      about extra semicolons.
      Similar to userspace commit
      https://github.com/SELinuxProject/selinux/commit/9d85aa60d12e468e7fd510c2b5475b5299b71622
      
      
      
      Signed-off-by: default avatarChristian Göttsche <cgzones@googlemail.com>
      [PM: whitespace/indenting tweaks]
      Signed-off-by: default avatarPaul Moore <paul@paul-moore.com>
      1d4e8036
    • Christian Göttsche's avatar
      selinux: update parameter documentation · 75920515
      Christian Göttsche authored
      
      security/selinux/include/audit.h:54: warning: Function parameter or member 'krule' not described in 'selinux_audit_rule_known'
      security/selinux/include/audit.h:54: warning: Excess function parameter 'rule' description in 'selinux_audit_rule_known'
      security/selinux/include/avc.h:130: warning: Function parameter or member 'state' not described in 'avc_audit'
      
      This also bring the parameter name of selinux_audit_rule_known() in sync
      between declaration and definition.
      
      Signed-off-by: default avatarChristian Göttsche <cgzones@googlemail.com>
      Signed-off-by: default avatarPaul Moore <paul@paul-moore.com>
      75920515
    • Christian Göttsche's avatar
      selinux: resolve checkpatch errors · ede17552
      Christian Göttsche authored
      
      Reported by checkpatch:
      
          security/selinux/nlmsgtab.c
          ---------------------------
          ERROR: that open brace { should be on the previous line
          #29: FILE: security/selinux/nlmsgtab.c:29:
          +static const struct nlmsg_perm nlmsg_route_perms[] =
          +{
      
          ERROR: that open brace { should be on the previous line
          #97: FILE: security/selinux/nlmsgtab.c:97:
          +static const struct nlmsg_perm nlmsg_tcpdiag_perms[] =
          +{
      
          ERROR: that open brace { should be on the previous line
          #105: FILE: security/selinux/nlmsgtab.c:105:
          +static const struct nlmsg_perm nlmsg_xfrm_perms[] =
          +{
      
          ERROR: that open brace { should be on the previous line
          #134: FILE: security/selinux/nlmsgtab.c:134:
          +static const struct nlmsg_perm nlmsg_audit_perms[] =
          +{
      
          security/selinux/ss/policydb.c
          ------------------------------
          ERROR: that open brace { should be on the previous line
          #318: FILE: security/selinux/ss/policydb.c:318:
          +static int (*destroy_f[SYM_NUM]) (void *key, void *datum, void *datap) =
          +{
      
          ERROR: that open brace { should be on the previous line
          #674: FILE: security/selinux/ss/policydb.c:674:
          +static int (*index_f[SYM_NUM]) (void *key, void *datum, void *datap) =
          +{
      
          ERROR: that open brace { should be on the previous line
          #1643: FILE: security/selinux/ss/policydb.c:1643:
          +static int (*read_f[SYM_NUM]) (struct policydb *p, struct symtab *s, void *fp) =
          +{
      
          ERROR: that open brace { should be on the previous line
          #3246: FILE: security/selinux/ss/policydb.c:3246:
          +                               void *datap) =
          +{
      
      Signed-off-by: default avatarChristian Göttsche <cgzones@googlemail.com>
      Signed-off-by: default avatarPaul Moore <paul@paul-moore.com>
      ede17552
  21. Apr 14, 2022
  22. Apr 04, 2022
  23. Mar 10, 2022
  24. Mar 03, 2022
  25. Mar 02, 2022
    • Paul Moore's avatar
      selinux: shorten the policy capability enum names · cdbec3ed
      Paul Moore authored
      
      The SELinux policy capability enum names are rather long and follow
      the "POLICYDB_CAPABILITY_XXX format".  While the "POLICYDB_" prefix
      is helpful in tying the enums to other SELinux policy constants,
      macros, etc. there is no reason why we need to spell out
      "CAPABILITY" completely.  Shorten "CAPABILITY" to "CAP" in order to
      make things a bit shorter and cleaner.
      
      Moving forward, the SELinux policy capability enum names should
      follow the "POLICYDB_CAP_XXX" format.
      
      Signed-off-by: default avatarPaul Moore <paul@paul-moore.com>
      cdbec3ed
  26. 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
Loading