Commit 74673fc5 authored by Linus Torvalds's avatar Linus Torvalds

Merge branch 'next-tpm' of git://git.kernel.org/pub/scm/linux/kernel/git/jmorris/linux-security

Pull TPM updates from James Morris:

 - Support for partial reads of /dev/tpm0.

 - Clean up for TPM 1.x code: move the commands to tpm1-cmd.c and make
   everything to use the same data structure for building TPM commands
   i.e. struct tpm_buf.

* 'next-tpm' of git://git.kernel.org/pub/scm/linux/kernel/git/jmorris/linux-security: (25 commits)
  tpm: add support for partial reads
  tpm: tpm_ibmvtpm: fix kdoc warnings
  tpm: fix kdoc for tpm2_flush_context_cmd()
  tpm: tpm_try_transmit() refactor error flow.
  tpm: use u32 instead of int for PCR index
  tpm1: reimplement tpm1_continue_selftest() using tpm_buf
  tpm1: reimplement SAVESTATE using tpm_buf
  tpm1: rename tpm1_pcr_read_dev to tpm1_pcr_read()
  tpm1: implement tpm1_pcr_read_dev() using tpm_buf structure
  tpm: tpm1: rewrite tpm1_get_random() using tpm_buf structure
  tpm: tpm-space.c remove unneeded semicolon
  tpm: tpm-interface.c drop unused macros
  tpm: add tpm_auto_startup() into tpm-interface.c
  tpm: factor out tpm_startup function
  tpm: factor out tpm 1.x pm suspend flow into tpm1-cmd.c
  tpm: move tpm 1.x selftest code from tpm-interface.c tpm1-cmd.c
  tpm: factor out tpm1_get_random into tpm1-cmd.c
  tpm: move tpm_getcap to tpm1-cmd.c
  tpm: move tpm1_pcr_extend to tpm1-cmd.c
  tpm: factor out tpm_get_timeouts()
  ...
parents 19f2e267 0db51ef2
...@@ -3,9 +3,19 @@ ...@@ -3,9 +3,19 @@
# Makefile for the kernel tpm device drivers. # Makefile for the kernel tpm device drivers.
# #
obj-$(CONFIG_TCG_TPM) += tpm.o obj-$(CONFIG_TCG_TPM) += tpm.o
tpm-y := tpm-interface.o tpm-dev.o tpm-sysfs.o tpm-chip.o tpm2-cmd.o \ tpm-y := tpm-chip.o
tpm-dev-common.o tpmrm-dev.o eventlog/common.o eventlog/tpm1.o \ tpm-y += tpm-dev-common.o
eventlog/tpm2.o tpm2-space.o tpm-y += tpm-dev.o
tpm-y += tpm-interface.o
tpm-y += tpm1-cmd.o
tpm-y += tpm2-cmd.o
tpm-y += tpmrm-dev.o
tpm-y += tpm2-space.o
tpm-y += tpm-sysfs.o
tpm-y += eventlog/common.o
tpm-y += eventlog/tpm1.o
tpm-y += eventlog/tpm2.o
tpm-$(CONFIG_ACPI) += tpm_ppi.o eventlog/acpi.o tpm-$(CONFIG_ACPI) += tpm_ppi.o eventlog/acpi.o
tpm-$(CONFIG_EFI) += eventlog/efi.o tpm-$(CONFIG_EFI) += eventlog/efi.o
tpm-$(CONFIG_OF) += eventlog/of.o tpm-$(CONFIG_OF) += eventlog/of.o
......
...@@ -649,7 +649,7 @@ int st33zp24_pm_resume(struct device *dev) ...@@ -649,7 +649,7 @@ int st33zp24_pm_resume(struct device *dev)
} else { } else {
ret = tpm_pm_resume(dev); ret = tpm_pm_resume(dev);
if (!ret) if (!ret)
tpm_do_selftest(chip); tpm1_do_selftest(chip);
} }
return ret; return ret;
} /* st33zp24_pm_resume() */ } /* st33zp24_pm_resume() */
......
...@@ -451,14 +451,9 @@ int tpm_chip_register(struct tpm_chip *chip) ...@@ -451,14 +451,9 @@ int tpm_chip_register(struct tpm_chip *chip)
{ {
int rc; int rc;
if (chip->ops->flags & TPM_OPS_AUTO_STARTUP) { rc = tpm_auto_startup(chip);
if (chip->flags & TPM_CHIP_FLAG_TPM2) if (rc)
rc = tpm2_auto_startup(chip); return rc;
else
rc = tpm1_auto_startup(chip);
if (rc)
return rc;
}
tpm_sysfs_add_device(chip); tpm_sysfs_add_device(chip);
......
...@@ -40,7 +40,7 @@ static void tpm_async_work(struct work_struct *work) ...@@ -40,7 +40,7 @@ static void tpm_async_work(struct work_struct *work)
tpm_put_ops(priv->chip); tpm_put_ops(priv->chip);
if (ret > 0) { if (ret > 0) {
priv->data_pending = ret; priv->response_length = ret;
mod_timer(&priv->user_read_timer, jiffies + (120 * HZ)); mod_timer(&priv->user_read_timer, jiffies + (120 * HZ));
} }
mutex_unlock(&priv->buffer_mutex); mutex_unlock(&priv->buffer_mutex);
...@@ -63,7 +63,8 @@ static void tpm_timeout_work(struct work_struct *work) ...@@ -63,7 +63,8 @@ static void tpm_timeout_work(struct work_struct *work)
timeout_work); timeout_work);
mutex_lock(&priv->buffer_mutex); mutex_lock(&priv->buffer_mutex);
priv->data_pending = 0; priv->response_read = true;
priv->response_length = 0;
memset(priv->data_buffer, 0, sizeof(priv->data_buffer)); memset(priv->data_buffer, 0, sizeof(priv->data_buffer));
mutex_unlock(&priv->buffer_mutex); mutex_unlock(&priv->buffer_mutex);
wake_up_interruptible(&priv->async_wait); wake_up_interruptible(&priv->async_wait);
...@@ -74,6 +75,7 @@ void tpm_common_open(struct file *file, struct tpm_chip *chip, ...@@ -74,6 +75,7 @@ void tpm_common_open(struct file *file, struct tpm_chip *chip,
{ {
priv->chip = chip; priv->chip = chip;
priv->space = space; priv->space = space;
priv->response_read = true;
mutex_init(&priv->buffer_mutex); mutex_init(&priv->buffer_mutex);
timer_setup(&priv->user_read_timer, user_reader_timeout, 0); timer_setup(&priv->user_read_timer, user_reader_timeout, 0);
...@@ -90,22 +92,35 @@ ssize_t tpm_common_read(struct file *file, char __user *buf, ...@@ -90,22 +92,35 @@ ssize_t tpm_common_read(struct file *file, char __user *buf,
ssize_t ret_size = 0; ssize_t ret_size = 0;
int rc; int rc;
del_singleshot_timer_sync(&priv->user_read_timer);
flush_work(&priv->timeout_work);
mutex_lock(&priv->buffer_mutex); mutex_lock(&priv->buffer_mutex);
if (priv->data_pending) { if (priv->response_length) {
ret_size = min_t(ssize_t, size, priv->data_pending); priv->response_read = true;
if (ret_size > 0) {
rc = copy_to_user(buf, priv->data_buffer, ret_size); ret_size = min_t(ssize_t, size, priv->response_length);
memset(priv->data_buffer, 0, priv->data_pending); if (!ret_size) {
if (rc) priv->response_length = 0;
ret_size = -EFAULT; goto out;
} }
priv->data_pending = 0; rc = copy_to_user(buf, priv->data_buffer + *off, ret_size);
if (rc) {
memset(priv->data_buffer, 0, TPM_BUFSIZE);
priv->response_length = 0;
ret_size = -EFAULT;
} else {
memset(priv->data_buffer + *off, 0, ret_size);
priv->response_length -= ret_size;
*off += ret_size;
}
} }
out:
if (!priv->response_length) {
*off = 0;
del_singleshot_timer_sync(&priv->user_read_timer);
flush_work(&priv->timeout_work);
}
mutex_unlock(&priv->buffer_mutex); mutex_unlock(&priv->buffer_mutex);
return ret_size; return ret_size;
} }
...@@ -125,7 +140,8 @@ ssize_t tpm_common_write(struct file *file, const char __user *buf, ...@@ -125,7 +140,8 @@ ssize_t tpm_common_write(struct file *file, const char __user *buf,
* tpm_read or a user_read_timer timeout. This also prevents split * tpm_read or a user_read_timer timeout. This also prevents split
* buffered writes from blocking here. * buffered writes from blocking here.
*/ */
if (priv->data_pending != 0 || priv->command_enqueued) { if ((!priv->response_read && priv->response_length) ||
priv->command_enqueued) {
ret = -EBUSY; ret = -EBUSY;
goto out; goto out;
} }
...@@ -150,6 +166,10 @@ ssize_t tpm_common_write(struct file *file, const char __user *buf, ...@@ -150,6 +166,10 @@ ssize_t tpm_common_write(struct file *file, const char __user *buf,
goto out; goto out;
} }
priv->response_length = 0;
priv->response_read = false;
*off = 0;
/* /*
* If in nonblocking mode schedule an async job to send * If in nonblocking mode schedule an async job to send
* the command return the size. * the command return the size.
...@@ -168,7 +188,7 @@ ssize_t tpm_common_write(struct file *file, const char __user *buf, ...@@ -168,7 +188,7 @@ ssize_t tpm_common_write(struct file *file, const char __user *buf,
tpm_put_ops(priv->chip); tpm_put_ops(priv->chip);
if (ret > 0) { if (ret > 0) {
priv->data_pending = ret; priv->response_length = ret;
mod_timer(&priv->user_read_timer, jiffies + (120 * HZ)); mod_timer(&priv->user_read_timer, jiffies + (120 * HZ));
ret = size; ret = size;
} }
...@@ -184,7 +204,7 @@ __poll_t tpm_common_poll(struct file *file, poll_table *wait) ...@@ -184,7 +204,7 @@ __poll_t tpm_common_poll(struct file *file, poll_table *wait)
poll_wait(file, &priv->async_wait, wait); poll_wait(file, &priv->async_wait, wait);
if (priv->data_pending) if (!priv->response_read || priv->response_length)
mask = EPOLLIN | EPOLLRDNORM; mask = EPOLLIN | EPOLLRDNORM;
else else
mask = EPOLLOUT | EPOLLWRNORM; mask = EPOLLOUT | EPOLLWRNORM;
...@@ -201,7 +221,7 @@ void tpm_common_release(struct file *file, struct file_priv *priv) ...@@ -201,7 +221,7 @@ void tpm_common_release(struct file *file, struct file_priv *priv)
del_singleshot_timer_sync(&priv->user_read_timer); del_singleshot_timer_sync(&priv->user_read_timer);
flush_work(&priv->timeout_work); flush_work(&priv->timeout_work);
file->private_data = NULL; file->private_data = NULL;
priv->data_pending = 0; priv->response_length = 0;
} }
int __init tpm_dev_common_init(void) int __init tpm_dev_common_init(void)
......
...@@ -9,14 +9,13 @@ struct file_priv { ...@@ -9,14 +9,13 @@ struct file_priv {
struct tpm_chip *chip; struct tpm_chip *chip;
struct tpm_space *space; struct tpm_space *space;
/* Holds the amount of data passed or an error code from async op */
ssize_t data_pending;
struct mutex buffer_mutex; struct mutex buffer_mutex;
struct timer_list user_read_timer; /* user needs to claim result */ struct timer_list user_read_timer; /* user needs to claim result */
struct work_struct timeout_work; struct work_struct timeout_work;
struct work_struct async_work; struct work_struct async_work;
wait_queue_head_t async_wait; wait_queue_head_t async_wait;
size_t response_length;
bool response_read;
bool command_enqueued; bool command_enqueued;
u8 data_buffer[TPM_BUFSIZE]; u8 data_buffer[TPM_BUFSIZE];
......
This diff is collapsed.
...@@ -102,19 +102,19 @@ static ssize_t pcrs_show(struct device *dev, struct device_attribute *attr, ...@@ -102,19 +102,19 @@ static ssize_t pcrs_show(struct device *dev, struct device_attribute *attr,
cap_t cap; cap_t cap;
u8 digest[TPM_DIGEST_SIZE]; u8 digest[TPM_DIGEST_SIZE];
ssize_t rc; ssize_t rc;
int i, j, num_pcrs; u32 i, j, num_pcrs;
char *str = buf; char *str = buf;
struct tpm_chip *chip = to_tpm_chip(dev); struct tpm_chip *chip = to_tpm_chip(dev);
rc = tpm_getcap(chip, TPM_CAP_PROP_PCR, &cap, rc = tpm1_getcap(chip, TPM_CAP_PROP_PCR, &cap,
"attempting to determine the number of PCRS", "attempting to determine the number of PCRS",
sizeof(cap.num_pcrs)); sizeof(cap.num_pcrs));
if (rc) if (rc)
return 0; return 0;
num_pcrs = be32_to_cpu(cap.num_pcrs); num_pcrs = be32_to_cpu(cap.num_pcrs);
for (i = 0; i < num_pcrs; i++) { for (i = 0; i < num_pcrs; i++) {
rc = tpm_pcr_read_dev(chip, i, digest); rc = tpm1_pcr_read(chip, i, digest);
if (rc) if (rc)
break; break;
str += sprintf(str, "PCR-%02d: ", i); str += sprintf(str, "PCR-%02d: ", i);
...@@ -132,9 +132,9 @@ static ssize_t enabled_show(struct device *dev, struct device_attribute *attr, ...@@ -132,9 +132,9 @@ static ssize_t enabled_show(struct device *dev, struct device_attribute *attr,
cap_t cap; cap_t cap;
ssize_t rc; ssize_t rc;
rc = tpm_getcap(to_tpm_chip(dev), TPM_CAP_FLAG_PERM, &cap, rc = tpm1_getcap(to_tpm_chip(dev), TPM_CAP_FLAG_PERM, &cap,
"attempting to determine the permanent enabled state", "attempting to determine the permanent enabled state",
sizeof(cap.perm_flags)); sizeof(cap.perm_flags));
if (rc) if (rc)
return 0; return 0;
...@@ -149,9 +149,9 @@ static ssize_t active_show(struct device *dev, struct device_attribute *attr, ...@@ -149,9 +149,9 @@ static ssize_t active_show(struct device *dev, struct device_attribute *attr,
cap_t cap; cap_t cap;
ssize_t rc; ssize_t rc;
rc = tpm_getcap(to_tpm_chip(dev), TPM_CAP_FLAG_PERM, &cap, rc = tpm1_getcap(to_tpm_chip(dev), TPM_CAP_FLAG_PERM, &cap,
"attempting to determine the permanent active state", "attempting to determine the permanent active state",
sizeof(cap.perm_flags)); sizeof(cap.perm_flags));
if (rc) if (rc)
return 0; return 0;
...@@ -166,9 +166,9 @@ static ssize_t owned_show(struct device *dev, struct device_attribute *attr, ...@@ -166,9 +166,9 @@ static ssize_t owned_show(struct device *dev, struct device_attribute *attr,
cap_t cap; cap_t cap;
ssize_t rc; ssize_t rc;
rc = tpm_getcap(to_tpm_chip(dev), TPM_CAP_PROP_OWNER, &cap, rc = tpm1_getcap(to_tpm_chip(dev), TPM_CAP_PROP_OWNER, &cap,
"attempting to determine the owner state", "attempting to determine the owner state",
sizeof(cap.owned)); sizeof(cap.owned));
if (rc) if (rc)
return 0; return 0;
...@@ -183,9 +183,9 @@ static ssize_t temp_deactivated_show(struct device *dev, ...@@ -183,9 +183,9 @@ static ssize_t temp_deactivated_show(struct device *dev,
cap_t cap; cap_t cap;
ssize_t rc; ssize_t rc;
rc = tpm_getcap(to_tpm_chip(dev), TPM_CAP_FLAG_VOL, &cap, rc = tpm1_getcap(to_tpm_chip(dev), TPM_CAP_FLAG_VOL, &cap,
"attempting to determine the temporary state", "attempting to determine the temporary state",
sizeof(cap.stclear_flags)); sizeof(cap.stclear_flags));
if (rc) if (rc)
return 0; return 0;
...@@ -202,18 +202,18 @@ static ssize_t caps_show(struct device *dev, struct device_attribute *attr, ...@@ -202,18 +202,18 @@ static ssize_t caps_show(struct device *dev, struct device_attribute *attr,
ssize_t rc; ssize_t rc;
char *str = buf; char *str = buf;
rc = tpm_getcap(chip, TPM_CAP_PROP_MANUFACTURER, &cap, rc = tpm1_getcap(chip, TPM_CAP_PROP_MANUFACTURER, &cap,
"attempting to determine the manufacturer", "attempting to determine the manufacturer",
sizeof(cap.manufacturer_id)); sizeof(cap.manufacturer_id));
if (rc) if (rc)
return 0; return 0;
str += sprintf(str, "Manufacturer: 0x%x\n", str += sprintf(str, "Manufacturer: 0x%x\n",
be32_to_cpu(cap.manufacturer_id)); be32_to_cpu(cap.manufacturer_id));
/* Try to get a TPM version 1.2 TPM_CAP_VERSION_INFO */ /* Try to get a TPM version 1.2 TPM_CAP_VERSION_INFO */
rc = tpm_getcap(chip, TPM_CAP_VERSION_1_2, &cap, rc = tpm1_getcap(chip, TPM_CAP_VERSION_1_2, &cap,
"attempting to determine the 1.2 version", "attempting to determine the 1.2 version",
sizeof(cap.tpm_version_1_2)); sizeof(cap.tpm_version_1_2));
if (!rc) { if (!rc) {
str += sprintf(str, str += sprintf(str,
"TCG version: %d.%d\nFirmware version: %d.%d\n", "TCG version: %d.%d\nFirmware version: %d.%d\n",
...@@ -223,9 +223,9 @@ static ssize_t caps_show(struct device *dev, struct device_attribute *attr, ...@@ -223,9 +223,9 @@ static ssize_t caps_show(struct device *dev, struct device_attribute *attr,
cap.tpm_version_1_2.revMinor); cap.tpm_version_1_2.revMinor);
} else { } else {
/* Otherwise just use TPM_STRUCT_VER */ /* Otherwise just use TPM_STRUCT_VER */
rc = tpm_getcap(chip, TPM_CAP_VERSION_1_1, &cap, rc = tpm1_getcap(chip, TPM_CAP_VERSION_1_1, &cap,
"attempting to determine the 1.1 version", "attempting to determine the 1.1 version",
sizeof(cap.tpm_version)); sizeof(cap.tpm_version));
if (rc) if (rc)
return 0; return 0;
str += sprintf(str, str += sprintf(str,
......
...@@ -134,22 +134,31 @@ enum tpm2_algorithms { ...@@ -134,22 +134,31 @@ enum tpm2_algorithms {
}; };
enum tpm2_command_codes { enum tpm2_command_codes {
TPM2_CC_FIRST = 0x011F, TPM2_CC_FIRST = 0x011F,
TPM2_CC_CREATE_PRIMARY = 0x0131, TPM2_CC_HIERARCHY_CONTROL = 0x0121,
TPM2_CC_SELF_TEST = 0x0143, TPM2_CC_HIERARCHY_CHANGE_AUTH = 0x0129,
TPM2_CC_STARTUP = 0x0144, TPM2_CC_CREATE_PRIMARY = 0x0131,
TPM2_CC_SHUTDOWN = 0x0145, TPM2_CC_SEQUENCE_COMPLETE = 0x013E,
TPM2_CC_CREATE = 0x0153, TPM2_CC_SELF_TEST = 0x0143,
TPM2_CC_LOAD = 0x0157, TPM2_CC_STARTUP = 0x0144,
TPM2_CC_UNSEAL = 0x015E, TPM2_CC_SHUTDOWN = 0x0145,
TPM2_CC_CONTEXT_LOAD = 0x0161, TPM2_CC_NV_READ = 0x014E,
TPM2_CC_CONTEXT_SAVE = 0x0162, TPM2_CC_CREATE = 0x0153,
TPM2_CC_FLUSH_CONTEXT = 0x0165, TPM2_CC_LOAD = 0x0157,
TPM2_CC_GET_CAPABILITY = 0x017A, TPM2_CC_SEQUENCE_UPDATE = 0x015C,
TPM2_CC_GET_RANDOM = 0x017B, TPM2_CC_UNSEAL = 0x015E,
TPM2_CC_PCR_READ = 0x017E, TPM2_CC_CONTEXT_LOAD = 0x0161,
TPM2_CC_PCR_EXTEND = 0x0182, TPM2_CC_CONTEXT_SAVE = 0x0162,
TPM2_CC_LAST = 0x018F, TPM2_CC_FLUSH_CONTEXT = 0x0165,
TPM2_CC_VERIFY_SIGNATURE = 0x0177,
TPM2_CC_GET_CAPABILITY = 0x017A,
TPM2_CC_GET_RANDOM = 0x017B,
TPM2_CC_PCR_READ = 0x017E,
TPM2_CC_PCR_EXTEND = 0x0182,
TPM2_CC_EVENT_SEQUENCE_COMPLETE = 0x0185,
TPM2_CC_HASH_SEQUENCE_START = 0x0186,
TPM2_CC_CREATE_LOADED = 0x0191,
TPM2_CC_LAST = 0x0193, /* Spec 1.36 */
}; };
enum tpm2_permanent_handles { enum tpm2_permanent_handles {
...@@ -368,18 +377,6 @@ enum tpm_sub_capabilities { ...@@ -368,18 +377,6 @@ enum tpm_sub_capabilities {
TPM_CAP_PROP_TIS_DURATION = 0x120, TPM_CAP_PROP_TIS_DURATION = 0x120,
}; };
typedef union {
struct tpm_input_header in;
struct tpm_output_header out;
} tpm_cmd_header;
struct tpm_pcrread_out {
u8 pcr_result[TPM_DIGEST_SIZE];
} __packed;
struct tpm_pcrread_in {
__be32 pcr_idx;
} __packed;
/* 128 bytes is an arbitrary cap. This could be as large as TPM_BUFSIZE - 18 /* 128 bytes is an arbitrary cap. This could be as large as TPM_BUFSIZE - 18
* bytes, but 128 is still a relatively large number of random bytes and * bytes, but 128 is still a relatively large number of random bytes and
...@@ -387,28 +384,6 @@ struct tpm_pcrread_in { ...@@ -387,28 +384,6 @@ struct tpm_pcrread_in {
* compiler warnings about stack frame size. */ * compiler warnings about stack frame size. */
#define TPM_MAX_RNG_DATA 128 #define TPM_MAX_RNG_DATA 128
struct tpm_getrandom_out {
__be32 rng_data_len;
u8 rng_data[TPM_MAX_RNG_DATA];
} __packed;
struct tpm_getrandom_in {
__be32 num_bytes;
} __packed;
typedef union {
struct tpm_pcrread_in pcrread_in;
struct tpm_pcrread_out pcrread_out;
struct tpm_getrandom_in getrandom_in;
struct tpm_getrandom_out getrandom_out;
} tpm_cmd_params;
struct tpm_cmd_t {
tpm_cmd_header header;
tpm_cmd_params params;
} __packed;
/* A string buffer type for constructing TPM commands. This is based on the /* A string buffer type for constructing TPM commands. This is based on the
* ideas of string buffer code in security/keys/trusted.h but is heap based * ideas of string buffer code in security/keys/trusted.h but is heap based
* in order to keep the stack usage minimal. * in order to keep the stack usage minimal.
...@@ -531,12 +506,20 @@ ssize_t tpm_transmit_cmd(struct tpm_chip *chip, struct tpm_space *space, ...@@ -531,12 +506,20 @@ ssize_t tpm_transmit_cmd(struct tpm_chip *chip, struct tpm_space *space,
void *buf, size_t bufsiz, void *buf, size_t bufsiz,
size_t min_rsp_body_length, unsigned int flags, size_t min_rsp_body_length, unsigned int flags,
const char *desc); const char *desc);
int tpm_startup(struct tpm_chip *chip);
ssize_t tpm_getcap(struct tpm_chip *chip, u32 subcap_id, cap_t *cap,
const char *desc, size_t min_cap_length);
int tpm_get_timeouts(struct tpm_chip *); int tpm_get_timeouts(struct tpm_chip *);
int tpm_auto_startup(struct tpm_chip *chip);
int tpm1_pm_suspend(struct tpm_chip *chip, u32 tpm_suspend_pcr);
int tpm1_auto_startup(struct tpm_chip *chip); int tpm1_auto_startup(struct tpm_chip *chip);
int tpm_do_selftest(struct tpm_chip *chip); int tpm1_do_selftest(struct tpm_chip *chip);
int tpm1_get_timeouts(struct tpm_chip *chip);
unsigned long tpm1_calc_ordinal_duration(struct tpm_chip *chip, u32 ordinal);
int tpm1_pcr_extend(struct tpm_chip *chip, u32 pcr_idx, const u8 *hash,
const char *log_msg);
int tpm1_pcr_read(struct tpm_chip *chip, u32 pcr_idx, u8 *res_buf);
ssize_t tpm1_getcap(struct tpm_chip *chip, u32 subcap_id, cap_t *cap,
const char *desc, size_t min_cap_length);
int tpm1_get_random(struct tpm_chip *chip, u8 *out, size_t max);
unsigned long tpm_calc_ordinal_duration(struct tpm_chip *chip, u32 ordinal); unsigned long tpm_calc_ordinal_duration(struct tpm_chip *chip, u32 ordinal);
int tpm_pm_suspend(struct device *dev); int tpm_pm_suspend(struct device *dev);
int tpm_pm_resume(struct device *dev); int tpm_pm_resume(struct device *dev);
...@@ -560,7 +543,6 @@ void tpm_chip_unregister(struct tpm_chip *chip); ...@@ -560,7 +543,6 @@ void tpm_chip_unregister(struct tpm_chip *chip);
void tpm_sysfs_add_device(struct tpm_chip *chip); void tpm_sysfs_add_device(struct tpm_chip *chip);
int tpm_pcr_read_dev(struct tpm_chip *chip, int pcr_idx, u8 *res_buf);
#ifdef CONFIG_ACPI #ifdef CONFIG_ACPI
extern void tpm_add_ppi(struct tpm_chip *chip); extern void tpm_add_ppi(struct tpm_chip *chip);
...@@ -575,8 +557,9 @@ static inline u32 tpm2_rc_value(u32 rc) ...@@ -575,8 +557,9 @@ static inline u32 tpm2_rc_value(u32 rc)
return (rc & BIT(7)) ? rc & 0xff : rc; return (rc & BIT(7)) ? rc & 0xff : rc;
} }
int tpm2_pcr_read(struct tpm_chip *chip, int pcr_idx, u8 *res_buf); int tpm2_get_timeouts(struct tpm_chip *chip);
int tpm2_pcr_extend(struct tpm_chip *chip, int pcr_idx, u32 count, int tpm2_pcr_read(struct tpm_chip *chip, u32 pcr_idx, u8 *res_buf);
int tpm2_pcr_extend(struct tpm_chip *chip, u32 pcr_idx, u32 count,
struct tpm2_digest *digests); struct tpm2_digest *digests);
int tpm2_get_random(struct tpm_chip *chip, u8 *dest, size_t max); int tpm2_get_random(struct tpm_chip *chip, u8 *dest, size_t max);
void tpm2_flush_context_cmd(struct tpm_chip *chip, u32 handle, void tpm2_flush_context_cmd(struct tpm_chip *chip, u32 handle,
......
This diff is collapsed.
This diff is collapsed.
...@@ -373,7 +373,7 @@ static int tpm2_map_response_header(struct tpm_chip *chip, u32 cc, u8 *rsp, ...@@ -373,7 +373,7 @@ static int tpm2_map_response_header(struct tpm_chip *chip, u32 cc, u8 *rsp,
dev_err(&chip->dev, "%s: unknown handle 0x%08X\n", dev_err(&chip->dev, "%s: unknown handle 0x%08X\n",
__func__, phandle); __func__, phandle);
break; break;
}; }
return 0; return 0;
out_no_slots: out_no_slots:
......
...@@ -369,6 +369,7 @@ static int i2c_nuvoton_send(struct tpm_chip *chip, u8 *buf, size_t len) ...@@ -369,6 +369,7 @@ static int i2c_nuvoton_send(struct tpm_chip *chip, u8 *buf, size_t len)
struct device *dev = chip->dev.parent; struct device *dev = chip->dev.parent;
struct i2c_client *client = to_i2c_client(dev); struct i2c_client *client = to_i2c_client(dev);
u32 ordinal; u32 ordinal;
unsigned long duration;
size_t count = 0; size_t count = 0;
int burst_count, bytes2write, retries, rc = -EIO; int burst_count, bytes2write, retries, rc = -EIO;
...@@ -455,12 +456,12 @@ static int i2c_nuvoton_send(struct tpm_chip *chip, u8 *buf, size_t len) ...@@ -455,12 +456,12 @@ static int i2c_nuvoton_send(struct tpm_chip *chip, u8 *buf, size_t len)
return rc; return rc;
} }
ordinal = be32_to_cpu(*((__be32 *) (buf + 6))); ordinal = be32_to_cpu(*((__be32 *) (buf + 6)));
rc = i2c_nuvoton_wait_for_data_avail(chip, duration = tpm_calc_ordinal_duration(chip, ordinal);
tpm_calc_ordinal_duration(chip,
ordinal), rc = i2c_nuvoton_wait_for_data_avail(chip, duration, &priv->read_queue);
&priv->read_queue);
if (rc) { if (rc) {
dev_err(dev, "%s() timeout command duration\n", __func__); dev_err(dev, "%s() timeout command duration %ld\n",
__func__, duration);
i2c_nuvoton_ready(chip); i2c_nuvoton_ready(chip);
return rc; return rc;
} }
......
...@@ -39,8 +39,7 @@ static const struct vio_device_id tpm_ibmvtpm_device_table[] = { ...@@ -39,8 +39,7 @@ static const struct vio_device_id tpm_ibmvtpm_device_table[] = {
MODULE_DEVICE_TABLE(vio, tpm_ibmvtpm_device_table); MODULE_DEVICE_TABLE(vio, tpm_ibmvtpm_device_table);
/** /**
* * ibmvtpm_send_crq_word() - Send a CRQ request
* ibmvtpm_send_crq_word - Send a CRQ request
* @vdev: vio device struct * @vdev: vio device struct
* @w1: pre-constructed first word of tpm crq (second word is reserved) * @w1: pre-constructed first word of tpm crq (second word is reserved)
* *
...@@ -54,8 +53,7 @@ static int ibmvtpm_send_crq_word(struct vio_dev *vdev, u64 w1) ...@@ -54,8 +53,7 @@ static int ibmvtpm_send_crq_word(struct vio_dev *vdev, u64 w1)
} }
/** /**
* * ibmvtpm_send_crq() - Send a CRQ request
* ibmvtpm_send_crq - Send a CRQ request
* *
* @vdev: vio device struct * @vdev: vio device struct
* @valid: Valid field * @valid: Valid field
......
...@@ -473,11 +473,7 @@ static int tpm_tis_send_main(struct tpm_chip *chip, const u8 *buf, size_t len) ...@@ -473,11 +473,7 @@ static int tpm_tis_send_main(struct tpm_chip *chip, const u8 *buf, size_t len)
if (chip->flags & TPM_CHIP_FLAG_IRQ) { if (chip->flags & TPM_CHIP_FLAG_IRQ) {
ordinal = be32_to_cpu(*((__be32 *) (buf + 6))); ordinal = be32_to_cpu(*((__be32 *) (buf + 6)));
if (chip->flags & TPM_CHIP_FLAG_TPM2) dur = tpm_calc_ordinal_duration(chip, ordinal);
dur = tpm2_calc_ordinal_duration(chip, ordinal);
else
dur = tpm_calc_ordinal_duration(chip, ordinal);
if (wait_for_tpm_stat if (wait_for_tpm_stat
(chip, TPM_STS_DATA_AVAIL | TPM_STS_VALID, dur, (chip, TPM_STS_DATA_AVAIL | TPM_STS_VALID, dur,
&priv->read_queue, false) < 0) { &priv->read_queue, false) < 0) {
...@@ -668,7 +664,7 @@ static int tpm_tis_gen_interrupt(struct tpm_chip *chip) ...@@ -668,7 +664,7 @@ static int tpm_tis_gen_interrupt(struct tpm_chip *chip)
if (chip->flags & TPM_CHIP_FLAG_TPM2) if (chip->flags & TPM_CHIP_FLAG_TPM2)
return tpm2_get_tpm_pt(chip, 0x100, &cap2, desc); return tpm2_get_tpm_pt(chip, 0x100, &cap2, desc);
else else
return tpm_getcap(chip, TPM_CAP_PROP_TIS_TIMEOUT, &cap, desc, return tpm1_getcap(chip, TPM_CAP_PROP_TIS_TIMEOUT, &cap, desc,
0); 0);
} }
...@@ -1060,7 +1056,7 @@ int tpm_tis_resume(struct device *dev) ...@@ -1060,7 +1056,7 @@ int tpm_tis_resume(struct device *dev)
* an error code but for unknown reason it isn't handled. * an error code but for unknown reason it isn't handled.
*/ */
if (!(chip->flags & TPM_CHIP_FLAG_TPM2)) if (!(chip->flags & TPM_CHIP_FLAG_TPM2))
tpm_do_selftest(chip); tpm1_do_selftest(chip);
return 0; return 0;
} }
......
...@@ -53,8 +53,8 @@ struct tpm_class_ops { ...@@ -53,8 +53,8 @@ struct tpm_class_ops {
#if defined(CONFIG_TCG_TPM) || defined(CONFIG_TCG_TPM_MODULE) #if defined(CONFIG_TCG_TPM) || defined(CONFIG_TCG_TPM_MODULE)
extern int tpm_is_tpm2(struct tpm_chip *chip); extern int tpm_is_tpm2(struct tpm_chip *chip);
extern int tpm_pcr_read(struct tpm_chip *chip, int pcr_idx, u8 *res_buf); extern int tpm_pcr_read(struct tpm_chip *chip, u32 pcr_idx, u8 *res_buf);
extern int tpm_pcr_extend(struct tpm_chip *chip, int pcr_idx, const u8 *hash); 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_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_get_random(struct tpm_chip *chip, u8 *data, size_t max);
extern int tpm_seal_trusted(struct tpm_chip *chip, extern int tpm_seal_trusted(struct tpm_chip *chip,
...@@ -69,15 +69,18 @@ static inline int tpm_is_tpm2(struct tpm_chip *chip) ...@@ -69,15 +69,18 @@ static inline int tpm_is_tpm2(struct tpm_chip *chip)
{ {
return -ENODEV; return -ENODEV;
} }
static inline int tpm_pcr_read(struct tpm_chip *chip, int pcr_idx, u8 *res_buf)
static inline int tpm_pcr_read(struct tpm_chip *chip, u32 pcr_idx, u8 *res_buf)
{ {
return -ENODEV; return -ENODEV;
} }
static inline int tpm_pcr_extend(struct tpm_chip *chip, int pcr_idx,
static inline int tpm_pcr_extend(struct tpm_chip *chip, u32 pcr_idx,
const u8 *hash) const u8 *hash)
{ {
return -ENODEV; return -ENODEV;
} }
static inline int tpm_send(struct tpm_chip *chip, void *cmd, size_t buflen) static inline int tpm_send(struct tpm_chip *chip, void *cmd, size_t buflen)
{ {
return -ENODEV; return -ENODEV;
......
...@@ -643,7 +643,7 @@ int ima_calc_buffer_hash(const void *buf, loff_t len, ...@@ -643,7 +643,7 @@ int ima_calc_buffer_hash(const void *buf, loff_t len,
return calc_buffer_shash(buf, len, hash); return calc_buffer_shash(buf, len, hash);
} }
static void __init ima_pcrread(int idx, u8 *pcr) static void __init ima_pcrread(u32 idx, u8 *pcr)
{ {
if (!ima_tpm_chip) if (!ima_tpm_chip)
return; return;
...@@ -659,7 +659,8 @@ static int __init ima_calc_boot_aggregate_tfm(char *digest, ...@@ -659,7 +659,8 @@ static int __init ima_calc_boot_aggregate_tfm(char *digest,
struct crypto_shash *tfm) struct crypto_shash *tfm)
{ {
u8 pcr_i[TPM_DIGEST_SIZE]; u8 pcr_i[TPM_DIGEST_SIZE];
int rc, i; int rc;
u32 i;
SHASH_DESC_ON_STACK(shash, tfm); SHASH_DESC_ON_STACK(shash, tfm);
shash->tfm = tfm; shash->tfm = tfm;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment