Skip to content

Commit b7960b9

Browse files
committed
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>
1 parent bc677a9 commit b7960b9

3 files changed

Lines changed: 21 additions & 28 deletions

File tree

drivers/char/tpm/tpm2-cmd.c

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -282,9 +282,17 @@ int tpm2_get_random(struct tpm_chip *chip, u8 *dest, size_t max)
282282

283283
do {
284284
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+
}
288296
tpm_buf_append_u16(&buf, num_bytes);
289297
err = tpm_buf_fill_hmac_session(chip, &buf);
290298
if (err) {

include/linux/tpm.h

Lines changed: 0 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -536,29 +536,6 @@ void tpm_buf_append_hmac_session(struct tpm_chip *chip, struct tpm_buf *buf,
536536
int passphraselen);
537537
void tpm_buf_append_auth(struct tpm_chip *chip, struct tpm_buf *buf,
538538
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-
}
562539

563540
#ifdef CONFIG_TCG_TPM2_HMAC
564541

security/keys/trusted-keys/trusted_tpm2.c

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -481,8 +481,10 @@ static int tpm2_unseal_cmd(struct tpm_chip *chip,
481481
struct trusted_key_options *options,
482482
u32 blob_handle)
483483
{
484+
struct tpm_header *head;
484485
struct tpm_buf buf;
485486
u16 data_len;
487+
int offset;
486488
u8 *data;
487489
int rc;
488490

@@ -519,8 +521,14 @@ static int tpm2_unseal_cmd(struct tpm_chip *chip,
519521
tpm2_buf_append_auth(&buf, options->policyhandle,
520522
NULL /* nonce */, 0, 0,
521523
options->blobauth, options->blobauth_len);
522-
tpm_buf_append_hmac_session_opt(chip, &buf, TPM2_SA_ENCRYPT,
523-
NULL, 0);
524+
if (tpm2_chip_auth(chip)) {
525+
tpm_buf_append_hmac_session(chip, &buf, TPM2_SA_ENCRYPT, NULL, 0);
526+
} else {
527+
offset = buf.handles * 4 + TPM_HEADER_SIZE;
528+
head = (struct tpm_header *)buf.data;
529+
if (tpm_buf_length(&buf) == offset)
530+
head->tag = cpu_to_be16(TPM2_ST_NO_SESSIONS);
531+
}
524532
}
525533

526534
rc = tpm_buf_fill_hmac_session(chip, &buf);

0 commit comments

Comments
 (0)