Skip to content

Commit 0637c10

Browse files
stefano-garzarellajarkkojs
authored andcommitted
tpm/tpm_ftpm_tee: support TPM_CHIP_FLAG_SYNC
This driver does not support interrupts, and receiving the response is synchronous with sending the command. Enable synchronous send() with TPM_CHIP_FLAG_SYNC, which implies that ->send() already fills the provided buffer with a response, and ->recv() is not implemented. Signed-off-by: Stefano Garzarella <sgarzare@redhat.com> Reviewed-by: Sumit Garg <sumit.garg@oss.qualcomm.com> Reviewed-by: Jarkko Sakkinen <jarkko@kernel.org> Signed-off-by: Jarkko Sakkinen <jarkko@kernel.org>
1 parent 04fe470 commit 0637c10

2 files changed

Lines changed: 19 additions & 49 deletions

File tree

drivers/char/tpm/tpm_ftpm_tee.c

Lines changed: 19 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -31,47 +31,19 @@ static const uuid_t ftpm_ta_uuid =
3131
0x82, 0xCB, 0x34, 0x3F, 0xB7, 0xF3, 0x78, 0x96);
3232

3333
/**
34-
* ftpm_tee_tpm_op_recv() - retrieve fTPM response.
35-
* @chip: the tpm_chip description as specified in driver/char/tpm/tpm.h.
36-
* @buf: the buffer to store data.
37-
* @count: the number of bytes to read.
38-
*
39-
* Return:
40-
* In case of success the number of bytes received.
41-
* On failure, -errno.
42-
*/
43-
static int ftpm_tee_tpm_op_recv(struct tpm_chip *chip, u8 *buf, size_t count)
44-
{
45-
struct ftpm_tee_private *pvt_data = dev_get_drvdata(chip->dev.parent);
46-
size_t len;
47-
48-
len = pvt_data->resp_len;
49-
if (count < len) {
50-
dev_err(&chip->dev,
51-
"%s: Invalid size in recv: count=%zd, resp_len=%zd\n",
52-
__func__, count, len);
53-
return -EIO;
54-
}
55-
56-
memcpy(buf, pvt_data->resp_buf, len);
57-
pvt_data->resp_len = 0;
58-
59-
return len;
60-
}
61-
62-
/**
63-
* ftpm_tee_tpm_op_send() - send TPM commands through the TEE shared memory.
34+
* ftpm_tee_tpm_op_send() - send TPM commands through the TEE shared memory
35+
* and retrieve the response.
6436
* @chip: the tpm_chip description as specified in driver/char/tpm/tpm.h
65-
* @buf: the buffer to send.
37+
* @buf: the buffer to send and to store the response.
6638
* @bufsiz: the size of the buffer.
67-
* @len: the number of bytes to send.
39+
* @cmd_len: the number of bytes to send.
6840
*
6941
* Return:
70-
* In case of success, returns 0.
42+
* In case of success, returns the number of bytes received.
7143
* On failure, -errno
7244
*/
7345
static int ftpm_tee_tpm_op_send(struct tpm_chip *chip, u8 *buf, size_t bufsiz,
74-
size_t len)
46+
size_t cmd_len)
7547
{
7648
struct ftpm_tee_private *pvt_data = dev_get_drvdata(chip->dev.parent);
7749
size_t resp_len;
@@ -82,16 +54,15 @@ static int ftpm_tee_tpm_op_send(struct tpm_chip *chip, u8 *buf, size_t bufsiz,
8254
struct tee_param command_params[4];
8355
struct tee_shm *shm = pvt_data->shm;
8456

85-
if (len > MAX_COMMAND_SIZE) {
57+
if (cmd_len > MAX_COMMAND_SIZE) {
8658
dev_err(&chip->dev,
8759
"%s: len=%zd exceeds MAX_COMMAND_SIZE supported by fTPM TA\n",
88-
__func__, len);
60+
__func__, cmd_len);
8961
return -EIO;
9062
}
9163

9264
memset(&transceive_args, 0, sizeof(transceive_args));
9365
memset(command_params, 0, sizeof(command_params));
94-
pvt_data->resp_len = 0;
9566

9667
/* Invoke FTPM_OPTEE_TA_SUBMIT_COMMAND function of fTPM TA */
9768
transceive_args = (struct tee_ioctl_invoke_arg) {
@@ -105,7 +76,7 @@ static int ftpm_tee_tpm_op_send(struct tpm_chip *chip, u8 *buf, size_t bufsiz,
10576
.attr = TEE_IOCTL_PARAM_ATTR_TYPE_MEMREF_INPUT,
10677
.u.memref = {
10778
.shm = shm,
108-
.size = len,
79+
.size = cmd_len,
10980
.shm_offs = 0,
11081
},
11182
};
@@ -117,7 +88,7 @@ static int ftpm_tee_tpm_op_send(struct tpm_chip *chip, u8 *buf, size_t bufsiz,
11788
return PTR_ERR(temp_buf);
11889
}
11990
memset(temp_buf, 0, (MAX_COMMAND_SIZE + MAX_RESPONSE_SIZE));
120-
memcpy(temp_buf, buf, len);
91+
memcpy(temp_buf, buf, cmd_len);
12192

12293
command_params[1] = (struct tee_param) {
12394
.attr = TEE_IOCTL_PARAM_ATTR_TYPE_MEMREF_INOUT,
@@ -158,17 +129,20 @@ static int ftpm_tee_tpm_op_send(struct tpm_chip *chip, u8 *buf, size_t bufsiz,
158129
__func__, resp_len);
159130
return -EIO;
160131
}
132+
if (resp_len > bufsiz) {
133+
dev_err(&chip->dev,
134+
"%s: resp_len=%zd exceeds bufsiz=%zd\n",
135+
__func__, resp_len, bufsiz);
136+
return -EIO;
137+
}
161138

162-
/* sanity checks look good, cache the response */
163-
memcpy(pvt_data->resp_buf, temp_buf, resp_len);
164-
pvt_data->resp_len = resp_len;
139+
memcpy(buf, temp_buf, resp_len);
165140

166-
return 0;
141+
return resp_len;
167142
}
168143

169144
static const struct tpm_class_ops ftpm_tee_tpm_ops = {
170145
.flags = TPM_OPS_AUTO_STARTUP,
171-
.recv = ftpm_tee_tpm_op_recv,
172146
.send = ftpm_tee_tpm_op_send,
173147
};
174148

@@ -253,7 +227,7 @@ static int ftpm_tee_probe(struct device *dev)
253227
}
254228

255229
pvt_data->chip = chip;
256-
pvt_data->chip->flags |= TPM_CHIP_FLAG_TPM2;
230+
pvt_data->chip->flags |= TPM_CHIP_FLAG_TPM2 | TPM_CHIP_FLAG_SYNC;
257231

258232
/* Create a character device for the fTPM */
259233
rc = tpm_chip_register(pvt_data->chip);

drivers/char/tpm/tpm_ftpm_tee.h

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,16 +22,12 @@
2222
* struct ftpm_tee_private - fTPM's private data
2323
* @chip: struct tpm_chip instance registered with tpm framework.
2424
* @session: fTPM TA session identifier.
25-
* @resp_len: cached response buffer length.
26-
* @resp_buf: cached response buffer.
2725
* @ctx: TEE context handler.
2826
* @shm: Memory pool shared with fTPM TA in TEE.
2927
*/
3028
struct ftpm_tee_private {
3129
struct tpm_chip *chip;
3230
u32 session;
33-
size_t resp_len;
34-
u8 resp_buf[MAX_RESPONSE_SIZE];
3531
struct tee_context *ctx;
3632
struct tee_shm *shm;
3733
};

0 commit comments

Comments
 (0)