1. 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
  2. 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
  3. 08 5月, 2020 2 次提交
  4. 29 2月, 2020 1 次提交
  5. 23 1月, 2020 4 次提交
  6. 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
  7. 10 12月, 2019 1 次提交
  8. 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
  9. 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
  10. 06 8月, 2019 3 次提交
  11. 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
  12. 24 6月, 2019 1 次提交
  13. 20 6月, 2019 1 次提交
  14. 14 6月, 2019 2 次提交
  15. 05 6月, 2019 1 次提交
  16. 30 5月, 2019 1 次提交
  17. 20 5月, 2019 1 次提交
  18. 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
  19. 01 2月, 2019 1 次提交
  20. 18 12月, 2018 1 次提交
  21. 13 12月, 2018 1 次提交
    • P
      security: audit and remove any unnecessary uses of module.h · 876979c9
      Paul Gortmaker 提交于
      Historically a lot of these existed because we did not have
      a distinction between what was modular code and what was providing
      support to modules via EXPORT_SYMBOL and friends.  That changed
      when we forked out support for the latter into the export.h file.
      This means we should be able to reduce the usage of module.h
      in code that is obj-y Makefile or bool Kconfig.
      
      The advantage in removing such instances is that module.h itself
      sources about 15 other headers; adding significantly to what we feed
      cpp, and it can obscure what headers we are effectively using.
      
      Since module.h might have been the implicit source for init.h
      (for __init) and for export.h (for EXPORT_SYMBOL) we consider each
      instance for the presence of either and replace as needed.
      
      Cc: James Morris <jmorris@namei.org>
      Cc: "Serge E. Hallyn" <serge@hallyn.com>
      Cc: John Johansen <john.johansen@canonical.com>
      Cc: Mimi Zohar <zohar@linux.ibm.com>
      Cc: Dmitry Kasatkin <dmitry.kasatkin@gmail.com>
      Cc: David Howells <dhowells@redhat.com>
      Cc: linux-security-module@vger.kernel.org
      Cc: linux-integrity@vger.kernel.org
      Cc: keyrings@vger.kernel.org
      Signed-off-by: NPaul Gortmaker <paul.gortmaker@windriver.com>
      Signed-off-by: NJames Morris <james.morris@microsoft.com>
      876979c9
  22. 11 12月, 2018 3 次提交
  23. 18 7月, 2018 4 次提交
  24. 17 7月, 2018 2 次提交
  25. 31 5月, 2018 1 次提交