1. 21 7月, 2020 1 次提交
    • T
      ima: Support additional conditionals in the KEXEC_CMDLINE hook function · 4834177e
      Tyler Hicks 提交于
      Take the properties of the kexec kernel's inode and the current task
      ownership into consideration when matching a KEXEC_CMDLINE operation to
      the rules in the IMA policy. This allows for some uniformity when
      writing IMA policy rules for KEXEC_KERNEL_CHECK, KEXEC_INITRAMFS_CHECK,
      and KEXEC_CMDLINE operations.
      
      Prior to this patch, it was not possible to write a set of rules like
      this:
      
       dont_measure func=KEXEC_KERNEL_CHECK obj_type=foo_t
       dont_measure func=KEXEC_INITRAMFS_CHECK obj_type=foo_t
       dont_measure func=KEXEC_CMDLINE obj_type=foo_t
       measure func=KEXEC_KERNEL_CHECK
       measure func=KEXEC_INITRAMFS_CHECK
       measure func=KEXEC_CMDLINE
      
      The inode information associated with the kernel being loaded by a
      kexec_kernel_load(2) syscall can now be included in the decision to
      measure or not
      
      Additonally, the uid, euid, and subj_* conditionals can also now be
      used in KEXEC_CMDLINE rules. There was no technical reason as to why
      those conditionals weren't being considered previously other than
      ima_match_rules() didn't have a valid inode to use so it immediately
      bailed out for KEXEC_CMDLINE operations rather than going through the
      full list of conditional comparisons.
      Signed-off-by: NTyler Hicks <tyhicks@linux.microsoft.com>
      Cc: Eric Biederman <ebiederm@xmission.com>
      Cc: kexec@lists.infradead.org
      Reviewed-by: NLakshmi Ramasubramanian <nramas@linux.microsoft.com>
      Signed-off-by: NMimi Zohar <zohar@linux.ibm.com>
      4834177e
  2. 05 6月, 2020 1 次提交
    • R
      ima: Directly free *entry in ima_alloc_init_template() if digests is NULL · 42413b49
      Roberto Sassu 提交于
      To support multiple template digests, the static array entry->digest has
      been replaced with a dynamically allocated array in commit aa724fe1
      ("ima: Switch to dynamically allocated buffer for template digests"). The
      array is allocated in ima_alloc_init_template() and if the returned pointer
      is NULL, ima_free_template_entry() is called.
      
      However, (*entry)->template_desc is not yet initialized while it is used by
      ima_free_template_entry(). This patch fixes the issue by directly freeing
      *entry without calling ima_free_template_entry().
      
      Fixes: aa724fe1 ("ima: Switch to dynamically allocated buffer for template digests")
      Reported-by: syzbot+223310b454ba6b75974e@syzkaller.appspotmail.com
      Signed-off-by: NRoberto Sassu <roberto.sassu@huawei.com>
      Signed-off-by: NMimi Zohar <zohar@linux.ibm.com>
      42413b49
  3. 20 4月, 2020 2 次提交
  4. 12 12月, 2019 1 次提交
    • L
      IMA: Add support to limit measuring keys · e9085e0a
      Lakshmi Ramasubramanian 提交于
      Limit measuring keys to those keys being loaded onto a given set of
      keyrings only and when the user id (uid) matches if uid is specified
      in the policy.
      
      This patch defines a new IMA policy option namely "keyrings=" that
      can be used to specify a set of keyrings. If this option is specified
      in the policy for "measure func=KEY_CHECK" then only the keys
      loaded onto a keyring given in the "keyrings=" option are measured.
      
      If uid is specified in the policy then the key is measured only if
      the current user id matches the one specified in the policy.
      
      Added a new parameter namely "keyring" (name of the keyring) to
      process_buffer_measurement(). The keyring name is passed to
      ima_get_action() to determine the required action.
      ima_match_rules() is updated to check keyring in the policy, if
      specified, for KEY_CHECK function.
      Signed-off-by: NLakshmi Ramasubramanian <nramas@linux.microsoft.com>
      Signed-off-by: NMimi Zohar <zohar@linux.ibm.com>
      e9085e0a
  5. 30 8月, 2019 1 次提交
    • G
      ima: ima_api: Use struct_size() in kzalloc() · 2a7f0e53
      Gustavo A. R. Silva 提交于
      One of the more common cases of allocation size calculations is finding
      the size of a structure that has a zero-sized array at the end, along
      with memory for some number of elements for that array. For example:
      
      struct ima_template_entry {
      	...
              struct ima_field_data template_data[0]; /* template related data */
      };
      
      instance = kzalloc(sizeof(struct ima_template_entry) + count * sizeof(struct ima_field_data), GFP_NOFS);
      
      Instead of leaving these open-coded and prone to type mistakes, we can
      now use the new struct_size() helper:
      
      instance = kzalloc(struct_size(instance, entry, count), GFP_NOFS);
      
      This code was detected with the help of Coccinelle.
      Signed-off-by: NGustavo A. R. Silva <gustavo@embeddedor.com>
      Signed-off-by: NMimi Zohar <zohar@linux.ibm.com>
      2a7f0e53
  6. 06 8月, 2019 3 次提交
  7. 24 6月, 2019 1 次提交
  8. 20 6月, 2019 1 次提交
  9. 14 6月, 2019 1 次提交
  10. 05 6月, 2019 1 次提交
  11. 13 12月, 2018 1 次提交
    • P
      security: audit and remove any unnecessary uses of module.h · 876979c9
      Paul Gortmaker 提交于
      Historically a lot of these existed because we did not have
      a distinction between what was modular code and what was providing
      support to modules via EXPORT_SYMBOL and friends.  That changed
      when we forked out support for the latter into the export.h file.
      This means we should be able to reduce the usage of module.h
      in code that is obj-y Makefile or bool Kconfig.
      
      The advantage in removing such instances is that module.h itself
      sources about 15 other headers; adding significantly to what we feed
      cpp, and it can obscure what headers we are effectively using.
      
      Since module.h might have been the implicit source for init.h
      (for __init) and for export.h (for EXPORT_SYMBOL) we consider each
      instance for the presence of either and replace as needed.
      
      Cc: James Morris <jmorris@namei.org>
      Cc: "Serge E. Hallyn" <serge@hallyn.com>
      Cc: John Johansen <john.johansen@canonical.com>
      Cc: Mimi Zohar <zohar@linux.ibm.com>
      Cc: Dmitry Kasatkin <dmitry.kasatkin@gmail.com>
      Cc: David Howells <dhowells@redhat.com>
      Cc: linux-security-module@vger.kernel.org
      Cc: linux-integrity@vger.kernel.org
      Cc: keyrings@vger.kernel.org
      Signed-off-by: NPaul Gortmaker <paul.gortmaker@windriver.com>
      Signed-off-by: NJames Morris <james.morris@microsoft.com>
      876979c9
  12. 27 11月, 2018 1 次提交
  13. 11 10月, 2018 1 次提交
  14. 15 5月, 2018 1 次提交
  15. 25 3月, 2018 1 次提交
  16. 23 3月, 2018 1 次提交
    • M
      IMA: Support using new creds in appraisal policy · d906c10d
      Matthew Garrett 提交于
      The existing BPRM_CHECK functionality in IMA validates against the
      credentials of the existing process, not any new credentials that the
      child process may transition to. Add an additional CREDS_CHECK target
      and refactor IMA to pass the appropriate creds structure. In
      ima_bprm_check(), check with both the existing process credentials and
      the credentials that will be committed when the new process is started.
      This will not change behaviour unless the system policy is extended to
      include CREDS_CHECK targets - BPRM_CHECK will continue to check the same
      credentials that it did previously.
      
      After this patch, an IMA policy rule along the lines of:
      
      measure func=CREDS_CHECK subj_type=unconfined_t
      
      will trigger if a process is executed and runs as unconfined_t, ignoring
      the context of the parent process. This is in contrast to:
      
      measure func=BPRM_CHECK subj_type=unconfined_t
      
      which will trigger if the process that calls exec() is already executing
      in unconfined_t, ignoring the context that the child process executes
      into.
      Signed-off-by: NMatthew Garrett <mjg59@google.com>
      Signed-off-by: NMimi Zohar <zohar@linux.vnet.ibm.com>
      
      Changelog:
      - initialize ima_creds_status
      d906c10d
  17. 29 1月, 2018 1 次提交
  18. 18 12月, 2017 1 次提交
    • M
      ima: support new "hash" and "dont_hash" policy actions · da1b0029
      Mimi Zohar 提交于
      The builtin ima_appraise_tcb policy, which is specified on the boot
      command line, can be replaced with a custom policy, normally early in
      the boot process.  Custom policies can be more restrictive in some ways,
      like requiring file signatures, but can be less restrictive in other
      ways, like not appraising mutable files.  With a less restrictive policy
      in place, files in the builtin policy might not be hashed and labeled
      with a security.ima hash.  On reboot, files which should be labeled in
      the ima_appraise_tcb are not labeled, possibly preventing the system
      from booting properly.
      
      To resolve this problem, this patch extends the existing IMA policy
      actions "measure", "dont_measure", "appraise", "dont_appraise", and
      "audit" with "hash" and "dont_hash".  The new "hash" action will write
      the file hash as security.ima, but without requiring the file to be
      appraised as well.
      
      For example, the builtin ima_appraise_tcb policy includes the rule,
      "appraise fowner=0".  Adding the "hash fowner=0" rule to a custom
      policy, will cause the needed file hashes to be calculated and written
      as security.ima xattrs.
      Signed-off-by: NMimi Zohar <zohar@linux.vnet.ibm.com>
      Signed-off-by: NStefan Berger <stefanb@linux.vnet.ibm.com>
      da1b0029
  19. 09 11月, 2017 1 次提交
    • M
      ima: always measure and audit files in policy · f3cc6b25
      Mimi Zohar 提交于
      All files matching a "measure" rule must be included in the IMA
      measurement list, even when the file hash cannot be calculated.
      Similarly, all files matching an "audit" rule must be audited, even when
      the file hash can not be calculated.
      
      The file data hash field contained in the IMA measurement list template
      data will contain 0's instead of the actual file hash digest.
      
      Note:
      In general, adding, deleting or in anyway changing which files are
      included in the IMA measurement list is not a good idea, as it might
      result in not being able to unseal trusted keys sealed to a specific
      TPM PCR value.  This patch not only adds file measurements that were
      not previously measured, but specifies that the file hash value for
      these files will be 0's.
      
      As the IMA measurement list ordering is not consistent from one boot
      to the next, it is unlikely that anyone is sealing keys based on the
      IMA measurement list.  Remote attestation servers should be able to
      process these new measurement records, but might complain about
      these unknown records.
      Signed-off-by: NMimi Zohar <zohar@linux.vnet.ibm.com>
      Reviewed-by: NDmitry Kasatkin <dmitry.kasatkin@huawei.com>
      f3cc6b25
  20. 28 1月, 2017 2 次提交
  21. 30 6月, 2016 3 次提交
  22. 28 3月, 2016 1 次提交
  23. 21 2月, 2016 1 次提交
  24. 19 2月, 2016 2 次提交
  25. 22 5月, 2015 2 次提交
    • R
      ima: pass iint to ima_add_violation() · 8d94eb9b
      Roberto Sassu 提交于
      This patch adds the iint associated to the current inode as a new
      parameter of ima_add_violation(). The passed iint is always not NULL
      if a violation is detected. This modification will be used to determine
      the inode for which there is a violation.
      
      Since the 'd' and 'd-ng' template field init() functions were detecting
      a violation from the value of the iint pointer, they now check the new
      field 'violation', added to the 'ima_event_data' structure.
      
      Changelog:
       - v1:
         - modified an old comment (Roberto Sassu)
      Signed-off-by: NRoberto Sassu <rsassu@suse.de>
      Signed-off-by: NMimi Zohar <zohar@linux.vnet.ibm.com>
      8d94eb9b
    • R
      ima: wrap event related data to the new ima_event_data structure · 23b57419
      Roberto Sassu 提交于
      All event related data has been wrapped into the new 'ima_event_data'
      structure. The main benefit of this patch is that a new information
      can be made available to template fields initialization functions
      by simply adding a new field to the new structure instead of modifying
      the definition of those functions.
      
      Changelog:
       - v2:
         - f_dentry replaced with f_path.dentry (Roberto Sassu)
         - removed declaration of temporary variables in template field functions
           when possible (suggested by Dmitry Kasatkin)
      Signed-off-by: NRoberto Sassu <rsassu@suse.de>
      Signed-off-by: NMimi Zohar <zohar@linux.vnet.ibm.com>
      23b57419
  26. 20 11月, 2014 1 次提交
  27. 18 11月, 2014 1 次提交
    • D
      ima: load x509 certificate from the kernel · fd5f4e90
      Dmitry Kasatkin 提交于
      Define configuration option to load X509 certificate into the
      IMA trusted kernel keyring. It implements ima_load_x509() hook
      to load X509 certificate into the .ima trusted kernel keyring
      from the root filesystem.
      
      Changes in v3:
      * use ima_policy_flag in ima_get_action()
        ima_load_x509 temporarily clears ima_policy_flag to disable
        appraisal to load key. Use it to skip appraisal rules.
      * Key directory path changed to /etc/keys (Mimi)
      * Expand IMA_LOAD_X509 Kconfig help
      
      Changes in v2:
      * added '__init'
      * use ima_policy_flag to disable appraisal to load keys
      Signed-off-by: NDmitry Kasatkin <d.kasatkin@samsung.com>
      Signed-off-by: NMimi Zohar <zohar@linux.vnet.ibm.com>
      fd5f4e90
  28. 08 10月, 2014 1 次提交
  29. 18 9月, 2014 1 次提交
    • R
      ima: detect violations for mmaped files · 1b68bdf9
      Roberto Sassu 提交于
      This patch fixes the detection of the 'open_writers' violation for mmaped
      files.
      
      before) an 'open_writers' violation is detected if the policy contains
              a rule with the criteria: func=FILE_CHECK mask=MAY_READ
      
      after) an 'open_writers' violation is detected if the current event
             matches one of the policy rules.
      
      With the old behaviour, the 'open_writers' violation is not detected
      in the following case:
      
      policy:
      measure func=FILE_MMAP mask=MAY_EXEC
      
      steps:
      1) open a shared library for writing
      2) execute a binary that links that shared library
      3) during the binary execution, modify the shared library and save
         the change
      
      result:
      the 'open_writers' violation measurement is not present in the IMA list.
      
      Only binaries executed are protected from writes. For libraries mapped
      in memory there is the flag MAP_DENYWRITE for this purpose, but according
      to the output of 'man mmap', the mmap flag is ignored.
      
      Since ima_rdwr_violation_check() is now called by process_measurement()
      the information about if the inode must be measured is already provided
      by ima_get_action(). Thus the unnecessary function ima_must_measure()
      has been removed.
      
      Changes in v3 (Dmitry Kasatkin):
      - Violation for MMAP_CHECK function are verified since this patch
      - Changed patch description a bit
      Signed-off-by: NRoberto Sassu <roberto.sassu@polito.it>
      Signed-off-by: NDmitry Kasatkin <d.kasatkin@samsung.com>
      Signed-off-by: NMimi Zohar <zohar@linux.vnet.ibm.com>
      1b68bdf9
  30. 09 9月, 2014 1 次提交
    • D
      ima: remove usage of filename parameter · 17f4bad3
      Dmitry Kasatkin 提交于
      In all cases except ima_bprm_check() the filename was not defined
      and ima_d_path() was used to find the full path.  Unfortunately,
      the bprm filename is a relative pathname (eg. ./<dir>/filename).
      
      ima_bprm_check() selects between bprm->interp and bprm->filename.
      The following dump demonstrates the differences between using
      filename and interp.
      
      bprm->filename
       filename: ./foo.sh, pathname: /root/bin/foo.sh
       filename: ./foo.sh, pathname: /bin/dash
      
      bprm->interp
       filename: ./foo.sh, pathname: /root/bin/foo.sh
       filename: /bin/sh, pathname: /bin/dash
      
      In both cases the pathnames are currently the same.  This patch
      removes usage of filename and interp in favor of d_absolute_path.
      
      Changes v3:
      - 11 extra bytes for "deleted" not needed (Mimi)
      - purpose "replace relative bprm filename with full pathname" (Mimi)
      
      Changes v2:
      - use d_absolute_path() instead of d_path to work in chroot environments.
      Signed-off-by: NDmitry Kasatkin <d.kasatkin@samsung.com>
      Signed-off-by: NMimi Zohar <zohar@linux.vnet.ibm.com>
      17f4bad3
  31. 04 6月, 2014 1 次提交
    • M
      ima: audit log files opened with O_DIRECT flag · f9b2a735
      Mimi Zohar 提交于
      Files are measured or appraised based on the IMA policy.  When a
      file, in policy, is opened with the O_DIRECT flag, a deadlock
      occurs.
      
      The first attempt at resolving this lockdep temporarily removed the
      O_DIRECT flag and restored it, after calculating the hash.  The
      second attempt introduced the O_DIRECT_HAVELOCK flag. Based on this
      flag, do_blockdev_direct_IO() would skip taking the i_mutex a second
      time.  The third attempt, by Dmitry Kasatkin, resolves the i_mutex
      locking issue, by re-introducing the IMA mutex, but uncovered
      another problem.  Reading a file with O_DIRECT flag set, writes
      directly to userspace pages.  A second patch allocates a user-space
      like memory.  This works for all IMA hooks, except ima_file_free(),
      which is called on __fput() to recalculate the file hash.
      
      Until this last issue is addressed, do not 'collect' the
      measurement for measuring, appraising, or auditing files opened
      with the O_DIRECT flag set.  Based on policy, permit or deny file
      access.  This patch defines a new IMA policy rule option named
      'permit_directio'.  Policy rules could be defined, based on LSM
      or other criteria, to permit specific applications to open files
      with the O_DIRECT flag set.
      
      Changelog v1:
      - permit or deny file access based IMA policy rules
      Signed-off-by: NMimi Zohar <zohar@linux.vnet.ibm.com>
      Acked-by: NDmitry Kasatkin <d.kasatkin@samsung.com>
      Cc: <stable@vger.kernel.org>
      f9b2a735
  32. 08 3月, 2014 1 次提交