Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

tpm2-sessions: Open code tpm_buf_append_hmac_session()

Open code 'tpm_buf_append_hmac_session_opt' to the call site, as it only
masks a call sequence and does otherwise nothing particularly useful.

Signed-off-by: Jarkko Sakkinen <jarkko.sakkinen@opinsys.com>
Reviewed-by: Jonathan McDowell <noodles@meta.com>

authored by

Jarkko Sakkinen and committed by
Jarkko Sakkinen
b7960b90 bc677a92

+21 -28
+11 -3
drivers/char/tpm/tpm2-cmd.c
··· 282 282 283 283 do { 284 284 tpm_buf_reset(&buf, TPM2_ST_SESSIONS, TPM2_CC_GET_RANDOM); 285 - tpm_buf_append_hmac_session_opt(chip, &buf, TPM2_SA_ENCRYPT 286 - | TPM2_SA_CONTINUE_SESSION, 287 - NULL, 0); 285 + if (tpm2_chip_auth(chip)) { 286 + tpm_buf_append_hmac_session(chip, &buf, 287 + TPM2_SA_ENCRYPT | 288 + TPM2_SA_CONTINUE_SESSION, 289 + NULL, 0); 290 + } else { 291 + offset = buf.handles * 4 + TPM_HEADER_SIZE; 292 + head = (struct tpm_header *)buf.data; 293 + if (tpm_buf_length(&buf) == offset) 294 + head->tag = cpu_to_be16(TPM2_ST_NO_SESSIONS); 295 + } 288 296 tpm_buf_append_u16(&buf, num_bytes); 289 297 err = tpm_buf_fill_hmac_session(chip, &buf); 290 298 if (err) {
-23
include/linux/tpm.h
··· 536 536 int passphraselen); 537 537 void tpm_buf_append_auth(struct tpm_chip *chip, struct tpm_buf *buf, 538 538 u8 *passphrase, int passphraselen); 539 - static inline void tpm_buf_append_hmac_session_opt(struct tpm_chip *chip, 540 - struct tpm_buf *buf, 541 - u8 attributes, 542 - u8 *passphrase, 543 - int passphraselen) 544 - { 545 - struct tpm_header *head; 546 - int offset; 547 - 548 - if (tpm2_chip_auth(chip)) { 549 - tpm_buf_append_hmac_session(chip, buf, attributes, passphrase, passphraselen); 550 - } else { 551 - offset = buf->handles * 4 + TPM_HEADER_SIZE; 552 - head = (struct tpm_header *)buf->data; 553 - 554 - /* 555 - * If the only sessions are optional, the command tag must change to 556 - * TPM2_ST_NO_SESSIONS. 557 - */ 558 - if (tpm_buf_length(buf) == offset) 559 - head->tag = cpu_to_be16(TPM2_ST_NO_SESSIONS); 560 - } 561 - } 562 539 563 540 #ifdef CONFIG_TCG_TPM2_HMAC 564 541
+10 -2
security/keys/trusted-keys/trusted_tpm2.c
··· 481 481 struct trusted_key_options *options, 482 482 u32 blob_handle) 483 483 { 484 + struct tpm_header *head; 484 485 struct tpm_buf buf; 485 486 u16 data_len; 487 + int offset; 486 488 u8 *data; 487 489 int rc; 488 490 ··· 521 519 tpm2_buf_append_auth(&buf, options->policyhandle, 522 520 NULL /* nonce */, 0, 0, 523 521 options->blobauth, options->blobauth_len); 524 - tpm_buf_append_hmac_session_opt(chip, &buf, TPM2_SA_ENCRYPT, 525 - NULL, 0); 522 + if (tpm2_chip_auth(chip)) { 523 + tpm_buf_append_hmac_session(chip, &buf, TPM2_SA_ENCRYPT, NULL, 0); 524 + } else { 525 + offset = buf.handles * 4 + TPM_HEADER_SIZE; 526 + head = (struct tpm_header *)buf.data; 527 + if (tpm_buf_length(&buf) == offset) 528 + head->tag = cpu_to_be16(TPM2_ST_NO_SESSIONS); 529 + } 526 530 } 527 531 528 532 rc = tpm_buf_fill_hmac_session(chip, &buf);