tpm: fix byte order related arithmetic inconsistency in tpm_getcap()
You should not do arithmetic with __be32 or __le32 types because sometimes it results incorrect results. Calculations must be done only with integers that are in in the CPU byte order. This commit migrates tpm_getcap() to struct tpm_buf in order to sort out these issues. Signed-off-by: Jarkko Sakkinen <jarkko.sakkinen@linux.intel.com> Reviewed-by: Jason Gunthorpe <jgunthorpe@obsidianresearch.com>
This commit is contained in:
parent
d8c3eab5cb
commit
124bdcf4a6
|
@ -552,31 +552,33 @@ static const struct tpm_input_header tpm_getcap_header = {
|
||||||
ssize_t tpm_getcap(struct tpm_chip *chip, u32 subcap_id, cap_t *cap,
|
ssize_t tpm_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)
|
||||||
{
|
{
|
||||||
struct tpm_cmd_t tpm_cmd;
|
struct tpm_buf buf;
|
||||||
int rc;
|
int rc;
|
||||||
|
|
||||||
tpm_cmd.header.in = tpm_getcap_header;
|
rc = tpm_buf_init(&buf, TPM_TAG_RQU_COMMAND, TPM_ORD_GET_CAP);
|
||||||
|
if (rc)
|
||||||
|
return rc;
|
||||||
|
|
||||||
if (subcap_id == TPM_CAP_VERSION_1_1 ||
|
if (subcap_id == TPM_CAP_VERSION_1_1 ||
|
||||||
subcap_id == TPM_CAP_VERSION_1_2) {
|
subcap_id == TPM_CAP_VERSION_1_2) {
|
||||||
tpm_cmd.params.getcap_in.cap = cpu_to_be32(subcap_id);
|
tpm_buf_append_u32(&buf, subcap_id);
|
||||||
/*subcap field not necessary */
|
tpm_buf_append_u32(&buf, 0);
|
||||||
tpm_cmd.params.getcap_in.subcap_size = cpu_to_be32(0);
|
|
||||||
tpm_cmd.header.in.length -= cpu_to_be32(sizeof(__be32));
|
|
||||||
} else {
|
} else {
|
||||||
if (subcap_id == TPM_CAP_FLAG_PERM ||
|
if (subcap_id == TPM_CAP_FLAG_PERM ||
|
||||||
subcap_id == TPM_CAP_FLAG_VOL)
|
subcap_id == TPM_CAP_FLAG_VOL)
|
||||||
tpm_cmd.params.getcap_in.cap =
|
tpm_buf_append_u32(&buf, TPM_CAP_FLAG);
|
||||||
cpu_to_be32(TPM_CAP_FLAG);
|
|
||||||
else
|
else
|
||||||
tpm_cmd.params.getcap_in.cap =
|
tpm_buf_append_u32(&buf, TPM_CAP_PROP);
|
||||||
cpu_to_be32(TPM_CAP_PROP);
|
|
||||||
tpm_cmd.params.getcap_in.subcap_size = cpu_to_be32(4);
|
tpm_buf_append_u32(&buf, 4);
|
||||||
tpm_cmd.params.getcap_in.subcap = cpu_to_be32(subcap_id);
|
tpm_buf_append_u32(&buf, subcap_id);
|
||||||
}
|
}
|
||||||
rc = tpm_transmit_cmd(chip, NULL, &tpm_cmd, TPM_INTERNAL_RESULT_SIZE,
|
rc = tpm_transmit_cmd(chip, NULL, buf.data, PAGE_SIZE,
|
||||||
min_cap_length, 0, desc);
|
min_cap_length, 0, desc);
|
||||||
if (!rc)
|
if (!rc)
|
||||||
*cap = tpm_cmd.params.getcap_out.cap;
|
*cap = *(cap_t *)&buf.data[TPM_HEADER_SIZE + 4];
|
||||||
|
|
||||||
|
tpm_buf_destroy(&buf);
|
||||||
return rc;
|
return rc;
|
||||||
}
|
}
|
||||||
EXPORT_SYMBOL_GPL(tpm_getcap);
|
EXPORT_SYMBOL_GPL(tpm_getcap);
|
||||||
|
|
|
@ -339,17 +339,6 @@ enum tpm_sub_capabilities {
|
||||||
TPM_CAP_PROP_TIS_DURATION = 0x120,
|
TPM_CAP_PROP_TIS_DURATION = 0x120,
|
||||||
};
|
};
|
||||||
|
|
||||||
struct tpm_getcap_params_in {
|
|
||||||
__be32 cap;
|
|
||||||
__be32 subcap_size;
|
|
||||||
__be32 subcap;
|
|
||||||
} __packed;
|
|
||||||
|
|
||||||
struct tpm_getcap_params_out {
|
|
||||||
__be32 cap_size;
|
|
||||||
cap_t cap;
|
|
||||||
} __packed;
|
|
||||||
|
|
||||||
struct tpm_readpubek_params_out {
|
struct tpm_readpubek_params_out {
|
||||||
u8 algorithm[4];
|
u8 algorithm[4];
|
||||||
u8 encscheme[2];
|
u8 encscheme[2];
|
||||||
|
@ -399,10 +388,8 @@ struct tpm_startup_in {
|
||||||
} __packed;
|
} __packed;
|
||||||
|
|
||||||
typedef union {
|
typedef union {
|
||||||
struct tpm_getcap_params_out getcap_out;
|
|
||||||
struct tpm_readpubek_params_out readpubek_out;
|
struct tpm_readpubek_params_out readpubek_out;
|
||||||
u8 readpubek_out_buffer[sizeof(struct tpm_readpubek_params_out)];
|
u8 readpubek_out_buffer[sizeof(struct tpm_readpubek_params_out)];
|
||||||
struct tpm_getcap_params_in getcap_in;
|
|
||||||
struct tpm_pcrread_in pcrread_in;
|
struct tpm_pcrread_in pcrread_in;
|
||||||
struct tpm_pcrread_out pcrread_out;
|
struct tpm_pcrread_out pcrread_out;
|
||||||
struct tpm_pcrextend_in pcrextend_in;
|
struct tpm_pcrextend_in pcrextend_in;
|
||||||
|
|
Loading…
Reference in New Issue