On Fri, Nov 11, 2022 at 03:16:31PM -0800, Evan Green wrote: > security: keys: trusted: Verify creation data > > If a loaded key contains creation data, ask the TPM to verify that > creation data. This allows users like encrypted hibernate to know that > the loaded and parsed creation data has not been tampered with. I don't understand what the purpose of this is. I thought that the way to "seal" a key to a TPM PCR is to include the PCR in the "policy". Are you doing that too? What is the purpose of using the "creation data"? > + /* Auth */ > + tpm_buf_append_u32(&buf, 9); > + tpm_buf_append_u32(&buf, TPM2_RS_PW); > + tpm_buf_append_u16(&buf, 0); > + tpm_buf_append_u8(&buf, 0); > + tpm_buf_append_u16(&buf, 0); This is struct tpm2_null_auth_area, so this is another place that could take advantage of a new helper function to append it. > + /* Creation data hash */ > + if (payload->creation_hash_len < 2) { > + rc = -EINVAL; > + goto out; > + } > + > + tpm_buf_append_u16(&buf, payload->creation_hash_len - 2); > + tpm_buf_append(&buf, payload->creation_hash + 2, > + payload->creation_hash_len - 2); So the first two bytes of creation_hash are a redundant length field that needs to be ignored here? Perhaps tpm2_key_encode() shouldn't include that redundant length field? > + > + /* signature scheme */ > + tpm_buf_append_u16(&buf, TPM_ALG_NULL); > + > + /* creation ticket */ > + tpm_buf_append(&buf, payload->tk, payload->tk_len); > + > + rc = tpm_transmit_cmd(chip, &buf, 6, "certifying creation data"); > + if (rc) > + goto out; This is another instance of the bug where a positive TPM2_RC_* code is being returned from a function that is supposed to return a negative errno value. - Eric