Skip to content
Snippets Groups Projects
  1. Jul 09, 2024
    • Paul Moore's avatar
      selinux,smack: remove the capability checks in the removexattr hooks · dd44477e
      Paul Moore authored
      
      Commit 61df7b82 ("lsm: fixup the inode xattr capability handling")
      moved the responsibility of doing the inode xattr capability checking
      out of the individual LSMs and into the LSM framework itself.
      Unfortunately, while the original commit added the capability checks
      to both the setxattr and removexattr code in the LSM framework, it
      only removed the setxattr capability checks from the individual LSMs,
      leaving duplicated removexattr capability checks in both the SELinux
      and Smack code.
      
      This patch removes the duplicated code from SELinux and Smack.
      
      Fixes: 61df7b82 ("lsm: fixup the inode xattr capability handling")
      Acked-by: default avatarCasey Schaufler <casey@schaufler-ca.com>
      Signed-off-by: default avatarPaul Moore <paul@paul-moore.com>
      dd44477e
  2. Jun 19, 2024
    • Konstantin Andreev's avatar
      smack: unix sockets: fix accept()ed socket label · e86cac0a
      Konstantin Andreev authored
      
      When a process accept()s connection from a unix socket
      (either stream or seqpacket)
      it gets the socket with the label of the connecting process.
      
      For example, if a connecting process has a label 'foo',
      the accept()ed socket will also have 'in' and 'out' labels 'foo',
      regardless of the label of the listener process.
      
      This is because kernel creates unix child sockets
      in the context of the connecting process.
      
      I do not see any obvious way for the listener to abuse
      alien labels coming with the new socket, but,
      to be on the safe side, it's better fix new socket labels.
      
      Signed-off-by: default avatarKonstantin Andreev <andreev@swemel.ru>
      Signed-off-by: default avatarCasey Schaufler <casey@schaufler-ca.com>
      e86cac0a
  3. Jun 13, 2024
    • GUO Zihua's avatar
      ima: Avoid blocking in RCU read-side critical section · 9a95c5bf
      GUO Zihua authored
      
      A panic happens in ima_match_policy:
      
      BUG: unable to handle kernel NULL pointer dereference at 0000000000000010
      PGD 42f873067 P4D 0
      Oops: 0000 [#1] SMP NOPTI
      CPU: 5 PID: 1286325 Comm: kubeletmonit.sh
      Kdump: loaded Tainted: P
      Hardware name: QEMU Standard PC (i440FX + PIIX, 1996),
                     BIOS 0.0.0 02/06/2015
      RIP: 0010:ima_match_policy+0x84/0x450
      Code: 49 89 fc 41 89 cf 31 ed 89 44 24 14 eb 1c 44 39
            7b 18 74 26 41 83 ff 05 74 20 48 8b 1b 48 3b 1d
            f2 b9 f4 00 0f 84 9c 01 00 00 <44> 85 73 10 74 ea
            44 8b 6b 14 41 f6 c5 01 75 d4 41 f6 c5 02 74 0f
      RSP: 0018:ff71570009e07a80 EFLAGS: 00010207
      RAX: 0000000000000000 RBX: 0000000000000000 RCX: 0000000000000200
      RDX: ffffffffad8dc7c0 RSI: 0000000024924925 RDI: ff3e27850dea2000
      RBP: 0000000000000000 R08: 0000000000000000 R09: ffffffffabfce739
      R10: ff3e27810cc42400 R11: 0000000000000000 R12: ff3e2781825ef970
      R13: 00000000ff3e2785 R14: 000000000000000c R15: 0000000000000001
      FS:  00007f5195b51740(0000)
      GS:ff3e278b12d40000(0000) knlGS:0000000000000000
      CS:  0010 DS: 0000 ES: 0000 CR0: 0000000080050033
      CR2: 0000000000000010 CR3: 0000000626d24002 CR4: 0000000000361ee0
      DR0: 0000000000000000 DR1: 0000000000000000 DR2: 0000000000000000
      DR3: 0000000000000000 DR6: 00000000fffe0ff0 DR7: 0000000000000400
      Call Trace:
       ima_get_action+0x22/0x30
       process_measurement+0xb0/0x830
       ? page_add_file_rmap+0x15/0x170
       ? alloc_set_pte+0x269/0x4c0
       ? prep_new_page+0x81/0x140
       ? simple_xattr_get+0x75/0xa0
       ? selinux_file_open+0x9d/0xf0
       ima_file_check+0x64/0x90
       path_openat+0x571/0x1720
       do_filp_open+0x9b/0x110
       ? page_counter_try_charge+0x57/0xc0
       ? files_cgroup_alloc_fd+0x38/0x60
       ? __alloc_fd+0xd4/0x250
       ? do_sys_open+0x1bd/0x250
       do_sys_open+0x1bd/0x250
       do_syscall_64+0x5d/0x1d0
       entry_SYSCALL_64_after_hwframe+0x65/0xca
      
      Commit c7423dbd ("ima: Handle -ESTALE returned by
      ima_filter_rule_match()") introduced call to ima_lsm_copy_rule within a
      RCU read-side critical section which contains kmalloc with GFP_KERNEL.
      This implies a possible sleep and violates limitations of RCU read-side
      critical sections on non-PREEMPT systems.
      
      Sleeping within RCU read-side critical section might cause
      synchronize_rcu() returning early and break RCU protection, allowing a
      UAF to happen.
      
      The root cause of this issue could be described as follows:
      |	Thread A	|	Thread B	|
      |			|ima_match_policy	|
      |			|  rcu_read_lock	|
      |ima_lsm_update_rule	|			|
      |  synchronize_rcu	|			|
      |			|    kmalloc(GFP_KERNEL)|
      |			|      sleep		|
      ==> synchronize_rcu returns early
      |  kfree(entry)		|			|
      |			|    entry = entry->next|
      ==> UAF happens and entry now becomes NULL (or could be anything).
      |			|    entry->action	|
      ==> Accessing entry might cause panic.
      
      To fix this issue, we are converting all kmalloc that is called within
      RCU read-side critical section to use GFP_ATOMIC.
      
      Fixes: c7423dbd ("ima: Handle -ESTALE returned by ima_filter_rule_match()")
      Cc: stable@vger.kernel.org
      Signed-off-by: default avatarGUO Zihua <guozihua@huawei.com>
      Acked-by: default avatarJohn Johansen <john.johansen@canonical.com>
      Reviewed-by: default avatarMimi Zohar <zohar@linux.ibm.com>
      Reviewed-by: default avatarCasey Schaufler <casey@schaufler-ca.com>
      [PM: fixed missing comment, long lines, !CONFIG_IMA_LSM_RULES case]
      Signed-off-by: default avatarPaul Moore <paul@paul-moore.com>
      9a95c5bf
  4. Jun 05, 2024
    • Casey Schaufler's avatar
      smack: tcp: ipv4, fix incorrect labeling · 2fe209d0
      Casey Schaufler authored
      
      Currently, Smack mirrors the label of incoming tcp/ipv4 connections:
      when a label 'foo' connects to a label 'bar' with tcp/ipv4,
      'foo' always gets 'foo' in returned ipv4 packets. So,
      1) returned packets are incorrectly labeled ('foo' instead of 'bar')
      2) 'bar' can write to 'foo' without being authorized to write.
      
      Here is a scenario how to see this:
      
      * Take two machines, let's call them C and S,
         with active Smack in the default state
         (no settings, no rules, no labeled hosts, only builtin labels)
      
      * At S, add Smack rule 'foo bar w'
         (labels 'foo' and 'bar' are instantiated at S at this moment)
      
      * At S, at label 'bar', launch a program
         that listens for incoming tcp/ipv4 connections
      
      * From C, at label 'foo', connect to the listener at S.
         (label 'foo' is instantiated at C at this moment)
         Connection succeedes and works.
      
      * Send some data in both directions.
      * Collect network traffic of this connection.
      
      All packets in both directions are labeled with the CIPSO
      of the label 'foo'. Hence, label 'bar' writes to 'foo' without
      being authorized, and even without ever being known at C.
      
      If anybody cares: exactly the same happens with DCCP.
      
      This behavior 1st manifested in release 2.6.29.4 (see Fixes below)
      and it looks unintentional. At least, no explanation was provided.
      
      I changed returned packes label into the 'bar',
      to bring it into line with the Smack documentation claims.
      
      Signed-off-by: default avatarKonstantin Andreev <andreev@swemel.ru>
      Signed-off-by: default avatarCasey Schaufler <casey@schaufler-ca.com>
      2fe209d0
  5. Jun 03, 2024
    • Paul Moore's avatar
      lsm: fixup the inode xattr capability handling · 61df7b82
      Paul Moore authored
      
      The current security_inode_setxattr() and security_inode_removexattr()
      hooks rely on individual LSMs to either call into the associated
      capability hooks (cap_inode_setxattr() or cap_inode_removexattr()), or
      return a magic value of 1 to indicate that the LSM layer itself should
      perform the capability checks.  Unfortunately, with the default return
      value for these LSM hooks being 0, an individual LSM hook returning a
      1 will cause the LSM hook processing to exit early, potentially
      skipping a LSM.  Thankfully, with the exception of the BPF LSM, none
      of the LSMs which currently register inode xattr hooks should end up
      returning a value of 1, and in the BPF LSM case, with the BPF LSM hooks
      executing last there should be no real harm in stopping processing of
      the LSM hooks.  However, the reliance on the individual LSMs to either
      call the capability hooks themselves, or signal the LSM with a return
      value of 1, is fragile and relies on a specific set of LSMs being
      enabled.  This patch is an effort to resolve, or minimize, these
      issues.
      
      Before we discuss the solution, there are a few observations and
      considerations that we need to take into account:
      * BPF LSM registers an implementation for every LSM hook, and that
        implementation simply returns the hook's default return value, a
        0 in this case.  We want to ensure that the default BPF LSM behavior
        results in the capability checks being called.
      * SELinux and Smack do not expect the traditional capability checks
        to be applied to the xattrs that they "own".
      * SELinux and Smack are currently written in such a way that the
        xattr capability checks happen before any additional LSM specific
        access control checks.  SELinux does apply SELinux specific access
        controls to all xattrs, even those not "owned" by SELinux.
      * IMA and EVM also register xattr hooks but assume that the LSM layer
        and specific LSMs have already authorized the basic xattr operation.
      
      In order to ensure we perform the capability based access controls
      before the individual LSM access controls, perform only one capability
      access control check for each operation, and clarify the logic around
      applying the capability controls, we need a mechanism to determine if
      any of the enabled LSMs "own" a particular xattr and want to take
      responsibility for controlling access to that xattr.  The solution in
      this patch is to create a new LSM hook, 'inode_xattr_skipcap', that is
      not exported to the rest of the kernel via a security_XXX() function,
      but is used by the LSM layer to determine if a LSM wants to control
      access to a given xattr and avoid the traditional capability controls.
      Registering an inode_xattr_skipcap hook is optional, if a LSM declines
      to register an implementation, or uses an implementation that simply
      returns the default value (0), there is no effect as the LSM continues
      to enforce the capability based controls (unless another LSM takes
      ownership of the xattr).  If none of the LSMs signal that the
      capability checks should be skipped, the capability check is performed
      and if access is granted the individual LSM xattr access control hooks
      are executed, keeping with the DAC-before-LSM convention.
      
      Cc: stable@vger.kernel.org
      Acked-by: default avatarCasey Schaufler <casey@schaufler-ca.com>
      Signed-off-by: default avatarPaul Moore <paul@paul-moore.com>
      61df7b82
  6. May 13, 2024
    • Davide Caratti's avatar
      netlabel: fix RCU annotation for IPv4 options on socket creation · 8ec9897e
      Davide Caratti authored
      
      Xiumei reports the following splat when netlabel and TCP socket are used:
      
       =============================
       WARNING: suspicious RCU usage
       6.9.0-rc2+ #637 Not tainted
       -----------------------------
       net/ipv4/cipso_ipv4.c:1880 suspicious rcu_dereference_protected() usage!
      
       other info that might help us debug this:
      
       rcu_scheduler_active = 2, debug_locks = 1
       1 lock held by ncat/23333:
        #0: ffffffff906030c0 (rcu_read_lock){....}-{1:2}, at: netlbl_sock_setattr+0x25/0x1b0
      
       stack backtrace:
       CPU: 11 PID: 23333 Comm: ncat Kdump: loaded Not tainted 6.9.0-rc2+ #637
       Hardware name: Supermicro SYS-6027R-72RF/X9DRH-7TF/7F/iTF/iF, BIOS 3.0  07/26/2013
       Call Trace:
        <TASK>
        dump_stack_lvl+0xa9/0xc0
        lockdep_rcu_suspicious+0x117/0x190
        cipso_v4_sock_setattr+0x1ab/0x1b0
        netlbl_sock_setattr+0x13e/0x1b0
        selinux_netlbl_socket_post_create+0x3f/0x80
        selinux_socket_post_create+0x1a0/0x460
        security_socket_post_create+0x42/0x60
        __sock_create+0x342/0x3a0
        __sys_socket_create.part.22+0x42/0x70
        __sys_socket+0x37/0xb0
        __x64_sys_socket+0x16/0x20
        do_syscall_64+0x96/0x180
        ? do_user_addr_fault+0x68d/0xa30
        ? exc_page_fault+0x171/0x280
        ? asm_exc_page_fault+0x22/0x30
        entry_SYSCALL_64_after_hwframe+0x71/0x79
       RIP: 0033:0x7fbc0ca3fc1b
       Code: 73 01 c3 48 8b 0d 05 f2 1b 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 b8 29 00 00 00 0f 05 <48> 3d 01 f0 ff ff 73 01 c3 48 8b 0d d5 f1 1b 00 f7 d8 64 89 01 48
       RSP: 002b:00007fff18635208 EFLAGS: 00000246 ORIG_RAX: 0000000000000029
       RAX: ffffffffffffffda RBX: 0000000000000001 RCX: 00007fbc0ca3fc1b
       RDX: 0000000000000006 RSI: 0000000000000001 RDI: 0000000000000002
       RBP: 000055d24f80f8a0 R08: 0000000000000003 R09: 0000000000000001
      
      R10: 0000000000020000 R11: 0000000000000246 R12: 000055d24f80f8a0
       R13: 0000000000000000 R14: 000055d24f80fb88 R15: 0000000000000000
        </TASK>
      
      The current implementation of cipso_v4_sock_setattr() replaces IP options
      under the assumption that the caller holds the socket lock; however, such
      assumption is not true, nor needed, in selinux_socket_post_create() hook.
      
      Let all callers of cipso_v4_sock_setattr() specify the "socket lock held"
      condition, except selinux_socket_post_create() _ where such condition can
      safely be set as true even without holding the socket lock.
      
      Fixes: f6d8bd05 ("inet: add RCU protection to inet->opt")
      Reported-by: default avatarXiumei Mu <xmu@redhat.com>
      Signed-off-by: default avatarDavide Caratti <dcaratti@redhat.com>
      Acked-by: default avatarCasey Schaufler <casey@schaufler-ca.com>
      Acked-by: default avatarPaul Moore <paul@paul-moore.com>
      Link: https://lore.kernel.org/r/f4260d000a3a55b9e8b6a3b4e3fffc7da9f82d41.1715359817.git.dcaratti@redhat.com
      
      
      Signed-off-by: default avatarJakub Kicinski <kuba@kernel.org>
      8ec9897e
  7. Apr 09, 2024
  8. Mar 14, 2024
  9. Feb 16, 2024
  10. Feb 14, 2024
  11. Jan 24, 2024
    • Roberto Sassu's avatar
      smack: Initialize the in-memory inode in smack_inode_init_security() · e63d86b8
      Roberto Sassu authored
      
      Currently, Smack initializes in-memory new inodes in three steps. It first
      sets the xattrs in smack_inode_init_security(), fetches them in
      smack_d_instantiate() and finally, in the same function, sets the in-memory
      inodes depending on xattr values, unless they are in specially-handled
      filesystems.
      
      Other than being inefficient, this also prevents filesystems not supporting
      xattrs from working properly since, without xattrs, there is no way to pass
      the label determined in smack_inode_init_security() to
      smack_d_instantiate().
      
      Since the LSM infrastructure allows setting and getting the security field
      without xattrs through the inode_setsecurity and inode_getsecurity hooks,
      make the inode creation work too, by initializing the in-memory inode
      earlier in smack_inode_init_security().
      
      Also mark the inode as instantiated, to prevent smack_d_instantiate() from
      overwriting the security field. As mentioned above, this potentially has
      impact for inodes in specially-handled filesystems in
      smack_d_instantiate(), if they are not handled in the same way in
      smack_inode_init_security().
      
      Filesystems other than tmpfs don't call security_inode_init_security(), so
      they would be always initialized in smack_d_instantiate(), as before. For
      tmpfs, the current behavior is to assign to inodes the label '*', but
      actually that label is overwritten with the one fetched from the SMACK64
      xattr, set in smack_inode_init_security() (default: '_').
      
      Initializing the in-memory inode is straightforward: if not transmuting,
      nothing more needs to be done; if transmuting, overwrite the current inode
      label with the one from the parent directory, and set SMK_INODE_TRANSMUTE.
      Finally, set SMK_INODE_INSTANT for all cases, to mark the inode as
      instantiated.
      
      Signed-off-by: default avatarRoberto Sassu <roberto.sassu@huawei.com>
      Signed-off-by: default avatarCasey Schaufler <casey@schaufler-ca.com>
      e63d86b8
    • Roberto Sassu's avatar
      smack: Always determine inode labels in smack_inode_init_security() · 51b15e79
      Roberto Sassu authored
      
      The inode_init_security hook is already a good place to initialize the
      in-memory inode. And that is also what SELinux does.
      
      In preparation for this, move the existing smack_inode_init_security() code
      outside the 'if (xattr)' condition, and set the xattr, if provided.
      
      This change does not have any impact on the current code, since every time
      security_inode_init_security() is called, the initxattr() callback is
      passed and, thus, xattr is non-NULL.
      
      Signed-off-by: default avatarRoberto Sassu <roberto.sassu@huawei.com>
      Signed-off-by: default avatarCasey Schaufler <casey@schaufler-ca.com>
      51b15e79
    • Roberto Sassu's avatar
      smack: Handle SMACK64TRANSMUTE in smack_inode_setsecurity() · ac02f007
      Roberto Sassu authored
      
      If the SMACK64TRANSMUTE xattr is provided, and the inode is a directory,
      update the in-memory inode flags by setting SMK_INODE_TRANSMUTE.
      
      Cc: stable@vger.kernel.org
      Fixes: 5c6d1125 ("Smack: Transmute labels on specified directories") # v2.6.38.x
      Signed-off-by: default avatarRoberto Sassu <roberto.sassu@huawei.com>
      Signed-off-by: default avatarCasey Schaufler <casey@schaufler-ca.com>
      ac02f007
    • Roberto Sassu's avatar
      smack: Set SMACK64TRANSMUTE only for dirs in smack_inode_setxattr() · 9c821692
      Roberto Sassu authored
      
      Since the SMACK64TRANSMUTE xattr makes sense only for directories, enforce
      this restriction in smack_inode_setxattr().
      
      Cc: stable@vger.kernel.org
      Fixes: 5c6d1125 ("Smack: Transmute labels on specified directories") # v2.6.38.x
      Signed-off-by: default avatarRoberto Sassu <roberto.sassu@huawei.com>
      Signed-off-by: default avatarCasey Schaufler <casey@schaufler-ca.com>
      9c821692
  12. Dec 24, 2023
    • Alfred Piccioni's avatar
      lsm: new security_file_ioctl_compat() hook · f1bb47a3
      Alfred Piccioni authored
      
      Some ioctl commands do not require ioctl permission, but are routed to
      other permissions such as FILE_GETATTR or FILE_SETATTR. This routing is
      done by comparing the ioctl cmd to a set of 64-bit flags (FS_IOC_*).
      
      However, if a 32-bit process is running on a 64-bit kernel, it emits
      32-bit flags (FS_IOC32_*) for certain ioctl operations. These flags are
      being checked erroneously, which leads to these ioctl operations being
      routed to the ioctl permission, rather than the correct file
      permissions.
      
      This was also noted in a RED-PEN finding from a while back -
      "/* RED-PEN how should LSM module know it's handling 32bit? */".
      
      This patch introduces a new hook, security_file_ioctl_compat(), that is
      called from the compat ioctl syscall. All current LSMs have been changed
      to support this hook.
      
      Reviewing the three places where we are currently using
      security_file_ioctl(), it appears that only SELinux needs a dedicated
      compat change; TOMOYO and SMACK appear to be functional without any
      change.
      
      Cc: stable@vger.kernel.org
      Fixes: 0b24dcb7 ("Revert "selinux: simplify ioctl checking"")
      Signed-off-by: default avatarAlfred Piccioni <alpic@google.com>
      Reviewed-by: default avatarStephen Smalley <stephen.smalley.work@gmail.com>
      [PM: subject tweak, line length fixes, and alignment corrections]
      Signed-off-by: default avatarPaul Moore <paul@paul-moore.com>
      f1bb47a3
  13. Dec 21, 2023
  14. Dec 12, 2023
  15. Nov 13, 2023
  16. Aug 15, 2023
  17. Aug 07, 2023
  18. Jul 10, 2023
    • Roberto Sassu's avatar
      smack: Set the SMACK64TRANSMUTE xattr in smack_inode_init_security() · baed456a
      Roberto Sassu authored
      
      With the newly added ability of LSMs to supply multiple xattrs, set
      SMACK64TRASMUTE in smack_inode_init_security(), instead of d_instantiate().
      Do it by incrementing SMACK_INODE_INIT_XATTRS to 2 and by calling
      lsm_get_xattr_slot() a second time, if the transmuting conditions are met.
      
      The LSM infrastructure passes all xattrs provided by LSMs to the
      filesystems through the initxattrs() callback, so that filesystems can
      store xattrs in the disk.
      
      After the change, the SMK_INODE_TRANSMUTE inode flag is always set by
      d_instantiate() after fetching SMACK64TRANSMUTE from the disk. Before it
      was done by smack_inode_post_setxattr() as result of the __vfs_setxattr()
      call.
      
      Removing __vfs_setxattr() also prevents invalidating the EVM HMAC, by
      adding a new xattr without checking and updating the existing HMAC.
      
      Signed-off-by: default avatarRoberto Sassu <roberto.sassu@huawei.com>
      Reviewed-by: default avatarCasey Schaufler <casey@schaufler-ca.com>
      Signed-off-by: default avatarPaul Moore <paul@paul-moore.com>
      baed456a
    • Roberto Sassu's avatar
      security: Allow all LSMs to provide xattrs for inode_init_security hook · 6bcdfd2c
      Roberto Sassu authored
      
      Currently, the LSM infrastructure supports only one LSM providing an xattr
      and EVM calculating the HMAC on that xattr, plus other inode metadata.
      
      Allow all LSMs to provide one or multiple xattrs, by extending the security
      blob reservation mechanism. Introduce the new lbs_xattr_count field of the
      lsm_blob_sizes structure, so that each LSM can specify how many xattrs it
      needs, and the LSM infrastructure knows how many xattr slots it should
      allocate.
      
      Modify the inode_init_security hook definition, by passing the full
      xattr array allocated in security_inode_init_security(), and the current
      number of xattr slots in that array filled by LSMs. The first parameter
      would allow EVM to access and calculate the HMAC on xattrs supplied by
      other LSMs, the second to not leave gaps in the xattr array, when an LSM
      requested but did not provide xattrs (e.g. if it is not initialized).
      
      Introduce lsm_get_xattr_slot(), which LSMs can call as many times as the
      number specified in the lbs_xattr_count field of the lsm_blob_sizes
      structure. During each call, lsm_get_xattr_slot() increments the number of
      filled xattrs, so that at the next invocation it returns the next xattr
      slot to fill.
      
      Cleanup security_inode_init_security(). Unify the !initxattrs and
      initxattrs case by simply not allocating the new_xattrs array in the
      former. Update the documentation to reflect the changes, and fix the
      description of the xattr name, as it is not allocated anymore.
      
      Adapt both SELinux and Smack to use the new definition of the
      inode_init_security hook, and to call lsm_get_xattr_slot() to obtain and
      fill the reserved slots in the xattr array.
      
      Move the xattr->name assignment after the xattr->value one, so that it is
      done only in case of successful memory allocation.
      
      Finally, change the default return value of the inode_init_security hook
      from zero to -EOPNOTSUPP, so that BPF LSM correctly follows the hook
      conventions.
      
      Reported-by: default avatarNicolas Bouchinet <nicolas.bouchinet@clip-os.org>
      Link: https://lore.kernel.org/linux-integrity/Y1FTSIo+1x+4X0LS@archlinux/
      
      
      Signed-off-by: default avatarRoberto Sassu <roberto.sassu@huawei.com>
      Acked-by: default avatarCasey Schaufler <casey@schaufler-ca.com>
      [PM: minor comment and variable tweaks, approved by RS]
      Signed-off-by: default avatarPaul Moore <paul@paul-moore.com>
      6bcdfd2c
  19. May 11, 2023
    • Roberto Sassu's avatar
      smack: Record transmuting in smk_transmuted · 2c085f3a
      Roberto Sassu authored
      
      smack_dentry_create_files_as() determines whether transmuting should occur
      based on the label of the parent directory the new inode will be added to,
      and not the label of the directory where it is created.
      
      This helps for example to do transmuting on overlayfs, since the latter
      first creates the inode in the working directory, and then moves it to the
      correct destination.
      
      However, despite smack_dentry_create_files_as() provides the correct label,
      smack_inode_init_security() does not know from passed information whether
      or not transmuting occurred. Without this information,
      smack_inode_init_security() cannot set SMK_INODE_CHANGED in smk_flags,
      which will result in the SMACK64TRANSMUTE xattr not being set in
      smack_d_instantiate().
      
      Thus, add the smk_transmuted field to the task_smack structure, and set it
      in smack_dentry_create_files_as() to smk_task if transmuting occurred. If
      smk_task is equal to smk_transmuted in smack_inode_init_security(), act as
      if transmuting was successful but without taking the label from the parent
      directory (the inode label was already set correctly from the current
      credentials in smack_inode_alloc_security()).
      
      Signed-off-by: default avatarRoberto Sassu <roberto.sassu@huawei.com>
      Signed-off-by: default avatarCasey Schaufler <casey@schaufler-ca.com>
      2c085f3a
    • Roberto Sassu's avatar
      smack: Retrieve transmuting information in smack_inode_getsecurity() · 3a3d8fce
      Roberto Sassu authored
      
      Enhance smack_inode_getsecurity() to retrieve the value for
      SMACK64TRANSMUTE from the inode security blob, similarly to SMACK64.
      
      This helps to display accurate values in the situation where the security
      labels come from mount options and not from xattrs.
      
      Signed-off-by: default avatarRoberto Sassu <roberto.sassu@huawei.com>
      Signed-off-by: default avatarCasey Schaufler <casey@schaufler-ca.com>
      3a3d8fce
  20. Apr 05, 2023
  21. Mar 20, 2023
    • Paul Moore's avatar
      selinux: remove the runtime disable functionality · f22f9aaf
      Paul Moore authored
      
      After working with the larger SELinux-based distros for several
      years, we're finally at a place where we can disable the SELinux
      runtime disable functionality.  The existing kernel deprecation
      notice explains the functionality and why we want to remove it:
      
        The selinuxfs "disable" node allows SELinux to be disabled at
        runtime prior to a policy being loaded into the kernel.  If
        disabled via this mechanism, SELinux will remain disabled until
        the system is rebooted.
      
        The preferred method of disabling SELinux is via the "selinux=0"
        boot parameter, but the selinuxfs "disable" node was created to
        make it easier for systems with primitive bootloaders that did not
        allow for easy modification of the kernel command line.
        Unfortunately, allowing for SELinux to be disabled at runtime makes
        it difficult to secure the kernel's LSM hooks using the
        "__ro_after_init" feature.
      
      It is that last sentence, mentioning the '__ro_after_init' hardening,
      which is the real motivation for this change, and if you look at the
      diffstat you'll see that the impact of this patch reaches across all
      the different LSMs, helping prevent tampering at the LSM hook level.
      
      From a SELinux perspective, it is important to note that if you
      continue to disable SELinux via "/etc/selinux/config" it may appear
      that SELinux is disabled, but it is simply in an uninitialized state.
      If you load a policy with `load_policy -i`, you will see SELinux
      come alive just as if you had loaded the policy during early-boot.
      
      It is also worth noting that the "/sys/fs/selinux/disable" file is
      always writable now, regardless of the Kconfig settings, but writing
      to the file has no effect on the system, other than to display an
      error on the console if a non-zero/true value is written.
      
      Finally, in the several years where we have been working on
      deprecating this functionality, there has only been one instance of
      someone mentioning any user visible breakage.  In this particular
      case it was an individual's kernel test system, and the workaround
      documented in the deprecation notice ("selinux=0" on the kernel
      command line) resolved the issue without problem.
      
      Acked-by: default avatarCasey Schaufler <casey@schaufler-ca.com>
      Signed-off-by: default avatarPaul Moore <paul@paul-moore.com>
      f22f9aaf
  22. Mar 08, 2023
  23. Feb 21, 2023
  24. Jan 19, 2023
    • 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
  25. 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
  26. Oct 20, 2022
    • Christian Brauner's avatar
      smack: implement get, set and remove acl hook · 44faac01
      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. Smack 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 all becomes very simple hooks for smack.
      
      Link: https://lore.kernel.org/all/20220801145520.1532837-1-brauner@kernel.org
      
       [1]
      Reviewed-by: default avatarCasey Schaufler <casey@schaufler-ca.com>
      Reviewed-by: default avatarPaul Moore <paul@paul-moore.com>
      Signed-off-by: default avatarChristian Brauner (Microsoft) <brauner@kernel.org>
      44faac01
  27. Sep 27, 2022
Loading