mirror of
https://github.com/armbian/linux-cix.git
synced 2026-01-06 12:30:45 -08:00
Merge tag 'tpmdd-next-v5.12-rc1-v2' of git://git.kernel.org/pub/scm/linux/kernel/git/jarkko/linux-tpmdd
Pull tpm updates from Jarkko Sakkinen:
"New features:
- Cr50 I2C TPM driver
- sysfs exports of PCR registers in TPM 2.0 chips
Bug fixes:
- bug fixes for tpm_tis driver, which had a racy wait for hardware
state change to be ready to send a command to the TPM chip. The bug
has existed already since 2006, but has only made itself known in
recent past. This is the same as the "last time" :-)
- Otherwise there's bunch of fixes for not as alarming regressions. I
think the list is about the same as last time, except I added fixes
for some disjoint bugs in trusted keys that I found some time ago"
* tag 'tpmdd-next-v5.12-rc1-v2' of git://git.kernel.org/pub/scm/linux/kernel/git/jarkko/linux-tpmdd:
KEYS: trusted: Reserve TPM for seal and unseal operations
KEYS: trusted: Fix migratable=1 failing
KEYS: trusted: Fix incorrect handling of tpm_get_random()
tpm/ppi: Constify static struct attribute_group
ABI: add sysfs description for tpm exports of PCR registers
tpm: add sysfs exports for all banks of PCR registers
keys: Update comment for restrict_link_by_key_or_keyring_chain
tpm: Remove tpm_dev_wq_lock
char: tpm: add i2c driver for cr50
tpm: Fix fall-through warnings for Clang
tpm_tis: Clean up locality release
tpm_tis: Fix check_locality for correct locality acquisition
This commit is contained in:
@@ -194,3 +194,17 @@ Description: The "tpm_version_major" property shows the TCG spec major version
|
||||
Example output::
|
||||
|
||||
2
|
||||
|
||||
What: /sys/class/tpm/tpmX/pcr-H/N
|
||||
Date: March 2021
|
||||
KernelVersion: 5.12
|
||||
Contact: linux-integrity@vger.kernel.org
|
||||
Description: produces output in compact hex representation for PCR
|
||||
number N from hash bank H. N is the numeric value of
|
||||
the PCR number and H is the crypto string
|
||||
representation of the hash
|
||||
|
||||
Example output::
|
||||
|
||||
cat /sys/class/tpm/tpm0/pcr-sha256/7
|
||||
2ED93F199692DC6788EFA6A1FE74514AB9760B2A6CEEAEF6C808C13E4ABB0D42
|
||||
|
||||
@@ -244,9 +244,10 @@ int restrict_link_by_key_or_keyring(struct key *dest_keyring,
|
||||
* @payload: The payload of the new key.
|
||||
* @trusted: A key or ring of keys that can be used to vouch for the new cert.
|
||||
*
|
||||
* Check the new certificate only against the key or keys passed in the data
|
||||
* parameter. If one of those is the signing key and validates the new
|
||||
* certificate, then mark the new certificate as being ok to link.
|
||||
* Check the new certificate against the key or keys passed in the data
|
||||
* parameter and against the keys already linked to the destination keyring. If
|
||||
* one of those is the signing key and validates the new certificate, then mark
|
||||
* the new certificate as being ok to link.
|
||||
*
|
||||
* Returns 0 if the new certificate was accepted, -ENOKEY if we
|
||||
* couldn't find a matching parent certificate in the trusted list,
|
||||
|
||||
@@ -86,6 +86,16 @@ config TCG_TIS_SYNQUACER
|
||||
To compile this driver as a module, choose M here;
|
||||
the module will be called tpm_tis_synquacer.
|
||||
|
||||
config TCG_TIS_I2C_CR50
|
||||
tristate "TPM Interface Specification 2.0 Interface (I2C - CR50)"
|
||||
depends on I2C
|
||||
select TCG_CR50
|
||||
help
|
||||
This is a driver for the Google cr50 I2C TPM interface which is a
|
||||
custom microcontroller and requires a custom i2c protocol interface
|
||||
to handle the limitations of the hardware. To compile this driver
|
||||
as a module, choose M here; the module will be called tcg_tis_i2c_cr50.
|
||||
|
||||
config TCG_TIS_I2C_ATMEL
|
||||
tristate "TPM Interface Specification 1.2 Interface (I2C - Atmel)"
|
||||
depends on I2C
|
||||
|
||||
@@ -27,6 +27,8 @@ obj-$(CONFIG_TCG_TIS_SPI) += tpm_tis_spi.o
|
||||
tpm_tis_spi-y := tpm_tis_spi_main.o
|
||||
tpm_tis_spi-$(CONFIG_TCG_TIS_SPI_CR50) += tpm_tis_spi_cr50.o
|
||||
|
||||
obj-$(CONFIG_TCG_TIS_I2C_CR50) += tpm_tis_i2c_cr50.o
|
||||
|
||||
obj-$(CONFIG_TCG_TIS_I2C_ATMEL) += tpm_i2c_atmel.o
|
||||
obj-$(CONFIG_TCG_TIS_I2C_INFINEON) += tpm_i2c_infineon.o
|
||||
obj-$(CONFIG_TCG_TIS_I2C_NUVOTON) += tpm_i2c_nuvoton.o
|
||||
|
||||
@@ -210,6 +210,7 @@ static int get_event_name(char *dest, struct tcpa_event *event,
|
||||
default:
|
||||
break;
|
||||
}
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -278,6 +278,8 @@ static void tpm_devs_release(struct device *dev)
|
||||
{
|
||||
struct tpm_chip *chip = container_of(dev, struct tpm_chip, devs);
|
||||
|
||||
dump_stack();
|
||||
|
||||
/* release the master device reference */
|
||||
put_device(&chip->dev);
|
||||
}
|
||||
|
||||
@@ -20,7 +20,6 @@
|
||||
#include "tpm-dev.h"
|
||||
|
||||
static struct workqueue_struct *tpm_dev_wq;
|
||||
static DEFINE_MUTEX(tpm_dev_wq_lock);
|
||||
|
||||
static ssize_t tpm_dev_transmit(struct tpm_chip *chip, struct tpm_space *space,
|
||||
u8 *buf, size_t bufsiz)
|
||||
|
||||
@@ -337,11 +337,190 @@ static const struct attribute_group tpm2_dev_group = {
|
||||
.attrs = tpm2_dev_attrs,
|
||||
};
|
||||
|
||||
struct tpm_pcr_attr {
|
||||
int alg_id;
|
||||
int pcr;
|
||||
struct device_attribute attr;
|
||||
};
|
||||
|
||||
#define to_tpm_pcr_attr(a) container_of(a, struct tpm_pcr_attr, attr)
|
||||
|
||||
static ssize_t pcr_value_show(struct device *dev,
|
||||
struct device_attribute *attr,
|
||||
char *buf)
|
||||
{
|
||||
struct tpm_pcr_attr *ha = to_tpm_pcr_attr(attr);
|
||||
struct tpm_chip *chip = to_tpm_chip(dev);
|
||||
struct tpm_digest digest;
|
||||
int i;
|
||||
int digest_size = 0;
|
||||
int rc;
|
||||
char *str = buf;
|
||||
|
||||
for (i = 0; i < chip->nr_allocated_banks; i++)
|
||||
if (ha->alg_id == chip->allocated_banks[i].alg_id)
|
||||
digest_size = chip->allocated_banks[i].digest_size;
|
||||
/* should never happen */
|
||||
if (!digest_size)
|
||||
return -EINVAL;
|
||||
|
||||
digest.alg_id = ha->alg_id;
|
||||
rc = tpm_pcr_read(chip, ha->pcr, &digest);
|
||||
if (rc)
|
||||
return rc;
|
||||
for (i = 0; i < digest_size; i++)
|
||||
str += sprintf(str, "%02X", digest.digest[i]);
|
||||
str += sprintf(str, "\n");
|
||||
|
||||
return str - buf;
|
||||
}
|
||||
|
||||
/*
|
||||
* The following set of defines represents all the magic to build
|
||||
* the per hash attribute groups for displaying each bank of PCRs.
|
||||
* The only slight problem with this approach is that every PCR is
|
||||
* hard coded to be present, so you don't know if an PCR is missing
|
||||
* until a cat of the file returns -EINVAL
|
||||
*
|
||||
* Also note you must ignore checkpatch warnings in this macro
|
||||
* code. This is deep macro magic that checkpatch.pl doesn't
|
||||
* understand.
|
||||
*/
|
||||
|
||||
/* Note, this must match TPM2_PLATFORM_PCR which is fixed at 24. */
|
||||
#define _TPM_HELPER(_alg, _hash, F) \
|
||||
F(_alg, _hash, 0) \
|
||||
F(_alg, _hash, 1) \
|
||||
F(_alg, _hash, 2) \
|
||||
F(_alg, _hash, 3) \
|
||||
F(_alg, _hash, 4) \
|
||||
F(_alg, _hash, 5) \
|
||||
F(_alg, _hash, 6) \
|
||||
F(_alg, _hash, 7) \
|
||||
F(_alg, _hash, 8) \
|
||||
F(_alg, _hash, 9) \
|
||||
F(_alg, _hash, 10) \
|
||||
F(_alg, _hash, 11) \
|
||||
F(_alg, _hash, 12) \
|
||||
F(_alg, _hash, 13) \
|
||||
F(_alg, _hash, 14) \
|
||||
F(_alg, _hash, 15) \
|
||||
F(_alg, _hash, 16) \
|
||||
F(_alg, _hash, 17) \
|
||||
F(_alg, _hash, 18) \
|
||||
F(_alg, _hash, 19) \
|
||||
F(_alg, _hash, 20) \
|
||||
F(_alg, _hash, 21) \
|
||||
F(_alg, _hash, 22) \
|
||||
F(_alg, _hash, 23)
|
||||
|
||||
/* ignore checkpatch warning about trailing ; in macro. */
|
||||
#define PCR_ATTR(_alg, _hash, _pcr) \
|
||||
static struct tpm_pcr_attr dev_attr_pcr_##_hash##_##_pcr = { \
|
||||
.alg_id = _alg, \
|
||||
.pcr = _pcr, \
|
||||
.attr = { \
|
||||
.attr = { \
|
||||
.name = __stringify(_pcr), \
|
||||
.mode = 0444 \
|
||||
}, \
|
||||
.show = pcr_value_show \
|
||||
} \
|
||||
};
|
||||
|
||||
#define PCR_ATTRS(_alg, _hash) \
|
||||
_TPM_HELPER(_alg, _hash, PCR_ATTR)
|
||||
|
||||
/* ignore checkpatch warning about trailing , in macro. */
|
||||
#define PCR_ATTR_VAL(_alg, _hash, _pcr) \
|
||||
&dev_attr_pcr_##_hash##_##_pcr.attr.attr,
|
||||
|
||||
#define PCR_ATTR_GROUP_ARRAY(_alg, _hash) \
|
||||
static struct attribute *pcr_group_attrs_##_hash[] = { \
|
||||
_TPM_HELPER(_alg, _hash, PCR_ATTR_VAL) \
|
||||
NULL \
|
||||
}
|
||||
|
||||
#define PCR_ATTR_GROUP(_alg, _hash) \
|
||||
static struct attribute_group pcr_group_##_hash = { \
|
||||
.name = "pcr-" __stringify(_hash), \
|
||||
.attrs = pcr_group_attrs_##_hash \
|
||||
}
|
||||
|
||||
#define PCR_ATTR_BUILD(_alg, _hash) \
|
||||
PCR_ATTRS(_alg, _hash) \
|
||||
PCR_ATTR_GROUP_ARRAY(_alg, _hash); \
|
||||
PCR_ATTR_GROUP(_alg, _hash)
|
||||
/*
|
||||
* End of macro structure to build an attribute group containing 24
|
||||
* PCR value files for each supported hash algorithm
|
||||
*/
|
||||
|
||||
/*
|
||||
* The next set of macros implements the cleverness for each hash to
|
||||
* build a static attribute group called pcr_group_<hash> which can be
|
||||
* added to chip->groups[].
|
||||
*
|
||||
* The first argument is the TPM algorithm id and the second is the
|
||||
* hash used as both the suffix and the group name. Note: the group
|
||||
* name is a directory in the top level tpm class with the name
|
||||
* pcr-<hash>, so it must not clash with any other names already
|
||||
* in the sysfs directory.
|
||||
*/
|
||||
PCR_ATTR_BUILD(TPM_ALG_SHA1, sha1);
|
||||
PCR_ATTR_BUILD(TPM_ALG_SHA256, sha256);
|
||||
PCR_ATTR_BUILD(TPM_ALG_SHA384, sha384);
|
||||
PCR_ATTR_BUILD(TPM_ALG_SHA512, sha512);
|
||||
PCR_ATTR_BUILD(TPM_ALG_SM3_256, sm3);
|
||||
|
||||
|
||||
void tpm_sysfs_add_device(struct tpm_chip *chip)
|
||||
{
|
||||
int i;
|
||||
|
||||
WARN_ON(chip->groups_cnt != 0);
|
||||
|
||||
if (chip->flags & TPM_CHIP_FLAG_TPM2)
|
||||
chip->groups[chip->groups_cnt++] = &tpm2_dev_group;
|
||||
else
|
||||
chip->groups[chip->groups_cnt++] = &tpm1_dev_group;
|
||||
|
||||
/* add one group for each bank hash */
|
||||
for (i = 0; i < chip->nr_allocated_banks; i++) {
|
||||
switch (chip->allocated_banks[i].alg_id) {
|
||||
case TPM_ALG_SHA1:
|
||||
chip->groups[chip->groups_cnt++] = &pcr_group_sha1;
|
||||
break;
|
||||
case TPM_ALG_SHA256:
|
||||
chip->groups[chip->groups_cnt++] = &pcr_group_sha256;
|
||||
break;
|
||||
case TPM_ALG_SHA384:
|
||||
chip->groups[chip->groups_cnt++] = &pcr_group_sha384;
|
||||
break;
|
||||
case TPM_ALG_SHA512:
|
||||
chip->groups[chip->groups_cnt++] = &pcr_group_sha512;
|
||||
break;
|
||||
case TPM_ALG_SM3_256:
|
||||
chip->groups[chip->groups_cnt++] = &pcr_group_sm3;
|
||||
break;
|
||||
default:
|
||||
/*
|
||||
* If triggers, send a patch to add both a
|
||||
* PCR_ATTR_BUILD() macro above for the
|
||||
* missing algorithm as well as an additional
|
||||
* case in this switch statement.
|
||||
*/
|
||||
dev_err(&chip->dev,
|
||||
"TPM with unsupported bank algorithm 0x%04x",
|
||||
chip->allocated_banks[i].alg_id);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* This will only trigger if someone has added an additional
|
||||
* hash to the tpm_algorithms enum without incrementing
|
||||
* TPM_MAX_HASHES.
|
||||
*/
|
||||
WARN_ON(chip->groups_cnt > TPM_MAX_HASHES + 1);
|
||||
}
|
||||
|
||||
@@ -164,8 +164,6 @@ extern const struct file_operations tpmrm_fops;
|
||||
extern struct idr dev_nums_idr;
|
||||
|
||||
ssize_t tpm_transmit(struct tpm_chip *chip, u8 *buf, size_t bufsiz);
|
||||
ssize_t tpm_transmit_cmd(struct tpm_chip *chip, struct tpm_buf *buf,
|
||||
size_t min_rsp_body_length, const char *desc);
|
||||
int tpm_get_timeouts(struct tpm_chip *);
|
||||
int tpm_auto_startup(struct tpm_chip *chip);
|
||||
|
||||
@@ -194,8 +192,6 @@ static inline void tpm_msleep(unsigned int delay_msec)
|
||||
int tpm_chip_start(struct tpm_chip *chip);
|
||||
void tpm_chip_stop(struct tpm_chip *chip);
|
||||
struct tpm_chip *tpm_find_get_ops(struct tpm_chip *chip);
|
||||
__must_check int tpm_try_get_ops(struct tpm_chip *chip);
|
||||
void tpm_put_ops(struct tpm_chip *chip);
|
||||
|
||||
struct tpm_chip *tpm_chip_alloc(struct device *dev,
|
||||
const struct tpm_class_ops *ops);
|
||||
|
||||
@@ -358,7 +358,7 @@ static struct attribute *ppi_attrs[] = {
|
||||
&dev_attr_tcg_operations.attr,
|
||||
&dev_attr_vs_operations.attr, NULL,
|
||||
};
|
||||
static struct attribute_group ppi_attr_grp = {
|
||||
static const struct attribute_group ppi_attr_grp = {
|
||||
.name = "ppi",
|
||||
.attrs = ppi_attrs
|
||||
};
|
||||
|
||||
@@ -125,7 +125,8 @@ static bool check_locality(struct tpm_chip *chip, int l)
|
||||
if (rc < 0)
|
||||
return false;
|
||||
|
||||
if ((access & (TPM_ACCESS_ACTIVE_LOCALITY | TPM_ACCESS_VALID)) ==
|
||||
if ((access & (TPM_ACCESS_ACTIVE_LOCALITY | TPM_ACCESS_VALID
|
||||
| TPM_ACCESS_REQUEST_USE)) ==
|
||||
(TPM_ACCESS_ACTIVE_LOCALITY | TPM_ACCESS_VALID)) {
|
||||
priv->locality = l;
|
||||
return true;
|
||||
@@ -134,58 +135,13 @@ static bool check_locality(struct tpm_chip *chip, int l)
|
||||
return false;
|
||||
}
|
||||
|
||||
static bool locality_inactive(struct tpm_chip *chip, int l)
|
||||
{
|
||||
struct tpm_tis_data *priv = dev_get_drvdata(&chip->dev);
|
||||
int rc;
|
||||
u8 access;
|
||||
|
||||
rc = tpm_tis_read8(priv, TPM_ACCESS(l), &access);
|
||||
if (rc < 0)
|
||||
return false;
|
||||
|
||||
if ((access & (TPM_ACCESS_VALID | TPM_ACCESS_ACTIVE_LOCALITY))
|
||||
== TPM_ACCESS_VALID)
|
||||
return true;
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
static int release_locality(struct tpm_chip *chip, int l)
|
||||
{
|
||||
struct tpm_tis_data *priv = dev_get_drvdata(&chip->dev);
|
||||
unsigned long stop, timeout;
|
||||
long rc;
|
||||
|
||||
tpm_tis_write8(priv, TPM_ACCESS(l), TPM_ACCESS_ACTIVE_LOCALITY);
|
||||
|
||||
stop = jiffies + chip->timeout_a;
|
||||
|
||||
if (chip->flags & TPM_CHIP_FLAG_IRQ) {
|
||||
again:
|
||||
timeout = stop - jiffies;
|
||||
if ((long)timeout <= 0)
|
||||
return -1;
|
||||
|
||||
rc = wait_event_interruptible_timeout(priv->int_queue,
|
||||
(locality_inactive(chip, l)),
|
||||
timeout);
|
||||
|
||||
if (rc > 0)
|
||||
return 0;
|
||||
|
||||
if (rc == -ERESTARTSYS && freezing(current)) {
|
||||
clear_thread_flag(TIF_SIGPENDING);
|
||||
goto again;
|
||||
}
|
||||
} else {
|
||||
do {
|
||||
if (locality_inactive(chip, l))
|
||||
return 0;
|
||||
tpm_msleep(TPM_TIMEOUT);
|
||||
} while (time_before(jiffies, stop));
|
||||
}
|
||||
return -1;
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int request_locality(struct tpm_chip *chip, int l)
|
||||
|
||||
790
drivers/char/tpm/tpm_tis_i2c_cr50.c
Normal file
790
drivers/char/tpm/tpm_tis_i2c_cr50.c
Normal file
File diff suppressed because it is too large
Load Diff
@@ -31,6 +31,7 @@ struct tpm_chip;
|
||||
struct trusted_key_payload;
|
||||
struct trusted_key_options;
|
||||
|
||||
/* if you add a new hash to this, increment TPM_MAX_HASHES below */
|
||||
enum tpm_algorithms {
|
||||
TPM_ALG_ERROR = 0x0000,
|
||||
TPM_ALG_SHA1 = 0x0004,
|
||||
@@ -42,6 +43,12 @@ enum tpm_algorithms {
|
||||
TPM_ALG_SM3_256 = 0x0012,
|
||||
};
|
||||
|
||||
/*
|
||||
* maximum number of hashing algorithms a TPM can have. This is
|
||||
* basically a count of every hash in tpm_algorithms above
|
||||
*/
|
||||
#define TPM_MAX_HASHES 5
|
||||
|
||||
struct tpm_digest {
|
||||
u16 alg_id;
|
||||
u8 digest[TPM_MAX_DIGEST_SIZE];
|
||||
@@ -146,7 +153,7 @@ struct tpm_chip {
|
||||
|
||||
struct dentry *bios_dir[TPM_NUM_EVENT_LOG_FILES];
|
||||
|
||||
const struct attribute_group *groups[3];
|
||||
const struct attribute_group *groups[3 + TPM_MAX_HASHES];
|
||||
unsigned int groups_cnt;
|
||||
|
||||
u32 nr_allocated_banks;
|
||||
@@ -397,6 +404,10 @@ static inline u32 tpm2_rc_value(u32 rc)
|
||||
#if defined(CONFIG_TCG_TPM) || defined(CONFIG_TCG_TPM_MODULE)
|
||||
|
||||
extern int tpm_is_tpm2(struct tpm_chip *chip);
|
||||
extern __must_check int tpm_try_get_ops(struct tpm_chip *chip);
|
||||
extern void tpm_put_ops(struct tpm_chip *chip);
|
||||
extern ssize_t tpm_transmit_cmd(struct tpm_chip *chip, struct tpm_buf *buf,
|
||||
size_t min_rsp_body_length, const char *desc);
|
||||
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,
|
||||
@@ -410,7 +421,6 @@ 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)
|
||||
{
|
||||
|
||||
@@ -403,9 +403,12 @@ static int osap(struct tpm_buf *tb, struct osapsess *s,
|
||||
int ret;
|
||||
|
||||
ret = tpm_get_random(chip, ononce, TPM_NONCE_SIZE);
|
||||
if (ret != TPM_NONCE_SIZE)
|
||||
if (ret < 0)
|
||||
return ret;
|
||||
|
||||
if (ret != TPM_NONCE_SIZE)
|
||||
return -EIO;
|
||||
|
||||
tpm_buf_reset(tb, TPM_TAG_RQU_COMMAND, TPM_ORD_OSAP);
|
||||
tpm_buf_append_u16(tb, type);
|
||||
tpm_buf_append_u32(tb, handle);
|
||||
@@ -496,8 +499,12 @@ static int tpm_seal(struct tpm_buf *tb, uint16_t keytype,
|
||||
goto out;
|
||||
|
||||
ret = tpm_get_random(chip, td->nonceodd, TPM_NONCE_SIZE);
|
||||
if (ret < 0)
|
||||
return ret;
|
||||
|
||||
if (ret != TPM_NONCE_SIZE)
|
||||
goto out;
|
||||
return -EIO;
|
||||
|
||||
ordinal = htonl(TPM_ORD_SEAL);
|
||||
datsize = htonl(datalen);
|
||||
pcrsize = htonl(pcrinfosize);
|
||||
@@ -601,9 +608,12 @@ static int tpm_unseal(struct tpm_buf *tb,
|
||||
|
||||
ordinal = htonl(TPM_ORD_UNSEAL);
|
||||
ret = tpm_get_random(chip, nonceodd, TPM_NONCE_SIZE);
|
||||
if (ret < 0)
|
||||
return ret;
|
||||
|
||||
if (ret != TPM_NONCE_SIZE) {
|
||||
pr_info("trusted_key: tpm_get_random failed (%d)\n", ret);
|
||||
return ret;
|
||||
return -EIO;
|
||||
}
|
||||
ret = TSS_authhmac(authdata1, keyauth, TPM_NONCE_SIZE,
|
||||
enonce1, nonceodd, cont, sizeof(uint32_t),
|
||||
@@ -791,7 +801,7 @@ static int getoptions(char *c, struct trusted_key_payload *pay,
|
||||
case Opt_migratable:
|
||||
if (*args[0].from == '0')
|
||||
pay->migratable = 0;
|
||||
else
|
||||
else if (*args[0].from != '1')
|
||||
return -EINVAL;
|
||||
break;
|
||||
case Opt_pcrlock:
|
||||
@@ -1013,8 +1023,12 @@ static int trusted_instantiate(struct key *key,
|
||||
case Opt_new:
|
||||
key_len = payload->key_len;
|
||||
ret = tpm_get_random(chip, payload->key, key_len);
|
||||
if (ret < 0)
|
||||
goto out;
|
||||
|
||||
if (ret != key_len) {
|
||||
pr_info("trusted_key: key_create failed (%d)\n", ret);
|
||||
ret = -EIO;
|
||||
goto out;
|
||||
}
|
||||
if (tpm2)
|
||||
|
||||
@@ -83,6 +83,12 @@ int tpm2_seal_trusted(struct tpm_chip *chip,
|
||||
if (rc)
|
||||
return rc;
|
||||
|
||||
rc = tpm_buf_init(&buf, TPM2_ST_SESSIONS, TPM2_CC_CREATE);
|
||||
if (rc) {
|
||||
tpm_put_ops(chip);
|
||||
return rc;
|
||||
}
|
||||
|
||||
tpm_buf_append_u32(&buf, options->keyhandle);
|
||||
tpm2_buf_append_auth(&buf, TPM2_RS_PW,
|
||||
NULL /* nonce */, 0,
|
||||
@@ -130,7 +136,7 @@ int tpm2_seal_trusted(struct tpm_chip *chip,
|
||||
goto out;
|
||||
}
|
||||
|
||||
rc = tpm_send(chip, buf.data, tpm_buf_length(&buf));
|
||||
rc = tpm_transmit_cmd(chip, &buf, 4, "sealing data");
|
||||
if (rc)
|
||||
goto out;
|
||||
|
||||
@@ -157,6 +163,7 @@ out:
|
||||
rc = -EPERM;
|
||||
}
|
||||
|
||||
tpm_put_ops(chip);
|
||||
return rc;
|
||||
}
|
||||
|
||||
@@ -211,7 +218,7 @@ static int tpm2_load_cmd(struct tpm_chip *chip,
|
||||
goto out;
|
||||
}
|
||||
|
||||
rc = tpm_send(chip, buf.data, tpm_buf_length(&buf));
|
||||
rc = tpm_transmit_cmd(chip, &buf, 4, "loading blob");
|
||||
if (!rc)
|
||||
*blob_handle = be32_to_cpup(
|
||||
(__be32 *) &buf.data[TPM_HEADER_SIZE]);
|
||||
@@ -260,7 +267,7 @@ static int tpm2_unseal_cmd(struct tpm_chip *chip,
|
||||
options->blobauth /* hmac */,
|
||||
TPM_DIGEST_SIZE);
|
||||
|
||||
rc = tpm_send(chip, buf.data, tpm_buf_length(&buf));
|
||||
rc = tpm_transmit_cmd(chip, &buf, 6, "unsealing");
|
||||
if (rc > 0)
|
||||
rc = -EPERM;
|
||||
|
||||
@@ -304,12 +311,19 @@ int tpm2_unseal_trusted(struct tpm_chip *chip,
|
||||
u32 blob_handle;
|
||||
int rc;
|
||||
|
||||
rc = tpm2_load_cmd(chip, payload, options, &blob_handle);
|
||||
rc = tpm_try_get_ops(chip);
|
||||
if (rc)
|
||||
return rc;
|
||||
|
||||
rc = tpm2_load_cmd(chip, payload, options, &blob_handle);
|
||||
if (rc)
|
||||
goto out;
|
||||
|
||||
rc = tpm2_unseal_cmd(chip, payload, options, blob_handle);
|
||||
tpm2_flush_context(chip, blob_handle);
|
||||
|
||||
out:
|
||||
tpm_put_ops(chip);
|
||||
|
||||
return rc;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user