tpm: factor out tpm1 code into tpm1-cmd.c
Subsystems (3)
cover tpm: factor out tpm1 code into tpm1-cmd.c
Move tpm 1.x implementation to tpm1-cmd.c similarly to tpm2-cmd.c This is work in progress of possible dropping compiling out one tpm 1.x or tpm 2.x in case not needed on a target platform.
Tomas Winkler (4):
tmp: move tpm1_pcr_extend to tpm1-cmd.c
tmp: move tpm_getcap to tpm1-cmd.c
tmp: factor out tpm1_get_random into tpm1-cmd.c
tpm: move tpm1 selftest code from tpm-interface tpm1-cmd.c
drivers/char/tpm/st33zp24/st33zp24.c | 2 +- drivers/char/tpm/tpm-interface.c | 273 +---------------------------------- drivers/char/tpm/tpm-sysfs.c | 50 +++---- drivers/char/tpm/tpm.h | 12 +- drivers/char/tpm/tpm1-cmd.c | 267 +++++++++++++++++++++++++++++++++- drivers/char/tpm/tpm_tis_core.c | 4 +- 6 files changed, 303 insertions(+), 305 deletions(-)
Signature · 6 lines
2.14.3 -- To unsubscribe from this list: send the line "unsubscribe linux-security-module" in the body of a message to majordomo at vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
PATCH 1/4 tmp: move tpm1_pcr_extend to tpm1-cmd.c
Move tpm1_pcr_extend to tpm1-cmd.c and remove
unused pcrextend_header structure.
--- drivers/char/tpm/tpm-interface.c | 28 ---------------------------- drivers/char/tpm/tpm.h | 2 ++ drivers/char/tpm/tpm1-cmd.c | 23 +++++++++++++++++++++++ 3 files changed, 25 insertions(+), 28 deletions(-)
drivers/char/tpm/tpm-interface.c +0 -28
@@ -514,34 +514,6 @@ int tpm_pcr_read(struct tpm_chip *chip, int pcr_idx, u8 *res_buf) }EXPORT_SYMBOL_GPL (tpm_pcr_read); -#define TPM_ORD_PCR_EXTEND 20 -#define EXTEND_PCR_RESULT_SIZE 34 -#define EXTEND_PCR_RESULT_BODY_SIZE 20 -static const struct tpm_input_header pcrextend_header = { - .tag =cpu_to_be16 (TPM_TAG_RQU_COMMAND ), - .length =cpu_to_be32 (34 ), - .ordinal =cpu_to_be32 (TPM_ORD_PCR_EXTEND ) -}; - -static int tpm1_pcr_extend (struct tpm_chip *chip,int pcr_idx,const u8 *hash, -char *log_msg) -{ -struct tpm_buf buf; -int rc; - - rc =tpm_buf_init (&buf,TPM_TAG_RQU_COMMAND ,TPM_ORD_PCR_EXTEND ); -if (rc) -return rc; - -tpm_buf_append_u32 (&buf, pcr_idx); -tpm_buf_append (&buf, hash,TPM_DIGEST_SIZE ); - - rc =tpm_transmit_cmd (chip,NULL , buf.data,EXTEND_PCR_RESULT_SIZE , -EXTEND_PCR_RESULT_BODY_SIZE ,0 , log_msg); -tpm_buf_destroy (&buf); -return rc; -} -/** * tpm_pcr_extend - extend a PCR value in SHA1 bank. * @chip: a &struct tpm_chip instance, %NULL for the default chip
drivers/char/tpm/tpm.h +2 -0
@@ -535,6 +535,8 @@ int tpm_do_selftest(struct tpm_chip *chip);int tpm1_auto_startup (struct tpm_chip *chip);int tpm1_get_timeouts (struct tpm_chip *chip);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, +const char *log_msg);int tpm_pm_suspend (struct device *dev);int tpm_pm_resume (struct device *dev);
drivers/char/tpm/tpm1-cmd.c +23 -0
@@ -414,3 +414,26 @@ int tpm1_get_timeouts(struct tpm_chip *chip) chip->flags |=TPM_CHIP_FLAG_HAVE_TIMEOUTS ;return 0 ; } + +#define TPM_ORD_PCR_EXTEND 20 +#define EXTEND_PCR_RESULT_SIZE 34 +#define EXTEND_PCR_RESULT_BODY_SIZE 20 +int tpm1_pcr_extend (struct tpm_chip *chip,int pcr_idx,const u8 *hash, +const char *log_msg) +{ +struct tpm_buf buf; +int rc; + + rc =tpm_buf_init (&buf,TPM_TAG_RQU_COMMAND ,TPM_ORD_PCR_EXTEND ); +if (rc) +return rc; + +tpm_buf_append_u32 (&buf, pcr_idx); +tpm_buf_append (&buf, hash,TPM_DIGEST_SIZE ); + + rc =tpm_transmit_cmd (chip,NULL , buf.data,EXTEND_PCR_RESULT_SIZE , +EXTEND_PCR_RESULT_BODY_SIZE ,0 , log_msg); +tpm_buf_destroy (&buf); +return rc; +} +
Signature · 6 lines
2.14.3 -- To unsubscribe from this list: send the line "unsubscribe linux-security-module" in the body of a message to majordomo at vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
PATCH 2/4 tmp: move tpm_getcap to tpm1-cmd.c
In reply to Tomas Winkler1. Move tpm_getcap to tpm1-cmd. Rename the function to tpm1_getcap.
2. Remove unsed tpm_getcap_header with unused constant as the functionality is implemented using tpm_buf construct.
--- drivers/char/tpm/tpm-interface.c | 47 +----------------------------------- drivers/char/tpm/tpm-sysfs.c | 48 ++++++++++++++++++------------------- drivers/char/tpm/tpm.h | 4 ++-- drivers/char/tpm/tpm1-cmd.c | 51 +++++++++++++++++++++++++++++++++------- drivers/char/tpm/tpm_tis_core.c | 2 +- 5 files changed, 71 insertions(+), 81 deletions(-)
drivers/char/tpm/tpm-interface.c +1 -46
@@ -354,52 +354,6 @@ int tpm_startup(struct tpm_chip *chip)return rc; } -#define TPM_DIGEST_SIZE 20 -#define TPM_RET_CODE_IDX 6 -#define TPM_INTERNAL_RESULT_SIZE 200 -#define TPM_ORD_GET_CAP 101 -#define TPM_ORD_GET_RANDOM 70 - -static const struct tpm_input_header tpm_getcap_header = { - .tag =cpu_to_be16 (TPM_TAG_RQU_COMMAND ), - .length =cpu_to_be32 (22 ), - .ordinal =cpu_to_be32 (TPM_ORD_GET_CAP ) -}; - -ssize_t tpm_getcap (struct tpm_chip *chip,u32 subcap_id,cap_t *cap, -const char *desc,size_t min_cap_length) -{ -struct tpm_buf buf; -int rc; - - 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 || - subcap_id ==TPM_CAP_VERSION_1_2 ) { -tpm_buf_append_u32 (&buf, subcap_id); -tpm_buf_append_u32 (&buf,0 ); - }else { -if (subcap_id ==TPM_CAP_FLAG_PERM || - subcap_id ==TPM_CAP_FLAG_VOL ) -tpm_buf_append_u32 (&buf,TPM_CAP_FLAG ); -else -tpm_buf_append_u32 (&buf,TPM_CAP_PROP ); - -tpm_buf_append_u32 (&buf,4 ); -tpm_buf_append_u32 (&buf, subcap_id); - } - rc =tpm_transmit_cmd (chip,NULL , buf.data,PAGE_SIZE , - min_cap_length,0 , desc); -if (!rc) - *cap = *(cap_t *)&buf.data[TPM_HEADER_SIZE +4 ]; - -tpm_buf_destroy (&buf); -return rc; -} -EXPORT_SYMBOL_GPL (tpm_getcap); -int tpm_get_timeouts (struct tpm_chip *chip) {if (chip->flags &TPM_CHIP_FLAG_HAVE_TIMEOUTS )
@@ -753,6 +707,7 @@ int tpm_pm_resume(struct device *dev) }EXPORT_SYMBOL_GPL (tpm_pm_resume); +#define TPM_ORD_GET_RANDOM 70#define TPM_GETRANDOM_RESULT_SIZE 18static const struct tpm_input_header tpm_getrandom_header = { .tag =cpu_to_be16 (TPM_TAG_RQU_COMMAND ),
drivers/char/tpm/tpm-sysfs.c +24 -24
96 lines not on this page · raw message
drivers/char/tpm/tpm.h +2 -2
@@ -527,8 +527,6 @@ ssize_t tpm_transmit_cmd(struct tpm_chip *chip, struct tpm_space *space, size_t min_rsp_body_length, unsigned int flags, const char *desc);int tpm_startup (struct tpm_chip *chip); -ssize_t tpm_getcap (struct tpm_chip *chip,u32 subcap_id,cap_t *cap, -const char *desc,size_t min_cap_length);int tpm_get_timeouts (struct tpm_chip *);int tpm_do_selftest (struct tpm_chip *chip);
@@ -537,6 +535,8 @@ int tpm1_get_timeouts(struct tpm_chip *chip);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,const char *log_msg); +ssize_t tpm1_getcap (struct tpm_chip *chip,u32 subcap_id,cap_t *cap, +const char *desc,size_t min_cap_length);int tpm_pm_suspend (struct device *dev);int tpm_pm_resume (struct device *dev);
drivers/char/tpm/tpm1-cmd.c +43 -8
70 lines not on this page · raw message
drivers/char/tpm/tpm_tis_core.c +1 -1
@@ -628,7 +628,7 @@ static int tpm_tis_gen_interrupt(struct tpm_chip *chip)if (chip->flags &TPM_CHIP_FLAG_TPM2 )return tpm2_get_tpm_pt (chip,0x100 , &cap2, desc);else -return tpm_getcap (chip,TPM_CAP_PROP_TIS_TIMEOUT , &cap, desc, +return tpm1_getcap (chip,TPM_CAP_PROP_TIS_TIMEOUT , &cap, desc,0 ); }
Signature · 6 lines
2.14.3 -- To unsubscribe from this list: send the line "unsubscribe linux-security-module" in the body of a message to majordomo at vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
PATCH 3/4 tmp: factor out tpm1_get_random into tpm1-cmd.c
In reply to Tomas WinklerFactor out get random implementation from tpm-interface.c into tpm1_get_random function in tpm1-cmd.c.
No functional changes.
--- drivers/char/tpm/tpm-interface.c | 56 ++++------------------------------------ drivers/char/tpm/tpm.h | 2 ++ drivers/char/tpm/tpm1-cmd.c | 54 ++++++++++++++++++++++++++++++++++++++ 3 files changed, 61 insertions(+), 51 deletions(-)
drivers/char/tpm/tpm-interface.c +5 -51
@@ -707,14 +707,6 @@ int tpm_pm_resume(struct device *dev) }EXPORT_SYMBOL_GPL (tpm_pm_resume); -#define TPM_ORD_GET_RANDOM 70 -#define TPM_GETRANDOM_RESULT_SIZE 18 -static const struct tpm_input_header tpm_getrandom_header = { - .tag =cpu_to_be16 (TPM_TAG_RQU_COMMAND ), - .length =cpu_to_be32 (14 ), - .ordinal =cpu_to_be32 (TPM_ORD_GET_RANDOM ) -}; -/** * tpm_get_random() - get random bytes from the TPM's RNG * @chip: a &struct tpm_chip instance, %NULL for the default chip
@@ -725,57 +717,19 @@ static const struct tpm_input_header tpm_getrandom_header = {*/ int tpm_get_random (struct tpm_chip *chip,u8 *out,size_t max) { -struct tpm_cmd_t tpm_cmd; -u32 recd, num_bytes =min_t (u32, max,TPM_MAX_RNG_DATA ), rlength; -int err, total =0 , retries =5 ; -u8 *dest = out; - -if (!out || !num_bytes || max >TPM_MAX_RNG_DATA ) -return -EINVAL ; +int err; chip =tpm_chip_find_get (chip);if (!chip)return -ENODEV ; -if (chip->flags &TPM_CHIP_FLAG_TPM2 ) { +if (chip->flags &TPM_CHIP_FLAG_TPM2 ) err =tpm2_get_random (chip, out, max); -tpm_put_ops (chip); -return err; - } - -do { - tpm_cmd.header.in = tpm_getrandom_header; - tpm_cmd.params.getrandom_in.num_bytes =cpu_to_be32 (num_bytes); - - err =tpm_transmit_cmd (chip,NULL , &tpm_cmd, -TPM_GETRANDOM_RESULT_SIZE + num_bytes, - offsetof(struct tpm_getrandom_out , - rng_data), -0 ,"attempting get random" ); -if (err) -break ; - - recd =be32_to_cpu (tpm_cmd.params.getrandom_out.rng_data_len); -if (recd > num_bytes) { - total = -EFAULT ; -break ; - } - - rlength =be32_to_cpu (tpm_cmd.header.out.length); -if (rlength < offsetof(struct tpm_getrandom_out , rng_data) + - recd) { - total = -EFAULT ; -break ; - } -memcpy (dest, tpm_cmd.params.getrandom_out.rng_data, recd); - - dest += recd; - total += recd; - num_bytes -= recd; - }while (retries-- && total < max); +else + err =tpm1_get_random (chip, out, max);tpm_put_ops (chip); -return total ? total : -EIO ; +return err; }EXPORT_SYMBOL_GPL (tpm_get_random);
drivers/char/tpm/tpm.h +2 -0
@@ -537,6 +537,8 @@ int tpm1_pcr_extend(struct tpm_chip *chip, int pcr_idx, const u8 *hash, const char *log_msg);ssize_t tpm1_getcap (struct tpm_chip *chip,u32 subcap_id,cap_t *cap,const char *desc,size_t min_cap_length); +int tpm1_get_random (struct tpm_chip *chip,u8 *out,size_t max); +int tpm_pm_suspend (struct device *dev);int tpm_pm_resume (struct device *dev);
drivers/char/tpm/tpm1-cmd.c +54 -0
57 lines not on this page · raw message
Signature · 6 lines
2.14.3 -- To unsubscribe from this list: send the line "unsubscribe linux-security-module" in the body of a message to majordomo at vger.kernel.org More majordomo info@ http://vger.kernel.org/majordomo-info.html
PATCH 4/4 tpm: move tpm1 selftest code from tpm-interface tpm1-cmd.c
In reply to Tomas WinklerMove the tmp1 selftest code functions to tpm1-cmd.c tpm_pcr_read_dev to tpm1_pcr_read_dev tpm_continue_selftest to tpm1_continue_selftest tpm_do_selftest to tpm1_do_selftest
--- drivers/char/tpm/st33zp24/st33zp24.c | 2 +- drivers/char/tpm/tpm-interface.c | 144 +---------------------------------- drivers/char/tpm/tpm-sysfs.c | 2 +- drivers/char/tpm/tpm.h | 4 +- drivers/char/tpm/tpm1-cmd.c | 139 +++++++++++++++++++++++++++++++++ drivers/char/tpm/tpm_tis_core.c | 2 +- 6 files changed, 147 insertions(+), 146 deletions(-)
drivers/char/tpm/st33zp24/st33zp24.c +1 -1
@@ -651,7 +651,7 @@ int st33zp24_pm_resume(struct device *dev) }else { ret =tpm_pm_resume (dev);if (!ret) -tpm_do_selftest (chip); +tpm1_do_selftest (chip); }return ret; }/* st33zp24_pm_resume() */
drivers/char/tpm/tpm-interface.c +3 -141
165 lines not on this page · raw message
drivers/char/tpm/tpm-sysfs.c +1 -1
@@ -114,7 +114,7 @@ static ssize_t pcrs_show(struct device *dev, struct device_attribute *attr, num_pcrs =be32_to_cpu (cap.num_pcrs);for (i =0 ; i < num_pcrs; i++) { - rc =tpm_pcr_read_dev (chip, i, digest); + rc =tpm1_pcr_read_dev (chip, i, digest);if (rc)break ; str +=sprintf (str,"PCR-%02d: " , i);
drivers/char/tpm/tpm.h +2 -2
@@ -528,8 +528,8 @@ ssize_t tpm_transmit_cmd(struct tpm_chip *chip, struct tpm_space *space, const char *desc);int tpm_startup (struct tpm_chip *chip);int tpm_get_timeouts (struct tpm_chip *); -int tpm_do_selftest (struct tpm_chip *chip); +int tpm1_do_selftest (struct tpm_chip *chip);int tpm1_auto_startup (struct tpm_chip *chip);int tpm1_get_timeouts (struct tpm_chip *chip);unsigned long tpm1_calc_ordinal_duration (struct tpm_chip *chip,u32 ordinal);
@@ -538,6 +538,7 @@ int tpm1_pcr_extend(struct tpm_chip *chip, int pcr_idx, const u8 *hash,ssize_t tpm1_getcap (struct tpm_chip *chip,u32 subcap_id,cap_t *cap,const char *desc,size_t min_cap_length);int tpm1_get_random (struct tpm_chip *chip,u8 *out,size_t max); +int tpm1_pcr_read_dev (struct tpm_chip *chip,int pcr_idx,u8 *res_buf);int tpm_pm_suspend (struct device *dev);int tpm_pm_resume (struct device *dev);
@@ -561,7 +562,6 @@ void tpm_chip_unregister(struct tpm_chip *chip);void tpm_sysfs_add_device (struct tpm_chip *chip); -int tpm_pcr_read_dev (struct tpm_chip *chip,int pcr_idx,u8 *res_buf);#ifdef CONFIG_ACPI extern void tpm_add_ppi (struct tpm_chip *chip);
drivers/char/tpm/tpm1-cmd.c +139 -0
142 lines not on this page · raw message
drivers/char/tpm/tpm_tis_core.c +1 -1
@@ -1018,7 +1018,7 @@ int tpm_tis_resume(struct device *dev)* an error code but for unknown reason it isn't handled. */ if (!(chip->flags &TPM_CHIP_FLAG_TPM2 )) -tpm_do_selftest (chip); +tpm1_do_selftest (chip);return 0 ; }
Signature · 6 lines
2.14.3 -- To unsubscribe from this list: send the line "unsubscribe linux-security-module" in the body of a message to majordomo at vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
Re: [PATCH 3/4] tmp: factor out tpm1_get_random into tpm1-cmd.c
In reply to Tomas WinklerQuoted 5 lines · Tomas Winkler
Factor out get random implementation from
tpm-interface.cintotpm1_get_randomfunction intpm1-cmd.c.
No functional changes.Signed-off-by Tomas Winkler <[email protected]>
While you are doing this, please make it use tpm_buf so tha we get stuff out of that nasty union. Using "helper" structs is still fine, just move it right before the function implementation out of tpm.h (there are examples of this tpm2-cmd.c).
/Jarkko
--
To unsubscribe from this list: send the line "unsubscribe linux-security-module" in the body of a message to majordomo at vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Re: [PATCH 4/4] tpm: move tpm1 selftest code from tpm-interface tpm1-cmd.c
In reply to Tomas WinklerQuoted 6 lines · Tomas Winkler
Move the tmp1 selftest code functions to
tpm1-cmd.ctpm_pcr_read_devtotpm1_pcr_read_devtpm_continue_selftesttotpm1_continue_selftesttpm_do_selftesttotpm1_do_selftestSigned-off-by Tomas Winkler <[email protected]>
The same remark about tpm_buf as for tpm_get_random().
/Jarkko
--
To unsubscribe from this list: send the line "unsubscribe linux-security-module" in the body of a message to majordomo at vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
RE: [PATCH 3/4] tmp: factor out tpm1_get_random into tpm1-cmd.c
In reply to Jarkko SakkinenQuoted 7 lines · Tomas Winkler
Quoted 4 lines
Factor out get random implementation from
tpm-interface.cintotpm1_get_randomfunction intpm1-cmd.c.
No functional changes.
Quoted 6 lines
Quoted 1 line
Signed-off-by Tomas Winkler <[email protected]>While you are doing this, please make it use
tpm_bufso tha we get stuff out of that nasty union. Using "helper" structs is still fine, just move it right before the function implementation out oftpm.h(there are examples of thistpm2-cmd.c).
Sure, but not while moving code, this is dangerous. Should be done after code is moved. Thanks
Tomas
????{.n?+???????+%?????????w??{.n?+????{??????????v?^?)????w*jg??????????j????G?????????j:+v???w?j?m????????w?????f???h?????????
Re: [PATCH 3/4] tmp: factor out tpm1_get_random into tpm1-cmd.c
Quoted 7 lines · Tomas
Quoted 7 lines · Tomas Winkler
Quoted 4 lines
Factor out get random implementation from
tpm-interface.cintotpm1_get_randomfunction intpm1-cmd.c.
No functional changes.
Quoted 8 lines
Quoted 6 lines
Quoted 1 line
Signed-off-by Tomas Winkler <[email protected]>While you are doing this, please make it use
tpm_bufso tha we get stuff out of that nasty union. Using "helper" structs is still fine, just move it right before the function implementation out oftpm.h(there are examples of thistpm2-cmd.c).Sure, but not while moving code, this is dangerous. Should be done after code is moved.
Makes sense have use two steps here.
/Jarkko
--
To unsubscribe from this list: send the line "unsubscribe linux-security-module" in the body of a message to majordomo at vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html