1. 11 8月, 2021 1 次提交
    • T
      dm ima: measure data on table load · 91ccbbac
      Tushar Sugandhi 提交于
      DM configures a block device with various target specific attributes
      passed to it as a table.  DM loads the table, and calls each target’s
      respective constructors with the attributes as input parameters.
      Some of these attributes are critical to ensure the device meets
      certain security bar.  Thus, IMA should measure these attributes, to
      ensure they are not tampered with, during the lifetime of the device.
      So that the external services can have high confidence in the
      configuration of the block-devices on a given system.
      
      Some devices may have large tables.  And a given device may change its
      state (table-load, suspend, resume, rename, remove, table-clear etc.)
      many times.  Measuring these attributes each time when the device
      changes its state will significantly increase the size of the IMA logs.
      Further, once configured, these attributes are not expected to change
      unless a new table is loaded, or a device is removed and recreated.
      Therefore the clear-text of the attributes should only be measured
      during table load, and the hash of the active/inactive table should be
      measured for the remaining device state changes.
      
      Export IMA function ima_measure_critical_data() to allow measurement
      of DM device parameters, as well as target specific attributes, during
      table load.  Compute the hash of the inactive table and store it for
      measurements during future state change.  If a load is called multiple
      times, update the inactive table hash with the hash of the latest
      populated table.  So that the correct inactive table hash is measured
      when the device transitions to different states like resume, remove,
      rename, etc.
      Signed-off-by: NTushar Sugandhi <tusharsu@linux.microsoft.com>
      Signed-off-by: Colin Ian King <colin.king@canonical.com> # leak fix
      Signed-off-by: NMike Snitzer <snitzer@redhat.com>
      91ccbbac
  2. 09 6月, 2021 1 次提交
  3. 21 4月, 2021 1 次提交
  4. 10 4月, 2021 1 次提交
  5. 23 3月, 2021 2 次提交
    • P
      lsm: separate security_task_getsecid() into subjective and objective variants · 4ebd7651
      Paul Moore 提交于
      Of the three LSMs that implement the security_task_getsecid() LSM
      hook, all three LSMs provide the task's objective security
      credentials.  This turns out to be unfortunate as most of the hook's
      callers seem to expect the task's subjective credentials, although
      a small handful of callers do correctly expect the objective
      credentials.
      
      This patch is the first step towards fixing the problem: it splits
      the existing security_task_getsecid() hook into two variants, one
      for the subjective creds, one for the objective creds.
      
        void security_task_getsecid_subj(struct task_struct *p,
      				   u32 *secid);
        void security_task_getsecid_obj(struct task_struct *p,
      				  u32 *secid);
      
      While this patch does fix all of the callers to use the correct
      variant, in order to keep this patch focused on the callers and to
      ease review, the LSMs continue to use the same implementation for
      both hooks.  The net effect is that this patch should not change
      the behavior of the kernel in any way, it will be up to the latter
      LSM specific patches in this series to change the hook
      implementations and return the correct credentials.
      
      Acked-by: Mimi Zohar <zohar@linux.ibm.com> (IMA)
      Acked-by: NCasey Schaufler <casey@schaufler-ca.com>
      Reviewed-by: NRichard Guy Briggs <rgb@redhat.com>
      Signed-off-by: NPaul Moore <paul@paul-moore.com>
      4ebd7651
    • M
      ima: without an IMA policy loaded, return quickly · f873b28f
      Mimi Zohar 提交于
      Unless an IMA policy is loaded, don't bother checking for an appraise
      policy rule.  Return immediately.
      Signed-off-by: NMimi Zohar <zohar@linux.ibm.com>
      f873b28f
  6. 24 1月, 2021 1 次提交
  7. 15 1月, 2021 4 次提交
  8. 26 11月, 2020 1 次提交
  9. 21 11月, 2020 1 次提交
    • L
      ima: select ima-buf template for buffer measurement · dea87d08
      Lakshmi Ramasubramanian 提交于
      The default IMA template used for all policy rules is the value set
      for CONFIG_IMA_DEFAULT_TEMPLATE if the policy rule does not specify
      a template. The default IMA template for buffer measurements should be
      'ima-buf' - so that the measured buffer is correctly included in the IMA
      measurement log entry.
      
      With the default template format, buffer measurements are added to
      the measurement list, but do not include the buffer data, making it
      difficult, if not impossible, to validate. Including 'ima-buf'
      template records in the measurement list by default, should not impact
      existing attestation servers without 'ima-buf' template support.
      
      Initialize a global 'ima-buf' template and select that template,
      by default, for buffer measurements.
      Signed-off-by: NLakshmi Ramasubramanian <nramas@linux.microsoft.com>
      Signed-off-by: NMimi Zohar <zohar@linux.ibm.com>
      dea87d08
  10. 03 11月, 2020 1 次提交
    • A
      ima: defer arch_ima_get_secureboot() call to IMA init time · b000d5cb
      Ard Biesheuvel 提交于
      Chester reports that it is necessary to introduce a new way to pass
      the EFI secure boot status between the EFI stub and the core kernel
      on ARM systems. The usual way of obtaining this information is by
      checking the SecureBoot and SetupMode EFI variables, but this can
      only be done after the EFI variable workqueue is created, which
      occurs in a subsys_initcall(), whereas arch_ima_get_secureboot()
      is called much earlier by the IMA framework.
      
      However, the IMA framework itself is started as a late_initcall,
      and the only reason the call to arch_ima_get_secureboot() occurs
      so early is because it happens in the context of a __setup()
      callback that parses the ima_appraise= command line parameter.
      
      So let's refactor this code a little bit, by using a core_param()
      callback to capture the command line argument, and deferring any
      reasoning based on its contents to the IMA init routine.
      
      Cc: Chester Lin <clin@suse.com>
      Cc: Dmitry Kasatkin <dmitry.kasatkin@gmail.com>
      Cc: James Morris <jmorris@namei.org>
      Cc: "Serge E. Hallyn" <serge@hallyn.com>
      Link: https://lore.kernel.org/linux-arm-kernel/20200904072905.25332-2-clin@suse.com/Signed-off-by: NArd Biesheuvel <ardb@kernel.org>
      Reported-by: kernel test robot <lkp@intel.com> [missing core_param()]
      [zohar@linux.ibm.com: included linux/module.h]
      Tested-by: NChester Lin <clin@suse.com>
      Signed-off-by: NMimi Zohar <zohar@linux.ibm.com>
      b000d5cb
  11. 05 10月, 2020 6 次提交
  12. 17 9月, 2020 1 次提交
    • K
      ima: Fix NULL pointer dereference in ima_file_hash · aa662fc0
      KP Singh 提交于
      ima_file_hash can be called when there is no iint->ima_hash available
      even though the inode exists in the integrity cache. It is fairly
      common for a file to not have a hash. (e.g. an mknodat, prior to the
      file being closed).
      
      Another example where this can happen (suggested by Jann Horn):
      
      Process A does:
      
      	while(1) {
      		unlink("/tmp/imafoo");
      		fd = open("/tmp/imafoo", O_RDWR|O_CREAT|O_TRUNC, 0700);
      		if (fd == -1) {
      			perror("open");
      			continue;
      		}
      		write(fd, "A", 1);
      		close(fd);
      	}
      
      and Process B does:
      
      	while (1) {
      		int fd = open("/tmp/imafoo", O_RDONLY);
      		if (fd == -1)
      			continue;
          		char *mapping = mmap(NULL, 0x1000, PROT_READ|PROT_EXEC,
      			 	     MAP_PRIVATE, fd, 0);
      		if (mapping != MAP_FAILED)
      			munmap(mapping, 0x1000);
      		close(fd);
        	}
      
      Due to the race to get the iint->mutex between ima_file_hash and
      process_measurement iint->ima_hash could still be NULL.
      
      Fixes: 6beea7af ("ima: add the ability to query the cached hash of a given file")
      Signed-off-by: NKP Singh <kpsingh@google.com>
      Reviewed-by: NFlorent Revest <revest@chromium.org>
      Signed-off-by: NMimi Zohar <zohar@linux.ibm.com>
      aa662fc0
  13. 09 9月, 2020 1 次提交
  14. 21 7月, 2020 1 次提交
    • T
      ima: Support additional conditionals in the KEXEC_CMDLINE hook function · 4834177e
      Tyler Hicks 提交于
      Take the properties of the kexec kernel's inode and the current task
      ownership into consideration when matching a KEXEC_CMDLINE operation to
      the rules in the IMA policy. This allows for some uniformity when
      writing IMA policy rules for KEXEC_KERNEL_CHECK, KEXEC_INITRAMFS_CHECK,
      and KEXEC_CMDLINE operations.
      
      Prior to this patch, it was not possible to write a set of rules like
      this:
      
       dont_measure func=KEXEC_KERNEL_CHECK obj_type=foo_t
       dont_measure func=KEXEC_INITRAMFS_CHECK obj_type=foo_t
       dont_measure func=KEXEC_CMDLINE obj_type=foo_t
       measure func=KEXEC_KERNEL_CHECK
       measure func=KEXEC_INITRAMFS_CHECK
       measure func=KEXEC_CMDLINE
      
      The inode information associated with the kernel being loaded by a
      kexec_kernel_load(2) syscall can now be included in the decision to
      measure or not
      
      Additonally, the uid, euid, and subj_* conditionals can also now be
      used in KEXEC_CMDLINE rules. There was no technical reason as to why
      those conditionals weren't being considered previously other than
      ima_match_rules() didn't have a valid inode to use so it immediately
      bailed out for KEXEC_CMDLINE operations rather than going through the
      full list of conditional comparisons.
      Signed-off-by: NTyler Hicks <tyhicks@linux.microsoft.com>
      Cc: Eric Biederman <ebiederm@xmission.com>
      Cc: kexec@lists.infradead.org
      Reviewed-by: NLakshmi Ramasubramanian <nramas@linux.microsoft.com>
      Signed-off-by: NMimi Zohar <zohar@linux.ibm.com>
      4834177e
  15. 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
  16. 12 6月, 2020 1 次提交
  17. 23 5月, 2020 1 次提交
  18. 20 4月, 2020 1 次提交
  19. 29 2月, 2020 2 次提交
  20. 23 1月, 2020 1 次提交
  21. 12 12月, 2019 2 次提交
    • L
      IMA: Add support to limit measuring keys · e9085e0a
      Lakshmi Ramasubramanian 提交于
      Limit measuring keys to those keys being loaded onto a given set of
      keyrings only and when the user id (uid) matches if uid is specified
      in the policy.
      
      This patch defines a new IMA policy option namely "keyrings=" that
      can be used to specify a set of keyrings. If this option is specified
      in the policy for "measure func=KEY_CHECK" then only the keys
      loaded onto a keyring given in the "keyrings=" option are measured.
      
      If uid is specified in the policy then the key is measured only if
      the current user id matches the one specified in the policy.
      
      Added a new parameter namely "keyring" (name of the keyring) to
      process_buffer_measurement(). The keyring name is passed to
      ima_get_action() to determine the required action.
      ima_match_rules() is updated to check keyring in the policy, if
      specified, for KEY_CHECK function.
      Signed-off-by: NLakshmi Ramasubramanian <nramas@linux.microsoft.com>
      Signed-off-by: NMimi Zohar <zohar@linux.ibm.com>
      e9085e0a
    • L
      IMA: Check IMA policy flag · c5563bad
      Lakshmi Ramasubramanian 提交于
      process_buffer_measurement() may be called prior to IMA being
      initialized (for instance, when the IMA hook is called when
      a key is added to the .builtin_trusted_keys keyring), which
      would result in a kernel panic.
      
      This patch adds the check in process_buffer_measurement()
      to return immediately if IMA is not initialized yet.
      Signed-off-by: NLakshmi Ramasubramanian <nramas@linux.microsoft.com>
      Signed-off-by: NMimi Zohar <zohar@linux.ibm.com>
      c5563bad
  22. 12 11月, 2019 2 次提交
    • N
      ima: Check against blacklisted hashes for files with modsig · 273df864
      Nayna Jain 提交于
      Asymmetric private keys are used to sign multiple files. The kernel
      currently supports checking against blacklisted keys. However, if the
      public key is blacklisted, any file signed by the blacklisted key will
      automatically fail signature verification. Blacklisting the public key
      is not fine enough granularity, as we might want to only blacklist a
      particular file.
      
      This patch adds support for checking against the blacklisted hash of
      the file, without the appended signature, based on the IMA policy. It
      defines a new policy option "appraise_flag=check_blacklist".
      
      In addition to the blacklisted binary hashes stored in the firmware
      "dbx" variable, the Linux kernel may be configured to load blacklisted
      binary hashes onto the .blacklist keyring as well. The following
      example shows how to blacklist a specific kernel module hash.
      
        $ sha256sum kernel/kheaders.ko
        77fa889b35a05338ec52e51591c1b89d4c8d1c99a21251d7c22b1a8642a6bad3
        kernel/kheaders.ko
      
        $ grep BLACKLIST .config
        CONFIG_SYSTEM_BLACKLIST_KEYRING=y
        CONFIG_SYSTEM_BLACKLIST_HASH_LIST="blacklist-hash-list"
      
        $ cat certs/blacklist-hash-list
        "bin:77fa889b35a05338ec52e51591c1b89d4c8d1c99a21251d7c22b1a8642a6bad3"
      
      Update the IMA custom measurement and appraisal policy
      rules (/etc/ima-policy):
      
        measure func=MODULE_CHECK template=ima-modsig
        appraise func=MODULE_CHECK appraise_flag=check_blacklist
        appraise_type=imasig|modsig
      
      After building, installing, and rebooting the kernel:
      
         545660333 ---lswrv      0     0   \_ blacklist:
        bin:77fa889b35a05338ec52e51591c1b89d4c8d1c99a21251d7c22b1a8642a6bad3
      
        measure func=MODULE_CHECK template=ima-modsig
        appraise func=MODULE_CHECK appraise_flag=check_blacklist
        appraise_type=imasig|modsig
      
        modprobe: ERROR: could not insert 'kheaders': Permission denied
      
        10 0c9834db5a0182c1fb0cdc5d3adcf11a11fd83dd ima-sig
        sha256:3bc6ed4f0b4d6e31bc1dbc9ef844605abc7afdc6d81a57d77a1ec9407997c40
        2 /usr/lib/modules/5.4.0-rc3+/kernel/kernel/kheaders.ko
      
        10 82aad2bcc3fa8ed94762356b5c14838f3bcfa6a0 ima-modsig
        sha256:3bc6ed4f0b4d6e31bc1dbc9ef844605abc7afdc6d81a57d77a1ec9407997c40
        2 /usr/lib/modules/5.4.0rc3+/kernel/kernel/kheaders.ko  sha256:77fa889b3
        5a05338ec52e51591c1b89d4c8d1c99a21251d7c22b1a8642a6bad3
        3082029a06092a864886f70d010702a082028b30820287020101310d300b0609608648
        016503040201300b06092a864886f70d01070131820264....
      
        10 25b72217cc1152b44b134ce2cd68f12dfb71acb3 ima-buf
        sha256:8b58427fedcf8f4b20bc8dc007f2e232bf7285d7b93a66476321f9c2a3aa132
        b blacklisted-hash
        77fa889b35a05338ec52e51591c1b89d4c8d1c99a21251d7c22b1a8642a6bad3
      Signed-off-by: NNayna Jain <nayna@linux.ibm.com>
      [zohar@linux.ibm.com: updated patch description]
      Signed-off-by: NMimi Zohar <zohar@linux.ibm.com>
      Signed-off-by: NMichael Ellerman <mpe@ellerman.id.au>
      Link: https://lore.kernel.org/r/1572492694-6520-8-git-send-email-zohar@linux.ibm.com
      273df864
    • N
      ima: Make process_buffer_measurement() generic · e14555e3
      Nayna Jain 提交于
      process_buffer_measurement() is limited to measuring the kexec boot
      command line. This patch makes process_buffer_measurement() more
      generic, allowing it to measure other types of buffer data (e.g.
      blacklisted binary hashes or key hashes).
      
      process_buffer_measurement() may be called directly from an IMA hook
      or as an auxiliary measurement record. In both cases the buffer
      measurement is based on policy. This patch modifies the function to
      conditionally retrieve the policy defined PCR and template for the IMA
      hook case.
      Signed-off-by: NNayna Jain <nayna@linux.ibm.com>
      [zohar@linux.ibm.com: added comment in process_buffer_measurement()]
      Signed-off-by: NMimi Zohar <zohar@linux.ibm.com>
      Signed-off-by: NMichael Ellerman <mpe@ellerman.id.au>
      Link: https://lore.kernel.org/r/1572492694-6520-6-git-send-email-zohar@linux.ibm.com
      e14555e3
  23. 20 8月, 2019 2 次提交
    • M
      kexec: Allow kexec_file() with appropriate IMA policy when locked down · 29d3c1c8
      Matthew Garrett 提交于
      Systems in lockdown mode should block the kexec of untrusted kernels.
      For x86 and ARM we can ensure that a kernel is trustworthy by validating
      a PE signature, but this isn't possible on other architectures. On those
      platforms we can use IMA digital signatures instead. Add a function to
      determine whether IMA has or will verify signatures for a given event type,
      and if so permit kexec_file() even if the kernel is otherwise locked down.
      This is restricted to cases where CONFIG_INTEGRITY_TRUSTED_KEYRING is set
      in order to prevent an attacker from loading additional keys at runtime.
      Signed-off-by: NMatthew Garrett <mjg59@google.com>
      Acked-by: NMimi Zohar <zohar@linux.ibm.com>
      Cc: Dmitry Kasatkin <dmitry.kasatkin@gmail.com>
      Cc: linux-integrity@vger.kernel.org
      Signed-off-by: NJames Morris <jmorris@namei.org>
      29d3c1c8
    • J
      kexec_file: split KEXEC_VERIFY_SIG into KEXEC_SIG and KEXEC_SIG_FORCE · 99d5cadf
      Jiri Bohac 提交于
      This is a preparatory patch for kexec_file_load() lockdown.  A locked down
      kernel needs to prevent unsigned kernel images from being loaded with
      kexec_file_load().  Currently, the only way to force the signature
      verification is compiling with KEXEC_VERIFY_SIG.  This prevents loading
      usigned images even when the kernel is not locked down at runtime.
      
      This patch splits KEXEC_VERIFY_SIG into KEXEC_SIG and KEXEC_SIG_FORCE.
      Analogous to the MODULE_SIG and MODULE_SIG_FORCE for modules, KEXEC_SIG
      turns on the signature verification but allows unsigned images to be
      loaded.  KEXEC_SIG_FORCE disallows images without a valid signature.
      Signed-off-by: NJiri Bohac <jbohac@suse.cz>
      Signed-off-by: NDavid Howells <dhowells@redhat.com>
      Signed-off-by: NMatthew Garrett <mjg59@google.com>
      cc: kexec@lists.infradead.org
      Signed-off-by: NJames Morris <jmorris@namei.org>
      99d5cadf
  24. 06 8月, 2019 4 次提交