Skip to content

Commit

Permalink
Merge tag 'tpm-v6.3-rc1' of git://git.kernel.org/pub/scm/linux/kernel…
Browse files Browse the repository at this point in the history
…/git/jarkko/linux-tpmdd

Pull tpm updates from Jarkko Sakkinen:
 "In additon to bug fixes, these are noteworthy changes:

   - In TPM I2C drivers, migrate from probe() to probe_new() (a new
     driver model in I2C).

   - TPM CRB: Pluton support

   - Add duplicate hash detection to the blacklist keyring in order to
     give more meaningful klog output than e.g. [1]"

Link: https://askubuntu.com/questions/1436856/ubuntu-22-10-blacklist-problem-blacklisting-hash-13-message-on-boot [1]

* tag 'tpm-v6.3-rc1' of git://git.kernel.org/pub/scm/linux/kernel/git/jarkko/linux-tpmdd:
  tpm: add vendor flag to command code validation
  tpm: Add reserved memory event log
  tpm: Use managed allocation for bios event log
  tpm: tis_i2c: Convert to i2c's .probe_new()
  tpm: tpm_i2c_nuvoton: Convert to i2c's .probe_new()
  tpm: tpm_i2c_infineon: Convert to i2c's .probe_new()
  tpm: tpm_i2c_atmel: Convert to i2c's .probe_new()
  tpm: st33zp24: Convert to i2c's .probe_new()
  KEYS: asymmetric: Fix ECDSA use via keyctl uapi
  certs: don't try to update blacklist keys
  KEYS: Add new function key_create()
  certs: make blacklisted hash available in klog
  tpm_crb: Add support for CRB devices based on Pluton
  crypto: certs: fix FIPS selftest dependency
  • Loading branch information
torvalds committed Feb 20, 2023
2 parents 69adb0b + 85b93bb commit 219ac97
Show file tree
Hide file tree
Showing 19 changed files with 293 additions and 86 deletions.
21 changes: 12 additions & 9 deletions certs/blacklist.c
Original file line number Diff line number Diff line change
Expand Up @@ -183,16 +183,19 @@ static int mark_raw_hash_blacklisted(const char *hash)
{
key_ref_t key;

key = key_create_or_update(make_key_ref(blacklist_keyring, true),
"blacklist",
hash,
NULL,
0,
BLACKLIST_KEY_PERM,
KEY_ALLOC_NOT_IN_QUOTA |
KEY_ALLOC_BUILT_IN);
key = key_create(make_key_ref(blacklist_keyring, true),
"blacklist",
hash,
NULL,
0,
BLACKLIST_KEY_PERM,
KEY_ALLOC_NOT_IN_QUOTA |
KEY_ALLOC_BUILT_IN);
if (IS_ERR(key)) {
pr_err("Problem blacklisting hash (%ld)\n", PTR_ERR(key));
if (PTR_ERR(key) == -EEXIST)
pr_warn("Duplicate blacklisted hash %s\n", hash);
else
pr_err("Problem blacklisting hash %s: %pe\n", hash, key);
return PTR_ERR(key);
}
return 0;
Expand Down
2 changes: 1 addition & 1 deletion crypto/asymmetric_keys/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,6 @@ config FIPS_SIGNATURE_SELFTEST
for FIPS.
depends on KEYS
depends on ASYMMETRIC_KEY_TYPE
depends on PKCS7_MESSAGE_PARSER
depends on PKCS7_MESSAGE_PARSER=X509_CERTIFICATE_PARSER

endif # ASYMMETRIC_KEY_TYPE
1 change: 1 addition & 0 deletions crypto/asymmetric_keys/pkcs7_verify.c
Original file line number Diff line number Diff line change
Expand Up @@ -485,3 +485,4 @@ int pkcs7_supply_detached_data(struct pkcs7_message *pkcs7,
pkcs7->data_len = datalen;
return 0;
}
EXPORT_SYMBOL_GPL(pkcs7_supply_detached_data);
24 changes: 22 additions & 2 deletions crypto/asymmetric_keys/public_key.c
Original file line number Diff line number Diff line change
Expand Up @@ -186,8 +186,28 @@ static int software_key_query(const struct kernel_pkey_params *params,

len = crypto_akcipher_maxsize(tfm);
info->key_size = len * 8;
info->max_data_size = len;
info->max_sig_size = len;

if (strncmp(pkey->pkey_algo, "ecdsa", 5) == 0) {
/*
* ECDSA key sizes are much smaller than RSA, and thus could
* operate on (hashed) inputs that are larger than key size.
* For example SHA384-hashed input used with secp256r1
* based keys. Set max_data_size to be at least as large as
* the largest supported hash size (SHA512)
*/
info->max_data_size = 64;

/*
* Verify takes ECDSA-Sig (described in RFC 5480) as input,
* which is actually 2 'key_size'-bit integers encoded in
* ASN.1. Account for the ASN.1 encoding overhead here.
*/
info->max_sig_size = 2 * (len + 3) + 2;
} else {
info->max_data_size = len;
info->max_sig_size = len;
}

info->max_enc_size = len;
info->max_dec_size = len;
info->supported_ops = (KEYCTL_SUPPORTS_ENCRYPT |
Expand Down
5 changes: 3 additions & 2 deletions drivers/char/tpm/eventlog/acpi.c
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
* Access to the event log extended by the TCG BIOS of PC platform
*/

#include <linux/device.h>
#include <linux/seq_file.h>
#include <linux/fs.h>
#include <linux/security.h>
Expand Down Expand Up @@ -135,7 +136,7 @@ int tpm_read_log_acpi(struct tpm_chip *chip)
}

/* malloc EventLog space */
log->bios_event_log = kmalloc(len, GFP_KERNEL);
log->bios_event_log = devm_kmalloc(&chip->dev, len, GFP_KERNEL);
if (!log->bios_event_log)
return -ENOMEM;

Expand All @@ -160,7 +161,7 @@ int tpm_read_log_acpi(struct tpm_chip *chip)
return format;

err:
kfree(log->bios_event_log);
devm_kfree(&chip->dev, log->bios_event_log);
log->bios_event_log = NULL;
return ret;
}
13 changes: 7 additions & 6 deletions drivers/char/tpm/eventlog/efi.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
* Thiebaud Weksteen <[email protected]>
*/

#include <linux/device.h>
#include <linux/efi.h>
#include <linux/tpm_eventlog.h>

Expand Down Expand Up @@ -55,7 +56,7 @@ int tpm_read_log_efi(struct tpm_chip *chip)
}

/* malloc EventLog space */
log->bios_event_log = kmemdup(log_tbl->log, log_size, GFP_KERNEL);
log->bios_event_log = devm_kmemdup(&chip->dev, log_tbl->log, log_size, GFP_KERNEL);
if (!log->bios_event_log) {
ret = -ENOMEM;
goto out;
Expand All @@ -76,7 +77,7 @@ int tpm_read_log_efi(struct tpm_chip *chip)
MEMREMAP_WB);
if (!final_tbl) {
pr_err("Could not map UEFI TPM final log\n");
kfree(log->bios_event_log);
devm_kfree(&chip->dev, log->bios_event_log);
ret = -ENOMEM;
goto out;
}
Expand All @@ -91,11 +92,11 @@ int tpm_read_log_efi(struct tpm_chip *chip)
* Allocate memory for the 'combined log' where we will append the
* 'final events log' to.
*/
tmp = krealloc(log->bios_event_log,
log_size + final_events_log_size,
GFP_KERNEL);
tmp = devm_krealloc(&chip->dev, log->bios_event_log,
log_size + final_events_log_size,
GFP_KERNEL);
if (!tmp) {
kfree(log->bios_event_log);
devm_kfree(&chip->dev, log->bios_event_log);
ret = -ENOMEM;
goto out;
}
Expand Down
35 changes: 33 additions & 2 deletions drivers/char/tpm/eventlog/of.c
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,44 @@
* Read the event log created by the firmware on PPC64
*/

#include <linux/device.h>
#include <linux/slab.h>
#include <linux/io.h>
#include <linux/ioport.h>
#include <linux/of.h>
#include <linux/of_address.h>
#include <linux/of_reserved_mem.h>
#include <linux/tpm_eventlog.h>

#include "../tpm.h"
#include "common.h"

static int tpm_read_log_memory_region(struct tpm_chip *chip)
{
struct device_node *node;
struct resource res;
int rc;

node = of_parse_phandle(chip->dev.parent->of_node, "memory-region", 0);
if (!node)
return -ENODEV;

rc = of_address_to_resource(node, 0, &res);
of_node_put(node);
if (rc)
return rc;

chip->log.bios_event_log = devm_memremap(&chip->dev, res.start, resource_size(&res),
MEMREMAP_WB);
if (IS_ERR(chip->log.bios_event_log))
return -ENOMEM;

chip->log.bios_event_log_end = chip->log.bios_event_log + resource_size(&res);

return chip->flags & TPM_CHIP_FLAG_TPM2 ? EFI_TCG2_EVENT_LOG_FORMAT_TCG_2 :
EFI_TCG2_EVENT_LOG_FORMAT_TCG_1_2;
}

int tpm_read_log_of(struct tpm_chip *chip)
{
struct device_node *np;
Expand All @@ -38,7 +69,7 @@ int tpm_read_log_of(struct tpm_chip *chip)
sizep = of_get_property(np, "linux,sml-size", NULL);
basep = of_get_property(np, "linux,sml-base", NULL);
if (sizep == NULL && basep == NULL)
return -ENODEV;
return tpm_read_log_memory_region(chip);
if (sizep == NULL || basep == NULL)
return -EIO;

Expand All @@ -65,7 +96,7 @@ int tpm_read_log_of(struct tpm_chip *chip)
return -EIO;
}

log->bios_event_log = kmemdup(__va(base), size, GFP_KERNEL);
log->bios_event_log = devm_kmemdup(&chip->dev, __va(base), size, GFP_KERNEL);
if (!log->bios_event_log)
return -ENOMEM;

Expand Down
5 changes: 2 additions & 3 deletions drivers/char/tpm/st33zp24/i2c.c
Original file line number Diff line number Diff line change
Expand Up @@ -101,8 +101,7 @@ static const struct st33zp24_phy_ops i2c_phy_ops = {
* @return: 0 in case of success.
* -1 in other case.
*/
static int st33zp24_i2c_probe(struct i2c_client *client,
const struct i2c_device_id *id)
static int st33zp24_i2c_probe(struct i2c_client *client)
{
struct st33zp24_i2c_phy *phy;

Expand Down Expand Up @@ -161,7 +160,7 @@ static struct i2c_driver st33zp24_i2c_driver = {
.of_match_table = of_match_ptr(of_st33zp24_i2c_match),
.acpi_match_table = ACPI_PTR(st33zp24_i2c_acpi_match),
},
.probe = st33zp24_i2c_probe,
.probe_new = st33zp24_i2c_probe,
.remove = st33zp24_i2c_remove,
.id_table = st33zp24_i2c_id
};
Expand Down
1 change: 0 additions & 1 deletion drivers/char/tpm/tpm-chip.c
Original file line number Diff line number Diff line change
Expand Up @@ -267,7 +267,6 @@ static void tpm_dev_release(struct device *dev)
idr_remove(&dev_nums_idr, chip->dev_num);
mutex_unlock(&idr_lock);

kfree(chip->log.bios_event_log);
kfree(chip->work_space.context_buf);
kfree(chip->work_space.session_buf);
kfree(chip->allocated_banks);
Expand Down
4 changes: 3 additions & 1 deletion drivers/char/tpm/tpm2-cmd.c
Original file line number Diff line number Diff line change
Expand Up @@ -777,10 +777,12 @@ int tpm2_auto_startup(struct tpm_chip *chip)

int tpm2_find_cc(struct tpm_chip *chip, u32 cc)
{
u32 cc_mask;
int i;

cc_mask = 1 << TPM2_CC_ATTR_VENDOR | GENMASK(15, 0);
for (i = 0; i < chip->nr_commands; i++)
if (cc == (chip->cc_attrs_tbl[i] & GENMASK(15, 0)))
if (cc == (chip->cc_attrs_tbl[i] & cc_mask))
return i;

return -1;
Expand Down
Loading

0 comments on commit 219ac97

Please sign in to comment.