Skip to content

Commit 546bce5

Browse files
committed
Merge tag 'tpmdd-next-6.15-rc7' of git://git.kernel.org/pub/scm/linux/kernel/git/jarkko/linux-tpmdd
Pull tpm fixes from Jarkko Sakkinen: "A few last minute fixes for v6.15" * tag 'tpmdd-next-6.15-rc7' of git://git.kernel.org/pub/scm/linux/kernel/git/jarkko/linux-tpmdd: tpm: tis: Double the timeout B to 4s char: tpm: tpm-buf: Add sanity check fallback in read helpers tpm: Mask TPM RC in tpm2_start_auth_session()
2 parents 74a6325 + 2f661f7 commit 546bce5

File tree

4 files changed

+30
-19
lines changed

4 files changed

+30
-19
lines changed

drivers/char/tpm/tpm-buf.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -201,7 +201,7 @@ static void tpm_buf_read(struct tpm_buf *buf, off_t *offset, size_t count, void
201201
*/
202202
u8 tpm_buf_read_u8(struct tpm_buf *buf, off_t *offset)
203203
{
204-
u8 value;
204+
u8 value = 0;
205205

206206
tpm_buf_read(buf, offset, sizeof(value), &value);
207207

@@ -218,7 +218,7 @@ EXPORT_SYMBOL_GPL(tpm_buf_read_u8);
218218
*/
219219
u16 tpm_buf_read_u16(struct tpm_buf *buf, off_t *offset)
220220
{
221-
u16 value;
221+
u16 value = 0;
222222

223223
tpm_buf_read(buf, offset, sizeof(value), &value);
224224

@@ -235,7 +235,7 @@ EXPORT_SYMBOL_GPL(tpm_buf_read_u16);
235235
*/
236236
u32 tpm_buf_read_u32(struct tpm_buf *buf, off_t *offset)
237237
{
238-
u32 value;
238+
u32 value = 0;
239239

240240
tpm_buf_read(buf, offset, sizeof(value), &value);
241241

drivers/char/tpm/tpm2-sessions.c

Lines changed: 6 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -40,11 +40,6 @@
4040
*
4141
* These are the usage functions:
4242
*
43-
* tpm2_start_auth_session() which allocates the opaque auth structure
44-
* and gets a session from the TPM. This must be called before
45-
* any of the following functions. The session is protected by a
46-
* session_key which is derived from a random salt value
47-
* encrypted to the NULL seed.
4843
* tpm2_end_auth_session() kills the session and frees the resources.
4944
* Under normal operation this function is done by
5045
* tpm_buf_check_hmac_response(), so this is only to be used on
@@ -963,16 +958,13 @@ static int tpm2_load_null(struct tpm_chip *chip, u32 *null_key)
963958
}
964959

965960
/**
966-
* tpm2_start_auth_session() - create a HMAC authentication session with the TPM
967-
* @chip: the TPM chip structure to create the session with
961+
* tpm2_start_auth_session() - Create an a HMAC authentication session
962+
* @chip: A TPM chip
968963
*
969-
* This function loads the NULL seed from its saved context and starts
970-
* an authentication session on the null seed, fills in the
971-
* @chip->auth structure to contain all the session details necessary
972-
* for performing the HMAC, encrypt and decrypt operations and
973-
* returns. The NULL seed is flushed before this function returns.
964+
* Loads the ephemeral key (null seed), and starts an HMAC authenticated
965+
* session. The null seed is flushed before the return.
974966
*
975-
* Return: zero on success or actual error encountered.
967+
* Returns zero on success, or a POSIX error code.
976968
*/
977969
int tpm2_start_auth_session(struct tpm_chip *chip)
978970
{
@@ -1024,7 +1016,7 @@ int tpm2_start_auth_session(struct tpm_chip *chip)
10241016
/* hash algorithm for session */
10251017
tpm_buf_append_u16(&buf, TPM_ALG_SHA256);
10261018

1027-
rc = tpm_transmit_cmd(chip, &buf, 0, "start auth session");
1019+
rc = tpm_ret_to_err(tpm_transmit_cmd(chip, &buf, 0, "StartAuthSession"));
10281020
tpm2_flush_context(chip, null_key);
10291021

10301022
if (rc == TPM2_RC_SUCCESS)

drivers/char/tpm/tpm_tis_core.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ enum tis_int_flags {
5454
enum tis_defaults {
5555
TIS_MEM_LEN = 0x5000,
5656
TIS_SHORT_TIMEOUT = 750, /* ms */
57-
TIS_LONG_TIMEOUT = 2000, /* 2 sec */
57+
TIS_LONG_TIMEOUT = 4000, /* 4 secs */
5858
TIS_TIMEOUT_MIN_ATML = 14700, /* usecs */
5959
TIS_TIMEOUT_MAX_ATML = 15000, /* usecs */
6060
};

include/linux/tpm.h

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -224,7 +224,7 @@ enum tpm2_const {
224224

225225
enum tpm2_timeouts {
226226
TPM2_TIMEOUT_A = 750,
227-
TPM2_TIMEOUT_B = 2000,
227+
TPM2_TIMEOUT_B = 4000,
228228
TPM2_TIMEOUT_C = 200,
229229
TPM2_TIMEOUT_D = 30,
230230
TPM2_DURATION_SHORT = 20,
@@ -257,6 +257,7 @@ enum tpm2_return_codes {
257257
TPM2_RC_TESTING = 0x090A, /* RC_WARN */
258258
TPM2_RC_REFERENCE_H0 = 0x0910,
259259
TPM2_RC_RETRY = 0x0922,
260+
TPM2_RC_SESSION_MEMORY = 0x0903,
260261
};
261262

262263
enum tpm2_command_codes {
@@ -437,6 +438,24 @@ static inline u32 tpm2_rc_value(u32 rc)
437438
return (rc & BIT(7)) ? rc & 0xbf : rc;
438439
}
439440

441+
/*
442+
* Convert a return value from tpm_transmit_cmd() to POSIX error code.
443+
*/
444+
static inline ssize_t tpm_ret_to_err(ssize_t ret)
445+
{
446+
if (ret < 0)
447+
return ret;
448+
449+
switch (tpm2_rc_value(ret)) {
450+
case TPM2_RC_SUCCESS:
451+
return 0;
452+
case TPM2_RC_SESSION_MEMORY:
453+
return -ENOMEM;
454+
default:
455+
return -EFAULT;
456+
}
457+
}
458+
440459
#if defined(CONFIG_TCG_TPM) || defined(CONFIG_TCG_TPM_MODULE)
441460

442461
extern int tpm_is_tpm2(struct tpm_chip *chip);

0 commit comments

Comments
 (0)