Skip to content
Snippets Groups Projects
  1. Jan 24, 2024
    • Kees Cook's avatar
      exec: Check __FMODE_EXEC instead of in_execve for LSMs · 4759ff71
      Kees Cook authored
      
      After commit 978ffcbf ("execve: open the executable file before
      doing anything else"), current->in_execve was no longer in sync with the
      open(). This broke AppArmor and TOMOYO which depend on this flag to
      distinguish "open" operations from being "exec" operations.
      
      Instead of moving around in_execve, switch to using __FMODE_EXEC, which
      is where the "is this an exec?" intent is stored. Note that TOMOYO still
      uses in_execve around cred handling.
      
      Reported-by: Kevin Locke's avatarKevin Locke <kevin@kevinlocke.name>
      Closes: https://lore.kernel.org/all/ZbE4qn9_h14OqADK@kevinlocke.name
      
      
      Suggested-by: default avatarLinus Torvalds <torvalds@linux-foundation.org>
      Fixes: 978ffcbf ("execve: open the executable file before doing anything else")
      Cc: Josh Triplett <josh@joshtriplett.org>
      Cc: John Johansen <john.johansen@canonical.com>
      Cc: Paul Moore <paul@paul-moore.com>
      Cc: James Morris <jmorris@namei.org>
      Cc: Serge E. Hallyn <serge@hallyn.com>
      Cc: Kentaro Takeda <takedakn@nttdata.co.jp>
      Cc: Tetsuo Handa <penguin-kernel@I-love.SAKURA.ne.jp>
      Cc: Alexander Viro <viro@zeniv.linux.org.uk>
      Cc: Christian Brauner <brauner@kernel.org>
      Cc: Jan Kara <jack@suse.cz>
      Cc: Eric Biederman <ebiederm@xmission.com>
      Cc: Andrew Morton <akpm@linux-foundation.org>
      Cc: Sebastian Andrzej Siewior <bigeasy@linutronix.de>
      Cc:  <linux-fsdevel@vger.kernel.org>
      Cc:  <linux-mm@kvack.org>
      Cc:  <apparmor@lists.ubuntu.com>
      Cc:  <linux-security-module@vger.kernel.org>
      Signed-off-by: default avatarKees Cook <keescook@chromium.org>
      Signed-off-by: default avatarLinus Torvalds <torvalds@linux-foundation.org>
      4759ff71
  2. 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
  3. Nov 13, 2023
    • Paul Moore's avatar
      lsm: mark the lsm_id variables are marked as static · b1a867ee
      Paul Moore authored
      
      As the kernel test robot helpfully reminded us, all of the lsm_id
      instances defined inside the various LSMs should be marked as static.
      The one exception is Landlock which uses its lsm_id variable across
      multiple source files with an extern declaration in a header file.
      
      Reported-by: default avatarkernel test robot <lkp@intel.com>
      Suggested-by: default avatarCasey Schaufler <casey@schaufler-ca.com>
      Reviewed-by: default avatarCasey Schaufler <casey@schaufler-ca.com>
      Signed-off-by: default avatarPaul Moore <paul@paul-moore.com>
      b1a867ee
    • Casey Schaufler's avatar
      LSM: Identify modules by more than name · f3b8788c
      Casey Schaufler authored
      
      Create a struct lsm_id to contain identifying information about Linux
      Security Modules (LSMs). At inception this contains the name of the
      module and an identifier associated with the security module.  Change
      the security_add_hooks() interface to use this structure.  Change the
      individual modules to maintain their own struct lsm_id and pass it to
      security_add_hooks().
      
      The values are for LSM identifiers are defined in a new UAPI
      header file linux/lsm.h. Each existing LSM has been updated to
      include it's LSMID in the lsm_id.
      
      The LSM ID values are sequential, with the oldest module
      LSM_ID_CAPABILITY being the lowest value and the existing modules
      numbered in the order they were included in the main line kernel.
      This is an arbitrary convention for assigning the values, but
      none better presents itself. The value 0 is defined as being invalid.
      The values 1-99 are reserved for any special case uses which may
      arise in the future. This may include attributes of the LSM
      infrastructure itself, possibly related to namespacing or network
      attribute management. A special range is identified for such attributes
      to help reduce confusion for developers unfamiliar with LSMs.
      
      LSM attribute values are defined for the attributes presented by
      modules that are available today. As with the LSM IDs, The value 0
      is defined as being invalid. The values 1-99 are reserved for any
      special case uses which may arise in the future.
      
      Cc: linux-security-module <linux-security-module@vger.kernel.org>
      Signed-off-by: default avatarCasey Schaufler <casey@schaufler-ca.com>
      Reviewed-by: default avatarKees Cook <keescook@chromium.org>
      Reviewed-by: default avatarSerge Hallyn <serge@hallyn.com>
      Reviewed-by: default avatarMickael Salaun <mic@digikod.net>
      Reviewed-by: default avatarJohn Johansen <john.johansen@canonical.com>
      Signed-off-by: default avatarKees Cook <keescook@chromium.org>
      Nacked-by: default avatarTetsuo Handa <penguin-kernel@I-love.SAKURA.ne.jp>
      [PM: forward ported beyond v6.6 due merge window changes]
      Signed-off-by: default avatarPaul Moore <paul@paul-moore.com>
      f3b8788c
  4. Sep 14, 2023
  5. Aug 13, 2023
  6. Aug 05, 2023
  7. Jul 23, 2023
    • Christian Göttsche's avatar
      tomoyo: add format attributes to functions · a959dbd9
      Christian Göttsche authored
      
      Format attributes on functions taking format string can help compilers
      detect argument type or count mismatches.
      
      Please the compiler when building with W=1:
      
          security/tomoyo/audit.c: In function ‘tomoyo_init_log’:
          security/tomoyo/audit.c:290:9: error: function ‘tomoyo_init_log’ might be a candidate for ‘gnu_printf’ format attribute [-Werror=suggest-attribute=format]
            290 |         vsnprintf(buf + pos, len - pos, fmt, args);
                |         ^~~~~~~~~
          security/tomoyo/audit.c: In function ‘tomoyo_write_log2’:
          security/tomoyo/audit.c:376:9: error: function ‘tomoyo_write_log2’ might be a candidate for ‘gnu_printf’ format attribute [-Werror=suggest-attribute=format]
            376 |         buf = tomoyo_init_log(r, len, fmt, args);
                |         ^~~
          security/tomoyo/common.c: In function ‘tomoyo_addprintf’:
          security/tomoyo/common.c:193:9: error: function ‘tomoyo_addprintf’ might be a candidate for ‘gnu_printf’ format attribute [-Werror=suggest-attribute=format]
            193 |         vsnprintf(buffer + pos, len - pos - 1, fmt, args);
                |         ^~~~~~~~~
      
      Signed-off-by: default avatarChristian Göttsche <cgzones@googlemail.com>
      Signed-off-by: default avatarTetsuo Handa <penguin-kernel@I-love.SAKURA.ne.jp>
      a959dbd9
  8. Jun 09, 2023
    • Lorenzo Stoakes's avatar
      mm/gup: remove vmas parameter from get_user_pages_remote() · ca5e8632
      Lorenzo Stoakes authored
      The only instances of get_user_pages_remote() invocations which used the
      vmas parameter were for a single page which can instead simply look up the
      VMA directly. In particular:-
      
      - __update_ref_ctr() looked up the VMA but did nothing with it so we simply
        remove it.
      
      - __access_remote_vm() was already using vma_lookup() when the original
        lookup failed so by doing the lookup directly this also de-duplicates the
        code.
      
      We are able to perform these VMA operations as we already hold the
      mmap_lock in order to be able to call get_user_pages_remote().
      
      As part of this work we add get_user_page_vma_remote() which abstracts the
      VMA lookup, error handling and decrementing the page reference count should
      the VMA lookup fail.
      
      This forms part of a broader set of patches intended to eliminate the vmas
      parameter altogether.
      
      [akpm@linux-foundation.org: avoid passing NULL to PTR_ERR]
      Link: https://lkml.kernel.org/r/d20128c849ecdbf4dd01cc828fcec32127ed939a.1684350871.git.lstoakes@gmail.com
      
      
      Signed-off-by: default avatarLorenzo Stoakes <lstoakes@gmail.com>
      Reviewed-by: Catalin Marinas <catalin.marinas@arm.com> (for arm64)
      Acked-by: default avatarDavid Hildenbrand <david@redhat.com>
      Reviewed-by: Janosch Frank <frankja@linux.ibm.com> (for s390)
      Reviewed-by: default avatarChristoph Hellwig <hch@lst.de>
      Cc: Christian König <christian.koenig@amd.com>
      Cc: Dennis Dalessandro <dennis.dalessandro@cornelisnetworks.com>
      Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
      Cc: Jarkko Sakkinen <jarkko@kernel.org>
      Cc: Jason Gunthorpe <jgg@nvidia.com>
      Cc: Jens Axboe <axboe@kernel.dk>
      Cc: Matthew Wilcox (Oracle) <willy@infradead.org>
      Cc: Sakari Ailus <sakari.ailus@linux.intel.com>
      Cc: Sean Christopherson <seanjc@google.com>
      Signed-off-by: default avatarAndrew Morton <akpm@linux-foundation.org>
      ca5e8632
  9. 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
  10. Mar 01, 2023
  11. Jan 13, 2023
  12. Jan 09, 2023
    • Masahiro Yamada's avatar
      tomoyo: Omit use of bin2c · 80f8be7a
      Masahiro Yamada authored
      
      bin2c was, as its name implies, introduced to convert a binary file to
      C code.
      
      However, I did not see any good reason ever for using this tool because
      using the .incbin directive is much faster, and often results in simpler
      code.
      
      Most of the uses of bin2c have been killed, for example:
      
        - 13610aa9 ("kernel/configs: use .incbin directive to embed config_data.gz")
        - 4c0f032d ("s390/purgatory: Omit use of bin2c")
      
      security/tomoyo/Makefile has even less reason for using bin2c because
      the policy files are text data. So, sed is enough for converting them
      to C string literals, and what is nicer, generates human-readable
      builtin-policy.h.
      
      This is the last user of bin2c. After this commit lands, bin2c will be
      removed.
      
      Signed-off-by: default avatarMasahiro Yamada <masahiroy@kernel.org>
      [penguin-kernel: Update sed script to also escape backslash and quote ]
      Signed-off-by: default avatarTetsuo Handa <penguin-kernel@I-love.SAKURA.ne.jp>
      80f8be7a
  13. Jan 07, 2023
  14. Oct 19, 2022
  15. Aug 21, 2022
  16. May 23, 2022
  17. Feb 23, 2022
    • Randy Dunlap's avatar
      TOMOYO: fix __setup handlers return values · 39844b7e
      Randy Dunlap authored
      
      __setup() handlers should return 1 if the parameter is handled.
      Returning 0 causes the entire string to be added to init's
      environment strings (limited to 32 strings), unnecessarily polluting it.
      
      Using the documented strings "TOMOYO_loader=string1" and
      "TOMOYO_trigger=string2" causes an Unknown parameter message:
        Unknown kernel command line parameters
          "BOOT_IMAGE=/boot/bzImage-517rc5 TOMOYO_loader=string1 \
           TOMOYO_trigger=string2", will be passed to user space.
      
      and these strings are added to init's environment string space:
        Run /sbin/init as init process
          with arguments:
           /sbin/init
          with environment:
           HOME=/
           TERM=linux
           BOOT_IMAGE=/boot/bzImage-517rc5
           TOMOYO_loader=string1
           TOMOYO_trigger=string2
      
      With this change, these __setup handlers act as expected,
      and init's environment is not polluted with these strings.
      
      Fixes: 0e4ae0e0 ("TOMOYO: Make several options configurable.")
      Signed-off-by: default avatarRandy Dunlap <rdunlap@infradead.org>
      Reported-by: default avatarIgor Zhbanov <i.zhbanov@omprussia.ru>
      Link: https://lore.kernel.org/r/64644a2f-4a20-bab3-1e15-3b2cdd0defe3@omprussia.ru
      
      
      Cc: James Morris <jmorris@namei.org>
      Cc: Kentaro Takeda <takedakn@nttdata.co.jp>
      Cc: tomoyo-dev-en@lists.osdn.me
      Cc: "Serge E. Hallyn" <serge@hallyn.com>
      Signed-off-by: default avatarTetsuo Handa <penguin-kernel@I-love.SAKURA.ne.jp>
      39844b7e
  18. Feb 07, 2022
  19. 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
  20. Sep 03, 2021
  21. Jun 15, 2021
    • ChenXiaoSong's avatar
      tomoyo: fix doc warnings · 98eaa63e
      ChenXiaoSong authored
      
      Fix gcc W=1 warnings:
      
      security/tomoyo/audit.c:331: warning: Function parameter or member 'matched_acl' not described in 'tomoyo_get_audit'
      security/tomoyo/securityfs_if.c:146: warning: Function parameter or member 'inode' not described in 'tomoyo_release'
      security/tomoyo/tomoyo.c:122: warning: Function parameter or member 'path' not described in 'tomoyo_inode_getattr'
      security/tomoyo/tomoyo.c:497: warning: Function parameter or member 'clone_flags' not described in 'tomoyo_task_alloc'
      security/tomoyo/util.c:92: warning: Function parameter or member 'time64' not described in 'tomoyo_convert_time'
      
      Signed-off-by: default avatarChenXiaoSong <chenxiaosong2@huawei.com>
      [ penguin-kernel: Also adjust spaces and similar warnings ]
      Signed-off-by: default avatarTetsuo Handa <penguin-kernel@I-love.SAKURA.ne.jp>
      98eaa63e
  22. Mar 28, 2021
  23. Feb 01, 2021
  24. Dec 06, 2020
  25. Nov 27, 2020
  26. Nov 03, 2020
  27. Oct 28, 2020
  28. Oct 12, 2020
    • Tetsuo Handa's avatar
      tomoyo: Loosen pathname/domainname validation. · a2075167
      Tetsuo Handa authored
      
      Since commit e2dc9bf3 ("umd: Transform fork_usermode_blob into
      fork_usermode_driver") started calling execve() on a program written in
      a local mount which is not connected to mount tree,
      tomoyo_realpath_from_path() started returning a pathname in
      "$fsname:/$pathname" format which violates TOMOYO's domainname rule that
      it must start with "<$namespace>" followed by zero or more repetitions of
      pathnames which start with '/'.
      
      Since $fsname must not contain '.' since commit 79c0b2df ("add
      filesystem subtype support"), tomoyo_correct_path() can recognize a token
      which appears '/' before '.' appears (e.g. proc:/self/exe ) as a pathname
      while rejecting a token which appears '.' before '/' appears (e.g.
      exec.realpath="/bin/bash" ) as a condition parameter.
      
      Therefore, accept domainnames which contain pathnames which do not start
      with '/' but contain '/' before '.' (e.g. <kernel> tmpfs:/bpfilter_umh ).
      
      Signed-off-by: default avatarTetsuo Handa <penguin-kernel@I-love.SAKURA.ne.jp>
      a2075167
  29. Sep 09, 2020
    • Tetsuo Handa's avatar
      tomoyo: Loosen pathname/domainname validation. · 5384d92e
      Tetsuo Handa authored
      
      Since commit e2dc9bf3 ("umd: Transform fork_usermode_blob into
      fork_usermode_driver") started calling execve() on a program written in
      a local mount which is not connected to mount tree,
      tomoyo_realpath_from_path() started returning a pathname in
      "$fsname:/$pathname" format which violates TOMOYO's domainname rule that
      it must start with "<$namespace>" followed by zero or more repetitions of
      pathnames which start with '/'.
      
      Since $fsname must not contain '.' since commit 79c0b2df ("add
      filesystem subtype support"), tomoyo_correct_path() can recognize a token
      which appears '/' before '.' appears (e.g. proc:/self/exe ) as a pathname
      while rejecting a token which appears '.' before '/' appears (e.g.
      exec.realpath="/bin/bash" ) as a condition parameter.
      
      Therefore, accept domainnames which contain pathnames which do not start
      with '/' but contain '/' before '.' (e.g. <kernel> tmpfs:/bpfilter_umh ).
      
      Signed-off-by: default avatarTetsuo Handa <penguin-kernel@I-love.SAKURA.ne.jp>
      5384d92e
  30. Aug 23, 2020
  31. Aug 12, 2020
  32. Jul 21, 2020
  33. Jun 13, 2020
    • Masahiro Yamada's avatar
      treewide: replace '---help---' in Kconfig files with 'help' · a7f7f624
      Masahiro Yamada authored
      
      Since commit 84af7a61 ("checkpatch: kconfig: prefer 'help' over
      '---help---'"), the number of '---help---' has been gradually
      decreasing, but there are still more than 2400 instances.
      
      This commit finishes the conversion. While I touched the lines,
      I also fixed the indentation.
      
      There are a variety of indentation styles found.
      
        a) 4 spaces + '---help---'
        b) 7 spaces + '---help---'
        c) 8 spaces + '---help---'
        d) 1 space + 1 tab + '---help---'
        e) 1 tab + '---help---'    (correct indentation)
        f) 1 tab + 1 space + '---help---'
        g) 1 tab + 2 spaces + '---help---'
      
      In order to convert all of them to 1 tab + 'help', I ran the
      following commend:
      
        $ find . -name 'Kconfig*' | xargs sed -i 's/^[[:space:]]*---help---/\thelp/'
      
      Signed-off-by: default avatarMasahiro Yamada <masahiroy@kernel.org>
      a7f7f624
  34. May 29, 2020
Loading