Cover Letter - TPM2.0: Add securityfs support for
cover Cover Letter - TPM2.0: Add securityfs support for
Overview:
=========
Patch adds support for enabling securityfs for TPM2.0. The patch currently adds support for only binary_bios_measurements.
The structure for TPM2.0 is compliant with TCG Spec for 2.0 family. Also , the reading of data has the assumption that writer would have followed TCG Spec and so everything is in little-endian.
The tpm device driver code has been refactored to:
* Identify the TPM version - 1.2 or 2.0
* Calls corresponding compatible seq_ops for iterating over eventlog.
Files Description:
===================
* tpm-chip.c : Adds call to setup bios log for TPM2.0.
* tpm2_of.c : Reads the device tree entries to find the location and size of event.
* tpm_eventlog_init.c : Provides common initialization functions between TPM2.0 and TPM1.2 to setup securityfs entries and seq_ops iterator. The functions has been moved from tpm_eventlog.c into this file.
* tpm_eventlog.c : Provides functions only specific to TPM1.2 version. Common initialization functions are moved to tpm_eventlog_init.c
* tpm2_eventlog.c : Provides functions specific only for TPM2.0 eventlog format.
* tpm2.h : Header file for TPM2.0 structures and functions.
Nayna Jain (2):
TPM2.0: Refactor eventlog methods. TPM2.0:Adds securityfs support for TPM2.0 eventlog
drivers/char/tpm/Makefile | 8 +- drivers/char/tpm/tpm-chip.c | 20 ++-- drivers/char/tpm/tpm2.h | 75 ++++++++++++ drivers/char/tpm/tpm2_eventlog.c | 224 +++++++++++++++++++++++++++++++++++ drivers/char/tpm/tpm2_of.c | 77 ++++++++++++ drivers/char/tpm/tpm_eventlog.c | 156 +----------------------- drivers/char/tpm/tpm_eventlog.h | 13 +- drivers/char/tpm/tpm_eventlog_init.c | 216 +++++++++++++++++++++++++++++++++ 8 files changed, 617 insertions(+), 172 deletions(-) create mode 100644 drivers/char/tpm/tpm2.h create mode 100644 drivers/char/tpm/tpm2_eventlog.c create mode 100644 drivers/char/tpm/tpm2_of.c create mode 100644 drivers/char/tpm/tpm_eventlog_init.c
Signature · 4 lines
2.5.0 ------------------------------------------------------------------------------
A message that is not in the archive (sent off-list or not yet received): 1469774679-25232-1-git-send-email-nayna-23VcF4HTsmIX0ybBhKVfKdBPR1lH4CV8@public.gmane.org
PATCH 1/2 TPM2.0: Refactor eventlog init functions for TPM1.2 and
Refactored eventlog.c file into tpm_eventlog.c and tpm_eventlog_init.c
Breakdown is:
* tpm_eventlog_init.c : Moved eventlog initialization methods like to setup securityfs, to open and release seqfile from tpm_eventlog.c to this file. This is to keep the logic of initialization for TPM1.2 and TPM2.0 in common file.
* tpm_eventlog.c : This file now has only methods specific to parsing and iterate TPM1.2 entry log formats. It can understand only TPM1.2 and is called by methods in tpm_eventlog_init if identified TPM device is TPM1.2.
--- drivers/char/tpm/Makefile | 4 +- drivers/char/tpm/tpm_eventlog.c | 156 +---------------------------- drivers/char/tpm/tpm_eventlog.h | 3 + drivers/char/tpm/tpm_eventlog_init.c | 183 +++++++++++++++++++++++++++++++++++ 4 files changed, 192 insertions(+), 154 deletions(-) create mode 100644 drivers/char/tpm/tpm_eventlog_init.c
drivers/char/tpm/Makefile +2 -2
@@ -6,10 +6,10 @@ tpm-y := tpm-interface.o tpm-dev.o tpm-sysfs.o tpm-chip.o tpm2-cmd.o tpm-$(CONFIG_ACPI) += tpm_ppi.o ifdef CONFIG_ACPI - tpm-y += tpm_eventlog.o tpm_acpi.o + tpm-y += tpm_eventlog_init.o tpm_eventlog.o tpm_acpi.o else ifdef CONFIG_TCG_IBMVTPM - tpm-y += tpm_eventlog.o tpm_of.o + tpm-y += tpm_eventlog_init.o tpm_eventlog.o tpm_of.o endif endif obj-$(CONFIG_TCG_TIS_CORE) += tpm_tis_core.o
drivers/char/tpm/tpm_eventlog.c +4 -152
186 lines not on this page · raw message
drivers/char/tpm/tpm_eventlog.h +3 -0
@@ -12,6 +12,9 @@#define do_endian_conversion (x) x#endif +extern const struct seq_operations tpm_ascii_b_measurments_seqops; +extern const struct seq_operations tpm_binary_b_measurments_seqops; +enum bios_platform_class {BIOS_CLIENT =0x00 ,BIOS_SERVER =0x01 ,
drivers/char/tpm/tpm_eventlog_init.c new file +183 -0
183 lines not on this page · raw message
Signature · 4 lines
2.5.0 ------------------------------------------------------------------------------
A message that is not in the archive (sent off-list or not yet received): 1469774679-25232-2-git-send-email-nayna-23VcF4HTsmIX0ybBhKVfKdBPR1lH4CV8@public.gmane.org
Re: [PATCH 1/2] TPM2.0: Refactor eventlog init functions for TPM1.2 and
Quoted 1 line · Nayna Jain
Refactored
eventlog.cfile intotpm_eventlog.candtpm_eventlog_init.c
If you are going to work on this stuff (and have the ability to test it) can you fix some of the generic pre-existing problems too?
drivers/char/tpm/tpm_eventlog_init.c line 88
Quoted 5 lines
drivers/char/tpm/tpm_eventlog_init.c new file +4
-0+static int tpm_ascii_bios_measurements_open(struct inode *inode, + struct file *file) +static int tpm_binary_bios_measurements_open(struct inode *inode, + struct file *file)
We don't need two (or more!) identical versions of this function, and it is easy to fix:
drivers/char/tpm/tpm_eventlog_init.c line 146
Quoted 4 lines
drivers/char/tpm/tpm_eventlog_init.c new file +4
-0+ bin_file = +securityfs_create_file ("binary_bios_measurements" , +S_IRUSR |S_IRGRP , tpm_dir,NULL , + &tpm_binary_bios_measurements_ops);
Replace NULL with &tpm_binary_b_measurments_seqops and recover it in the generic open using the inode->i_private pointer.
drivers/char/tpm/tpm_eventlog_init.c line 159
Quoted 3 lines
drivers/char/tpm/tpm_eventlog_init.c new file +3
-0+ ret =kmalloc (3 *sizeof (struct dentry *),GFP_KERNEL ); +if (!ret) + goto out_ascii;
I can't find a kfree for this memory, looks like it is leaking, please fix it.
Do not allocate memory for this, just include the dentry array directly in the tpm_chip as the sysfs does today.
You can change the signatures to accept tpm_chip in a cleanup patch as well, moving from the tpm2 patch.
Jason
------------------------------------------------------------------------------
A message that is not in the archive (sent off-list or not yet received): 20160729165708.GA6331-ePGOBjL8dl3ta4EC/59zMFaTQe2KTcn/@public.gmane.org
Re: [PATCH 1/2] TPM2.0: Refactor eventlog init functions for TPM1.2 and
Hi Jason,
Thanks for the review.
Quoted 5 lines · Jason Gunthorpe
Quoted 1 line · Nayna Jain
Refactored
eventlog.cfile intotpm_eventlog.candtpm_eventlog_init.cIf you are going to work on this stuff (and have the ability to test it) can you fix some of the generic pre-existing problems too?
Can you please help me to understand what in particular are you referring to by "some of the generic pre-existing problems" ?
Quoted 9 lines
drivers/char/tpm/tpm_eventlog_init.c line 88
Quoted 6 lines
drivers/char/tpm/tpm_eventlog_init.c new file +4
-0+static int tpm_ascii_bios_measurements_open(struct inode *inode, + struct file *file) +static int tpm_binary_bios_measurements_open(struct inode *inode, + struct file *file)We don't need two (or more!) identical versions of this function, and it is easy to fix:
Sure, will fix it.
Quoted 8 lines
drivers/char/tpm/tpm_eventlog_init.c line 146
Quoted 5 lines
drivers/char/tpm/tpm_eventlog_init.c new file +4
-0+ bin_file = +securityfs_create_file ("binary_bios_measurements" , +S_IRUSR |S_IRGRP , tpm_dir,NULL , + &tpm_binary_bios_measurements_ops);Replace NULL with
&tpm_binary_b_measurments_seqopsand recover it in the generic open using theinode->i_privatepointer.
Sure, will fix it.
Quoted 10 lines
drivers/char/tpm/tpm_eventlog_init.c line 159
Quoted 4 lines
drivers/char/tpm/tpm_eventlog_init.c new file +3
-0+ ret =kmalloc (3 *sizeof (struct dentry *),GFP_KERNEL ); +if (!ret) + goto out_ascii;I can't find a kfree for this memory, looks like it is leaking, please fix it.
Do not allocate memory for this, just include the dentry array directly in the
tpm_chipas the sysfs does today.
Do you mean here to define it as struct dentry *bios_dir[3] as member of struct tpm_chip ?
Quoted 4 lines
You can change the signatures to accept
tpm_chipin a cleanup patch as well, moving from the tpm2 patch.
Ok. Will address these comments in the next version of the patch I will be posting.
Thanks & Regards,
- Nayna
Quoted 2 lines
Jason
------------------------------------------------------------------------------
PATCH 2/2 TPM2.0:Adds securityfs support for TPM2.0 eventlog
In reply to a message not in the archiveAdds securityfs support for TPM2.0.
This patch currently supports only binary_bios_measurements.
--- drivers/char/tpm/Makefile | 8 +- drivers/char/tpm/tpm-chip.c | 20 ++-- drivers/char/tpm/tpm2.h | 75 ++++++++++++ drivers/char/tpm/tpm2_eventlog.c | 224 +++++++++++++++++++++++++++++++++++ drivers/char/tpm/tpm2_of.c | 77 ++++++++++++ drivers/char/tpm/tpm_eventlog.h | 10 +- drivers/char/tpm/tpm_eventlog_init.c | 71 ++++++++--- 7 files changed, 446 insertions(+), 39 deletions(-) create mode 100644 drivers/char/tpm/tpm2.h create mode 100644 drivers/char/tpm/tpm2_eventlog.c create mode 100644 drivers/char/tpm/tpm2_of.c
drivers/char/tpm/Makefile +6 -2
@@ -6,10 +6,14 @@ tpm-y := tpm-interface.o tpm-dev.o tpm-sysfs.o tpm-chip.o tpm2-cmd.o tpm-$(CONFIG_ACPI) += tpm_ppi.o ifdef CONFIG_ACPI - tpm-y += tpm_eventlog_init.o tpm_eventlog.o tpm_acpi.o + tpm-y += tpm_eventlog_init.o tpm2_eventlog.o tpm_eventlog.o tpm_acpi.o else ifdef CONFIG_TCG_IBMVTPM - tpm-y += tpm_eventlog_init.o tpm_eventlog.o tpm_of.o + tpm-y += tpm_eventlog_init.o tpm2_eventlog.o tpm_eventlog.o tpm_of.o +else +ifdef CONFIG_PPC64 + tpm-y += tpm_eventlog_init.o tpm2_eventlog.o tpm_eventlog.o tpm2_of.o +endif endif endif obj-$(CONFIG_TCG_TIS_CORE) += tpm_tis_core.o
drivers/char/tpm/tpm-chip.c +7 -13
@@ -283,20 +283,9 @@ static int tpm1_chip_register(struct tpm_chip *chip)tpm_sysfs_add_device (chip); - chip->bios_dir =tpm_bios_log_setup (dev_name (&chip->dev)); -return 0 ; } -static void tpm1_chip_unregister (struct tpm_chip *chip) -{ -if (chip->flags &TPM_CHIP_FLAG_TPM2 ) -return ; - -if (chip->bios_dir) -tpm_bios_log_teardown (chip->bios_dir); -} -static void tpm_del_legacy_sysfs (struct tpm_chip *chip) {struct attribute **i;
@@ -358,11 +347,14 @@ int tpm_chip_register(struct tpm_chip *chip)if (rc)return rc; + chip->bios_dir =tpm_bios_log_setup (chip); +tpm_add_ppi (chip); rc =tpm_add_char_device (chip);if (rc) { -tpm1_chip_unregister (chip); +if (chip->bios_dir) +tpm_bios_log_teardown (chip);return rc; }
@@ -398,7 +390,9 @@ void tpm_chip_unregister(struct tpm_chip *chip)tpm_del_legacy_sysfs (chip); -tpm1_chip_unregister (chip); +if (chip->bios_dir) +tpm_bios_log_teardown (chip); +tpm_del_char_device (chip); }EXPORT_SYMBOL_GPL (tpm_chip_unregister);
drivers/char/tpm/tpm2.h new file +75 -0
75 lines not on this page · raw message
drivers/char/tpm/tpm2_eventlog.c new file +224 -0
224 lines not on this page · raw message
drivers/char/tpm/tpm2_of.c new file +77 -0
77 lines not on this page · raw message
drivers/char/tpm/tpm_eventlog.h +5 -5
@@ -79,15 +79,15 @@ enum tcpa_pc_event_ids {int read_log (struct tpm_bios_log *log);#if defined(CONFIG_TCG_IBMVTPM ) || defined(CONFIG_TCG_IBMVTPM_MODULE ) || \ - defined(CONFIG_ACPI ) -extern struct dentry **tpm_bios_log_setup (const char *); -extern void tpm_bios_log_teardown (struct dentry **); + defined(CONFIG_ACPI ) || defined(CONFIG_PPC64 ) +extern struct dentry **tpm_bios_log_setup (struct tpm_chip *chip); +extern void tpm_bios_log_teardown (struct tpm_chip *chip);#else -static inline struct dentry **tpm_bios_log_setup (const char *name) +static inline struct dentry **tpm_bios_log_setup (struct tpm_chip *chip) {return NULL ; } -static inline void tpm_bios_log_teardown (struct dentry **dir) +static inline void tpm_bios_log_teardown (struct tpm_chip *chip) { }#endif
drivers/char/tpm/tpm_eventlog_init.c +52 -19
122 lines not on this page · raw message
Signature · 4 lines
2.5.0 ------------------------------------------------------------------------------
A message that is not in the archive (sent off-list or not yet received): 1469774679-25232-3-git-send-email-nayna-23VcF4HTsmIX0ybBhKVfKdBPR1lH4CV8@public.gmane.org
Re: [PATCH 2/2] TPM2.0:Adds securityfs support for TPM2.0 eventlog
drivers/char/tpm/tpm-chip.c int tpm_chip_register(struct tpm_chip *chip) · line 351
Quoted 2 lines · Nayna Jain
drivers/char/tpm/tpm-chip.c +2
-0+ chip->bios_dir =tpm_bios_log_setup (chip); +
And the next somewhat pre-existing issue is that we call tpm_bios_log_setup even if we don't have access to a bios log.
Does the bios log ever change or is it static at boot? Can we move read_log into the chip and do it once so we can tell if it worked before creating security fs stuff??
Quoted 1 line
+++
b/drivers/char/tpm/tpm2.h
You should probably pick a different name if this is only bios log stuff.
drivers/char/tpm/tpm2.h line 17
Quoted 4 lines
drivers/char/tpm/tpm2.h new file +4
-0+struct tcg_efispecideventalgorithmsize { +u16 algorithm_id; +u16 digest_size; +} __packed;
The bios log is defined to be host endian?
Please refernce the standard in a comment that these structs are coming from.
Quoted 10 lines
drivers/char/tpm/tpm2_of.c new file +9
-0+int read_log (struct tpm_bios_log *log) +{ +struct device_node *np; +u32 logSize; +const u32 *sizep; +const u64 *basep; + +if (log->bios_event_log !=NULL ) { + pr_err("%s: ERROR - Eventlog already initialized\n",
__func__);
No to all this logging.
If you really need some of it then use dev_dbg(&chip->dev) pr_err is not acceptable.
Yes, this means you need to safely get tpm_chip into read_log. Please make that a singular patch because the lifetime model will be quite complex.
drivers/char/tpm/tpm2_of.c line 38
Quoted 5 lines
drivers/char/tpm/tpm2_of.c new file +5
-0+ np =of_find_node_by_name (NULL ,"tpm" ); +if (!np) { +pr_err ("%s: ERROR - tpm entry not supported\n" , __func__); +return -ENODEV ; + }
If you are doing of stuff then you need to document it in Documentation/device-tree, so NAK on this without a proper documentation patch. (make sure you follow the special rules for these patches)
What is 'tpm' ? Is that the DT node that the TPM driver is binding too? If so then you need to use chip->pdev->of_node instead of 'of_find_node_by_name'.
Same comments applies to the pre-existing tpm_of.c, please fix that as well.
Why have you substantially copied tpm_of and called it tpm2_of? Don't do that.
drivers/char/tpm/tpm2_of.c line 46
Quoted 8 lines
drivers/char/tpm/tpm2_of.c new file +8
-0+ + sizep =of_get_property (np,"linux,sml-size" ,NULL ); +if (sizep ==NULL ) { +pr_err ("%s: ERROR - sml-get-allocated-size not found\n" , + __func__); + goto cleanup_eio; + } + logSize =be32_to_cpup (sizep);
If you call endianness converters then make sure to tag properly. eg sizep should be a be32, etc. Audit everything in eventlog, I saw other cases..
drivers/char/tpm/tpm2_of.c line 62
Quoted 4 lines
drivers/char/tpm/tpm2_of.c new file +4
-0+ log->bios_event_log =kmalloc (logSize,GFP_KERNEL ); +if (!log->bios_event_log) { +pr_err ("%s: ERROR - Not enough memory for firmware measurements\n" , + __func__);
Never log for ENOMEM, the kernel logs extensively already.
drivers/char/tpm/tpm_eventlog.h enum tcpa_pc_event_ids { · line 84
Quoted 7 lines
#if
defined(CONFIG_TCG_IBMVTPM)||defined(CONFIG_TCG_IBMVTPM_MODULE)|| \drivers/char/tpm/tpm_eventlog.h +3
-3-defined (CONFIG_ACPI) -extern struct dentry **tpm_bios_log_setup(const char *); -extern void tpm_bios_log_teardown (struct dentry **); + defined(CONFIG_ACPI) || defined(CONFIG_PPC64) +extern struct dentry **tpm_bios_log_setup (struct tpm_chip *chip); +extern void tpm_bios_log_teardown (struct tpm_chip *chip);
I'm really deeply unhappy about these ifdefs and the general scheme that was used to force this special difference into the tpm core.
Please find another way to do it.
IMHO, 'read_log' should simply try ACPI and OF in sequence to find the log.
drivers/char/tpm/tpm_eventlog_init.c static int is_bad(void *p) · line 160
Quoted 4 lines
drivers/char/tpm/tpm_eventlog_init.c +4
-0+ num_files = chip->flags &TPM_CHIP_FLAG_TPM2 ?2 :3 ; + ret =kmalloc_array (num_files,sizeof (struct dentry *),GFP_KERNEL ); +if (!ret) + goto out;
Follow the sysfs pattern please.
Jason
------------------------------------------------------------------------------
A message that is not in the archive (sent off-list or not yet received): 20160729171428.GB6331-ePGOBjL8dl3ta4EC/59zMFaTQe2KTcn/@public.gmane.org
Re: [PATCH 2/2] TPM2.0:Adds securityfs support for TPM2.0 eventlog
Quoted 5 lines · Jason Gunthorpe
The bios log is defined to be host endian?
Please reference the standard in a comment that these structs are coming from.
The BIOS log is little endian. That is, all multi-byte values are little endian. Examples are the pcrIndex, eventType, and eventSize, as well as the digest count and hashAlg.
From the "TCG PC Client Platform Firmware Profile Specification"
1.7 Specification Conventions
1. All constants and data SHALL be represented as Little Endian format
unless otherwise explicitly stated.
------------------------------------------------------------------------------
Re: [PATCH 2/2] TPM2.0:Adds securityfs support for TPM2.0 eventlog
Quoted 11 lines · Ken Goldman
Quoted 5 lines · Jason Gunthorpe
The bios log is defined to be host endian?
Please reference the standard in a comment that these structs are coming from.
The BIOS log is little endian. That is, all multi-byte values are little endian. Examples are the pcrIndex, eventType, and eventSize, as well as the digest count and hashAlg.
Quoted 6 lines
From the "TCG PC Client Platform Firmware Profile Specification"
1.7 Specification Conventions
1. All constants and data SHALL be represented as Little Endian format
unless otherwise explicitly stated.
Surely all those structs need to be tagged le32/etc then?
Jason
------------------------------------------------------------------------------