]> git.dujemihanovic.xyz Git - linux.git/commitdiff
Merge tag 'lsm-pr-20240911' of git://git.kernel.org/pub/scm/linux/kernel/git/pcmoore/lsm
authorLinus Torvalds <torvalds@linux-foundation.org>
Mon, 16 Sep 2024 16:19:47 +0000 (18:19 +0200)
committerLinus Torvalds <torvalds@linux-foundation.org>
Mon, 16 Sep 2024 16:19:47 +0000 (18:19 +0200)
Pull lsm updates from Paul Moore:

 - Move the LSM framework to static calls

   This transitions the vast majority of the LSM callbacks into static
   calls. Those callbacks which haven't been converted were left as-is
   due to the general ugliness of the changes required to support the
   static call conversion; we can revisit those callbacks at a future
   date.

 - Add the Integrity Policy Enforcement (IPE) LSM

   This adds a new LSM, Integrity Policy Enforcement (IPE). There is
   plenty of documentation about IPE in this patches, so I'll refrain
   from going into too much detail here, but the basic motivation behind
   IPE is to provide a mechanism such that administrators can restrict
   execution to only those binaries which come from integrity protected
   storage, e.g. a dm-verity protected filesystem. You will notice that
   IPE requires additional LSM hooks in the initramfs, dm-verity, and
   fs-verity code, with the associated patches carrying ACK/review tags
   from the associated maintainers. We couldn't find an obvious
   maintainer for the initramfs code, but the IPE patchset has been
   widely posted over several years.

   Both Deven Bowers and Fan Wu have contributed to IPE's development
   over the past several years, with Fan Wu agreeing to serve as the IPE
   maintainer moving forward. Once IPE is accepted into your tree, I'll
   start working with Fan to ensure he has the necessary accounts, keys,
   etc. so that he can start submitting IPE pull requests to you
   directly during the next merge window.

 - Move the lifecycle management of the LSM blobs to the LSM framework

   Management of the LSM blobs (the LSM state buffers attached to
   various kernel structs, typically via a void pointer named "security"
   or similar) has been mixed, some blobs were allocated/managed by
   individual LSMs, others were managed by the LSM framework itself.

   Starting with this pull we move management of all the LSM blobs,
   minus the XFRM blob, into the framework itself, improving consistency
   across LSMs, and reducing the amount of duplicated code across LSMs.
   Due to some additional work required to migrate the XFRM blob, it has
   been left as a todo item for a later date; from a practical
   standpoint this omission should have little impact as only SELinux
   provides a XFRM LSM implementation.

 - Fix problems with the LSM's handling of F_SETOWN

   The LSM hook for the fcntl(F_SETOWN) operation had a couple of
   problems: it was racy with itself, and it was disconnected from the
   associated DAC related logic in such a way that the LSM state could
   be updated in cases where the DAC state would not. We fix both of
   these problems by moving the security_file_set_fowner() hook into the
   same section of code where the DAC attributes are updated. Not only
   does this resolve the DAC/LSM synchronization issue, but as that code
   block is protected by a lock, it also resolve the race condition.

 - Fix potential problems with the security_inode_free() LSM hook

   Due to use of RCU to protect inodes and the placement of the LSM hook
   associated with freeing the inode, there is a bit of a challenge when
   it comes to managing any LSM state associated with an inode. The VFS
   folks are not open to relocating the LSM hook so we have to get
   creative when it comes to releasing an inode's LSM state.
   Traditionally we have used a single LSM callback within the hook that
   is triggered when the inode is "marked for death", but not actually
   released due to RCU.

   Unfortunately, this causes problems for LSMs which want to take an
   action when the inode's associated LSM state is actually released; so
   we add an additional LSM callback, inode_free_security_rcu(), that is
   called when the inode's LSM state is released in the RCU free
   callback.

 - Refactor two LSM hooks to better fit the LSM return value patterns

   The vast majority of the LSM hooks follow the "return 0 on success,
   negative values on failure" pattern, however, there are a small
   handful that have unique return value behaviors which has caused
   confusion in the past and makes it difficult for the BPF verifier to
   properly vet BPF LSM programs. This includes patches to
   convert two of these"special" LSM hooks to the common 0/-ERRNO pattern.

 - Various cleanups and improvements

   A handful of patches to remove redundant code, better leverage the
   IS_ERR_OR_NULL() helper, add missing "static" markings, and do some
   minor style fixups.

* tag 'lsm-pr-20240911' of git://git.kernel.org/pub/scm/linux/kernel/git/pcmoore/lsm: (40 commits)
  security: Update file_set_fowner documentation
  fs: Fix file_set_fowner LSM hook inconsistencies
  lsm: Use IS_ERR_OR_NULL() helper function
  lsm: remove LSM_COUNT and LSM_CONFIG_COUNT
  ipe: Remove duplicated include in ipe.c
  lsm: replace indirect LSM hook calls with static calls
  lsm: count the LSMs enabled at compile time
  kernel: Add helper macros for loop unrolling
  init/main.c: Initialize early LSMs after arch code, static keys and calls.
  MAINTAINERS: add IPE entry with Fan Wu as maintainer
  documentation: add IPE documentation
  ipe: kunit test for parser
  scripts: add boot policy generation program
  ipe: enable support for fs-verity as a trust provider
  fsverity: expose verified fsverity built-in signatures to LSMs
  lsm: add security_inode_setintegrity() hook
  ipe: add support for dm-verity as a trust provider
  dm-verity: expose root hash digest and signature data to LSMs
  block,lsm: add LSM blob and new LSM hooks for block devices
  ipe: add permissive toggle
  ...

1  2 
Documentation/admin-guide/kernel-parameters.txt
MAINTAINERS
fs/fcntl.c
security/Kconfig
security/selinux/hooks.c
security/selinux/netlabel.c
security/smack/smack_lsm.c

diff --cc MAINTAINERS
Simple merge
diff --cc fs/fcntl.c
index f6fde75a3bd51e8d9f4b1cfd04f968ffbe1a43f5,c28dc6c005f1743467342299e403b5078d81b664..081e5e3d89ea3c64eda138f9841d0a149c0b7411
@@@ -89,72 -87,24 +89,66 @@@ static int setfl(int fd, struct file * 
        return error;
  }
  
- static void f_modown(struct file *filp, struct pid *pid, enum pid_type type,
-                      int force)
 +/*
 + * Allocate an file->f_owner struct if it doesn't exist, handling racing
 + * allocations correctly.
 + */
 +int file_f_owner_allocate(struct file *file)
 +{
 +      struct fown_struct *f_owner;
 +
 +      f_owner = file_f_owner(file);
 +      if (f_owner)
 +              return 0;
 +
 +      f_owner = kzalloc(sizeof(struct fown_struct), GFP_KERNEL);
 +      if (!f_owner)
 +              return -ENOMEM;
 +
 +      rwlock_init(&f_owner->lock);
 +      f_owner->file = file;
 +      /* If someone else raced us, drop our allocation. */
 +      if (unlikely(cmpxchg(&file->f_owner, NULL, f_owner)))
 +              kfree(f_owner);
 +      return 0;
 +}
 +EXPORT_SYMBOL(file_f_owner_allocate);
 +
 +void file_f_owner_release(struct file *file)
 +{
 +      struct fown_struct *f_owner;
 +
 +      f_owner = file_f_owner(file);
 +      if (f_owner) {
 +              put_pid(f_owner->pid);
 +              kfree(f_owner);
 +      }
 +}
 +
+ void __f_setown(struct file *filp, struct pid *pid, enum pid_type type,
+               int force)
  {
 -      write_lock_irq(&filp->f_owner.lock);
 -      if (force || !filp->f_owner.pid) {
 -              put_pid(filp->f_owner.pid);
 -              filp->f_owner.pid = get_pid(pid);
 -              filp->f_owner.pid_type = type;
 +      struct fown_struct *f_owner;
 +
 +      f_owner = file_f_owner(filp);
 +      if (WARN_ON_ONCE(!f_owner))
 +              return;
 +
 +      write_lock_irq(&f_owner->lock);
 +      if (force || !f_owner->pid) {
 +              put_pid(f_owner->pid);
 +              f_owner->pid = get_pid(pid);
 +              f_owner->pid_type = type;
  
                if (pid) {
                        const struct cred *cred = current_cred();
 -                      filp->f_owner.uid = cred->uid;
 -                      filp->f_owner.euid = cred->euid;
+                       security_file_set_fowner(filp);
 +                      f_owner->uid = cred->uid;
 +                      f_owner->euid = cred->euid;
                }
        }
 -      write_unlock_irq(&filp->f_owner.lock);
 +      write_unlock_irq(&f_owner->lock);
  }
- void __f_setown(struct file *filp, struct pid *pid, enum pid_type type,
-               int force)
- {
-       security_file_set_fowner(filp);
-       f_modown(filp, pid, type, force);
- }
  EXPORT_SYMBOL(__f_setown);
  
  int f_setown(struct file *filp, int who, int force)
Simple merge
Simple merge
index 5ad2fd68abbf14b2f83a7fd1e0db6f658b09381b,fbe5f8c29f8137f528b68f23cc7222a9cf00be29..d51dfe89231229e78903f3aa552286326524dca2
@@@ -357,9 -357,9 +358,9 @@@ inet_conn_request_return
   */
  void selinux_netlbl_inet_csk_clone(struct sock *sk, u16 family)
  {
-       struct sk_security_struct *sksec = sk->sk_security;
+       struct sk_security_struct *sksec = selinux_sock(sk);
  
 -      if (family == PF_INET)
 +      if (family == PF_INET || family == PF_INET6)
                sksec->nlbl_state = NLBL_LABELED;
        else
                sksec->nlbl_state = NLBL_UNSET;
Simple merge