Skip to content

Commit 1d9f1b5

Browse files
committed
Merge tag 'for-next-tpm-7.1-rc1' of git://git.kernel.org/pub/scm/linux/kernel/git/jarkko/linux-tpmdd
Pull tpm updates from Jarkko Sakkinen: "Here are the accumulated fixes for 7.1-rc1 and a single structural change worth mentioning separately: Rafael's commit converting tpm_crb from ACPI driver to a platform driver" * tag 'for-next-tpm-7.1-rc1' of git://git.kernel.org/pub/scm/linux/kernel/git/jarkko/linux-tpmdd: tpm: tpm_tis: stop transmit if retries are exhausted tpm: tpm_tis: add error logging for data transfer tpm: avoid -Wunused-but-set-variable tpm: Use kfree_sensitive() to free auth session in tpm_dev_release() tpm2-sessions: Fix missing tpm_buf_destroy() in tpm2_read_public() tpm: Fix auth session leak in tpm2_get_random() error path tpm: i2c: atmel: fix block comment formatting tpm_crb: Convert ACPI driver to a platform one tpm: Make tcpci_pm_ops variable static const
2 parents 897d540 + 949692d commit 1d9f1b5

7 files changed

Lines changed: 64 additions & 40 deletions

File tree

drivers/char/tpm/tpm-chip.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -247,7 +247,7 @@ static void tpm_dev_release(struct device *dev)
247247
kfree(chip->work_space.context_buf);
248248
kfree(chip->work_space.session_buf);
249249
#ifdef CONFIG_TCG_TPM2_HMAC
250-
kfree(chip->auth);
250+
kfree_sensitive(chip->auth);
251251
#endif
252252
kfree(chip);
253253
}

drivers/char/tpm/tpm2-cmd.c

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ static bool disable_pcr_integrity;
2121
module_param(disable_pcr_integrity, bool, 0444);
2222
MODULE_PARM_DESC(disable_pcr_integrity, "Disable integrity protection of TPM2_PCR_Extend");
2323

24-
struct tpm2_hash tpm2_hash_map[] = {
24+
static const struct tpm2_hash tpm2_hash_map[] = {
2525
{HASH_ALGO_SHA1, TPM_ALG_SHA1},
2626
{HASH_ALGO_SHA256, TPM_ALG_SHA256},
2727
{HASH_ALGO_SHA384, TPM_ALG_SHA384},
@@ -295,10 +295,8 @@ int tpm2_get_random(struct tpm_chip *chip, u8 *dest, size_t max)
295295
}
296296
tpm_buf_append_u16(&buf, num_bytes);
297297
err = tpm_buf_fill_hmac_session(chip, &buf);
298-
if (err) {
299-
tpm_buf_destroy(&buf);
300-
return err;
301-
}
298+
if (err)
299+
goto out;
302300

303301
err = tpm_transmit_cmd(chip, &buf,
304302
offsetof(struct tpm2_get_random_out,

drivers/char/tpm/tpm2-sessions.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -203,8 +203,10 @@ static int tpm2_read_public(struct tpm_chip *chip, u32 handle, void *name)
203203
rc = tpm_buf_read_u16(&buf, &offset);
204204
name_size_alg = name_size(&buf.data[offset]);
205205

206-
if (name_size_alg < 0)
206+
if (name_size_alg < 0) {
207+
tpm_buf_destroy(&buf);
207208
return name_size_alg;
209+
}
208210

209211
if (rc != name_size_alg) {
210212
tpm_buf_destroy(&buf);
@@ -217,6 +219,7 @@ static int tpm2_read_public(struct tpm_chip *chip, u32 handle, void *name)
217219
}
218220

219221
memcpy(name, &buf.data[offset], rc);
222+
tpm_buf_destroy(&buf);
220223
return name_size_alg;
221224
}
222225
#endif /* CONFIG_TCG_TPM2_HMAC */

drivers/char/tpm/tpm_crb.c

Lines changed: 16 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
#include <linux/highmem.h>
1616
#include <linux/rculist.h>
1717
#include <linux/module.h>
18+
#include <linux/platform_device.h>
1819
#include <linux/pm_runtime.h>
1920
#ifdef CONFIG_ARM64
2021
#include <linux/arm-smccc.h>
@@ -602,13 +603,13 @@ static u64 crb_fixup_cmd_size(struct device *dev, struct resource *io_res,
602603
return io_res->end - start + 1;
603604
}
604605

605-
static int crb_map_io(struct acpi_device *device, struct crb_priv *priv,
606+
static int crb_map_io(struct device *dev, struct crb_priv *priv,
606607
struct acpi_table_tpm2 *buf)
607608
{
609+
struct acpi_device *device = ACPI_COMPANION(dev);
608610
struct list_head acpi_resource_list;
609611
struct resource iores_array[TPM_CRB_MAX_RESOURCES + 1] = { {0} };
610612
void __iomem *iobase_array[TPM_CRB_MAX_RESOURCES] = {NULL};
611-
struct device *dev = &device->dev;
612613
struct resource *iores;
613614
void __iomem **iobase_ptr;
614615
int i;
@@ -782,12 +783,13 @@ static int crb_map_pluton(struct device *dev, struct crb_priv *priv,
782783
return 0;
783784
}
784785

785-
static int crb_acpi_add(struct acpi_device *device)
786+
static int crb_acpi_probe(struct platform_device *pdev)
786787
{
788+
struct device *dev = &pdev->dev;
789+
struct acpi_device *device = ACPI_COMPANION(dev);
787790
struct acpi_table_tpm2 *buf;
788791
struct crb_priv *priv;
789792
struct tpm_chip *chip;
790-
struct device *dev = &device->dev;
791793
struct tpm2_crb_smc *crb_smc;
792794
struct tpm2_crb_ffa *crb_ffa;
793795
struct tpm2_crb_pluton *crb_pluton;
@@ -867,7 +869,7 @@ static int crb_acpi_add(struct acpi_device *device)
867869
priv->sm = sm;
868870
priv->hid = acpi_device_hid(device);
869871

870-
rc = crb_map_io(device, priv, buf);
872+
rc = crb_map_io(dev, priv, buf);
871873
if (rc)
872874
goto out;
873875

@@ -901,12 +903,9 @@ static int crb_acpi_add(struct acpi_device *device)
901903
return rc;
902904
}
903905

904-
static void crb_acpi_remove(struct acpi_device *device)
906+
static void crb_acpi_remove(struct platform_device *pdev)
905907
{
906-
struct device *dev = &device->dev;
907-
struct tpm_chip *chip = dev_get_drvdata(dev);
908-
909-
tpm_chip_unregister(chip);
908+
tpm_chip_unregister(platform_get_drvdata(pdev));
910909
}
911910

912911
static const struct dev_pm_ops crb_pm = {
@@ -919,19 +918,17 @@ static const struct acpi_device_id crb_device_ids[] = {
919918
};
920919
MODULE_DEVICE_TABLE(acpi, crb_device_ids);
921920

922-
static struct acpi_driver crb_acpi_driver = {
923-
.name = "tpm_crb",
924-
.ids = crb_device_ids,
925-
.ops = {
926-
.add = crb_acpi_add,
927-
.remove = crb_acpi_remove,
928-
},
929-
.drv = {
921+
static struct platform_driver crb_acpi_driver = {
922+
.probe = crb_acpi_probe,
923+
.remove = crb_acpi_remove,
924+
.driver = {
925+
.name = "tpm_crb_acpi",
926+
.acpi_match_table = crb_device_ids,
930927
.pm = &crb_pm,
931928
},
932929
};
933930

934-
module_acpi_driver(crb_acpi_driver);
931+
module_platform_driver(crb_acpi_driver);
935932
MODULE_AUTHOR("Jarkko Sakkinen <jarkko.sakkinen@linux.intel.com>");
936933
MODULE_DESCRIPTION("TPM2 Driver");
937934
MODULE_VERSION("0.1");

drivers/char/tpm/tpm_i2c_atmel.c

Lines changed: 23 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,11 @@
3131

3232
struct priv_data {
3333
size_t len;
34-
/* This is the amount we read on the first try. 25 was chosen to fit a
34+
/*
35+
* This is the amount we read on the first try. 25 was chosen to fit a
3536
* fair number of read responses in the buffer so a 2nd retry can be
36-
* avoided in small message cases. */
37+
* avoided in small message cases.
38+
*/
3739
u8 buffer[sizeof(struct tpm_header) + 25];
3840
};
3941

@@ -58,7 +60,9 @@ static int i2c_atmel_send(struct tpm_chip *chip, u8 *buf, size_t bufsiz,
5860
if (status < 0)
5961
return status;
6062

61-
/* The upper layer does not support incomplete sends. */
63+
/*
64+
* The upper layer does not support incomplete sends.
65+
*/
6266
if (status != len)
6367
return -E2BIG;
6468

@@ -76,9 +80,11 @@ static int i2c_atmel_recv(struct tpm_chip *chip, u8 *buf, size_t count)
7680
if (priv->len == 0)
7781
return -EIO;
7882

79-
/* Get the message size from the message header, if we didn't get the
83+
/*
84+
* Get the message size from the message header, if we didn't get the
8085
* whole message in read_status then we need to re-read the
81-
* message. */
86+
* message.
87+
*/
8288
expected_len = be32_to_cpu(hdr->length);
8389
if (expected_len > count)
8490
return -ENOMEM;
@@ -111,15 +117,19 @@ static u8 i2c_atmel_read_status(struct tpm_chip *chip)
111117
struct i2c_client *client = to_i2c_client(chip->dev.parent);
112118
int rc;
113119

114-
/* The TPM fails the I2C read until it is ready, so we do the entire
120+
/*
121+
* The TPM fails the I2C read until it is ready, so we do the entire
115122
* transfer here and buffer it locally. This way the common code can
116-
* properly handle the timeouts. */
123+
* properly handle the timeouts.
124+
*/
117125
priv->len = 0;
118126
memset(priv->buffer, 0, sizeof(priv->buffer));
119127

120128

121-
/* Once the TPM has completed the command the command remains readable
122-
* until another command is issued. */
129+
/*
130+
* Once the TPM has completed the command the command remains readable
131+
* until another command is issued.
132+
*/
123133
rc = i2c_master_recv(client, priv->buffer, sizeof(priv->buffer));
124134
dev_dbg(&chip->dev,
125135
"%s: sts=%d", __func__, rc);
@@ -172,9 +182,11 @@ static int i2c_atmel_probe(struct i2c_client *client)
172182

173183
dev_set_drvdata(&chip->dev, priv);
174184

175-
/* There is no known way to probe for this device, and all version
185+
/*
186+
* There is no known way to probe for this device, and all version
176187
* information seems to be read via TPM commands. Thus we rely on the
177-
* TPM startup process in the common code to detect the device. */
188+
* TPM startup process in the common code to detect the device.
189+
*/
178190

179191
return tpm_chip_register(chip);
180192
}

drivers/char/tpm/tpm_tis_core.c

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -471,6 +471,8 @@ static int tpm_tis_send_data(struct tpm_chip *chip, const u8 *buf, size_t len)
471471
status = tpm_tis_status(chip);
472472
if (!itpm && (status & TPM_STS_DATA_EXPECT) == 0) {
473473
rc = -EIO;
474+
dev_err(&chip->dev, "TPM_STS_DATA_EXPECT should be set. sts = 0x%08x\n",
475+
status);
474476
goto out_err;
475477
}
476478
}
@@ -491,6 +493,8 @@ static int tpm_tis_send_data(struct tpm_chip *chip, const u8 *buf, size_t len)
491493
status = tpm_tis_status(chip);
492494
if (!itpm && (status & TPM_STS_DATA_EXPECT) != 0) {
493495
rc = -EIO;
496+
dev_err(&chip->dev, "TPM_STS_DATA_EXPECT should be unset. sts = 0x%08x\n",
497+
status);
494498
goto out_err;
495499
}
496500

@@ -552,11 +556,16 @@ static int tpm_tis_send_main(struct tpm_chip *chip, const u8 *buf, size_t len)
552556
break;
553557
else if (rc != -EAGAIN && rc != -EIO)
554558
/* Data transfer failed, not recoverable */
555-
return rc;
559+
goto out_err;
556560

557561
usleep_range(priv->timeout_min, priv->timeout_max);
558562
}
559563

564+
if (rc == -EAGAIN || rc == -EIO) {
565+
dev_err(&chip->dev, "Exhausted %d tpm_tis_send_data retries\n", TPM_RETRY);
566+
goto out_err;
567+
}
568+
560569
/* go and do it */
561570
rc = tpm_tis_write8(priv, TPM_STS(priv->locality), TPM_STS_GO);
562571
if (rc < 0)

include/linux/tpm_eventlog.h

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -131,11 +131,16 @@ struct tcg_algorithm_info {
131131
};
132132

133133
#ifndef TPM_MEMREMAP
134-
#define TPM_MEMREMAP(start, size) NULL
134+
static inline void *TPM_MEMREMAP(unsigned long start, size_t size)
135+
{
136+
return NULL;
137+
}
135138
#endif
136139

137140
#ifndef TPM_MEMUNMAP
138-
#define TPM_MEMUNMAP(start, size) do{} while(0)
141+
static inline void TPM_MEMUNMAP(void *mapping, size_t size)
142+
{
143+
}
139144
#endif
140145

141146
/**

0 commit comments

Comments
 (0)