Skip to content

Commit a4d8c7c

Browse files
committed
Merge branch 'for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/jmorris/linux-security
Pull security subsystem fixes from James Morris: "This includes several fixes for TPM, as well as a fix for the x.509 certificate parser to address CVE-2015-5327" * 'for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/jmorris/linux-security: X.509: Fix the time validation [ver #2] tpm: fix compat 'ppi' link handling in tpm_chip_register() tpm: fix missing migratable flag in sealing functionality for TPM2 TPM: revert the list handling logic fixed in 398a1e7 TPM: Avoid reference to potentially freed memory tpm_tis: restore IRQ vector in IO memory after failed probing tpm_tis: free irq after probing
2 parents a18e2fa + cc25b99 commit a4d8c7c

5 files changed

Lines changed: 37 additions & 21 deletions

File tree

crypto/asymmetric_keys/x509_cert_parser.c

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -531,7 +531,11 @@ int x509_decode_time(time64_t *_t, size_t hdrlen,
531531
if (*p != 'Z')
532532
goto unsupported_time;
533533

534-
mon_len = month_lengths[mon];
534+
if (year < 1970 ||
535+
mon < 1 || mon > 12)
536+
goto invalid_time;
537+
538+
mon_len = month_lengths[mon - 1];
535539
if (mon == 2) {
536540
if (year % 4 == 0) {
537541
mon_len = 29;
@@ -543,14 +547,12 @@ int x509_decode_time(time64_t *_t, size_t hdrlen,
543547
}
544548
}
545549

546-
if (year < 1970 ||
547-
mon < 1 || mon > 12 ||
548-
day < 1 || day > mon_len ||
550+
if (day < 1 || day > mon_len ||
549551
hour > 23 ||
550552
min > 59 ||
551553
sec > 59)
552554
goto invalid_time;
553-
555+
554556
*_t = mktime64(year, mon, day, hour, min, sec);
555557
return 0;
556558

drivers/char/tpm/tpm-chip.c

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -226,21 +226,23 @@ int tpm_chip_register(struct tpm_chip *chip)
226226
if (rc)
227227
goto out_err;
228228

229-
if (!(chip->flags & TPM_CHIP_FLAG_TPM2)) {
230-
rc = __compat_only_sysfs_link_entry_to_kobj(&chip->pdev->kobj,
231-
&chip->dev.kobj,
232-
"ppi");
233-
if (rc)
234-
goto out_err;
235-
}
236-
237229
/* Make the chip available. */
238230
spin_lock(&driver_lock);
239-
list_add_rcu(&chip->list, &tpm_chip_list);
231+
list_add_tail_rcu(&chip->list, &tpm_chip_list);
240232
spin_unlock(&driver_lock);
241233

242234
chip->flags |= TPM_CHIP_FLAG_REGISTERED;
243235

236+
if (!(chip->flags & TPM_CHIP_FLAG_TPM2)) {
237+
rc = __compat_only_sysfs_link_entry_to_kobj(&chip->pdev->kobj,
238+
&chip->dev.kobj,
239+
"ppi");
240+
if (rc && rc != -ENOENT) {
241+
tpm_chip_unregister(chip);
242+
return rc;
243+
}
244+
}
245+
244246
return 0;
245247
out_err:
246248
tpm1_chip_unregister(chip);

drivers/char/tpm/tpm2-cmd.c

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -443,12 +443,13 @@ int tpm2_seal_trusted(struct tpm_chip *chip,
443443
TPM_DIGEST_SIZE);
444444

445445
/* sensitive */
446-
tpm_buf_append_u16(&buf, 4 + TPM_DIGEST_SIZE + payload->key_len);
446+
tpm_buf_append_u16(&buf, 4 + TPM_DIGEST_SIZE + payload->key_len + 1);
447447

448448
tpm_buf_append_u16(&buf, TPM_DIGEST_SIZE);
449449
tpm_buf_append(&buf, options->blobauth, TPM_DIGEST_SIZE);
450-
tpm_buf_append_u16(&buf, payload->key_len);
450+
tpm_buf_append_u16(&buf, payload->key_len + 1);
451451
tpm_buf_append(&buf, payload->key, payload->key_len);
452+
tpm_buf_append_u8(&buf, payload->migratable);
452453

453454
/* public */
454455
tpm_buf_append_u16(&buf, 14);
@@ -573,6 +574,8 @@ static int tpm2_unseal(struct tpm_chip *chip,
573574
u32 blob_handle)
574575
{
575576
struct tpm_buf buf;
577+
u16 data_len;
578+
u8 *data;
576579
int rc;
577580

578581
rc = tpm_buf_init(&buf, TPM2_ST_SESSIONS, TPM2_CC_UNSEAL);
@@ -591,11 +594,13 @@ static int tpm2_unseal(struct tpm_chip *chip,
591594
rc = -EPERM;
592595

593596
if (!rc) {
594-
payload->key_len = be16_to_cpup(
597+
data_len = be16_to_cpup(
595598
(__be16 *) &buf.data[TPM_HEADER_SIZE + 4]);
599+
data = &buf.data[TPM_HEADER_SIZE + 6];
596600

597-
memcpy(payload->key, &buf.data[TPM_HEADER_SIZE + 6],
598-
payload->key_len);
601+
memcpy(payload->key, data, data_len - 1);
602+
payload->key_len = data_len - 1;
603+
payload->migratable = data[data_len - 1];
599604
}
600605

601606
tpm_buf_destroy(&buf);

drivers/char/tpm/tpm_of.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,17 +53,18 @@ int read_log(struct tpm_bios_log *log)
5353
goto cleanup_eio;
5454
}
5555

56-
of_node_put(np);
5756
log->bios_event_log = kmalloc(*sizep, GFP_KERNEL);
5857
if (!log->bios_event_log) {
5958
pr_err("%s: ERROR - Not enough memory for BIOS measurements\n",
6059
__func__);
60+
of_node_put(np);
6161
return -ENOMEM;
6262
}
6363

6464
log->bios_event_log_end = log->bios_event_log + *sizep;
6565

6666
memcpy(log->bios_event_log, __va(*basep), *sizep);
67+
of_node_put(np);
6768

6869
return 0;
6970

drivers/char/tpm/tpm_tis.c

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -645,6 +645,7 @@ static int tpm_tis_init(struct device *dev, struct tpm_info *tpm_info,
645645
{
646646
u32 vendor, intfcaps, intmask;
647647
int rc, i, irq_s, irq_e, probe;
648+
int irq_r = -1;
648649
struct tpm_chip *chip;
649650
struct priv_data *priv;
650651

@@ -751,6 +752,7 @@ static int tpm_tis_init(struct device *dev, struct tpm_info *tpm_info,
751752
irq_s =
752753
ioread8(chip->vendor.iobase +
753754
TPM_INT_VECTOR(chip->vendor.locality));
755+
irq_r = irq_s;
754756
if (irq_s) {
755757
irq_e = irq_s;
756758
} else {
@@ -805,6 +807,8 @@ static int tpm_tis_init(struct device *dev, struct tpm_info *tpm_info,
805807
iowrite32(intmask,
806808
chip->vendor.iobase +
807809
TPM_INT_ENABLE(chip->vendor.locality));
810+
811+
devm_free_irq(dev, i, chip);
808812
}
809813
}
810814
if (chip->vendor.irq) {
@@ -831,7 +835,9 @@ static int tpm_tis_init(struct device *dev, struct tpm_info *tpm_info,
831835
chip->vendor.iobase +
832836
TPM_INT_ENABLE(chip->vendor.locality));
833837
}
834-
}
838+
} else if (irq_r != -1)
839+
iowrite8(irq_r, chip->vendor.iobase +
840+
TPM_INT_VECTOR(chip->vendor.locality));
835841

836842
if (chip->flags & TPM_CHIP_FLAG_TPM2) {
837843
chip->vendor.timeout_a = msecs_to_jiffies(TPM2_TIMEOUT_A);

0 commit comments

Comments
 (0)