1. 26 9月, 2021 7 次提交
  2. 14 4月, 2021 6 次提交
    • R
      ima: Allow direct upload of digest lists to securityfs · 76ca647b
      Roberto Sassu 提交于
      hulk inclusion
      category: feature
      feature: IMA Digest Lists extension
      bugzilla: 46797
      
      -------------------------------------------------
      
      This patch allows direct upload of digest lists by user space parsers.
      This operation is possible if the digest of the process's executable is
      found in the digest lists and its type is COMPACT_PARSER.
      
      ima_check_measured_appraised() is called at the end of ima_file_check() to
      verify that everything accessed by the user space parsers (except for
      directories and securityfs) has been processed by IMA. If a digest list
      was not processed by an IMA submodule, digest list lookup is disabled for
      that submodule.
      Signed-off-by: NRoberto Sassu <roberto.sassu@huawei.com>
      Signed-off-by: NTianxing Zhang <zhangtianxing3@huawei.com>
      Reviewed-by: NJason Yan <yanaijie@huawei.com>
      Signed-off-by: NZheng Zengkai <zhengzengkai@huawei.com>
      76ca647b
    • R
      ima: Add support for appraisal with digest lists · a44c2ae6
      Roberto Sassu 提交于
      hulk inclusion
      category: feature
      feature: IMA Digest Lists extension
      bugzilla: 46797
      
      -------------------------------------------------
      
      IMA-Appraise grants access to files with a valid signature or with actual
      file digest equal to the digest included in security.ima.
      
      This patch adds support for appraisal based on digest lists. Instead of
      using the reference value from security.ima, this patch checks if the
      calculated file digest is included in the uploaded digest lists.
      
      This functionality must be explicitly enabled by providing one of the
      following values for the ima_appraise_digest_list= kernel option:
      
      - digest: this mode enables appraisal verification with digest lists until
        EVM is initialized; after that, EVM verification must be successful even
        if the file digest is found in a digest list;
      
      - digest-nometadata: this mode enables appraisal verification with digest
        lists even after EVM has been initialized; files without security.evm are
        allowed if the digest of the content is found in the digest list, and
        security.evm is created with current values of xattrs (trust at first
        use); all files created in this way will have the new security.ima type
        EVM_IMA_XATTR_DIGEST_LIST; they can be accessed later only if this mode
        has been selected.
      Signed-off-by: NRoberto Sassu <roberto.sassu@huawei.com>
      Signed-off-by: NTianxing Zhang <zhangtianxing3@huawei.com>
      Reviewed-by: NJason Yan <yanaijie@huawei.com>
      Signed-off-by: NZheng Zengkai <zhengzengkai@huawei.com>
      a44c2ae6
    • R
      ima: Add support for measurement with digest lists · 31604143
      Roberto Sassu 提交于
      hulk inclusion
      category: feature
      feature: IMA Digest Lists extension
      bugzilla: 46797
      
      -------------------------------------------------
      
      IMA-Measure creates a new measurement entry every time a file is measured,
      unless the same entry is already in the measurement list.
      
      This patch introduces a new type of measurement list, recognizable by the
      PCR number specified with the new ima_digest_list_pcr= kernel option. This
      type of measurement list includes measurements of digest lists and files
      not found in those lists.
      
      The benefit of this patch is the availability of a predictable PCR that
      can be used to seal data or TPM keys to the OS software. Unlike standard
      measurements, digest list measurements only indicate that files with a
      digest in those lists could have been accessed, but not if and when. With
      standard measurements, however, the chosen PCR is unlikely predictable.
      
      Both standard and digest list measurements can be generated at the same
      time by adding '+' as a prefix to the value of ima_digest_list_pcr=
      (example: with ima_digest_list_pcr=+11, IMA generates standard measurements
      with PCR 10 and digest list measurements with PCR 11).
      Signed-off-by: NRoberto Sassu <roberto.sassu@huawei.com>
      Signed-off-by: NTianxing Zhang <zhangtianxing3@huawei.com>
      Reviewed-by: NJason Yan <yanaijie@huawei.com>
      Signed-off-by: NZheng Zengkai <zhengzengkai@huawei.com>
      31604143
    • R
      ima: Introduce new hook DIGEST_LIST_CHECK · a810bfd8
      Roberto Sassu 提交于
      hulk inclusion
      category: feature
      feature: IMA Digest Lists extension
      bugzilla: 46797
      
      -------------------------------------------------
      
      This patch introduces a new hook called DIGEST_LIST_CHECK to measure
      and appraise digest lists in addition to executables and shared libraries,
      without including the FILE_CHECK hook in the IMA policy.
      Signed-off-by: NRoberto Sassu <roberto.sassu@huawei.com>
      Signed-off-by: NTianxing Zhang <zhangtianxing3@huawei.com>
      Reviewed-by: NJason Yan <yanaijie@huawei.com>
      Signed-off-by: NZheng Zengkai <zhengzengkai@huawei.com>
      a810bfd8
    • R
      ima: Prevent usage of digest lists not measured or appraised · 5244bba6
      Roberto Sassu 提交于
      hulk inclusion
      category: feature
      feature: IMA Digest Lists extension
      bugzilla: 46797
      
      -------------------------------------------------
      
      Loading a digest list affects the behavior of IMA for subsequent
      operations. For example, if the digest of a file is found in a loaded
      digest list, the file won't be added to the measurement list (with PCR 11).
      If an administrator loaded the digest list before the IMA policy, he could
      hide from verifiers the fact that files in that digest list were accessed.
      
      To avoid this situation, this patch prevents usage of digest lists for an
      IMA submodule if that submodule didn't process it. If a digest list wasn't
      measured, the digest of measured files will not be searched in the digest
      list and regular measurement will be performed. The same mechanism applies
      for appraisal.
      Signed-off-by: NRoberto Sassu <roberto.sassu@huawei.com>
      Signed-off-by: NTianxing Zhang <zhangtianxing3@huawei.com>
      Reviewed-by: NJason Yan <yanaijie@huawei.com>
      Signed-off-by: NZheng Zengkai <zhengzengkai@huawei.com>
      5244bba6
    • R
      ima: Allow choice of file hash algorithm for measurement and audit · 6214e186
      Roberto Sassu 提交于
      hulk inclusion
      category: feature
      feature: IMA Digest Lists extension
      bugzilla: 46797
      
      -------------------------------------------------
      
      IMA reads the hash algorithm from security.ima, if exists, so that a
      signature can be verified with the correct file digest.
      
      This patch moves ima_read_xattr() and ima_get_hash_algo() to ima_main.c, so
      that the file digest in the measurement list or in the audit logs can be
      compared with a reference value calculated with a specific hash algorithm.
      
      In addition, this patch also allows the usage of security.ima with type
      EVM_IMA_XATTR_DIGSIG and signature length zero, so that the xattr can be
      used just to specify the hash algorithm.
      Signed-off-by: NRoberto Sassu <roberto.sassu@huawei.com>
      Signed-off-by: NTianxing Zhang <zhangtianxing3@huawei.com>
      Reviewed-by: NJason Yan <yanaijie@huawei.com>
      Signed-off-by: NZheng Zengkai <zhengzengkai@huawei.com>
      6214e186
  3. 05 10月, 2020 6 次提交
  4. 17 9月, 2020 1 次提交
    • K
      ima: Fix NULL pointer dereference in ima_file_hash · aa662fc0
      KP Singh 提交于
      ima_file_hash can be called when there is no iint->ima_hash available
      even though the inode exists in the integrity cache. It is fairly
      common for a file to not have a hash. (e.g. an mknodat, prior to the
      file being closed).
      
      Another example where this can happen (suggested by Jann Horn):
      
      Process A does:
      
      	while(1) {
      		unlink("/tmp/imafoo");
      		fd = open("/tmp/imafoo", O_RDWR|O_CREAT|O_TRUNC, 0700);
      		if (fd == -1) {
      			perror("open");
      			continue;
      		}
      		write(fd, "A", 1);
      		close(fd);
      	}
      
      and Process B does:
      
      	while (1) {
      		int fd = open("/tmp/imafoo", O_RDONLY);
      		if (fd == -1)
      			continue;
          		char *mapping = mmap(NULL, 0x1000, PROT_READ|PROT_EXEC,
      			 	     MAP_PRIVATE, fd, 0);
      		if (mapping != MAP_FAILED)
      			munmap(mapping, 0x1000);
      		close(fd);
        	}
      
      Due to the race to get the iint->mutex between ima_file_hash and
      process_measurement iint->ima_hash could still be NULL.
      
      Fixes: 6beea7af ("ima: add the ability to query the cached hash of a given file")
      Signed-off-by: NKP Singh <kpsingh@google.com>
      Reviewed-by: NFlorent Revest <revest@chromium.org>
      Signed-off-by: NMimi Zohar <zohar@linux.ibm.com>
      aa662fc0
  5. 09 9月, 2020 1 次提交
  6. 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
  7. 17 7月, 2020 1 次提交
    • L
      IMA: Add audit log for failure conditions · 34e980bb
      Lakshmi Ramasubramanian 提交于
      process_buffer_measurement() and ima_alloc_key_entry() functions need to
      log an audit message for auditing integrity measurement failures.
      
      Add audit message in these two functions. Remove "pr_devel" log message
      in process_buffer_measurement().
      
      Sample audit messages:
      
      [    6.303048] audit: type=1804 audit(1592506281.627:2): pid=1 uid=0 auid=4294967295 ses=4294967295 subj=kernel op=measuring_key cause=ENOMEM comm="swapper/0" name=".builtin_trusted_keys" res=0 errno=-12
      
      [    8.019432] audit: type=1804 audit(1592506283.344:10): pid=1 uid=0 auid=4294967295 ses=4294967295 subj=system_u:system_r:init_t:s0 op=measuring_kexec_cmdline cause=hashing_error comm="systemd" name="kexec-cmdline" res=0 errno=-22
      Signed-off-by: NLakshmi Ramasubramanian <nramas@linux.microsoft.com>
      Suggested-by: NMimi Zohar <zohar@linux.ibm.com>
      Signed-off-by: NMimi Zohar <zohar@linux.ibm.com>
      34e980bb
  8. 12 6月, 2020 1 次提交
  9. 23 5月, 2020 1 次提交
  10. 20 4月, 2020 1 次提交
  11. 29 2月, 2020 2 次提交
  12. 23 1月, 2020 1 次提交
  13. 12 12月, 2019 2 次提交
    • 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
    • L
      IMA: Check IMA policy flag · c5563bad
      Lakshmi Ramasubramanian 提交于
      process_buffer_measurement() may be called prior to IMA being
      initialized (for instance, when the IMA hook is called when
      a key is added to the .builtin_trusted_keys keyring), which
      would result in a kernel panic.
      
      This patch adds the check in process_buffer_measurement()
      to return immediately if IMA is not initialized yet.
      Signed-off-by: NLakshmi Ramasubramanian <nramas@linux.microsoft.com>
      Signed-off-by: NMimi Zohar <zohar@linux.ibm.com>
      c5563bad
  14. 12 11月, 2019 2 次提交
    • N
      ima: Check against blacklisted hashes for files with modsig · 273df864
      Nayna Jain 提交于
      Asymmetric private keys are used to sign multiple files. The kernel
      currently supports checking against blacklisted keys. However, if the
      public key is blacklisted, any file signed by the blacklisted key will
      automatically fail signature verification. Blacklisting the public key
      is not fine enough granularity, as we might want to only blacklist a
      particular file.
      
      This patch adds support for checking against the blacklisted hash of
      the file, without the appended signature, based on the IMA policy. It
      defines a new policy option "appraise_flag=check_blacklist".
      
      In addition to the blacklisted binary hashes stored in the firmware
      "dbx" variable, the Linux kernel may be configured to load blacklisted
      binary hashes onto the .blacklist keyring as well. The following
      example shows how to blacklist a specific kernel module hash.
      
        $ sha256sum kernel/kheaders.ko
        77fa889b35a05338ec52e51591c1b89d4c8d1c99a21251d7c22b1a8642a6bad3
        kernel/kheaders.ko
      
        $ grep BLACKLIST .config
        CONFIG_SYSTEM_BLACKLIST_KEYRING=y
        CONFIG_SYSTEM_BLACKLIST_HASH_LIST="blacklist-hash-list"
      
        $ cat certs/blacklist-hash-list
        "bin:77fa889b35a05338ec52e51591c1b89d4c8d1c99a21251d7c22b1a8642a6bad3"
      
      Update the IMA custom measurement and appraisal policy
      rules (/etc/ima-policy):
      
        measure func=MODULE_CHECK template=ima-modsig
        appraise func=MODULE_CHECK appraise_flag=check_blacklist
        appraise_type=imasig|modsig
      
      After building, installing, and rebooting the kernel:
      
         545660333 ---lswrv      0     0   \_ blacklist:
        bin:77fa889b35a05338ec52e51591c1b89d4c8d1c99a21251d7c22b1a8642a6bad3
      
        measure func=MODULE_CHECK template=ima-modsig
        appraise func=MODULE_CHECK appraise_flag=check_blacklist
        appraise_type=imasig|modsig
      
        modprobe: ERROR: could not insert 'kheaders': Permission denied
      
        10 0c9834db5a0182c1fb0cdc5d3adcf11a11fd83dd ima-sig
        sha256:3bc6ed4f0b4d6e31bc1dbc9ef844605abc7afdc6d81a57d77a1ec9407997c40
        2 /usr/lib/modules/5.4.0-rc3+/kernel/kernel/kheaders.ko
      
        10 82aad2bcc3fa8ed94762356b5c14838f3bcfa6a0 ima-modsig
        sha256:3bc6ed4f0b4d6e31bc1dbc9ef844605abc7afdc6d81a57d77a1ec9407997c40
        2 /usr/lib/modules/5.4.0rc3+/kernel/kernel/kheaders.ko  sha256:77fa889b3
        5a05338ec52e51591c1b89d4c8d1c99a21251d7c22b1a8642a6bad3
        3082029a06092a864886f70d010702a082028b30820287020101310d300b0609608648
        016503040201300b06092a864886f70d01070131820264....
      
        10 25b72217cc1152b44b134ce2cd68f12dfb71acb3 ima-buf
        sha256:8b58427fedcf8f4b20bc8dc007f2e232bf7285d7b93a66476321f9c2a3aa132
        b blacklisted-hash
        77fa889b35a05338ec52e51591c1b89d4c8d1c99a21251d7c22b1a8642a6bad3
      Signed-off-by: NNayna Jain <nayna@linux.ibm.com>
      [zohar@linux.ibm.com: updated patch description]
      Signed-off-by: NMimi Zohar <zohar@linux.ibm.com>
      Signed-off-by: NMichael Ellerman <mpe@ellerman.id.au>
      Link: https://lore.kernel.org/r/1572492694-6520-8-git-send-email-zohar@linux.ibm.com
      273df864
    • N
      ima: Make process_buffer_measurement() generic · e14555e3
      Nayna Jain 提交于
      process_buffer_measurement() is limited to measuring the kexec boot
      command line. This patch makes process_buffer_measurement() more
      generic, allowing it to measure other types of buffer data (e.g.
      blacklisted binary hashes or key hashes).
      
      process_buffer_measurement() may be called directly from an IMA hook
      or as an auxiliary measurement record. In both cases the buffer
      measurement is based on policy. This patch modifies the function to
      conditionally retrieve the policy defined PCR and template for the IMA
      hook case.
      Signed-off-by: NNayna Jain <nayna@linux.ibm.com>
      [zohar@linux.ibm.com: added comment in process_buffer_measurement()]
      Signed-off-by: NMimi Zohar <zohar@linux.ibm.com>
      Signed-off-by: NMichael Ellerman <mpe@ellerman.id.au>
      Link: https://lore.kernel.org/r/1572492694-6520-6-git-send-email-zohar@linux.ibm.com
      e14555e3
  15. 20 8月, 2019 2 次提交
    • M
      kexec: Allow kexec_file() with appropriate IMA policy when locked down · 29d3c1c8
      Matthew Garrett 提交于
      Systems in lockdown mode should block the kexec of untrusted kernels.
      For x86 and ARM we can ensure that a kernel is trustworthy by validating
      a PE signature, but this isn't possible on other architectures. On those
      platforms we can use IMA digital signatures instead. Add a function to
      determine whether IMA has or will verify signatures for a given event type,
      and if so permit kexec_file() even if the kernel is otherwise locked down.
      This is restricted to cases where CONFIG_INTEGRITY_TRUSTED_KEYRING is set
      in order to prevent an attacker from loading additional keys at runtime.
      Signed-off-by: NMatthew Garrett <mjg59@google.com>
      Acked-by: NMimi Zohar <zohar@linux.ibm.com>
      Cc: Dmitry Kasatkin <dmitry.kasatkin@gmail.com>
      Cc: linux-integrity@vger.kernel.org
      Signed-off-by: NJames Morris <jmorris@namei.org>
      29d3c1c8
    • J
      kexec_file: split KEXEC_VERIFY_SIG into KEXEC_SIG and KEXEC_SIG_FORCE · 99d5cadf
      Jiri Bohac 提交于
      This is a preparatory patch for kexec_file_load() lockdown.  A locked down
      kernel needs to prevent unsigned kernel images from being loaded with
      kexec_file_load().  Currently, the only way to force the signature
      verification is compiling with KEXEC_VERIFY_SIG.  This prevents loading
      usigned images even when the kernel is not locked down at runtime.
      
      This patch splits KEXEC_VERIFY_SIG into KEXEC_SIG and KEXEC_SIG_FORCE.
      Analogous to the MODULE_SIG and MODULE_SIG_FORCE for modules, KEXEC_SIG
      turns on the signature verification but allows unsigned images to be
      loaded.  KEXEC_SIG_FORCE disallows images without a valid signature.
      Signed-off-by: NJiri Bohac <jbohac@suse.cz>
      Signed-off-by: NDavid Howells <dhowells@redhat.com>
      Signed-off-by: NMatthew Garrett <mjg59@google.com>
      cc: kexec@lists.infradead.org
      Signed-off-by: NJames Morris <jmorris@namei.org>
      99d5cadf
  16. 06 8月, 2019 4 次提交
  17. 01 7月, 2019 1 次提交
    • P
      IMA: Define a new template field buf · 86b4da8c
      Prakhar Srivastava 提交于
      A buffer(kexec boot command line arguments) measured into IMA
      measuremnt list cannot be appraised, without already being
      aware of the buffer contents. Since hashes are non-reversible,
      raw buffer is needed for validation or regenerating hash for
      appraisal/attestation.
      
      Add support to store/read the buffer contents in HEX.
      The kexec cmdline hash is stored in the "d-ng" field of the
      template data.  It can be verified using
      sudo cat /sys/kernel/security/integrity/ima/ascii_runtime_measurements |
        grep  kexec-cmdline | cut -d' ' -f 6 | xxd -r -p | sha256sum
      
      - Add two new fields to ima_event_data to hold the buf and
      buf_len
      - Add a new template field 'buf' to be used to store/read
      the buffer data.
      - Updated process_buffer_meaurement to add the buffer to
      ima_event_data. process_buffer_measurement added in
      "Define a new IMA hook to measure the boot command line
       arguments"
      - Add a new template policy name ima-buf to represent
      'd-ng|n-ng|buf'
      Signed-off-by: NPrakhar Srivastava <prsriva02@gmail.com>
      Reviewed-by: NRoberto Sassu <roberto.sassu@huawei.com>
      Reviewed-by: NJames Morris <jamorris@linux.microsoft.com>
      Signed-off-by: NMimi Zohar <zohar@linux.ibm.com>
      86b4da8c