Skip to content

Commit f20c95b

Browse files
committed
Merge tag 'tpmdd-next-v5.20' of git://git.kernel.org/pub/scm/linux/kernel/git/jarkko/linux-tpmdd
Pull tpm updates from Jarkko Sakkinen: "Mostly TPM and also few keyring fixes" * tag 'tpmdd-next-v5.20' of git://git.kernel.org/pub/scm/linux/kernel/git/jarkko/linux-tpmdd: tpm: Add check for Failure mode for TPM2 modules tpm: eventlog: Fix section mismatch for DEBUG_SECTION_MISMATCH tpm: fix platform_no_drv_owner.cocci warning KEYS: asymmetric: enforce SM2 signature use pkey algo pkcs7: support EC-RDSA/streebog in SignerInfo pkcs7: parser support SM2 and SM3 algorithms combination sign-file: Fix confusing error messages X.509: Support parsing certificate using SM2 algorithm tpm: Add tpm_tis_i2c backend for tpm_tis_core tpm: Add tpm_tis_verify_crc to the tpm_tis_phy_ops protocol layer dt-bindings: trivial-devices: Add Infineon SLB9673 TPM tpm: Add upgrade/reduced mode support for TPM1.2 modules
2 parents 48a577d + 863ed94 commit f20c95b

File tree

14 files changed

+470
-5
lines changed

14 files changed

+470
-5
lines changed

Documentation/devicetree/bindings/trivial-devices.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,8 @@ properties:
141141
- infineon,slb9635tt
142142
# Infineon SLB9645 I2C TPM (new protocol, max 400khz)
143143
- infineon,slb9645tt
144+
# Infineon SLB9673 I2C TPM 2.0
145+
- infineon,slb9673
144146
# Infineon TLV493D-A1B6 I2C 3D Magnetic Sensor
145147
- infineon,tlv493d-a1b6
146148
# Infineon Multi-phase Digital VR Controller xdpe11280

crypto/asymmetric_keys/pkcs7_parser.c

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -248,6 +248,15 @@ int pkcs7_sig_note_digest_algo(void *context, size_t hdrlen,
248248
case OID_sha224:
249249
ctx->sinfo->sig->hash_algo = "sha224";
250250
break;
251+
case OID_sm3:
252+
ctx->sinfo->sig->hash_algo = "sm3";
253+
break;
254+
case OID_gost2012Digest256:
255+
ctx->sinfo->sig->hash_algo = "streebog256";
256+
break;
257+
case OID_gost2012Digest512:
258+
ctx->sinfo->sig->hash_algo = "streebog512";
259+
break;
251260
default:
252261
printk("Unsupported digest algo: %u\n", ctx->last_oid);
253262
return -ENOPKG;
@@ -277,6 +286,15 @@ int pkcs7_sig_note_pkey_algo(void *context, size_t hdrlen,
277286
ctx->sinfo->sig->pkey_algo = "ecdsa";
278287
ctx->sinfo->sig->encoding = "x962";
279288
break;
289+
case OID_SM2_with_SM3:
290+
ctx->sinfo->sig->pkey_algo = "sm2";
291+
ctx->sinfo->sig->encoding = "raw";
292+
break;
293+
case OID_gost2012PKey256:
294+
case OID_gost2012PKey512:
295+
ctx->sinfo->sig->pkey_algo = "ecrdsa";
296+
ctx->sinfo->sig->encoding = "raw";
297+
break;
280298
default:
281299
printk("Unsupported pkey algo: %u\n", ctx->last_oid);
282300
return -ENOPKG;

crypto/asymmetric_keys/public_key.c

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -304,6 +304,10 @@ static int cert_sig_digest_update(const struct public_key_signature *sig,
304304

305305
BUG_ON(!sig->data);
306306

307+
/* SM2 signatures always use the SM3 hash algorithm */
308+
if (!sig->hash_algo || strcmp(sig->hash_algo, "sm3") != 0)
309+
return -EINVAL;
310+
307311
ret = sm2_compute_z_digest(tfm_pkey, SM2_DEFAULT_USERID,
308312
SM2_DEFAULT_USERID_LEN, dgst);
309313
if (ret)
@@ -414,8 +418,7 @@ int public_key_verify_signature(const struct public_key *pkey,
414418
if (ret)
415419
goto error_free_key;
416420

417-
if (sig->pkey_algo && strcmp(sig->pkey_algo, "sm2") == 0 &&
418-
sig->data_size) {
421+
if (strcmp(pkey->pkey_algo, "sm2") == 0 && sig->data_size) {
419422
ret = cert_sig_digest_update(sig, tfm);
420423
if (ret)
421424
goto error_free_key;

crypto/asymmetric_keys/x509_cert_parser.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -508,6 +508,9 @@ int x509_extract_key_data(void *context, size_t hdrlen,
508508
case OID_gost2012PKey512:
509509
ctx->cert->pub->pkey_algo = "ecrdsa";
510510
break;
511+
case OID_sm2:
512+
ctx->cert->pub->pkey_algo = "sm2";
513+
break;
511514
case OID_id_ecPublicKey:
512515
if (parse_OID(ctx->params, ctx->params_size, &oid) != 0)
513516
return -EBADMSG;

drivers/char/tpm/Kconfig

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,18 @@ config TCG_TIS_SPI_CR50
7474
If you have a H1 secure module running Cr50 firmware on SPI bus,
7575
say Yes and it will be accessible from within Linux.
7676

77+
config TCG_TIS_I2C
78+
tristate "TPM Interface Specification 1.3 Interface / TPM 2.0 FIFO Interface - (I2C - generic)"
79+
depends on I2C
80+
select CRC_CCITT
81+
select TCG_TIS_CORE
82+
help
83+
If you have a TPM security chip, compliant with the TCG TPM PTP
84+
(I2C interface) specification and connected to an I2C bus master,
85+
say Yes and it will be accessible from within Linux.
86+
To compile this driver as a module, choose M here;
87+
the module will be called tpm_tis_i2c.
88+
7789
config TCG_TIS_SYNQUACER
7890
tristate "TPM Interface Specification 1.2 Interface / TPM 2.0 FIFO Interface (MMIO - SynQuacer)"
7991
depends on ARCH_SYNQUACER || COMPILE_TEST

drivers/char/tpm/Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ tpm_tis_spi-$(CONFIG_TCG_TIS_SPI_CR50) += tpm_tis_spi_cr50.o
2929

3030
obj-$(CONFIG_TCG_TIS_I2C_CR50) += tpm_tis_i2c_cr50.o
3131

32+
obj-$(CONFIG_TCG_TIS_I2C) += tpm_tis_i2c.o
3233
obj-$(CONFIG_TCG_TIS_I2C_ATMEL) += tpm_i2c_atmel.o
3334
obj-$(CONFIG_TCG_TIS_I2C_INFINEON) += tpm_i2c_infineon.o
3435
obj-$(CONFIG_TCG_TIS_I2C_NUVOTON) += tpm_i2c_nuvoton.o

drivers/char/tpm/tpm.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ enum tpm_addr {
5555
#define TPM_WARN_DOING_SELFTEST 0x802
5656
#define TPM_ERR_DEACTIVATED 0x6
5757
#define TPM_ERR_DISABLED 0x7
58+
#define TPM_ERR_FAILEDSELFTEST 0x1C
5859
#define TPM_ERR_INVALID_POSTINIT 38
5960

6061
#define TPM_TAG_RQU_COMMAND 193

drivers/char/tpm/tpm1-cmd.c

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -709,7 +709,12 @@ int tpm1_auto_startup(struct tpm_chip *chip)
709709
if (rc)
710710
goto out;
711711
rc = tpm1_do_selftest(chip);
712-
if (rc) {
712+
if (rc == TPM_ERR_FAILEDSELFTEST) {
713+
dev_warn(&chip->dev, "TPM self test failed, switching to the firmware upgrade mode\n");
714+
/* A TPM in this state possibly allows or needs a firmware upgrade */
715+
chip->flags |= TPM_CHIP_FLAG_FIRMWARE_UPGRADE;
716+
return 0;
717+
} else if (rc) {
713718
dev_err(&chip->dev, "TPM self test failed\n");
714719
goto out;
715720
}

drivers/char/tpm/tpm2-cmd.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -752,6 +752,12 @@ int tpm2_auto_startup(struct tpm_chip *chip)
752752
}
753753

754754
rc = tpm2_get_cc_attrs_tbl(chip);
755+
if (rc == TPM2_RC_FAILURE || (rc < 0 && rc != -ENOMEM)) {
756+
dev_info(&chip->dev,
757+
"TPM in field failure mode, requires firmware upgrade\n");
758+
chip->flags |= TPM_CHIP_FLAG_FIRMWARE_UPGRADE;
759+
rc = 0;
760+
}
755761

756762
out:
757763
/*

drivers/char/tpm/tpm_tis_core.c

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -289,6 +289,7 @@ static int tpm_tis_recv(struct tpm_chip *chip, u8 *buf, size_t count)
289289
int size = 0;
290290
int status;
291291
u32 expected;
292+
int rc;
292293

293294
if (count < TPM_HEADER_SIZE) {
294295
size = -EIO;
@@ -328,6 +329,13 @@ static int tpm_tis_recv(struct tpm_chip *chip, u8 *buf, size_t count)
328329
goto out;
329330
}
330331

332+
rc = tpm_tis_verify_crc(priv, (size_t)size, buf);
333+
if (rc < 0) {
334+
dev_err(&chip->dev, "CRC mismatch for response.\n");
335+
size = rc;
336+
goto out;
337+
}
338+
331339
out:
332340
tpm_tis_ready(chip);
333341
return size;
@@ -443,6 +451,12 @@ static int tpm_tis_send_main(struct tpm_chip *chip, const u8 *buf, size_t len)
443451
if (rc < 0)
444452
return rc;
445453

454+
rc = tpm_tis_verify_crc(priv, len, buf);
455+
if (rc < 0) {
456+
dev_err(&chip->dev, "CRC mismatch for command.\n");
457+
return rc;
458+
}
459+
446460
/* go and do it */
447461
rc = tpm_tis_write8(priv, TPM_STS(priv->locality), TPM_STS_GO);
448462
if (rc < 0)

0 commit comments

Comments
 (0)