mirror of
https://github.com/AuxXxilium/linux_dsm_epyc7002.git
synced 2024-12-18 14:36:43 +07:00
879b589210
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>
138 lines
3.7 KiB
C
138 lines
3.7 KiB
C
/*
|
|
* 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
|
|
*
|
|
* This program is free software; you can redistribute it and/or
|
|
* modify it under the terms of the GNU General Public License as
|
|
* published by the Free Software Foundation, version 2 of the
|
|
* License.
|
|
*
|
|
*/
|
|
#ifndef __LINUX_TPM_H__
|
|
#define __LINUX_TPM_H__
|
|
|
|
#include <crypto/hash_info.h>
|
|
|
|
#define TPM_DIGEST_SIZE 20 /* Max TPM v1.2 PCR size */
|
|
#define TPM_MAX_DIGEST_SIZE SHA512_DIGEST_SIZE
|
|
|
|
struct tpm_chip;
|
|
struct trusted_key_payload;
|
|
struct trusted_key_options;
|
|
|
|
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;
|
|
|
|
struct tpm_bank_info {
|
|
u16 alg_id;
|
|
u16 digest_size;
|
|
u16 crypto_id;
|
|
};
|
|
|
|
enum TPM_OPS_FLAGS {
|
|
TPM_OPS_AUTO_STARTUP = BIT(0),
|
|
};
|
|
|
|
struct tpm_class_ops {
|
|
unsigned int flags;
|
|
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);
|
|
void (*update_timeouts)(struct tpm_chip *chip,
|
|
unsigned long *timeout_cap);
|
|
int (*go_idle)(struct tpm_chip *chip);
|
|
int (*cmd_ready)(struct tpm_chip *chip);
|
|
int (*request_locality)(struct tpm_chip *chip, int loc);
|
|
int (*relinquish_locality)(struct tpm_chip *chip, int loc);
|
|
void (*clk_enable)(struct tpm_chip *chip, bool value);
|
|
};
|
|
|
|
#if defined(CONFIG_TCG_TPM) || defined(CONFIG_TCG_TPM_MODULE)
|
|
|
|
extern int tpm_is_tpm2(struct tpm_chip *chip);
|
|
extern int tpm_pcr_read(struct tpm_chip *chip, u32 pcr_idx,
|
|
struct tpm_digest *digest);
|
|
extern int tpm_pcr_extend(struct tpm_chip *chip, u32 pcr_idx, const u8 *hash);
|
|
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,
|
|
struct trusted_key_payload *payload,
|
|
struct trusted_key_options *options);
|
|
extern int tpm_unseal_trusted(struct tpm_chip *chip,
|
|
struct trusted_key_payload *payload,
|
|
struct trusted_key_options *options);
|
|
extern struct tpm_chip *tpm_default_chip(void);
|
|
#else
|
|
static inline int tpm_is_tpm2(struct tpm_chip *chip)
|
|
{
|
|
return -ENODEV;
|
|
}
|
|
|
|
static inline int tpm_pcr_read(struct tpm_chip *chip, int pcr_idx,
|
|
struct tpm_digest *digest)
|
|
{
|
|
return -ENODEV;
|
|
}
|
|
|
|
static inline int tpm_pcr_extend(struct tpm_chip *chip, u32 pcr_idx,
|
|
const u8 *hash)
|
|
{
|
|
return -ENODEV;
|
|
}
|
|
|
|
static inline int tpm_send(struct tpm_chip *chip, void *cmd, size_t buflen)
|
|
{
|
|
return -ENODEV;
|
|
}
|
|
static inline int tpm_get_random(struct tpm_chip *chip, u8 *data, size_t max)
|
|
{
|
|
return -ENODEV;
|
|
}
|
|
|
|
static inline int tpm_seal_trusted(struct tpm_chip *chip,
|
|
struct trusted_key_payload *payload,
|
|
struct trusted_key_options *options)
|
|
{
|
|
return -ENODEV;
|
|
}
|
|
static inline int tpm_unseal_trusted(struct tpm_chip *chip,
|
|
struct trusted_key_payload *payload,
|
|
struct trusted_key_options *options)
|
|
{
|
|
return -ENODEV;
|
|
}
|
|
static inline struct tpm_chip *tpm_default_chip(void)
|
|
{
|
|
return NULL;
|
|
}
|
|
#endif
|
|
#endif
|