]> Git Repo - linux.git/commitdiff
Merge tag 'selinux-pr-20220801' of git://git.kernel.org/pub/scm/linux/kernel/git...
authorLinus Torvalds <[email protected]>
Tue, 2 Aug 2022 21:51:47 +0000 (14:51 -0700)
committerLinus Torvalds <[email protected]>
Tue, 2 Aug 2022 21:51:47 +0000 (14:51 -0700)
Pull selinux updates from Paul Moore:
 "A relatively small set of patches for SELinux this time, eight patches
  in total with really only one significant change.

  The highlights are:

   - Add support for proper labeling of memfd_secret anonymous inodes.

     This will allow LSMs that implement the anonymous inode hooks to
     apply security policy to memfd_secret() fds.

   - Various small improvements to memory management: fixed leaks, freed
     memory when needed, boundary checks.

   - Hardened the selinux_audit_data struct with __randomize_layout.

   - A minor documentation tweak to fix a formatting/style issue"

* tag 'selinux-pr-20220801' of git://git.kernel.org/pub/scm/linux/kernel/git/pcmoore/selinux:
  selinux: selinux_add_opt() callers free memory
  selinux: Add boundary check in put_entry()
  selinux: fix memleak in security_read_state_kernel()
  docs: selinux: add '=' signs to kernel boot options
  mm: create security context for memfd_secret inodes
  selinux: fix typos in comments
  selinux: drop unnecessary NULL check
  selinux: add __randomize_layout to selinux_audit_data

1  2 
Documentation/admin-guide/kernel-parameters.txt
mm/secretmem.c
security/selinux/hooks.c

index 5e9147fe89688327fcb8ebfd46883abc72edd414,815af6d7a199a5c75fb9669feae270f69942091d..a79b1b367e665959f9a89d2a7bbc150c7d5d8b3c
        arm64.nomte     [ARM64] Unconditionally disable Memory Tagging Extension
                        support
  
 +      arm64.nosve     [ARM64] Unconditionally disable Scalable Vector
 +                      Extension support
 +
 +      arm64.nosme     [ARM64] Unconditionally disable Scalable Matrix
 +                      Extension support
 +
        ataflop=        [HW,M68k]
  
        atarimouse=     [HW,MOUSE] Atari Mouse
                        nosocket -- Disable socket memory accounting.
                        nokmem -- Disable kernel memory accounting.
  
-       checkreqprot    [SELINUX] Set initial checkreqprot flag value.
+       checkreqprot=   [SELINUX] Set initial checkreqprot flag value.
                        Format: { "0" | "1" }
                        See security/selinux/Kconfig help text.
                        0 -- check protection applied by kernel (includes
                        (in particular on some ATI chipsets).
                        The kernel tries to set a reasonable default.
  
-       enforcing       [SELINUX] Set initial enforcing status.
+       enforcing=      [SELINUX] Set initial enforcing status.
                        Format: {"0" | "1"}
                        See security/selinux/Kconfig help text.
                        0 -- permissive (log only, no denials).
  
                        protected: nVHE-based mode with support for guests whose
                                   state is kept private from the host.
 -                                 Not valid if the kernel is running in EL2.
  
                        Defaults to VHE/nVHE based on hardware support. Setting
                        mode to "protected" will disable kexec and hibernation
                                improves system performance, but it may also
                                expose users to several CPU vulnerabilities.
                                Equivalent to: nopti [X86,PPC]
 -                                             kpti=0 [ARM64]
 +                                             if nokaslr then kpti=0 [ARM64]
                                               nospectre_v1 [X86,PPC]
                                               nobp=0 [S390]
                                               nospectre_v2 [X86,PPC,S390,ARM64]
                                               srbds=off [X86,INTEL]
                                               no_entry_flush [PPC]
                                               no_uaccess_flush [PPC]
 +                                             mmio_stale_data=off [X86]
 +                                             retbleed=off [X86]
  
                                Exceptions:
                                               This does not have any effect on
                                Equivalent to: l1tf=flush,nosmt [X86]
                                               mds=full,nosmt [X86]
                                               tsx_async_abort=full,nosmt [X86]
 +                                             mmio_stale_data=full,nosmt [X86]
 +                                             retbleed=auto,nosmt [X86]
  
        mminit_loglevel=
                        [KNL] When CONFIG_DEBUG_MEMORY_INIT is set, this
                        log everything. Information is printed at KERN_DEBUG
                        so loglevel=8 may also need to be specified.
  
 +      mmio_stale_data=
 +                      [X86,INTEL] Control mitigation for the Processor
 +                      MMIO Stale Data vulnerabilities.
 +
 +                      Processor MMIO Stale Data is a class of
 +                      vulnerabilities that may expose data after an MMIO
 +                      operation. Exposed data could originate or end in
 +                      the same CPU buffers as affected by MDS and TAA.
 +                      Therefore, similar to MDS and TAA, the mitigation
 +                      is to clear the affected CPU buffers.
 +
 +                      This parameter controls the mitigation. The
 +                      options are:
 +
 +                      full       - Enable mitigation on vulnerable CPUs
 +
 +                      full,nosmt - Enable mitigation and disable SMT on
 +                                   vulnerable CPUs.
 +
 +                      off        - Unconditionally disable mitigation
 +
 +                      On MDS or TAA affected machines,
 +                      mmio_stale_data=off can be prevented by an active
 +                      MDS or TAA mitigation as these vulnerabilities are
 +                      mitigated with the same mechanism so in order to
 +                      disable this mitigation, you need to specify
 +                      mds=off and tsx_async_abort=off too.
 +
 +                      Not specifying this option is equivalent to
 +                      mmio_stale_data=full.
 +
 +                      For details see:
 +                      Documentation/admin-guide/hw-vuln/processor_mmio_stale_data.rst
 +
        module.sig_enforce
                        [KNL] When CONFIG_MODULE_SIG is set, this means that
                        modules without (valid) signatures will fail to load.
  
        retain_initrd   [RAM] Keep initrd memory after extraction
  
 +      retbleed=       [X86] Control mitigation of RETBleed (Arbitrary
 +                      Speculative Code Execution with Return Instructions)
 +                      vulnerability.
 +
 +                      off          - no mitigation
 +                      auto         - automatically select a migitation
 +                      auto,nosmt   - automatically select a mitigation,
 +                                     disabling SMT if necessary for
 +                                     the full mitigation (only on Zen1
 +                                     and older without STIBP).
 +                      ibpb         - mitigate short speculation windows on
 +                                     basic block boundaries too. Safe, highest
 +                                     perf impact.
 +                      unret        - force enable untrained return thunks,
 +                                     only effective on AMD f15h-f17h
 +                                     based systems.
 +                      unret,nosmt  - like unret, will disable SMT when STIBP
 +                                     is not available.
 +
 +                      Selecting 'auto' will choose a mitigation method at run
 +                      time according to the CPU.
 +
 +                      Not specifying this option is equivalent to retbleed=auto.
 +
        rfkill.default_state=
                0       "airplane mode".  All wifi, bluetooth, wimax, gps, fm,
                        etc. communication is blocked by default.
                        eibrs             - enhanced IBRS
                        eibrs,retpoline   - enhanced IBRS + Retpolines
                        eibrs,lfence      - enhanced IBRS + LFENCE
 +                      ibrs              - use IBRS to protect kernel
  
                        Not specifying this option is equivalent to
                        spectre_v2=auto.
                        expediting.  Set to zero to disable automatic
                        expediting.
  
 +      srcutree.srcu_max_nodelay [KNL]
 +                      Specifies the number of no-delay instances
 +                      per jiffy for which the SRCU grace period
 +                      worker thread will be rescheduled with zero
 +                      delay. Beyond this limit, worker thread will
 +                      be rescheduled with a sleep delay of one jiffy.
 +
 +      srcutree.srcu_max_nodelay_phase [KNL]
 +                      Specifies the per-grace-period phase, number of
 +                      non-sleeping polls of readers. Beyond this limit,
 +                      grace period worker thread will be rescheduled
 +                      with a sleep delay of one jiffy, between each
 +                      rescan of the readers, for a grace period phase.
 +
 +      srcutree.srcu_retry_check_delay [KNL]
 +                      Specifies number of microseconds of non-sleeping
 +                      delay between each non-sleeping poll of readers.
 +
        srcutree.small_contention_lim [KNL]
                        Specifies the number of update-side contention
                        events per jiffy will be tolerated before
diff --combined mm/secretmem.c
index f06279d6190a5f0eca83cb2ef5710b67077288da,f544ec66ebaf0520872cf3b16eafa7ba155c0ecd..71fb78f59d72c5496ebc197f337e44aee70416af
@@@ -55,28 -55,22 +55,28 @@@ static vm_fault_t secretmem_fault(struc
        gfp_t gfp = vmf->gfp_mask;
        unsigned long addr;
        struct page *page;
 +      vm_fault_t ret;
        int err;
  
        if (((loff_t)vmf->pgoff << PAGE_SHIFT) >= i_size_read(inode))
                return vmf_error(-EINVAL);
  
 +      filemap_invalidate_lock_shared(mapping);
 +
  retry:
        page = find_lock_page(mapping, offset);
        if (!page) {
                page = alloc_page(gfp | __GFP_ZERO);
 -              if (!page)
 -                      return VM_FAULT_OOM;
 +              if (!page) {
 +                      ret = VM_FAULT_OOM;
 +                      goto out;
 +              }
  
                err = set_direct_map_invalid_noflush(page);
                if (err) {
                        put_page(page);
 -                      return vmf_error(err);
 +                      ret = vmf_error(err);
 +                      goto out;
                }
  
                __SetPageUptodate(page);
@@@ -92,8 -86,7 +92,8 @@@
                        if (err == -EEXIST)
                                goto retry;
  
 -                      return vmf_error(err);
 +                      ret = vmf_error(err);
 +                      goto out;
                }
  
                addr = (unsigned long)page_address(page);
        }
  
        vmf->page = page;
 -      return VM_FAULT_LOCKED;
 +      ret = VM_FAULT_LOCKED;
 +
 +out:
 +      filemap_invalidate_unlock_shared(mapping);
 +      return ret;
  }
  
  static const struct vm_operations_struct secretmem_vm_ops = {
@@@ -173,20 -162,12 +173,20 @@@ static int secretmem_setattr(struct use
                             struct dentry *dentry, struct iattr *iattr)
  {
        struct inode *inode = d_inode(dentry);
 +      struct address_space *mapping = inode->i_mapping;
        unsigned int ia_valid = iattr->ia_valid;
 +      int ret;
 +
 +      filemap_invalidate_lock(mapping);
  
        if ((ia_valid & ATTR_SIZE) && inode->i_size)
 -              return -EINVAL;
 +              ret = -EINVAL;
 +      else
 +              ret = simple_setattr(mnt_userns, dentry, iattr);
 +
 +      filemap_invalidate_unlock(mapping);
  
 -      return simple_setattr(mnt_userns, dentry, iattr);
 +      return ret;
  }
  
  static const struct inode_operations secretmem_iops = {
@@@ -199,11 -180,20 +199,20 @@@ static struct file *secretmem_file_crea
  {
        struct file *file = ERR_PTR(-ENOMEM);
        struct inode *inode;
+       const char *anon_name = "[secretmem]";
+       const struct qstr qname = QSTR_INIT(anon_name, strlen(anon_name));
+       int err;
  
        inode = alloc_anon_inode(secretmem_mnt->mnt_sb);
        if (IS_ERR(inode))
                return ERR_CAST(inode);
  
+       err = security_inode_init_security_anon(inode, &qname, NULL);
+       if (err) {
+               file = ERR_PTR(err);
+               goto err_free_inode;
+       }
        file = alloc_file_pseudo(inode, secretmem_mnt, "secretmem",
                                 O_RDWR, &secretmem_fops);
        if (IS_ERR(file))
diff --combined security/selinux/hooks.c
index 1bbd53321d1338e928195067217f192a19ac1a68,9d08b91e05a27ef126082edcf2daa4ca2b120b4f..79573504783bb7f34f698ee9ef1b76c0f063c06a
@@@ -640,7 -640,7 +640,7 @@@ static int selinux_set_mnt_opts(struct 
         * we need to skip the double mount verification.
         *
         * This does open a hole in which we will not notice if the first
-        * mount using this sb set explict options and a second mount using
+        * mount using this sb set explicit options and a second mount using
         * this sb does not set any security options.  (The first options
         * will be used for both mounts)
         */
@@@ -944,10 -944,12 +944,12 @@@ out
        return rc;
  }
  
+ /*
+  * NOTE: the caller is resposible for freeing the memory even if on error.
+  */
  static int selinux_add_opt(int token, const char *s, void **mnt_opts)
  {
        struct selinux_mnt_opts *opts = *mnt_opts;
-       bool is_alloc_opts = false;
        u32 *dst_sid;
        int rc;
  
                /* eaten and completely ignored */
                return 0;
        if (!s)
-               return -ENOMEM;
+               return -EINVAL;
  
        if (!selinux_initialized(&selinux_state)) {
                pr_warn("SELinux: Unable to set superblock options before the security server is initialized\n");
                if (!opts)
                        return -ENOMEM;
                *mnt_opts = opts;
-               is_alloc_opts = true;
        }
  
        switch (token) {
        return rc;
  
  err:
-       if (is_alloc_opts) {
-               kfree(opts);
-               *mnt_opts = NULL;
-       }
        pr_warn(SEL_MOUNT_FAIL_MSG);
        return -EINVAL;
  }
@@@ -1019,7 -1016,7 +1016,7 @@@ static int show_sid(struct seq_file *m
        rc = security_sid_to_context(&selinux_state, sid,
                                             &context, &len);
        if (!rc) {
-               bool has_comma = context && strchr(context, ',');
+               bool has_comma = strchr(context, ',');
  
                seq_putc(m, '=');
                if (has_comma)
@@@ -2600,9 -2597,8 +2597,9 @@@ static int selinux_sb_eat_lsm_opts(cha
                                }
                        }
                        rc = selinux_add_opt(token, arg, mnt_opts);
 +                      kfree(arg);
 +                      arg = NULL;
                        if (unlikely(rc)) {
 -                              kfree(arg);
                                goto free_opt;
                        }
                } else {
@@@ -2793,13 -2789,17 +2790,13 @@@ static int selinux_fs_context_parse_par
                                          struct fs_parameter *param)
  {
        struct fs_parse_result result;
 -      int opt, rc;
 +      int opt;
  
        opt = fs_parse(fc, selinux_fs_parameters, param, &result);
        if (opt < 0)
                return opt;
  
 -      rc = selinux_add_opt(opt, param->string, &fc->security);
 -      if (!rc)
 -              param->string = NULL;
 -
 -      return rc;
 +      return selinux_add_opt(opt, param->string, &fc->security);
  }
  
  /* inode security operations */
@@@ -6792,7 -6792,7 +6789,7 @@@ static u32 bpf_map_fmode_to_av(fmode_t 
  }
  
  /* This function will check the file pass through unix socket or binder to see
-  * if it is a bpf related object. And apply correspinding checks on the bpf
+  * if it is a bpf related object. And apply corresponding checks on the bpf
   * object based on the type. The bpf maps and programs, not like other files and
   * socket, are using a shared anonymous inode inside the kernel as their inode.
   * So checking that inode cannot identify if the process have privilege to
This page took 0.102291 seconds and 4 git commands to generate.