Skip to content

Commit 4a94c43

Browse files
committed
Merge tag 'tpmdd-next-20191219' of git://git.infradead.org/users/jjs/linux-tpmdd
Pull tpm fixes from Jarkko Sakkinen: "Bunch of fixes for rc3" * tag 'tpmdd-next-20191219' of git://git.infradead.org/users/jjs/linux-tpmdd: tpm/tpm_ftpm_tee: add shutdown call back tpm: selftest: cleanup after unseal with wrong auth/policy test tpm: selftest: add test covering async mode tpm: fix invalid locking in NONBLOCKING mode security: keys: trusted: fix lost handle flush tpm_tis: reserve chip for duration of tpm_tis_core_init KEYS: asymmetric: return ENOMEM if akcipher_request_alloc() fails KEYS: remove CONFIG_KEYS_COMPAT
2 parents 80a0c2e + 1760eb6 commit 4a94c43

File tree

16 files changed

+88
-36
lines changed

16 files changed

+88
-36
lines changed

crypto/asymmetric_keys/asym_tpm.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -470,6 +470,7 @@ static int tpm_key_encrypt(struct tpm_key *tk,
470470
if (ret < 0)
471471
goto error_free_tfm;
472472

473+
ret = -ENOMEM;
473474
req = akcipher_request_alloc(tfm, GFP_KERNEL);
474475
if (!req)
475476
goto error_free_tfm;

crypto/asymmetric_keys/public_key.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -184,6 +184,7 @@ static int software_key_eds_op(struct kernel_pkey_params *params,
184184
if (IS_ERR(tfm))
185185
return PTR_ERR(tfm);
186186

187+
ret = -ENOMEM;
187188
req = akcipher_request_alloc(tfm, GFP_KERNEL);
188189
if (!req)
189190
goto error_free_tfm;

drivers/char/tpm/tpm-dev-common.c

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,13 +61,20 @@ static void tpm_dev_async_work(struct work_struct *work)
6161

6262
mutex_lock(&priv->buffer_mutex);
6363
priv->command_enqueued = false;
64+
ret = tpm_try_get_ops(priv->chip);
65+
if (ret) {
66+
priv->response_length = ret;
67+
goto out;
68+
}
69+
6470
ret = tpm_dev_transmit(priv->chip, priv->space, priv->data_buffer,
6571
sizeof(priv->data_buffer));
6672
tpm_put_ops(priv->chip);
6773
if (ret > 0) {
6874
priv->response_length = ret;
6975
mod_timer(&priv->user_read_timer, jiffies + (120 * HZ));
7076
}
77+
out:
7178
mutex_unlock(&priv->buffer_mutex);
7279
wake_up_interruptible(&priv->async_wait);
7380
}
@@ -204,6 +211,7 @@ ssize_t tpm_common_write(struct file *file, const char __user *buf,
204211
if (file->f_flags & O_NONBLOCK) {
205212
priv->command_enqueued = true;
206213
queue_work(tpm_dev_wq, &priv->async_work);
214+
tpm_put_ops(priv->chip);
207215
mutex_unlock(&priv->buffer_mutex);
208216
return size;
209217
}

drivers/char/tpm/tpm.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -218,7 +218,6 @@ int tpm2_pcr_read(struct tpm_chip *chip, u32 pcr_idx,
218218
int tpm2_pcr_extend(struct tpm_chip *chip, u32 pcr_idx,
219219
struct tpm_digest *digests);
220220
int tpm2_get_random(struct tpm_chip *chip, u8 *dest, size_t max);
221-
void tpm2_flush_context(struct tpm_chip *chip, u32 handle);
222221
ssize_t tpm2_get_tpm_pt(struct tpm_chip *chip, u32 property_id,
223222
u32 *value, const char *desc);
224223

drivers/char/tpm/tpm2-cmd.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -362,6 +362,7 @@ void tpm2_flush_context(struct tpm_chip *chip, u32 handle)
362362
tpm_transmit_cmd(chip, &buf, 0, "flushing context");
363363
tpm_buf_destroy(&buf);
364364
}
365+
EXPORT_SYMBOL_GPL(tpm2_flush_context);
365366

366367
struct tpm2_get_cap_out {
367368
u8 more_data;

drivers/char/tpm/tpm_ftpm_tee.c

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ static const uuid_t ftpm_ta_uuid =
3232
0x82, 0xCB, 0x34, 0x3F, 0xB7, 0xF3, 0x78, 0x96);
3333

3434
/**
35-
* ftpm_tee_tpm_op_recv - retrieve fTPM response.
35+
* ftpm_tee_tpm_op_recv() - retrieve fTPM response.
3636
* @chip: the tpm_chip description as specified in driver/char/tpm/tpm.h.
3737
* @buf: the buffer to store data.
3838
* @count: the number of bytes to read.
@@ -61,7 +61,7 @@ static int ftpm_tee_tpm_op_recv(struct tpm_chip *chip, u8 *buf, size_t count)
6161
}
6262

6363
/**
64-
* ftpm_tee_tpm_op_send - send TPM commands through the TEE shared memory.
64+
* ftpm_tee_tpm_op_send() - send TPM commands through the TEE shared memory.
6565
* @chip: the tpm_chip description as specified in driver/char/tpm/tpm.h
6666
* @buf: the buffer to send.
6767
* @len: the number of bytes to send.
@@ -208,7 +208,7 @@ static int ftpm_tee_match(struct tee_ioctl_version_data *ver, const void *data)
208208
}
209209

210210
/**
211-
* ftpm_tee_probe - initialize the fTPM
211+
* ftpm_tee_probe() - initialize the fTPM
212212
* @pdev: the platform_device description.
213213
*
214214
* Return:
@@ -298,7 +298,7 @@ static int ftpm_tee_probe(struct platform_device *pdev)
298298
}
299299

300300
/**
301-
* ftpm_tee_remove - remove the TPM device
301+
* ftpm_tee_remove() - remove the TPM device
302302
* @pdev: the platform_device description.
303303
*
304304
* Return:
@@ -328,6 +328,19 @@ static int ftpm_tee_remove(struct platform_device *pdev)
328328
return 0;
329329
}
330330

331+
/**
332+
* ftpm_tee_shutdown() - shutdown the TPM device
333+
* @pdev: the platform_device description.
334+
*/
335+
static void ftpm_tee_shutdown(struct platform_device *pdev)
336+
{
337+
struct ftpm_tee_private *pvt_data = dev_get_drvdata(&pdev->dev);
338+
339+
tee_shm_free(pvt_data->shm);
340+
tee_client_close_session(pvt_data->ctx, pvt_data->session);
341+
tee_client_close_context(pvt_data->ctx);
342+
}
343+
331344
static const struct of_device_id of_ftpm_tee_ids[] = {
332345
{ .compatible = "microsoft,ftpm" },
333346
{ }
@@ -341,6 +354,7 @@ static struct platform_driver ftpm_tee_driver = {
341354
},
342355
.probe = ftpm_tee_probe,
343356
.remove = ftpm_tee_remove,
357+
.shutdown = ftpm_tee_shutdown,
344358
};
345359

346360
module_platform_driver(ftpm_tee_driver);

drivers/char/tpm/tpm_tis_core.c

Lines changed: 18 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -978,13 +978,13 @@ int tpm_tis_core_init(struct device *dev, struct tpm_tis_data *priv, int irq,
978978

979979
if (wait_startup(chip, 0) != 0) {
980980
rc = -ENODEV;
981-
goto out_err;
981+
goto err_start;
982982
}
983983

984984
/* Take control of the TPM's interrupt hardware and shut it off */
985985
rc = tpm_tis_read32(priv, TPM_INT_ENABLE(priv->locality), &intmask);
986986
if (rc < 0)
987-
goto out_err;
987+
goto err_start;
988988

989989
intmask |= TPM_INTF_CMD_READY_INT | TPM_INTF_LOCALITY_CHANGE_INT |
990990
TPM_INTF_DATA_AVAIL_INT | TPM_INTF_STS_VALID_INT;
@@ -993,21 +993,21 @@ int tpm_tis_core_init(struct device *dev, struct tpm_tis_data *priv, int irq,
993993

994994
rc = tpm_chip_start(chip);
995995
if (rc)
996-
goto out_err;
996+
goto err_start;
997+
997998
rc = tpm2_probe(chip);
998-
tpm_chip_stop(chip);
999999
if (rc)
1000-
goto out_err;
1000+
goto err_probe;
10011001

10021002
rc = tpm_tis_read32(priv, TPM_DID_VID(0), &vendor);
10031003
if (rc < 0)
1004-
goto out_err;
1004+
goto err_probe;
10051005

10061006
priv->manufacturer_id = vendor;
10071007

10081008
rc = tpm_tis_read8(priv, TPM_RID(0), &rid);
10091009
if (rc < 0)
1010-
goto out_err;
1010+
goto err_probe;
10111011

10121012
dev_info(dev, "%s TPM (device-id 0x%X, rev-id %d)\n",
10131013
(chip->flags & TPM_CHIP_FLAG_TPM2) ? "2.0" : "1.2",
@@ -1016,13 +1016,13 @@ int tpm_tis_core_init(struct device *dev, struct tpm_tis_data *priv, int irq,
10161016
probe = probe_itpm(chip);
10171017
if (probe < 0) {
10181018
rc = -ENODEV;
1019-
goto out_err;
1019+
goto err_probe;
10201020
}
10211021

10221022
/* Figure out the capabilities */
10231023
rc = tpm_tis_read32(priv, TPM_INTF_CAPS(priv->locality), &intfcaps);
10241024
if (rc < 0)
1025-
goto out_err;
1025+
goto err_probe;
10261026

10271027
dev_dbg(dev, "TPM interface capabilities (0x%x):\n",
10281028
intfcaps);
@@ -1056,10 +1056,9 @@ int tpm_tis_core_init(struct device *dev, struct tpm_tis_data *priv, int irq,
10561056
if (tpm_get_timeouts(chip)) {
10571057
dev_err(dev, "Could not get TPM timeouts and durations\n");
10581058
rc = -ENODEV;
1059-
goto out_err;
1059+
goto err_probe;
10601060
}
10611061

1062-
tpm_chip_start(chip);
10631062
chip->flags |= TPM_CHIP_FLAG_IRQ;
10641063
if (irq) {
10651064
tpm_tis_probe_irq_single(chip, intmask, IRQF_SHARED,
@@ -1070,18 +1069,20 @@ int tpm_tis_core_init(struct device *dev, struct tpm_tis_data *priv, int irq,
10701069
} else {
10711070
tpm_tis_probe_irq(chip, intmask);
10721071
}
1073-
tpm_chip_stop(chip);
10741072
}
10751073

1074+
tpm_chip_stop(chip);
1075+
10761076
rc = tpm_chip_register(chip);
10771077
if (rc)
1078-
goto out_err;
1079-
1080-
if (chip->ops->clk_enable != NULL)
1081-
chip->ops->clk_enable(chip, false);
1078+
goto err_start;
10821079

10831080
return 0;
1084-
out_err:
1081+
1082+
err_probe:
1083+
tpm_chip_stop(chip);
1084+
1085+
err_start:
10851086
if ((chip->ops != NULL) && (chip->ops->clk_enable != NULL))
10861087
chip->ops->clk_enable(chip, false);
10871088

include/linux/tpm.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -403,6 +403,7 @@ extern int tpm_pcr_extend(struct tpm_chip *chip, u32 pcr_idx,
403403
extern int tpm_send(struct tpm_chip *chip, void *cmd, size_t buflen);
404404
extern int tpm_get_random(struct tpm_chip *chip, u8 *data, size_t max);
405405
extern struct tpm_chip *tpm_default_chip(void);
406+
void tpm2_flush_context(struct tpm_chip *chip, u32 handle);
406407
#else
407408
static inline int tpm_is_tpm2(struct tpm_chip *chip)
408409
{

security/keys/Kconfig

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,6 @@ config KEYS
2121

2222
If you are unsure as to whether this is required, answer N.
2323

24-
config KEYS_COMPAT
25-
def_bool y
26-
depends on COMPAT && KEYS
27-
2824
config KEYS_REQUEST_CACHE
2925
bool "Enable temporary caching of the last request_key() result"
3026
depends on KEYS

security/keys/Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ obj-y := \
1717
request_key_auth.o \
1818
user_defined.o
1919
compat-obj-$(CONFIG_KEY_DH_OPERATIONS) += compat_dh.o
20-
obj-$(CONFIG_KEYS_COMPAT) += compat.o $(compat-obj-y)
20+
obj-$(CONFIG_COMPAT) += compat.o $(compat-obj-y)
2121
obj-$(CONFIG_PROC_FS) += proc.o
2222
obj-$(CONFIG_SYSCTL) += sysctl.o
2323
obj-$(CONFIG_PERSISTENT_KEYRINGS) += persistent.o

0 commit comments

Comments
 (0)