Skip to content
This repository was archived by the owner on Nov 8, 2023. It is now read-only.

Commit e0cce98

Browse files
committed
Merge tag 'tpmdd-next-6.10-rc2' of git://git.kernel.org/pub/scm/linux/kernel/git/jarkko/linux-tpmdd
Pull tpm fixes from Jarkko Sakkinen: "This fixes two unaddressed review comments for the HMAC encryption patch set. They are cosmetic but we are better off, if such unnecessary glitches do not exist in the release. The important part is enabling the HMAC encryption by default only on x86-64 because that is the only sufficiently tested arch. Finally, there is a bug fix for SPI transfer buffer allocation, which did not take into account the SPI header size" * tag 'tpmdd-next-6.10-rc2' of git://git.kernel.org/pub/scm/linux/kernel/git/jarkko/linux-tpmdd: tpm: Enable TCG_TPM2_HMAC by default only for X86_64 tpm: Rename TPM2_OA_TMPL to TPM2_OA_NULL_KEY and make it local tpm: Open code tpm_buf_parameters() tpm_tis_spi: Account for SPI header when allocating TPM SPI xfer buffer
2 parents 8d6bc6a + d3e43a8 commit e0cce98

File tree

6 files changed

+31
-48
lines changed

6 files changed

+31
-48
lines changed

drivers/char/tpm/Kconfig

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ if TCG_TPM
2929

3030
config TCG_TPM2_HMAC
3131
bool "Use HMAC and encrypted transactions on the TPM bus"
32-
default y
32+
default X86_64
3333
select CRYPTO_ECDH
3434
select CRYPTO_LIB_AESCFB
3535
select CRYPTO_LIB_SHA256

drivers/char/tpm/tpm-buf.c

Lines changed: 0 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -223,30 +223,4 @@ u32 tpm_buf_read_u32(struct tpm_buf *buf, off_t *offset)
223223
}
224224
EXPORT_SYMBOL_GPL(tpm_buf_read_u32);
225225

226-
static u16 tpm_buf_tag(struct tpm_buf *buf)
227-
{
228-
struct tpm_header *head = (struct tpm_header *)buf->data;
229-
230-
return be16_to_cpu(head->tag);
231-
}
232-
233-
/**
234-
* tpm_buf_parameters - return the TPM response parameters area of the tpm_buf
235-
* @buf: tpm_buf to use
236-
*
237-
* Where the parameters are located depends on the tag of a TPM
238-
* command (it's immediately after the header for TPM_ST_NO_SESSIONS
239-
* or 4 bytes after for TPM_ST_SESSIONS). Evaluate this and return a
240-
* pointer to the first byte of the parameters area.
241-
*
242-
* @return: pointer to parameters area
243-
*/
244-
u8 *tpm_buf_parameters(struct tpm_buf *buf)
245-
{
246-
int offset = TPM_HEADER_SIZE;
247-
248-
if (tpm_buf_tag(buf) == TPM2_ST_SESSIONS)
249-
offset += 4;
250226

251-
return &buf->data[offset];
252-
}

drivers/char/tpm/tpm2-cmd.c

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -281,13 +281,15 @@ struct tpm2_get_random_out {
281281
int tpm2_get_random(struct tpm_chip *chip, u8 *dest, size_t max)
282282
{
283283
struct tpm2_get_random_out *out;
284+
struct tpm_header *head;
284285
struct tpm_buf buf;
285286
u32 recd;
286287
u32 num_bytes = max;
287288
int err;
288289
int total = 0;
289290
int retries = 5;
290291
u8 *dest_ptr = dest;
292+
off_t offset;
291293

292294
if (!num_bytes || max > TPM_MAX_RNG_DATA)
293295
return -EINVAL;
@@ -320,7 +322,13 @@ int tpm2_get_random(struct tpm_chip *chip, u8 *dest, size_t max)
320322
goto out;
321323
}
322324

323-
out = (struct tpm2_get_random_out *)tpm_buf_parameters(&buf);
325+
head = (struct tpm_header *)buf.data;
326+
offset = TPM_HEADER_SIZE;
327+
/* Skip the parameter size field: */
328+
if (be16_to_cpu(head->tag) == TPM2_ST_SESSIONS)
329+
offset += 4;
330+
331+
out = (struct tpm2_get_random_out *)&buf.data[offset];
324332
recd = min_t(u32, be16_to_cpu(out->size), num_bytes);
325333
if (tpm_buf_length(&buf) <
326334
TPM_HEADER_SIZE +

drivers/char/tpm/tpm2-sessions.c

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,9 @@
8080
/* maximum number of names the TPM must remember for authorization */
8181
#define AUTH_MAX_NAMES 3
8282

83+
#define AES_KEY_BYTES AES_KEYSIZE_128
84+
#define AES_KEY_BITS (AES_KEY_BYTES*8)
85+
8386
static int tpm2_create_primary(struct tpm_chip *chip, u32 hierarchy,
8487
u32 *handle, u8 *name);
8588

@@ -954,6 +957,20 @@ int tpm2_start_auth_session(struct tpm_chip *chip)
954957
}
955958
EXPORT_SYMBOL(tpm2_start_auth_session);
956959

960+
/*
961+
* A mask containing the object attributes for the kernel held null primary key
962+
* used in HMAC encryption. For more information on specific attributes look up
963+
* to "8.3 TPMA_OBJECT (Object Attributes)".
964+
*/
965+
#define TPM2_OA_NULL_KEY ( \
966+
TPM2_OA_NO_DA | \
967+
TPM2_OA_FIXED_TPM | \
968+
TPM2_OA_FIXED_PARENT | \
969+
TPM2_OA_SENSITIVE_DATA_ORIGIN | \
970+
TPM2_OA_USER_WITH_AUTH | \
971+
TPM2_OA_DECRYPT | \
972+
TPM2_OA_RESTRICTED)
973+
957974
/**
958975
* tpm2_parse_create_primary() - parse the data returned from TPM_CC_CREATE_PRIMARY
959976
*
@@ -1018,7 +1035,7 @@ static int tpm2_parse_create_primary(struct tpm_chip *chip, struct tpm_buf *buf,
10181035
val = tpm_buf_read_u32(buf, &offset_t);
10191036

10201037
/* object properties */
1021-
if (val != TPM2_OA_TMPL)
1038+
if (val != TPM2_OA_NULL_KEY)
10221039
return -EINVAL;
10231040

10241041
/* auth policy (empty) */
@@ -1178,7 +1195,7 @@ static int tpm2_create_primary(struct tpm_chip *chip, u32 hierarchy,
11781195
tpm_buf_append_u16(&template, TPM_ALG_SHA256);
11791196

11801197
/* object properties */
1181-
tpm_buf_append_u32(&template, TPM2_OA_TMPL);
1198+
tpm_buf_append_u32(&template, TPM2_OA_NULL_KEY);
11821199

11831200
/* sauth policy (empty) */
11841201
tpm_buf_append_u16(&template, 0);

drivers/char/tpm/tpm_tis_spi_main.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@
3737
#include "tpm_tis_spi.h"
3838

3939
#define MAX_SPI_FRAMESIZE 64
40+
#define SPI_HDRSIZE 4
4041

4142
/*
4243
* TCG SPI flow control is documented in section 6.4 of the spec[1]. In short,
@@ -247,7 +248,7 @@ static int tpm_tis_spi_write_bytes(struct tpm_tis_data *data, u32 addr,
247248
int tpm_tis_spi_init(struct spi_device *spi, struct tpm_tis_spi_phy *phy,
248249
int irq, const struct tpm_tis_phy_ops *phy_ops)
249250
{
250-
phy->iobuf = devm_kmalloc(&spi->dev, MAX_SPI_FRAMESIZE, GFP_KERNEL);
251+
phy->iobuf = devm_kmalloc(&spi->dev, SPI_HDRSIZE + MAX_SPI_FRAMESIZE, GFP_KERNEL);
251252
if (!phy->iobuf)
252253
return -ENOMEM;
253254

include/linux/tpm.h

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -394,21 +394,6 @@ enum tpm2_object_attributes {
394394
TPM2_OA_SIGN = BIT(18),
395395
};
396396

397-
/*
398-
* definitions for the canonical template. These are mandated
399-
* by the TCG key template documents
400-
*/
401-
402-
#define AES_KEY_BYTES AES_KEYSIZE_128
403-
#define AES_KEY_BITS (AES_KEY_BYTES*8)
404-
#define TPM2_OA_TMPL (TPM2_OA_NO_DA | \
405-
TPM2_OA_FIXED_TPM | \
406-
TPM2_OA_FIXED_PARENT | \
407-
TPM2_OA_SENSITIVE_DATA_ORIGIN | \
408-
TPM2_OA_USER_WITH_AUTH | \
409-
TPM2_OA_DECRYPT | \
410-
TPM2_OA_RESTRICTED)
411-
412397
enum tpm2_session_attributes {
413398
TPM2_SA_CONTINUE_SESSION = BIT(0),
414399
TPM2_SA_AUDIT_EXCLUSIVE = BIT(1),
@@ -437,8 +422,6 @@ u8 tpm_buf_read_u8(struct tpm_buf *buf, off_t *offset);
437422
u16 tpm_buf_read_u16(struct tpm_buf *buf, off_t *offset);
438423
u32 tpm_buf_read_u32(struct tpm_buf *buf, off_t *offset);
439424

440-
u8 *tpm_buf_parameters(struct tpm_buf *buf);
441-
442425
/*
443426
* Check if TPM device is in the firmware upgrade mode.
444427
*/

0 commit comments

Comments
 (0)