1. 21 7月, 2020 7 次提交
  2. 17 7月, 2020 7 次提交
    • 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
  3. 04 6月, 2020 1 次提交
    • 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
  4. 08 5月, 2020 2 次提交
  5. 29 2月, 2020 1 次提交
  6. 23 1月, 2020 4 次提交
  7. 12 12月, 2019 3 次提交
    • L
      IMA: Read keyrings= option from the IMA policy · 2b60c0ec
      Lakshmi Ramasubramanian 提交于
      Read "keyrings=" option, if specified in the IMA policy, and store in
      the list of IMA rules when the configured IMA policy is read.
      
      This patch defines a new policy token enum namely Opt_keyrings
      and an option flag IMA_KEYRINGS for reading "keyrings=" option
      from the IMA policy.
      
      Updated ima_parse_rule() to parse "keyrings=" option in the policy.
      Updated ima_policy_show() to display "keyrings=" option.
      
      The following example illustrates how key measurement can be verified.
      
      Sample "key" measurement rule in the IMA policy:
      
      measure func=KEY_CHECK uid=0 keyrings=.ima|.evm template=ima-buf
      
      Display "key" measurement in the IMA measurement list:
      
      cat /sys/kernel/security/ima/ascii_runtime_measurements
      
      10 faf3...e702 ima-buf sha256:27c915b8ddb9fae7214cf0a8a7043cc3eeeaa7539bcb136f8427067b5f6c3b7b .ima 308202863082...4aee
      
      Verify "key" measurement data for a key added to ".ima" keyring:
      
      cat /sys/kernel/security/integrity/ima/ascii_runtime_measurements | grep -m 1 "\.ima" | cut -d' ' -f 6 | xxd -r -p |tee ima-cert.der | sha256sum | cut -d' ' -f 1
      
      The output of the above command should match the template hash
      of the first "key" measurement entry in the IMA measurement list for
      the key added to ".ima" keyring.
      
      The file namely "ima-cert.der" generated by the above command
      should be a valid x509 certificate (in DER format) and should match
      the one that was used to import the key to the ".ima" keyring.
      The certificate file can be verified using openssl tool.
      Signed-off-by: NLakshmi Ramasubramanian <nramas@linux.microsoft.com>
      Signed-off-by: NMimi Zohar <zohar@linux.ibm.com>
      2b60c0ec
    • 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: Add KEY_CHECK func to measure keys · 5808611c
      Lakshmi Ramasubramanian 提交于
      Measure keys loaded onto any keyring.
      
      This patch defines a new IMA policy func namely KEY_CHECK to
      measure keys. Updated ima_match_rules() to check for KEY_CHECK
      and ima_parse_rule() to handle KEY_CHECK.
      Signed-off-by: NLakshmi Ramasubramanian <nramas@linux.microsoft.com>
      Signed-off-by: NMimi Zohar <zohar@linux.ibm.com>
      5808611c
  8. 10 12月, 2019 1 次提交
  9. 12 11月, 2019 1 次提交
    • 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
  10. 20 8月, 2019 1 次提交
    • 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
  11. 06 8月, 2019 3 次提交
  12. 01 8月, 2019 1 次提交
    • M
      ima: initialize the "template" field with the default template · b36f281f
      Mimi Zohar 提交于
      IMA policy rules are walked sequentially.  Depending on the ordering of
      the policy rules, the "template" field might be defined in one rule, but
      will be replaced by subsequent, applicable rules, even if the rule does
      not explicitly define the "template" field.
      
      This patch initializes the "template" once and only replaces the
      "template", when explicitly defined.
      
      Fixes: 19453ce0 ("IMA: support for per policy rule template formats")
      Signed-off-by: NMimi Zohar <zohar@linux.ibm.com>
      b36f281f
  13. 24 6月, 2019 1 次提交
  14. 20 6月, 2019 1 次提交
  15. 14 6月, 2019 2 次提交
  16. 05 6月, 2019 1 次提交
  17. 30 5月, 2019 1 次提交
  18. 20 5月, 2019 1 次提交
  19. 23 2月, 2019 1 次提交
    • G
      security: mark expected switch fall-throughs and add a missing break · 09186e50
      Gustavo A. R. Silva 提交于
      In preparation to enabling -Wimplicit-fallthrough, mark switch
      cases where we are expecting to fall through.
      
      This patch fixes the following warnings:
      
      security/integrity/ima/ima_template_lib.c:85:10: warning: this statement may fall through [-Wimplicit-fallthrough=]
      security/integrity/ima/ima_policy.c:940:18: warning: this statement may fall through [-Wimplicit-fallthrough=]
      security/integrity/ima/ima_policy.c:943:7: warning: this statement may fall through [-Wimplicit-fallthrough=]
      security/integrity/ima/ima_policy.c:972:21: warning: this statement may fall through [-Wimplicit-fallthrough=]
      security/integrity/ima/ima_policy.c:974:7: warning: this statement may fall through [-Wimplicit-fallthrough=]
      security/smack/smack_lsm.c:3391:9: warning: this statement may fall through [-Wimplicit-fallthrough=]
      security/apparmor/domain.c:569:6: warning: this statement may fall through [-Wimplicit-fallthrough=]
      
      Warning level 3 was used: -Wimplicit-fallthrough=3
      
      Also, add a missing break statement to fix the following warning:
      
      security/integrity/ima/ima_appraise.c:116:26: warning: this statement may fall through [-Wimplicit-fallthrough=]
      Acked-by: NJohn Johansen <john.johansen@canonical.com>
      Acked-by: NCasey Schaufler <casey@schaufler-ca.com>
      Signed-off-by: NGustavo A. R. Silva <gustavo@embeddedor.com>
      Acked-by: NMimi Zohar <zohar@linux.ibm.com>
      Signed-off-by: NJames Morris <james.morris@microsoft.com>
      09186e50