Skip to content

Commit 6519fea

Browse files
jejbjarkkojs
authored andcommitted
tpm: add hmac checks to tpm2_pcr_extend()
tpm2_pcr_extend() is used by trusted keys to extend a PCR to prevent a key from being re-loaded until the next reboot. To use this functionality securely, that extend must be protected by a session hmac. This patch adds HMAC protection so tampering with the tpm2_pcr_extend() command in flight is detected. Signed-off-by: James Bottomley <James.Bottomley@HansenPartnership.com> Reviewed-by: Jarkko Sakkinen <jarkko@kernel.org> Tested-by: Jarkko Sakkinen <jarkko@kernel.org> Signed-off-by: Jarkko Sakkinen <jarkko@kernel.org>
1 parent 1085b82 commit 6519fea

1 file changed

Lines changed: 10 additions & 17 deletions

File tree

drivers/char/tpm/tpm2-cmd.c

Lines changed: 10 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -216,13 +216,6 @@ int tpm2_pcr_read(struct tpm_chip *chip, u32 pcr_idx,
216216
return rc;
217217
}
218218

219-
struct tpm2_null_auth_area {
220-
__be32 handle;
221-
__be16 nonce_size;
222-
u8 attributes;
223-
__be16 auth_size;
224-
} __packed;
225-
226219
/**
227220
* tpm2_pcr_extend() - extend a PCR value
228221
*
@@ -236,24 +229,22 @@ int tpm2_pcr_extend(struct tpm_chip *chip, u32 pcr_idx,
236229
struct tpm_digest *digests)
237230
{
238231
struct tpm_buf buf;
239-
struct tpm2_null_auth_area auth_area;
240232
int rc;
241233
int i;
242234

243-
rc = tpm_buf_init(&buf, TPM2_ST_SESSIONS, TPM2_CC_PCR_EXTEND);
235+
rc = tpm2_start_auth_session(chip);
244236
if (rc)
245237
return rc;
246238

247-
tpm_buf_append_u32(&buf, pcr_idx);
239+
rc = tpm_buf_init(&buf, TPM2_ST_SESSIONS, TPM2_CC_PCR_EXTEND);
240+
if (rc) {
241+
tpm2_end_auth_session(chip);
242+
return rc;
243+
}
248244

249-
auth_area.handle = cpu_to_be32(TPM2_RS_PW);
250-
auth_area.nonce_size = 0;
251-
auth_area.attributes = 0;
252-
auth_area.auth_size = 0;
245+
tpm_buf_append_name(chip, &buf, pcr_idx, NULL);
246+
tpm_buf_append_hmac_session(chip, &buf, 0, NULL, 0);
253247

254-
tpm_buf_append_u32(&buf, sizeof(struct tpm2_null_auth_area));
255-
tpm_buf_append(&buf, (const unsigned char *)&auth_area,
256-
sizeof(auth_area));
257248
tpm_buf_append_u32(&buf, chip->nr_allocated_banks);
258249

259250
for (i = 0; i < chip->nr_allocated_banks; i++) {
@@ -262,7 +253,9 @@ int tpm2_pcr_extend(struct tpm_chip *chip, u32 pcr_idx,
262253
chip->allocated_banks[i].digest_size);
263254
}
264255

256+
tpm_buf_fill_hmac_session(chip, &buf);
265257
rc = tpm_transmit_cmd(chip, &buf, 0, "attempting extend a PCR value");
258+
rc = tpm_buf_check_hmac_response(chip, &buf, rc);
266259

267260
tpm_buf_destroy(&buf);
268261

0 commit comments

Comments
 (0)