* @pcr: pcr to extend the measurement
  * @func_data: func specific data, may be NULL
  * @buf_hash: measure buffer data hash
+ * @digest: buffer digest will be written to
+ * @digest_len: buffer length
  *
  * Based on policy, either the buffer data or buffer data hash is measured
  *
- * Return: 0 if the buffer has been successfully measured, a negative value
- * otherwise.
+ * Return: 0 if the buffer has been successfully measured, 1 if the digest
+ * has been written to the passed location but not added to a measurement entry,
+ * a negative value otherwise.
  */
 int process_buffer_measurement(struct user_namespace *mnt_userns,
                               struct inode *inode, const void *buf, int size,
                               const char *eventname, enum ima_hooks func,
                               int pcr, const char *func_data,
-                              bool buf_hash)
+                              bool buf_hash, u8 *digest, size_t digest_len)
 {
        int ret = 0;
        const char *audit_cause = "ENOMEM";
        int action = 0;
        u32 secid;
 
-       if (!ima_policy_flag)
+       if (digest && digest_len < digest_hash_len)
+               return -EINVAL;
+
+       if (!ima_policy_flag && !digest)
                return -ENOENT;
 
        template = ima_template_desc_buf();
                action = ima_get_action(mnt_userns, inode, current_cred(),
                                        secid, 0, func, &pcr, &template,
                                        func_data);
-               if (!(action & IMA_MEASURE))
+               if (!(action & IMA_MEASURE) && !digest)
                        return -ENOENT;
        }
 
                event_data.buf_len = digest_hash_len;
        }
 
+       if (digest)
+               memcpy(digest, iint.ima_hash->digest, digest_hash_len);
+
+       if (!ima_policy_flag || (func && !(action & IMA_MEASURE)))
+               return 1;
+
        ret = ima_alloc_init_template(&event_data, &entry, template);
        if (ret < 0) {
                audit_cause = "alloc_entry";
 
        process_buffer_measurement(file_mnt_user_ns(f.file), file_inode(f.file),
                                   buf, size, "kexec-cmdline", KEXEC_CMDLINE, 0,
-                                  NULL, false);
+                                  NULL, false, NULL, 0);
        fdput(f);
 }
 
  * @buf: pointer to buffer data
  * @buf_len: length of buffer data (in bytes)
  * @hash: measure buffer data hash
+ * @digest: buffer digest will be written to
+ * @digest_len: buffer length
  *
  * Measure data critical to the integrity of the kernel into the IMA log
  * and extend the pcr.  Examples of critical data could be various data
  * structures, policies, and states stored in kernel memory that can
  * impact the integrity of the system.
  *
- * Return: 0 if the buffer has been successfully measured, a negative value
- * otherwise.
+ * Return: 0 if the buffer has been successfully measured, 1 if the digest
+ * has been written to the passed location but not added to a measurement entry,
+ * a negative value otherwise.
  */
 int ima_measure_critical_data(const char *event_label,
                              const char *event_name,
                              const void *buf, size_t buf_len,
-                             bool hash)
+                             bool hash, u8 *digest, size_t digest_len)
 {
        if (!event_name || !event_label || !buf || !buf_len)
                return -ENOPARAM;
 
        return process_buffer_measurement(&init_user_ns, NULL, buf, buf_len,
                                          event_name, CRITICAL_DATA, 0,
-                                         event_label, hash);
+                                         event_label, hash, digest,
+                                         digest_len);
 }
 
 static int __init init_ima(void)