1. 28 7月, 2020 1 次提交
  2. 21 7月, 2020 9 次提交
    • B
      ima: move APPRAISE_BOOTPARAM dependency on ARCH_POLICY to runtime · 311aa6aa
      Bruno Meneguele 提交于
      The IMA_APPRAISE_BOOTPARAM config allows enabling different "ima_appraise="
      modes - log, fix, enforce - at run time, but not when IMA architecture
      specific policies are enabled.  This prevents properly labeling the
      filesystem on systems where secure boot is supported, but not enabled on the
      platform.  Only when secure boot is actually enabled should these IMA
      appraise modes be disabled.
      
      This patch removes the compile time dependency and makes it a runtime
      decision, based on the secure boot state of that platform.
      
      Test results as follows:
      
      -> x86-64 with secure boot enabled
      
      [    0.015637] Kernel command line: <...> ima_policy=appraise_tcb ima_appraise=fix
      [    0.015668] ima: Secure boot enabled: ignoring ima_appraise=fix boot parameter option
      
      -> powerpc with secure boot disabled
      
      [    0.000000] Kernel command line: <...> ima_policy=appraise_tcb ima_appraise=fix
      [    0.000000] Secure boot mode disabled
      
      -> Running the system without secure boot and with both options set:
      
      CONFIG_IMA_APPRAISE_BOOTPARAM=y
      CONFIG_IMA_ARCH_POLICY=y
      
      Audit prompts "missing-hash" but still allow execution and, consequently,
      filesystem labeling:
      
      type=INTEGRITY_DATA msg=audit(07/09/2020 12:30:27.778:1691) : pid=4976
      uid=root auid=root ses=2
      subj=unconfined_u:unconfined_r:unconfined_t:s0-s0:c0.c1023 op=appraise_data
      cause=missing-hash comm=bash name=/usr/bin/evmctl dev="dm-0" ino=493150
      res=no
      
      Cc: stable@vger.kernel.org
      Fixes: d958083a ("x86/ima: define arch_get_ima_policy() for x86")
      Signed-off-by: NBruno Meneguele <bmeneg@redhat.com>
      Cc: stable@vger.kernel.org # 5.0
      Signed-off-by: NMimi Zohar <zohar@linux.ibm.com>
      311aa6aa
    • T
      ima: AppArmor satisfies the audit rule requirements · 1768215a
      Tyler Hicks 提交于
      AppArmor meets all the requirements for IMA in terms of audit rules
      since commit e79c26d0 ("apparmor: Add support for audit rule
      filtering"). Update IMA's Kconfig section for CONFIG_IMA_LSM_RULES to
      reflect this.
      
      Fixes: e79c26d0 ("apparmor: Add support for audit rule filtering")
      Signed-off-by: NTyler Hicks <tyhicks@linux.microsoft.com>
      Signed-off-by: NMimi Zohar <zohar@linux.ibm.com>
      1768215a
    • T
      ima: Rename internal filter rule functions · b8867eed
      Tyler Hicks 提交于
      Rename IMA's internal filter rule functions from security_filter_rule_*()
      to ima_filter_rule_*(). This avoids polluting the security_* namespace,
      which is typically reserved for general security subsystem
      infrastructure.
      Signed-off-by: NTyler Hicks <tyhicks@linux.microsoft.com>
      Suggested-by: NCasey Schaufler <casey@schaufler-ca.com>
      [zohar@linux.ibm.com: reword using the term "filter", not "audit"]
      Signed-off-by: NMimi Zohar <zohar@linux.ibm.com>
      b8867eed
    • 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
    • T
      ima: Use the common function to detect LSM conditionals in a rule · 592b24cb
      Tyler Hicks 提交于
      Make broader use of ima_rule_contains_lsm_cond() to check if a given
      rule contains an LSM conditional. This is a code cleanup and has no
      user-facing change.
      Signed-off-by: NTyler Hicks <tyhicks@linux.microsoft.com>
      Reviewed-by: NMimi Zohar <zohar@linux.ibm.com>
      Signed-off-by: NMimi Zohar <zohar@linux.ibm.com>
      592b24cb
    • T
      ima: Move comprehensive rule validation checks out of the token parser · 30031b0e
      Tyler Hicks 提交于
      Use ima_validate_rule(), at the end of the token parsing stage, to
      verify combinations of actions, hooks, and flags. This is useful to
      increase readability by consolidating such checks into a single function
      and also because rule conditionals can be specified in arbitrary order
      making it difficult to do comprehensive rule validation until the entire
      rule has been parsed.
      
      This allows for the check that ties together the "keyrings" conditional
      with the KEY_CHECK function hook to be moved into the final rule
      validation.
      
      The modsig check no longer needs to compiled conditionally because the
      token parser will ensure that modsig support is enabled before accepting
      "imasig|modsig" appraise type values. The final rule validation will
      ensure that appraise_type and appraise_flag options are only present in
      appraise rules.
      
      Finally, this allows for the check that ties together the "pcr"
      conditional with the measure action to be moved into the final rule
      validation.
      Signed-off-by: NTyler Hicks <tyhicks@linux.microsoft.com>
      Signed-off-by: NMimi Zohar <zohar@linux.ibm.com>
      30031b0e
    • T
      ima: Use correct type for the args_p member of ima_rule_entry.lsm elements · aa0c0227
      Tyler Hicks 提交于
      Make args_p be of the char pointer type rather than have it be a void
      pointer that gets casted to char pointer when it is used. It is a simple
      NUL-terminated string as returned by match_strdup().
      Signed-off-by: NTyler Hicks <tyhicks@linux.microsoft.com>
      Signed-off-by: NMimi Zohar <zohar@linux.ibm.com>
      aa0c0227
    • T
      ima: Shallow copy the args_p member of ima_rule_entry.lsm elements · 39e5993d
      Tyler Hicks 提交于
      The args_p member is a simple string that is allocated by
      ima_rule_init(). Shallow copy it like other non-LSM references in
      ima_rule_entry structs.
      
      There are no longer any necessary error path cleanups to do in
      ima_lsm_copy_rule().
      Signed-off-by: NTyler Hicks <tyhicks@linux.microsoft.com>
      Signed-off-by: NTyler Hicks <tyhicks@linux.microsoft.com>
      Signed-off-by: NMimi Zohar <zohar@linux.ibm.com>
      39e5993d
    • T
      ima: Fail rule parsing when appraise_flag=blacklist is unsupportable · 5f3e9265
      Tyler Hicks 提交于
      Verifying that a file hash is not blacklisted is currently only
      supported for files with appended signatures (modsig).  In the future,
      this might change.
      
      For now, the "appraise_flag" option is only appropriate for appraise
      actions and its "blacklist" value is only appropriate when
      CONFIG_IMA_APPRAISE_MODSIG is enabled and "appraise_flag=blacklist" is
      only appropriate when "appraise_type=imasig|modsig" is also present.
      Make this clear at policy load so that IMA policy authors don't assume
      that other uses of "appraise_flag=blacklist" are supported.
      
      Fixes: 273df864 ("ima: Check against blacklisted hashes for files with modsig")
      Signed-off-by: NTyler Hicks <tyhicks@linux.microsoft.com>
      Reivewed-by: NNayna Jain <nayna@linux.ibm.com>
      Tested-by: NNayna Jain <nayna@linux.ibm.com>
      Signed-off-by: NMimi Zohar <zohar@linux.ibm.com>
      5f3e9265
  3. 17 7月, 2020 8 次提交
    • T
      ima: Fail rule parsing when the KEY_CHECK hook is combined with an invalid cond · eb624fe2
      Tyler Hicks 提交于
      The KEY_CHECK function only supports the uid, pcr, and keyrings
      conditionals. Make this clear at policy load so that IMA policy authors
      don't assume that other conditionals are supported.
      
      Fixes: 5808611c ("IMA: Add KEY_CHECK func to measure keys")
      Signed-off-by: NTyler Hicks <tyhicks@linux.microsoft.com>
      Reviewed-by: NLakshmi Ramasubramanian <nramas@linux.microsoft.com>
      Signed-off-by: NMimi Zohar <zohar@linux.ibm.com>
      eb624fe2
    • T
      ima: Fail rule parsing when the KEXEC_CMDLINE hook is combined with an invalid cond · db2045f5
      Tyler Hicks 提交于
      The KEXEC_CMDLINE hook function only supports the pcr conditional. Make
      this clear at policy load so that IMA policy authors don't assume that
      other conditionals are supported.
      
      Since KEXEC_CMDLINE's inception, ima_match_rules() has always returned
      true on any loaded KEXEC_CMDLINE rule without any consideration for
      other conditionals present in the rule. Make it clear that pcr is the
      only supported KEXEC_CMDLINE conditional by returning an error during
      policy load.
      
      An example of why this is a problem can be explained with the following
      rule:
      
       dont_measure func=KEXEC_CMDLINE obj_type=foo_t
      
      An IMA policy author would have assumed that rule is valid because the
      parser accepted it but the result was that measurements for all
      KEXEC_CMDLINE operations would be disabled.
      
      Fixes: b0935123 ("IMA: Define a new hook to measure the kexec boot command line arguments")
      Signed-off-by: NTyler Hicks <tyhicks@linux.microsoft.com>
      Reviewed-by: NMimi Zohar <zohar@linux.ibm.com>
      Reviewed-by: NLakshmi Ramasubramanian <nramas@linux.microsoft.com>
      Signed-off-by: NMimi Zohar <zohar@linux.ibm.com>
      db2045f5
    • T
      ima: Fail rule parsing when buffer hook functions have an invalid action · 71218343
      Tyler Hicks 提交于
      Buffer based hook functions, such as KEXEC_CMDLINE and KEY_CHECK, can
      only measure. The process_buffer_measurement() function quietly ignores
      all actions except measure so make this behavior clear at the time of
      policy load.
      
      The parsing of the keyrings conditional had a check to ensure that it
      was only specified with measure actions but the check should be on the
      hook function and not the keyrings conditional since
      "appraise func=KEY_CHECK" is not a valid rule.
      
      Fixes: b0935123 ("IMA: Define a new hook to measure the kexec boot command line arguments")
      Fixes: 5808611c ("IMA: Add KEY_CHECK func to measure keys")
      Signed-off-by: NTyler Hicks <tyhicks@linux.microsoft.com>
      Signed-off-by: NMimi Zohar <zohar@linux.ibm.com>
      71218343
    • T
      ima: Free the entire rule if it fails to parse · 2bdd737c
      Tyler Hicks 提交于
      Use ima_free_rule() to fix memory leaks of allocated ima_rule_entry
      members, such as .fsname and .keyrings, when an error is encountered
      during rule parsing.
      
      Set the args_p pointer to NULL after freeing it in the error path of
      ima_lsm_rule_init() so that it isn't freed twice.
      
      This fixes a memory leak seen when loading an rule that contains an
      additional piece of allocated memory, such as an fsname, followed by an
      invalid conditional:
      
       # echo "measure fsname=tmpfs bad=cond" > /sys/kernel/security/ima/policy
       -bash: echo: write error: Invalid argument
       # echo scan > /sys/kernel/debug/kmemleak
       # cat /sys/kernel/debug/kmemleak
       unreferenced object 0xffff98e7e4ece6c0 (size 8):
         comm "bash", pid 672, jiffies 4294791843 (age 21.855s)
         hex dump (first 8 bytes):
           74 6d 70 66 73 00 6b a5                          tmpfs.k.
         backtrace:
           [<00000000abab7413>] kstrdup+0x2e/0x60
           [<00000000f11ede32>] ima_parse_add_rule+0x7d4/0x1020
           [<00000000f883dd7a>] ima_write_policy+0xab/0x1d0
           [<00000000b17cf753>] vfs_write+0xde/0x1d0
           [<00000000b8ddfdea>] ksys_write+0x68/0xe0
           [<00000000b8e21e87>] do_syscall_64+0x56/0xa0
           [<0000000089ea7b98>] entry_SYSCALL_64_after_hwframe+0x44/0xa9
      
      Fixes: f1b08bbc ("ima: define a new policy condition based on the filesystem name")
      Fixes: 2b60c0ec ("IMA: Read keyrings= option from the IMA policy")
      Signed-off-by: NTyler Hicks <tyhicks@linux.microsoft.com>
      Signed-off-by: NMimi Zohar <zohar@linux.ibm.com>
      2bdd737c
    • T
      ima: Free the entire rule when deleting a list of rules · 465aee77
      Tyler Hicks 提交于
      Create a function, ima_free_rule(), to free all memory associated with
      an ima_rule_entry. Use the new function to fix memory leaks of allocated
      ima_rule_entry members, such as .fsname and .keyrings, when deleting a
      list of rules.
      
      Make the existing ima_lsm_free_rule() function specific to the LSM
      audit rule array of an ima_rule_entry and require that callers make an
      additional call to kfree to free the ima_rule_entry itself.
      
      This fixes a memory leak seen when loading by a valid rule that contains
      an additional piece of allocated memory, such as an fsname, followed by
      an invalid rule that triggers a policy load failure:
      
       # echo -e "dont_measure fsname=securityfs\nbad syntax" > \
          /sys/kernel/security/ima/policy
       -bash: echo: write error: Invalid argument
       # echo scan > /sys/kernel/debug/kmemleak
       # cat /sys/kernel/debug/kmemleak
       unreferenced object 0xffff9bab67ca12c0 (size 16):
         comm "bash", pid 684, jiffies 4295212803 (age 252.344s)
         hex dump (first 16 bytes):
           73 65 63 75 72 69 74 79 66 73 00 6b 6b 6b 6b a5  securityfs.kkkk.
         backtrace:
           [<00000000adc80b1b>] kstrdup+0x2e/0x60
           [<00000000d504cb0d>] ima_parse_add_rule+0x7d4/0x1020
           [<00000000444825ac>] ima_write_policy+0xab/0x1d0
           [<000000002b7f0d6c>] vfs_write+0xde/0x1d0
           [<0000000096feedcf>] ksys_write+0x68/0xe0
           [<0000000052b544a2>] do_syscall_64+0x56/0xa0
           [<000000007ead1ba7>] entry_SYSCALL_64_after_hwframe+0x44/0xa9
      
      Fixes: f1b08bbc ("ima: define a new policy condition based on the filesystem name")
      Fixes: 2b60c0ec ("IMA: Read keyrings= option from the IMA policy")
      Signed-off-by: NTyler Hicks <tyhicks@linux.microsoft.com>
      Signed-off-by: NMimi Zohar <zohar@linux.ibm.com>
      465aee77
    • T
      ima: Have the LSM free its audit rule · 9ff8a616
      Tyler Hicks 提交于
      Ask the LSM to free its audit rule rather than directly calling kfree().
      Both AppArmor and SELinux do additional work in their audit_rule_free()
      hooks. Fix memory leaks by allowing the LSMs to perform necessary work.
      
      Fixes: b1694245 ("ima: use the lsm policy update notifier")
      Signed-off-by: NTyler Hicks <tyhicks@linux.microsoft.com>
      Cc: Janne Karhunen <janne.karhunen@gmail.com>
      Cc: Casey Schaufler <casey@schaufler-ca.com>
      Reviewed-by: NMimi Zohar <zohar@linux.ibm.com>
      Signed-off-by: NMimi Zohar <zohar@linux.ibm.com>
      9ff8a616
    • 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
    • L
      integrity: Add errno field in audit message · 2f845882
      Lakshmi Ramasubramanian 提交于
      Error code is not included in the audit messages logged by
      the integrity subsystem.
      
      Define a new function integrity_audit_message() that takes error code
      in the "errno" parameter. Add "errno" field in the audit messages logged
      by the integrity subsystem and set the value passed in the "errno"
      parameter.
      
      [    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
      
      [    7.987647] audit: type=1802 audit(1592506283.312:9): pid=1 uid=0 auid=4294967295 ses=4294967295 subj=system_u:system_r:init_t:s0 op=policy_update cause=completed comm="systemd" res=1 errno=0
      
      [    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: NSteve Grubb <sgrubb@redhat.com>
      Suggested-by: NMimi Zohar <zohar@linux.ibm.com>
      Signed-off-by: NMimi Zohar <zohar@linux.ibm.com>
      2f845882
  4. 08 7月, 2020 1 次提交
  5. 25 6月, 2020 1 次提交
  6. 16 6月, 2020 1 次提交
  7. 12 6月, 2020 1 次提交
  8. 08 6月, 2020 1 次提交
  9. 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
  10. 04 6月, 2020 2 次提交
    • R
      ima: Call ima_calc_boot_aggregate() in ima_eventdigest_init() · 6cc7c266
      Roberto Sassu 提交于
      If the template field 'd' is chosen and the digest to be added to the
      measurement entry was not calculated with SHA1 or MD5, it is
      recalculated with SHA1, by using the passed file descriptor. However, this
      cannot be done for boot_aggregate, because there is no file descriptor.
      
      This patch adds a call to ima_calc_boot_aggregate() in
      ima_eventdigest_init(), so that the digest can be recalculated also for the
      boot_aggregate entry.
      
      Cc: stable@vger.kernel.org # 3.13.x
      Fixes: 3ce1217d ("ima: define template fields library and new helpers")
      Reported-by: NTakashi Iwai <tiwai@suse.de>
      Signed-off-by: NRoberto Sassu <roberto.sassu@huawei.com>
      Signed-off-by: NMimi Zohar <zohar@linux.ibm.com>
      6cc7c266
    • R
      ima: Directly assign the ima_default_policy pointer to ima_rules · 067a436b
      Roberto Sassu 提交于
      This patch prevents the following oops:
      
      [   10.771813] BUG: kernel NULL pointer dereference, address: 0000000000000
      [...]
      [   10.779790] RIP: 0010:ima_match_policy+0xf7/0xb80
      [...]
      [   10.798576] Call Trace:
      [   10.798993]  ? ima_lsm_policy_change+0x2b0/0x2b0
      [   10.799753]  ? inode_init_owner+0x1a0/0x1a0
      [   10.800484]  ? _raw_spin_lock+0x7a/0xd0
      [   10.801592]  ima_must_appraise.part.0+0xb6/0xf0
      [   10.802313]  ? ima_fix_xattr.isra.0+0xd0/0xd0
      [   10.803167]  ima_must_appraise+0x4f/0x70
      [   10.804004]  ima_post_path_mknod+0x2e/0x80
      [   10.804800]  do_mknodat+0x396/0x3c0
      
      It occurs when there is a failure during IMA initialization, and
      ima_init_policy() is not called. IMA hooks still call ima_match_policy()
      but ima_rules is NULL. This patch prevents the crash by directly assigning
      the ima_default_policy pointer to ima_rules when ima_rules is defined. This
      wouldn't alter the existing behavior, as ima_rules is always set at the end
      of ima_init_policy().
      
      Cc: stable@vger.kernel.org # 3.7.x
      Fixes: 07f6a794 ("ima: add appraise action keywords and default rules")
      Reported-by: NTakashi Iwai <tiwai@suse.de>
      Signed-off-by: NRoberto Sassu <roberto.sassu@huawei.com>
      Signed-off-by: NMimi Zohar <zohar@linux.ibm.com>
      067a436b
  11. 23 5月, 2020 1 次提交
  12. 15 5月, 2020 1 次提交
  13. 08 5月, 2020 8 次提交
  14. 20 4月, 2020 4 次提交