1. 14 4月, 2021 26 次提交
    • R
      ima: Add meta_immutable appraisal type · ab8c2a63
      Roberto Sassu 提交于
      hulk inclusion
      category: feature
      feature: IMA Digest Lists extension
      bugzilla: 46797
      
      -------------------------------------------------
      
      Currently, IMA supports the appraise_type=imasig option in the policy to
      require file signatures. This patch introduces the new option
      appraise_type=meta_immutable to require that file metadata are signed and
      immutable. This requirement can be satisfied by portable signatures and
      by digest lists if they are marked as immutable.
      
      The main purpose of this option is to ensure that file metadata are correct
      at the time of access, so that policies relying on labels can be correctly
      enforced. For example, requiring immutable metadata would prevent an
      administrator from altering the label assigned to a process during
      execve() by changing the label of the executable.
      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>
      ab8c2a63
    • R
      evm: Add support for digest lists of metadata · f51e0ce9
      Roberto Sassu 提交于
      hulk inclusion
      category: feature
      feature: IMA Digest Lists extension
      bugzilla: 46797
      
      -------------------------------------------------
      
      This patch adds support in EVM to verify file metadata digest with digest
      lists. Metadata digest, calculated in the same way as for portable
      signatures, is searched in the digest lists only if the file has the
      security.evm xattr with type EVM_IMA_XATTR_DIGEST_LIST.
      
      If the found digest is marked as immutable, content and xattr/attr updates
      are not allowed. Otherwise, after verification, the existing security.evm
      with the new type will be replaced with an HMAC, similarly to non-portable
      signatures.
      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>
      f51e0ce9
    • 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: Load all digest lists from a directory at boot time · d2f957c7
      Roberto Sassu 提交于
      hulk inclusion
      category: feature
      feature: IMA Digest Lists extension
      bugzilla: 46797
      
      -------------------------------------------------
      
      Digest lists should be uploaded to IMA as soon as possible, otherwise file
      digests would appear in the measurement list or access would be denied if
      appraisal is in enforcing mode.
      
      This patch adds a call to ima_load_digest_lists() in integrity_load_keys(),
      so that the function is executed when rootfs becomes available, before
      files are accessed.
      
      ima_load_digest_lists() iterates in the directory specified as value of
      CONFIG_IMA_DIGEST_LISTS_DIR and uploads all digest lists to the kernel.
      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>
      d2f957c7
    • 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: Introduce new securityfs files · a27b9771
      Roberto Sassu 提交于
      hulk inclusion
      category: feature
      feature: IMA Digest Lists extension
      bugzilla: 46797
      
      -------------------------------------------------
      
      This patch introduces three new files in the securityfs filesystem.
      digest_list_data: loads a digest list from the specified path and adds the
      digests to the hash table; digest_list_data_del: does the same but removes
      the digests from the hash table; digests_count: shows the current number of
      digests stored in the hash table.
      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>
      a27b9771
    • 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: Add parser of compact digest list · 4bc4c4ca
      Roberto Sassu 提交于
      hulk inclusion
      category: feature
      feature: IMA Digest Lists extension
      bugzilla: 46797
      
      -------------------------------------------------
      
      This patch introduces the parser of the compact digest list. The format is
      optimized to store a large quantity of data with the same type. It is the
      only format supported by the kernel. Digest lists can be uploaded by
      writing the path to securityfs, as the same as for IMA policies.
      
      A compact list is a set of consecutive data blocks, each consisting of a
      header and a payload. The header indicates the version of the header, the
      type of data, type modifiers, the hash algorithm, how many elements and the
      length of the payload.
      
      COMPACT_KEY identifies public keys used for signature verification of the
      digest lists; COMPACT_PARSER identifies digests of user space parsers
      allowed to directly upload parsed digest lists to the kernel; COMPACT_FILE
      identifies digests of regular files; COMPACT_METADATA identifies digest of
      file metadata.
      
      Type modifiers indicate attributes of the elements included in the payload.
      The COMPACT_MOD_IMMUTABLE modifier indicates that a file or metadata are
      immutable.
      
      This patch also introduces ima_lookup_loaded_digest() and
      ima_add_digest_data_entry() to search and add digests in the new hash table
      (ima_digests_htable).
      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>
      4bc4c4ca
    • R
      ima: Use ima_show_htable_value to show violations and hash table data · 2286f47b
      Roberto Sassu 提交于
      hulk inclusion
      category: feature
      feature: IMA Digest Lists extension
      bugzilla: 46797
      
      -------------------------------------------------
      
      ima_show_htable_violations() and ima_show_measurements_count() both call
      ima_show_htable_value() to copy the value of an atomic_long_t variable to
      a buffer.
      
      This patch modifies the definition of ima_show_htable_value(), so that this
      function can be used in any file_operations structure. The atomic_long_t
      variable used as source is chosen depending on the opened file in the
      securityfs filesystem.
      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>
      2286f47b
    • R
      ima: Generalize policy file operations · cde9df82
      Roberto Sassu 提交于
      hulk inclusion
      category: feature
      feature: IMA Digest Lists extension
      bugzilla: 46797
      
      -------------------------------------------------
      
      This patch renames ima_open_policy() and ima_release_policy() respectively
      to ima_open_data_upload() and ima_release_data_upload(). They will be used
      to implement file operations for interfaces allowing to load data from user
      space.
      
      A new flag (IMA_POLICY_BUSY) has been defined to prevent concurrent policy
      upload.
      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>
      cde9df82
    • R
      ima: Generalize ima_write_policy() and raise uploaded data size limit · fd2fdf9d
      Roberto Sassu 提交于
      hulk inclusion
      category: feature
      feature: IMA Digest Lists extension
      bugzilla: 46797
      
      -------------------------------------------------
      
      ima_write_policy() is being used to load a new policy from user space. This
      function can be reused to load different types of data.
      
      This patch renames ima_write_policy() to ima_write_data() and executes the
      appropriate actions depending on the opened file in securityfs.
      
      Also, this patch raises the uploaded data size limit to 64M, to accept
      files (e.g. digest lists) larger than a policy. The same limit is used for
      the SELinux 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>
      fd2fdf9d
    • R
      ima: Generalize ima_read_policy() · c2d80e34
      Roberto Sassu 提交于
      hulk inclusion
      category: feature
      feature: IMA Digest Lists extension
      bugzilla: 46797
      
      -------------------------------------------------
      
      This patch renames ima_read_policy() to ima_read_file() so that the
      function can be used to read files for different purposes. It also adds the
      opened file in securityfs as parameter so that the function can determine
      which action it should do with the passed data.
      
      This patch replaces kernel_read_file_from_path() with filp_open() +
      kernel_read_file() so that the file descriptor can be used for further
      checks.
      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>
      c2d80e34
    • 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
    • R
      ima: Add enforce-evm and log-evm modes to strictly check EVM status · 437b9486
      Roberto Sassu 提交于
      hulk inclusion
      category: feature
      feature: IMA Digest Lists extension
      bugzilla: 46797
      
      -------------------------------------------------
      
      IMA and EVM have been designed as two independent subsystems: the first for
      checking the integrity of file data; the second for checking file metadata.
      Making them independent allows users to adopt them incrementally.
      
      The point of intersection is in IMA-Appraise, which calls evm_verifyxattr()
      to ensure that security.ima wasn't modified during an offline attack. The
      design choice, to ensure incremental adoption, was to continue appraisal
      verification if evm_verifyxattr() returns INTEGRITY_UNKNOWN. This value is
      returned when EVM is not enabled in the kernel configuration, or if the
      HMAC key has not been loaded yet.
      
      Although this choice appears legitimate, it might not be suitable for
      hardened systems, where the administrator expects that access is denied if
      there is any error. An attacker could intentionally delete the EVM keys
      from the system and set the file digest in security.ima to the actual file
      digest so that the final appraisal status is INTEGRITY_PASS.
      
      This patch allows such hardened systems to strictly enforce an access
      control policy based on the validity of signatures/HMACs, by introducing
      two new values for the ima_appraise= kernel option: enforce-evm and
      log-evm.
      
      Cc: stable@vger.kernel.org
      Fixes: 2fe5d6de ("ima: integrity appraisal extension")
      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>
      437b9486
    • R
      ima: Don't remove security.ima if file must not be appraised · a07594d5
      Roberto Sassu 提交于
      hulk inclusion
      category: feature
      feature: IMA Digest Lists extension
      bugzilla: 46797
      
      ---------------------------
      
      Files might come from a remote source and might have xattrs, including
      security.ima. It should not be IMA task to decide whether security.ima
      should be kept or not. This patch removes the removexattr() system
      call in ima_inode_post_setattr().
      Signed-off-by: NRoberto Sassu <roberto.sassu@huawei.com>
      Reviewed-by: NMimi Zohar <zohar@linux.ibm.com>
      Reviewed-by: NJason Yan <yanaijie@huawei.com>
      Signed-off-by: NZheng Zengkai <zhengzengkai@huawei.com>
      a07594d5
    • R
      ima: Introduce template field evmsig and write to field sig as fallback · b5622fd6
      Roberto Sassu 提交于
      hulk inclusion
      category: feature
      feature: IMA Digest Lists extension
      bugzilla: 46797
      
      ---------------------------
      
      With the patch to accept EVM portable signatures when the
      appraise_type=imasig requirement is specified in the policy, appraisal can
      be successfully done even if the file does not have an IMA signature.
      
      However, remote attestation would not see that a different signature type
      was used, as only IMA signatures can be included in the measurement list.
      This patch solves the issue by introducing the new template field 'evmsig'
      to show EVM portable signatures and by including its value in the existing
      field 'sig' if the IMA signature is not found.
      Signed-off-by: NRoberto Sassu <roberto.sassu@huawei.com>
      Suggested-by: NMimi Zohar <zohar@linux.ibm.com>
      Reviewed-by: NJason Yan <yanaijie@huawei.com>
      Signed-off-by: NZheng Zengkai <zhengzengkai@huawei.com>
      b5622fd6
    • R
      ima: Allow imasig requirement to be satisfied by EVM portable signatures · bd7071df
      Roberto Sassu 提交于
      hulk inclusion
      category: feature
      feature: IMA Digest Lists extension
      bugzilla: 46797
      
      ---------------------------
      
      System administrators can require that all accessed files have a signature
      by specifying appraise_type=imasig in a policy rule.
      
      Currently, IMA signatures satisfy this requirement. Appended signatures may
      also satisfy this requirement, but are not applicable as IMA signatures.
      IMA/appended signatures ensure data source authentication for file content
      and prevent any change. EVM signatures instead ensure data source
      authentication for file metadata. Given that the digest or signature of the
      file content must be included in the metadata, EVM signatures provide the
      same file data guarantees of IMA signatures, as well as providing file
      metadata guarantees.
      
      This patch lets systems protected with EVM signatures pass appraisal
      verification if the appraise_type=imasig requirement is specified in the
      policy. This facilitates deployment in the scenarios where only EVM
      signatures are available.
      
      The patch makes the following changes:
      
      file xattr types:
      security.ima: IMA_XATTR_DIGEST/IMA_XATTR_DIGEST_NG
      security.evm: EVM_XATTR_PORTABLE_DIGSIG
      
      execve(), mmap(), open() behavior (with appraise_type=imasig):
      before: denied (file without IMA signature, imasig requirement not met)
      after: allowed (file with EVM portable signature, imasig requirement met)
      
      open(O_WRONLY) behavior (without appraise_type=imasig):
      before: allowed (file without IMA signature, not immutable)
      after: denied (file with EVM portable signature, immutable)
      
      In addition, similarly to IMA signatures, this patch temporarily allows
      new files without or with incomplete metadata to be opened so that content
      can be written.
      Signed-off-by: NRoberto Sassu <roberto.sassu@huawei.com>
      Reviewed-by: NMimi Zohar <zohar@linux.ibm.com>
      Reviewed-by: NJason Yan <yanaijie@huawei.com>
      Signed-off-by: NZheng Zengkai <zhengzengkai@huawei.com>
      bd7071df
    • R
      evm: Allow setxattr() and setattr() for unmodified metadata · ce02fabf
      Roberto Sassu 提交于
      hulk inclusion
      category: feature
      feature: IMA Digest Lists extension
      bugzilla: 46797
      
      ---------------------------
      
      With the patch to allow xattr/attr operations if a portable signature
      verification fails, cp and tar can copy all xattrs/attrs so that at the
      end of the process verification succeeds.
      
      However, it might happen that the xattrs/attrs are already set to the
      correct value (taken at signing time) and signature verification succeeds
      before the copy has completed. For example, an archive might contains files
      owned by root and the archive is extracted by root.
      
      Then, since portable signatures are immutable, all subsequent operations
      fail (e.g. fchown()), even if the operation is legitimate (does not alter
      the current value).
      
      This patch avoids this problem by reporting successful operation to user
      space when that operation does not alter the current value of xattrs/attrs.
      Signed-off-by: NRoberto Sassu <roberto.sassu@huawei.com>
      Reviewed-by: NJason Yan <yanaijie@huawei.com>
      Signed-off-by: NZheng Zengkai <zhengzengkai@huawei.com>
      ce02fabf
    • R
      evm: Allow xattr/attr operations for portable signatures · 475be7fa
      Roberto Sassu 提交于
      hulk inclusion
      category: feature
      feature: IMA Digest Lists extension
      bugzilla: 46797
      
      ---------------------------
      
      If files with portable signatures are copied from one location to another
      or are extracted from an archive, verification can temporarily fail until
      all xattrs/attrs are set in the destination. Only portable signatures may
      be moved or copied from one file to another, as they don't depend on
      system-specific information such as the inode generation. Instead portable
      signatures must include security.ima.
      
      Unlike other security.evm types, EVM portable signatures are also
      immutable. Thus, it wouldn't be a problem to allow xattr/attr operations
      when verification fails, as portable signatures will never be replaced with
      the HMAC on possibly corrupted xattrs/attrs.
      
      This patch first introduces a new integrity status called
      INTEGRITY_FAIL_IMMUTABLE, that allows callers of
      evm_verify_current_integrity() to detect that a portable signature didn't
      pass verification and then adds an exception in evm_protect_xattr() and
      evm_inode_setattr() for this status and returns 0 instead of -EPERM.
      Signed-off-by: NRoberto Sassu <roberto.sassu@huawei.com>
      Reviewed-by: NMimi Zohar <zohar@linux.ibm.com>
      Reviewed-by: NJason Yan <yanaijie@huawei.com>
      Signed-off-by: NZheng Zengkai <zhengzengkai@huawei.com>
      475be7fa
    • R
      evm: Ignore INTEGRITY_NOLABEL/INTEGRITY_NOXATTRS if conditions are safe · f74c413c
      Roberto Sassu 提交于
      hulk inclusion
      category: feature
      feature: IMA Digest Lists extension
      bugzilla: 46797
      
      ---------------------------
      
      When a file is being created, LSMs can set the initial label with the
      inode_init_security hook. If no HMAC key is loaded, the new file will have
      LSM xattrs but not the HMAC. It is also possible that the file remains
      without protected xattrs after creation if no active LSM provided it.
      
      Unfortunately, EVM will deny any further metadata operation on new files,
      as evm_protect_xattr() will always return the INTEGRITY_NOLABEL error, or
      INTEGRITY_NOXATTRS if no protected xattrs exist. This would limit the
      usability of EVM when only a public key is loaded, as commands such as cp
      or tar with the option to preserve xattrs won't work.
      
      This patch ignores these errors when they won't be an issue, if no HMAC key
      is loaded and cannot be loaded in the future (which can be enforced by
      setting the EVM_SETUP_COMPLETE initialization flag).
      Signed-off-by: NRoberto Sassu <roberto.sassu@huawei.com>
      Reviewed-by: NJason Yan <yanaijie@huawei.com>
      Signed-off-by: NZheng Zengkai <zhengzengkai@huawei.com>
      f74c413c
    • R
      evm: Introduce evm_status_revalidate() · 1c8c2846
      Roberto Sassu 提交于
      hulk inclusion
      category: feature
      feature: IMA Digest Lists extension
      bugzilla: 46797
      
      ---------------------------
      
      When EVM_ALLOW_METADATA_WRITES is set, EVM allows any operation on
      metadata. Its main purpose is to allow users to freely set metadata when it
      is protected by a portable signature, until an HMAC key is loaded.
      
      However, callers of evm_verifyxattr() are not notified about metadata
      changes and continue to rely on the last status returned by the function.
      For example IMA, since it caches the appraisal result, will not call again
      evm_verifyxattr() until the appraisal flags are cleared, and will grant
      access to the file even if there was a metadata operation that made the
      portable signature invalid.
      
      This patch introduces evm_status_revalidate(), which callers of
      evm_verifyxattr() can use in their xattr post hooks to determine whether
      re-validation is necessary and to do the proper actions. IMA calls it in
      its xattr post hooks to reset the appraisal flags, so that the EVM status
      is re-evaluated after a metadata operation.
      
      Lastly, this patch also adds a call to evm_reset_status() in
      evm_inode_post_setattr() to invalidate the cached EVM status after a
      setattr operation.
      Signed-off-by: NRoberto Sassu <roberto.sassu@huawei.com>
      Reviewed-by: NJason Yan <yanaijie@huawei.com>
      Signed-off-by: NZheng Zengkai <zhengzengkai@huawei.com>
      1c8c2846
    • R
      ima: Move ima_reset_appraise_flags() call to post hooks · d3df8e70
      Roberto Sassu 提交于
      hulk inclusion
      category: feature
      feature: IMA Digest Lists extension
      bugzilla: 46797
      
      ---------------------------
      
      ima_inode_setxattr() and ima_inode_removexattr() hooks are called before an
      operation is performed. Thus, ima_reset_appraise_flags() should not be
      called there, as flags might be unnecessarily reset if the operation is
      denied.
      
      This patch introduces the post hooks ima_inode_post_setxattr() and
      ima_inode_post_removexattr(), and adds the call to
      ima_reset_appraise_flags() in the new functions.
      Signed-off-by: NRoberto Sassu <roberto.sassu@huawei.com>
      Reviewed-by: NJason Yan <yanaijie@huawei.com>
      Signed-off-by: NZheng Zengkai <zhengzengkai@huawei.com>
      d3df8e70
    • R
      evm: Refuse EVM_ALLOW_METADATA_WRITES only if an HMAC key is loaded · 9b772f49
      Roberto Sassu 提交于
      hulk inclusion
      category: feature
      feature: IMA Digest Lists extension
      bugzilla: 46797
      
      ---------------------------
      
      EVM_ALLOW_METADATA_WRITES is an EVM initialization flag that can be set to
      temporarily disable metadata verification until all xattrs/attrs necessary
      to verify an EVM portable signature are copied to the file. This flag is
      cleared when EVM is initialized with an HMAC key, to avoid that the HMAC is
      calculated on unverified xattrs/attrs.
      
      Currently EVM unnecessarily denies setting this flag if EVM is initialized
      with a public key, which is not a concern as it cannot be used to trust
      xattrs/attrs updates. This patch removes this limitation.
      
      Cc: stable@vger.kernel.org # 4.16.x
      Fixes: ae1ba167 ("EVM: Allow userland to permit modification of EVM-protected metadata")
      Signed-off-by: NRoberto Sassu <roberto.sassu@huawei.com>
      Reviewed-by: NJason Yan <yanaijie@huawei.com>
      Signed-off-by: NZheng Zengkai <zhengzengkai@huawei.com>
      9b772f49
    • R
      evm: Load EVM key in ima_load_x509() to avoid appraisal · 9a37a4f2
      Roberto Sassu 提交于
      hulk inclusion
      category: feature
      feature: IMA Digest Lists extension
      bugzilla: 46797
      
      ---------------------------
      
      Public keys do not need to be appraised by IMA as the restriction on the
      IMA/EVM keyrings ensures that a key can be loaded only if it is signed with
      a key in the primary or secondary keyring.
      
      However, when evm_load_x509() is called, appraisal is already enabled and
      a valid IMA signature must be added to the EVM key to pass verification.
      
      Since the restriction is applied on both IMA and EVM keyrings, it is safe
      to disable appraisal also when the EVM key is loaded. This patch calls
      evm_load_x509() inside ima_load_x509() if CONFIG_IMA_LOAD_X509 is enabled.
      Signed-off-by: NRoberto Sassu <roberto.sassu@huawei.com>
      Reviewed-by: NMimi Zohar <zohar@linux.ibm.com>
      Reviewed-by: NJason Yan <yanaijie@huawei.com>
      Signed-off-by: NZheng Zengkai <zhengzengkai@huawei.com>
      9a37a4f2
    • R
      evm: Execute evm_inode_init_security() only when an HMAC key is loaded · 92aa9c3e
      Roberto Sassu 提交于
      hulk inclusion
      category: feature
      feature: IMA Digest Lists extension
      bugzilla: 46797
      
      ---------------------------
      
      evm_inode_init_security() requires an HMAC key to calculate the HMAC on
      initial xattrs provided by LSMs. However, it checks generically whether a
      key has been loaded, including also public keys, which is not correct as
      public keys are not suitable to calculate the HMAC.
      
      Originally, support for signature verification was introduced to verify a
      possibly immutable initial ram disk, when no new files are created, and to
      switch to HMAC for the root filesystem. By that time, an HMAC key should
      have been loaded and usable to calculate HMACs for new files.
      
      More recently support for requiring an HMAC key was removed from the
      kernel, so that signature verification can be used alone. Since this is a
      legitimate use case, evm_inode_init_security() should not return an error
      when no HMAC key has been loaded.
      
      This patch fixes this problem by replacing the evm_key_loaded() check with
      a check of the EVM_INIT_HMAC flag in evm_initialized.
      
      Cc: stable@vger.kernel.org # 4.5.x
      Fixes: 26ddabfe ("evm: enable EVM when X509 certificate is loaded")
      Signed-off-by: NRoberto Sassu <roberto.sassu@huawei.com>
      Reviewed-by: NMimi Zohar <zohar@linux.ibm.com>
      Reviewed-by: NJason Yan <yanaijie@huawei.com>
      Signed-off-by: NZheng Zengkai <zhengzengkai@huawei.com>
      92aa9c3e
  2. 13 4月, 2021 2 次提交
  3. 09 4月, 2021 4 次提交
  4. 12 1月, 2021 1 次提交
  5. 30 10月, 2020 1 次提交
  6. 05 10月, 2020 6 次提交