Commit 546bce57 authored by Linus Torvalds's avatar Linus Torvalds
Browse files
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()
parents 74a63255 2f661f71
Loading
Loading
Loading
Loading
+3 −3
Original line number Diff line number Diff line
@@ -201,7 +201,7 @@ static void tpm_buf_read(struct tpm_buf *buf, off_t *offset, size_t count, void
 */
u8 tpm_buf_read_u8(struct tpm_buf *buf, off_t *offset)
{
	u8 value;
	u8 value = 0;

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

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

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

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

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

+6 −14
Original line number Diff line number Diff line
@@ -40,11 +40,6 @@
 *
 * These are the usage functions:
 *
 * tpm2_start_auth_session() which allocates the opaque auth structure
 *	and gets a session from the TPM.  This must be called before
 *	any of the following functions.  The session is protected by a
 *	session_key which is derived from a random salt value
 *	encrypted to the NULL seed.
 * tpm2_end_auth_session() kills the session and frees the resources.
 *	Under normal operation this function is done by
 *	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)
}

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

	rc = tpm_transmit_cmd(chip, &buf, 0, "start auth session");
	rc = tpm_ret_to_err(tpm_transmit_cmd(chip, &buf, 0, "StartAuthSession"));
	tpm2_flush_context(chip, null_key);

	if (rc == TPM2_RC_SUCCESS)
+1 −1
Original line number Diff line number Diff line
@@ -54,7 +54,7 @@ enum tis_int_flags {
enum tis_defaults {
	TIS_MEM_LEN = 0x5000,
	TIS_SHORT_TIMEOUT = 750,	/* ms */
	TIS_LONG_TIMEOUT = 2000,	/* 2 sec */
	TIS_LONG_TIMEOUT = 4000,	/* 4 secs */
	TIS_TIMEOUT_MIN_ATML = 14700,	/* usecs */
	TIS_TIMEOUT_MAX_ATML = 15000,	/* usecs */
};
+20 −1
Original line number Diff line number Diff line
@@ -224,7 +224,7 @@ enum tpm2_const {

enum tpm2_timeouts {
	TPM2_TIMEOUT_A          =    750,
	TPM2_TIMEOUT_B          =   2000,
	TPM2_TIMEOUT_B          =   4000,
	TPM2_TIMEOUT_C          =    200,
	TPM2_TIMEOUT_D          =     30,
	TPM2_DURATION_SHORT     =     20,
@@ -257,6 +257,7 @@ enum tpm2_return_codes {
	TPM2_RC_TESTING		= 0x090A, /* RC_WARN */
	TPM2_RC_REFERENCE_H0	= 0x0910,
	TPM2_RC_RETRY		= 0x0922,
	TPM2_RC_SESSION_MEMORY	= 0x0903,
};

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

/*
 * Convert a return value from tpm_transmit_cmd() to POSIX error code.
 */
static inline ssize_t tpm_ret_to_err(ssize_t ret)
{
	if (ret < 0)
		return ret;

	switch (tpm2_rc_value(ret)) {
	case TPM2_RC_SUCCESS:
		return 0;
	case TPM2_RC_SESSION_MEMORY:
		return -ENOMEM;
	default:
		return -EFAULT;
	}
}

#if defined(CONFIG_TCG_TPM) || defined(CONFIG_TCG_TPM_MODULE)

extern int tpm_is_tpm2(struct tpm_chip *chip);