Commit 95adc6b4 authored by Tomas Winkler's avatar Tomas Winkler Committed by Jarkko Sakkinen

tpm: use u32 instead of int for PCR index

The TPM specs defines PCR index as a positive number, and there is
no reason to use a signed number. It is also a possible security
issue as currently no functions check for a negative index,
which may become a large number when converted to u32.

Adjust the API to use u32 instead of int in all PCR related
functions.
Signed-off-by: default avatarTomas Winkler <tomas.winkler@intel.com>
Reviewed-by: default avatarJarkko Sakkinen <jarkko.sakkinen@linux.intel.com>
Tested-by: default avatarJarkko Sakkinen <jarkko.sakkinen@linux.intel.com>
Signed-off-by: default avatarJarkko Sakkinen <jarkko.sakkinen@linux.intel.com>
parent c82e5954
...@@ -38,7 +38,7 @@ ...@@ -38,7 +38,7 @@
* recently changed pcr on suspend, so force the flush * recently changed pcr on suspend, so force the flush
* with an extend to the selected _unused_ non-volatile pcr. * with an extend to the selected _unused_ non-volatile pcr.
*/ */
static int tpm_suspend_pcr; static u32 tpm_suspend_pcr;
module_param_named(suspend_pcr, tpm_suspend_pcr, uint, 0644); module_param_named(suspend_pcr, tpm_suspend_pcr, uint, 0644);
MODULE_PARM_DESC(suspend_pcr, MODULE_PARM_DESC(suspend_pcr,
"PCR to use for dummy writes to facilitate flush on suspend."); "PCR to use for dummy writes to facilitate flush on suspend.");
...@@ -454,7 +454,7 @@ EXPORT_SYMBOL_GPL(tpm_is_tpm2); ...@@ -454,7 +454,7 @@ EXPORT_SYMBOL_GPL(tpm_is_tpm2);
* *
* Return: same as with tpm_transmit_cmd() * Return: same as with tpm_transmit_cmd()
*/ */
int tpm_pcr_read(struct tpm_chip *chip, int pcr_idx, u8 *res_buf) int tpm_pcr_read(struct tpm_chip *chip, u32 pcr_idx, u8 *res_buf)
{ {
int rc; int rc;
...@@ -484,7 +484,7 @@ EXPORT_SYMBOL_GPL(tpm_pcr_read); ...@@ -484,7 +484,7 @@ EXPORT_SYMBOL_GPL(tpm_pcr_read);
* *
* Return: same as with tpm_transmit_cmd() * Return: same as with tpm_transmit_cmd()
*/ */
int tpm_pcr_extend(struct tpm_chip *chip, int pcr_idx, const u8 *hash) int tpm_pcr_extend(struct tpm_chip *chip, u32 pcr_idx, const u8 *hash)
{ {
int rc; int rc;
struct tpm2_digest digest_list[ARRAY_SIZE(chip->active_banks)]; struct tpm2_digest digest_list[ARRAY_SIZE(chip->active_banks)];
......
...@@ -102,7 +102,7 @@ static ssize_t pcrs_show(struct device *dev, struct device_attribute *attr, ...@@ -102,7 +102,7 @@ static ssize_t pcrs_show(struct device *dev, struct device_attribute *attr,
cap_t cap; cap_t cap;
u8 digest[TPM_DIGEST_SIZE]; u8 digest[TPM_DIGEST_SIZE];
ssize_t rc; ssize_t rc;
int i, j, num_pcrs; u32 i, j, num_pcrs;
char *str = buf; char *str = buf;
struct tpm_chip *chip = to_tpm_chip(dev); struct tpm_chip *chip = to_tpm_chip(dev);
......
...@@ -509,14 +509,14 @@ ssize_t tpm_transmit_cmd(struct tpm_chip *chip, struct tpm_space *space, ...@@ -509,14 +509,14 @@ ssize_t tpm_transmit_cmd(struct tpm_chip *chip, struct tpm_space *space,
int tpm_get_timeouts(struct tpm_chip *); int tpm_get_timeouts(struct tpm_chip *);
int tpm_auto_startup(struct tpm_chip *chip); int tpm_auto_startup(struct tpm_chip *chip);
int tpm1_pm_suspend(struct tpm_chip *chip, int tpm_suspend_pcr); int tpm1_pm_suspend(struct tpm_chip *chip, u32 tpm_suspend_pcr);
int tpm1_auto_startup(struct tpm_chip *chip); int tpm1_auto_startup(struct tpm_chip *chip);
int tpm1_do_selftest(struct tpm_chip *chip); int tpm1_do_selftest(struct tpm_chip *chip);
int tpm1_get_timeouts(struct tpm_chip *chip); int tpm1_get_timeouts(struct tpm_chip *chip);
unsigned long tpm1_calc_ordinal_duration(struct tpm_chip *chip, u32 ordinal); unsigned long tpm1_calc_ordinal_duration(struct tpm_chip *chip, u32 ordinal);
int tpm1_pcr_extend(struct tpm_chip *chip, int pcr_idx, const u8 *hash, int tpm1_pcr_extend(struct tpm_chip *chip, u32 pcr_idx, const u8 *hash,
const char *log_msg); const char *log_msg);
int tpm1_pcr_read(struct tpm_chip *chip, int pcr_idx, u8 *res_buf); int tpm1_pcr_read(struct tpm_chip *chip, u32 pcr_idx, u8 *res_buf);
ssize_t tpm1_getcap(struct tpm_chip *chip, u32 subcap_id, cap_t *cap, ssize_t tpm1_getcap(struct tpm_chip *chip, u32 subcap_id, cap_t *cap,
const char *desc, size_t min_cap_length); const char *desc, size_t min_cap_length);
int tpm1_get_random(struct tpm_chip *chip, u8 *out, size_t max); int tpm1_get_random(struct tpm_chip *chip, u8 *out, size_t max);
...@@ -558,8 +558,8 @@ static inline u32 tpm2_rc_value(u32 rc) ...@@ -558,8 +558,8 @@ static inline u32 tpm2_rc_value(u32 rc)
} }
int tpm2_get_timeouts(struct tpm_chip *chip); int tpm2_get_timeouts(struct tpm_chip *chip);
int tpm2_pcr_read(struct tpm_chip *chip, int pcr_idx, u8 *res_buf); int tpm2_pcr_read(struct tpm_chip *chip, u32 pcr_idx, u8 *res_buf);
int tpm2_pcr_extend(struct tpm_chip *chip, int pcr_idx, u32 count, int tpm2_pcr_extend(struct tpm_chip *chip, u32 pcr_idx, u32 count,
struct tpm2_digest *digests); struct tpm2_digest *digests);
int tpm2_get_random(struct tpm_chip *chip, u8 *dest, size_t max); int tpm2_get_random(struct tpm_chip *chip, u8 *dest, size_t max);
void tpm2_flush_context_cmd(struct tpm_chip *chip, u32 handle, void tpm2_flush_context_cmd(struct tpm_chip *chip, u32 handle,
......
...@@ -449,7 +449,7 @@ int tpm1_get_timeouts(struct tpm_chip *chip) ...@@ -449,7 +449,7 @@ int tpm1_get_timeouts(struct tpm_chip *chip)
} }
#define TPM_ORD_PCR_EXTEND 20 #define TPM_ORD_PCR_EXTEND 20
int tpm1_pcr_extend(struct tpm_chip *chip, int pcr_idx, const u8 *hash, int tpm1_pcr_extend(struct tpm_chip *chip, u32 pcr_idx, const u8 *hash,
const char *log_msg) const char *log_msg)
{ {
struct tpm_buf buf; struct tpm_buf buf;
...@@ -572,7 +572,7 @@ int tpm1_get_random(struct tpm_chip *chip, u8 *dest, size_t max) ...@@ -572,7 +572,7 @@ int tpm1_get_random(struct tpm_chip *chip, u8 *dest, size_t max)
} }
#define TPM_ORD_PCRREAD 21 #define TPM_ORD_PCRREAD 21
int tpm1_pcr_read(struct tpm_chip *chip, int pcr_idx, u8 *res_buf) int tpm1_pcr_read(struct tpm_chip *chip, u32 pcr_idx, u8 *res_buf)
{ {
struct tpm_buf buf; struct tpm_buf buf;
int rc; int rc;
...@@ -729,7 +729,7 @@ int tpm1_auto_startup(struct tpm_chip *chip) ...@@ -729,7 +729,7 @@ int tpm1_auto_startup(struct tpm_chip *chip)
* * 0 on success, * * 0 on success,
* * < 0 on error. * * < 0 on error.
*/ */
int tpm1_pm_suspend(struct tpm_chip *chip, int tpm_suspend_pcr) int tpm1_pm_suspend(struct tpm_chip *chip, u32 tpm_suspend_pcr)
{ {
u8 dummy_hash[TPM_DIGEST_SIZE] = { 0 }; u8 dummy_hash[TPM_DIGEST_SIZE] = { 0 };
struct tpm_buf buf; struct tpm_buf buf;
......
...@@ -175,7 +175,7 @@ struct tpm2_pcr_read_out { ...@@ -175,7 +175,7 @@ struct tpm2_pcr_read_out {
* *
* Return: Same as with tpm_transmit_cmd. * Return: Same as with tpm_transmit_cmd.
*/ */
int tpm2_pcr_read(struct tpm_chip *chip, int pcr_idx, u8 *res_buf) int tpm2_pcr_read(struct tpm_chip *chip, u32 pcr_idx, u8 *res_buf)
{ {
int rc; int rc;
struct tpm_buf buf; struct tpm_buf buf;
...@@ -225,7 +225,7 @@ struct tpm2_null_auth_area { ...@@ -225,7 +225,7 @@ struct tpm2_null_auth_area {
* *
* Return: Same as with tpm_transmit_cmd. * Return: Same as with tpm_transmit_cmd.
*/ */
int tpm2_pcr_extend(struct tpm_chip *chip, int pcr_idx, u32 count, int tpm2_pcr_extend(struct tpm_chip *chip, u32 pcr_idx, u32 count,
struct tpm2_digest *digests) struct tpm2_digest *digests)
{ {
struct tpm_buf buf; struct tpm_buf buf;
...@@ -272,7 +272,6 @@ int tpm2_pcr_extend(struct tpm_chip *chip, int pcr_idx, u32 count, ...@@ -272,7 +272,6 @@ int tpm2_pcr_extend(struct tpm_chip *chip, int pcr_idx, u32 count,
return rc; return rc;
} }
struct tpm2_get_random_out { struct tpm2_get_random_out {
__be16 size; __be16 size;
u8 buffer[TPM_MAX_RNG_DATA]; u8 buffer[TPM_MAX_RNG_DATA];
......
...@@ -53,8 +53,8 @@ struct tpm_class_ops { ...@@ -53,8 +53,8 @@ struct tpm_class_ops {
#if defined(CONFIG_TCG_TPM) || defined(CONFIG_TCG_TPM_MODULE) #if defined(CONFIG_TCG_TPM) || defined(CONFIG_TCG_TPM_MODULE)
extern int tpm_is_tpm2(struct tpm_chip *chip); extern int tpm_is_tpm2(struct tpm_chip *chip);
extern int tpm_pcr_read(struct tpm_chip *chip, int pcr_idx, u8 *res_buf); extern int tpm_pcr_read(struct tpm_chip *chip, u32 pcr_idx, u8 *res_buf);
extern int tpm_pcr_extend(struct tpm_chip *chip, int pcr_idx, const u8 *hash); extern int tpm_pcr_extend(struct tpm_chip *chip, u32 pcr_idx, const u8 *hash);
extern int tpm_send(struct tpm_chip *chip, void *cmd, size_t buflen); extern int tpm_send(struct tpm_chip *chip, void *cmd, size_t buflen);
extern int tpm_get_random(struct tpm_chip *chip, u8 *data, size_t max); extern int tpm_get_random(struct tpm_chip *chip, u8 *data, size_t max);
extern int tpm_seal_trusted(struct tpm_chip *chip, extern int tpm_seal_trusted(struct tpm_chip *chip,
...@@ -69,15 +69,18 @@ static inline int tpm_is_tpm2(struct tpm_chip *chip) ...@@ -69,15 +69,18 @@ static inline int tpm_is_tpm2(struct tpm_chip *chip)
{ {
return -ENODEV; return -ENODEV;
} }
static inline int tpm_pcr_read(struct tpm_chip *chip, int pcr_idx, u8 *res_buf)
static inline int tpm_pcr_read(struct tpm_chip *chip, u32 pcr_idx, u8 *res_buf)
{ {
return -ENODEV; return -ENODEV;
} }
static inline int tpm_pcr_extend(struct tpm_chip *chip, int pcr_idx,
static inline int tpm_pcr_extend(struct tpm_chip *chip, u32 pcr_idx,
const u8 *hash) const u8 *hash)
{ {
return -ENODEV; return -ENODEV;
} }
static inline int tpm_send(struct tpm_chip *chip, void *cmd, size_t buflen) static inline int tpm_send(struct tpm_chip *chip, void *cmd, size_t buflen)
{ {
return -ENODEV; return -ENODEV;
......
...@@ -643,7 +643,7 @@ int ima_calc_buffer_hash(const void *buf, loff_t len, ...@@ -643,7 +643,7 @@ int ima_calc_buffer_hash(const void *buf, loff_t len,
return calc_buffer_shash(buf, len, hash); return calc_buffer_shash(buf, len, hash);
} }
static void __init ima_pcrread(int idx, u8 *pcr) static void __init ima_pcrread(u32 idx, u8 *pcr)
{ {
if (!ima_tpm_chip) if (!ima_tpm_chip)
return; return;
...@@ -659,7 +659,8 @@ static int __init ima_calc_boot_aggregate_tfm(char *digest, ...@@ -659,7 +659,8 @@ static int __init ima_calc_boot_aggregate_tfm(char *digest,
struct crypto_shash *tfm) struct crypto_shash *tfm)
{ {
u8 pcr_i[TPM_DIGEST_SIZE]; u8 pcr_i[TPM_DIGEST_SIZE];
int rc, i; int rc;
u32 i;
SHASH_DESC_ON_STACK(shash, tfm); SHASH_DESC_ON_STACK(shash, tfm);
shash->tfm = tfm; shash->tfm = tfm;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment