2019-06-01 15:08:55 +07:00
|
|
|
/* SPDX-License-Identifier: GPL-2.0-only */
|
2009-02-03 00:23:44 +07:00
|
|
|
/*
|
|
|
|
* Copyright (C) 2004,2007,2008 IBM Corporation
|
|
|
|
*
|
|
|
|
* Authors:
|
|
|
|
* Leendert van Doorn <leendert@watson.ibm.com>
|
|
|
|
* Dave Safford <safford@watson.ibm.com>
|
|
|
|
* Reiner Sailer <sailer@watson.ibm.com>
|
|
|
|
* Kylene Hall <kjhall@us.ibm.com>
|
|
|
|
* Debora Velarde <dvelarde@us.ibm.com>
|
|
|
|
*
|
|
|
|
* Maintained by: <tpmdd_devel@lists.sourceforge.net>
|
|
|
|
*
|
|
|
|
* Device driver for TCG/TCPA TPM (trusted platform module).
|
|
|
|
* Specifications at www.trustedcomputinggroup.org
|
|
|
|
*/
|
|
|
|
#ifndef __LINUX_TPM_H__
|
|
|
|
#define __LINUX_TPM_H__
|
|
|
|
|
2019-02-06 23:24:50 +07:00
|
|
|
#include <linux/hw_random.h>
|
|
|
|
#include <linux/acpi.h>
|
|
|
|
#include <linux/cdev.h>
|
|
|
|
#include <linux/fs.h>
|
2019-02-06 23:24:48 +07:00
|
|
|
#include <crypto/hash_info.h>
|
|
|
|
|
2013-05-21 21:40:47 +07:00
|
|
|
#define TPM_DIGEST_SIZE 20 /* Max TPM v1.2 PCR size */
|
2019-02-06 23:24:48 +07:00
|
|
|
#define TPM_MAX_DIGEST_SIZE SHA512_DIGEST_SIZE
|
2013-05-21 21:40:47 +07:00
|
|
|
|
2013-11-27 03:30:43 +07:00
|
|
|
struct tpm_chip;
|
2015-05-30 12:09:04 +07:00
|
|
|
struct trusted_key_payload;
|
|
|
|
struct trusted_key_options;
|
2013-11-27 03:30:43 +07:00
|
|
|
|
2019-02-06 23:24:48 +07:00
|
|
|
enum tpm_algorithms {
|
|
|
|
TPM_ALG_ERROR = 0x0000,
|
|
|
|
TPM_ALG_SHA1 = 0x0004,
|
|
|
|
TPM_ALG_KEYEDHASH = 0x0008,
|
|
|
|
TPM_ALG_SHA256 = 0x000B,
|
|
|
|
TPM_ALG_SHA384 = 0x000C,
|
|
|
|
TPM_ALG_SHA512 = 0x000D,
|
|
|
|
TPM_ALG_NULL = 0x0010,
|
|
|
|
TPM_ALG_SM3_256 = 0x0012,
|
|
|
|
};
|
|
|
|
|
|
|
|
struct tpm_digest {
|
|
|
|
u16 alg_id;
|
|
|
|
u8 digest[TPM_MAX_DIGEST_SIZE];
|
|
|
|
} __packed;
|
|
|
|
|
tpm: retrieve digest size of unknown algorithms with PCR read
Currently, the TPM driver retrieves the digest size from a table mapping
TPM algorithms identifiers to identifiers defined by the crypto subsystem.
If the algorithm is not defined by the latter, the digest size can be
retrieved from the output of the PCR read command.
The patch modifies the definition of tpm_pcr_read() and tpm2_pcr_read() to
pass the desired hash algorithm and obtain the digest size at TPM startup.
Algorithms and corresponding digest sizes are stored in the new structure
tpm_bank_info, member of tpm_chip, so that the information can be used by
other kernel subsystems.
tpm_bank_info contains: the TPM algorithm identifier, necessary to generate
the event log as defined by Trusted Computing Group (TCG); the digest size,
to pad/truncate a digest calculated with a different algorithm; the crypto
subsystem identifier, to calculate the digest of event data.
This patch also protects against data corruption that could happen in the
bus, by checking that the digest size returned by the TPM during a PCR read
matches the size of the algorithm passed to tpm2_pcr_read().
For the initial PCR read, when digest sizes are not yet available, this
patch ensures that the amount of data copied from the output returned by
the TPM does not exceed the size of the array data are copied to.
Signed-off-by: Roberto Sassu <roberto.sassu@huawei.com>
Reviewed-by: Jarkko Sakkinen <jarkko.sakkinen@linux.intel.com>
Tested-by: Jarkko Sakkinen <jarkko.sakkinen@linux.intel.com>
Acked-by: Mimi Zohar <zohar@linux.ibm.com>
Signed-off-by: Jarkko Sakkinen <jarkko.sakkinen@linux.intel.com>
2019-02-06 23:24:49 +07:00
|
|
|
struct tpm_bank_info {
|
|
|
|
u16 alg_id;
|
|
|
|
u16 digest_size;
|
|
|
|
u16 crypto_id;
|
|
|
|
};
|
|
|
|
|
2016-07-13 00:41:49 +07:00
|
|
|
enum TPM_OPS_FLAGS {
|
|
|
|
TPM_OPS_AUTO_STARTUP = BIT(0),
|
|
|
|
};
|
|
|
|
|
2013-11-27 03:30:43 +07:00
|
|
|
struct tpm_class_ops {
|
2016-07-13 00:41:49 +07:00
|
|
|
unsigned int flags;
|
2013-11-27 03:30:43 +07:00
|
|
|
const u8 req_complete_mask;
|
|
|
|
const u8 req_complete_val;
|
|
|
|
bool (*req_canceled)(struct tpm_chip *chip, u8 status);
|
|
|
|
int (*recv) (struct tpm_chip *chip, u8 *buf, size_t len);
|
|
|
|
int (*send) (struct tpm_chip *chip, u8 *buf, size_t len);
|
|
|
|
void (*cancel) (struct tpm_chip *chip);
|
|
|
|
u8 (*status) (struct tpm_chip *chip);
|
2019-01-31 05:06:58 +07:00
|
|
|
void (*update_timeouts)(struct tpm_chip *chip,
|
2014-05-22 07:26:44 +07:00
|
|
|
unsigned long *timeout_cap);
|
2018-06-28 22:13:33 +07:00
|
|
|
int (*go_idle)(struct tpm_chip *chip);
|
|
|
|
int (*cmd_ready)(struct tpm_chip *chip);
|
2017-03-24 16:45:49 +07:00
|
|
|
int (*request_locality)(struct tpm_chip *chip, int loc);
|
2018-03-05 18:34:49 +07:00
|
|
|
int (*relinquish_locality)(struct tpm_chip *chip, int loc);
|
2017-12-23 03:13:44 +07:00
|
|
|
void (*clk_enable)(struct tpm_chip *chip, bool value);
|
2013-11-27 03:30:43 +07:00
|
|
|
};
|
|
|
|
|
2019-02-06 23:24:50 +07:00
|
|
|
#define TPM_NUM_EVENT_LOG_FILES 3
|
|
|
|
|
|
|
|
/* Indexes the duration array */
|
|
|
|
enum tpm_duration {
|
|
|
|
TPM_SHORT = 0,
|
|
|
|
TPM_MEDIUM = 1,
|
|
|
|
TPM_LONG = 2,
|
|
|
|
TPM_LONG_LONG = 3,
|
|
|
|
TPM_UNDEFINED,
|
|
|
|
TPM_NUM_DURATIONS = TPM_UNDEFINED,
|
|
|
|
};
|
|
|
|
|
|
|
|
#define TPM_PPI_VERSION_LEN 3
|
|
|
|
|
|
|
|
struct tpm_space {
|
|
|
|
u32 context_tbl[3];
|
|
|
|
u8 *context_buf;
|
|
|
|
u32 session_tbl[3];
|
|
|
|
u8 *session_buf;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct tpm_bios_log {
|
|
|
|
void *bios_event_log;
|
|
|
|
void *bios_event_log_end;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct tpm_chip_seqops {
|
|
|
|
struct tpm_chip *chip;
|
|
|
|
const struct seq_operations *seqops;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct tpm_chip {
|
|
|
|
struct device dev;
|
|
|
|
struct device devs;
|
|
|
|
struct cdev cdev;
|
|
|
|
struct cdev cdevs;
|
|
|
|
|
|
|
|
/* A driver callback under ops cannot be run unless ops_sem is held
|
|
|
|
* (sometimes implicitly, eg for the sysfs code). ops becomes null
|
|
|
|
* when the driver is unregistered, see tpm_try_get_ops.
|
|
|
|
*/
|
|
|
|
struct rw_semaphore ops_sem;
|
|
|
|
const struct tpm_class_ops *ops;
|
|
|
|
|
|
|
|
struct tpm_bios_log log;
|
|
|
|
struct tpm_chip_seqops bin_log_seqops;
|
|
|
|
struct tpm_chip_seqops ascii_log_seqops;
|
|
|
|
|
|
|
|
unsigned int flags;
|
|
|
|
|
|
|
|
int dev_num; /* /dev/tpm# */
|
|
|
|
unsigned long is_open; /* only one allowed */
|
|
|
|
|
|
|
|
char hwrng_name[64];
|
|
|
|
struct hwrng hwrng;
|
|
|
|
|
|
|
|
struct mutex tpm_mutex; /* tpm is processing */
|
|
|
|
|
|
|
|
unsigned long timeout_a; /* jiffies */
|
|
|
|
unsigned long timeout_b; /* jiffies */
|
|
|
|
unsigned long timeout_c; /* jiffies */
|
|
|
|
unsigned long timeout_d; /* jiffies */
|
|
|
|
bool timeout_adjusted;
|
|
|
|
unsigned long duration[TPM_NUM_DURATIONS]; /* jiffies */
|
|
|
|
bool duration_adjusted;
|
|
|
|
|
|
|
|
struct dentry *bios_dir[TPM_NUM_EVENT_LOG_FILES];
|
|
|
|
|
|
|
|
const struct attribute_group *groups[3];
|
|
|
|
unsigned int groups_cnt;
|
|
|
|
|
|
|
|
u32 nr_allocated_banks;
|
|
|
|
struct tpm_bank_info *allocated_banks;
|
|
|
|
#ifdef CONFIG_ACPI
|
|
|
|
acpi_handle acpi_dev_handle;
|
|
|
|
char ppi_version[TPM_PPI_VERSION_LEN + 1];
|
|
|
|
#endif /* CONFIG_ACPI */
|
|
|
|
|
|
|
|
struct tpm_space work_space;
|
|
|
|
u32 last_cc;
|
|
|
|
u32 nr_commands;
|
|
|
|
u32 *cc_attrs_tbl;
|
|
|
|
|
|
|
|
/* active locality */
|
|
|
|
int locality;
|
|
|
|
};
|
|
|
|
|
2009-10-29 02:26:39 +07:00
|
|
|
#if defined(CONFIG_TCG_TPM) || defined(CONFIG_TCG_TPM_MODULE)
|
2009-02-03 00:23:44 +07:00
|
|
|
|
2017-11-05 18:16:26 +07:00
|
|
|
extern int tpm_is_tpm2(struct tpm_chip *chip);
|
tpm: retrieve digest size of unknown algorithms with PCR read
Currently, the TPM driver retrieves the digest size from a table mapping
TPM algorithms identifiers to identifiers defined by the crypto subsystem.
If the algorithm is not defined by the latter, the digest size can be
retrieved from the output of the PCR read command.
The patch modifies the definition of tpm_pcr_read() and tpm2_pcr_read() to
pass the desired hash algorithm and obtain the digest size at TPM startup.
Algorithms and corresponding digest sizes are stored in the new structure
tpm_bank_info, member of tpm_chip, so that the information can be used by
other kernel subsystems.
tpm_bank_info contains: the TPM algorithm identifier, necessary to generate
the event log as defined by Trusted Computing Group (TCG); the digest size,
to pad/truncate a digest calculated with a different algorithm; the crypto
subsystem identifier, to calculate the digest of event data.
This patch also protects against data corruption that could happen in the
bus, by checking that the digest size returned by the TPM during a PCR read
matches the size of the algorithm passed to tpm2_pcr_read().
For the initial PCR read, when digest sizes are not yet available, this
patch ensures that the amount of data copied from the output returned by
the TPM does not exceed the size of the array data are copied to.
Signed-off-by: Roberto Sassu <roberto.sassu@huawei.com>
Reviewed-by: Jarkko Sakkinen <jarkko.sakkinen@linux.intel.com>
Tested-by: Jarkko Sakkinen <jarkko.sakkinen@linux.intel.com>
Acked-by: Mimi Zohar <zohar@linux.ibm.com>
Signed-off-by: Jarkko Sakkinen <jarkko.sakkinen@linux.intel.com>
2019-02-06 23:24:49 +07:00
|
|
|
extern int tpm_pcr_read(struct tpm_chip *chip, u32 pcr_idx,
|
|
|
|
struct tpm_digest *digest);
|
2019-02-06 23:24:52 +07:00
|
|
|
extern int tpm_pcr_extend(struct tpm_chip *chip, u32 pcr_idx,
|
|
|
|
struct tpm_digest *digests);
|
2017-11-05 18:16:26 +07:00
|
|
|
extern int tpm_send(struct tpm_chip *chip, void *cmd, size_t buflen);
|
|
|
|
extern int tpm_get_random(struct tpm_chip *chip, u8 *data, size_t max);
|
|
|
|
extern int tpm_seal_trusted(struct tpm_chip *chip,
|
2015-05-30 12:09:04 +07:00
|
|
|
struct trusted_key_payload *payload,
|
|
|
|
struct trusted_key_options *options);
|
2017-11-05 18:16:26 +07:00
|
|
|
extern int tpm_unseal_trusted(struct tpm_chip *chip,
|
2015-05-30 12:09:04 +07:00
|
|
|
struct trusted_key_payload *payload,
|
|
|
|
struct trusted_key_options *options);
|
2018-06-27 02:09:30 +07:00
|
|
|
extern struct tpm_chip *tpm_default_chip(void);
|
2009-10-26 20:26:18 +07:00
|
|
|
#else
|
2017-11-05 18:16:26 +07:00
|
|
|
static inline int tpm_is_tpm2(struct tpm_chip *chip)
|
2015-05-30 12:09:04 +07:00
|
|
|
{
|
|
|
|
return -ENODEV;
|
|
|
|
}
|
2018-10-20 01:23:07 +07:00
|
|
|
|
tpm: retrieve digest size of unknown algorithms with PCR read
Currently, the TPM driver retrieves the digest size from a table mapping
TPM algorithms identifiers to identifiers defined by the crypto subsystem.
If the algorithm is not defined by the latter, the digest size can be
retrieved from the output of the PCR read command.
The patch modifies the definition of tpm_pcr_read() and tpm2_pcr_read() to
pass the desired hash algorithm and obtain the digest size at TPM startup.
Algorithms and corresponding digest sizes are stored in the new structure
tpm_bank_info, member of tpm_chip, so that the information can be used by
other kernel subsystems.
tpm_bank_info contains: the TPM algorithm identifier, necessary to generate
the event log as defined by Trusted Computing Group (TCG); the digest size,
to pad/truncate a digest calculated with a different algorithm; the crypto
subsystem identifier, to calculate the digest of event data.
This patch also protects against data corruption that could happen in the
bus, by checking that the digest size returned by the TPM during a PCR read
matches the size of the algorithm passed to tpm2_pcr_read().
For the initial PCR read, when digest sizes are not yet available, this
patch ensures that the amount of data copied from the output returned by
the TPM does not exceed the size of the array data are copied to.
Signed-off-by: Roberto Sassu <roberto.sassu@huawei.com>
Reviewed-by: Jarkko Sakkinen <jarkko.sakkinen@linux.intel.com>
Tested-by: Jarkko Sakkinen <jarkko.sakkinen@linux.intel.com>
Acked-by: Mimi Zohar <zohar@linux.ibm.com>
Signed-off-by: Jarkko Sakkinen <jarkko.sakkinen@linux.intel.com>
2019-02-06 23:24:49 +07:00
|
|
|
static inline int tpm_pcr_read(struct tpm_chip *chip, int pcr_idx,
|
|
|
|
struct tpm_digest *digest)
|
2017-11-05 18:16:26 +07:00
|
|
|
{
|
2009-10-26 20:26:18 +07:00
|
|
|
return -ENODEV;
|
|
|
|
}
|
2018-10-20 01:23:07 +07:00
|
|
|
|
|
|
|
static inline int tpm_pcr_extend(struct tpm_chip *chip, u32 pcr_idx,
|
2019-02-06 23:24:52 +07:00
|
|
|
struct tpm_digest *digests)
|
2017-11-05 18:16:26 +07:00
|
|
|
{
|
2009-10-26 20:26:18 +07:00
|
|
|
return -ENODEV;
|
|
|
|
}
|
2018-10-20 01:23:07 +07:00
|
|
|
|
2017-11-05 18:16:26 +07:00
|
|
|
static inline int tpm_send(struct tpm_chip *chip, void *cmd, size_t buflen)
|
|
|
|
{
|
2010-11-24 06:54:16 +07:00
|
|
|
return -ENODEV;
|
|
|
|
}
|
2017-11-05 18:16:26 +07:00
|
|
|
static inline int tpm_get_random(struct tpm_chip *chip, u8 *data, size_t max)
|
|
|
|
{
|
2012-06-08 01:47:14 +07:00
|
|
|
return -ENODEV;
|
|
|
|
}
|
2015-05-30 12:09:04 +07:00
|
|
|
|
2017-11-05 18:16:26 +07:00
|
|
|
static inline int tpm_seal_trusted(struct tpm_chip *chip,
|
2015-05-30 12:09:04 +07:00
|
|
|
struct trusted_key_payload *payload,
|
|
|
|
struct trusted_key_options *options)
|
|
|
|
{
|
|
|
|
return -ENODEV;
|
|
|
|
}
|
2017-11-05 18:16:26 +07:00
|
|
|
static inline int tpm_unseal_trusted(struct tpm_chip *chip,
|
2015-05-30 12:09:04 +07:00
|
|
|
struct trusted_key_payload *payload,
|
|
|
|
struct trusted_key_options *options)
|
|
|
|
{
|
|
|
|
return -ENODEV;
|
|
|
|
}
|
2018-06-27 02:09:30 +07:00
|
|
|
static inline struct tpm_chip *tpm_default_chip(void)
|
|
|
|
{
|
|
|
|
return NULL;
|
|
|
|
}
|
2009-02-03 00:23:44 +07:00
|
|
|
#endif
|
|
|
|
#endif
|