in-kernel resource manager
Subsystems (2)
v3 cover in-kernel resource manager
This patch set adds support for TPM spaces that provide an isolated execution context for transient objects and HMAC and policy sessions. A space is swapped into TPM volatile memory only when it is used and swapped out after the use.
There's a test script for trying out TPM spaces in
git://git.infradead.org/users/jjs/tpm2-scripts.git
A simple smoke test suite can be run by
sudo python -m unittest -v tpm2_smoke.SpaceTest
v3:
* Reverted back to /dev/tpmrm0 that was actually James' original proposal. It's the most pragmatic choice as it cannot be mixed with other TPM 2.0 and kernel idioms easily.
v2:
* Substitute virtual handle in ContextSave.
* Substitute virtual handles in GetCapability.
* Validate that the real response length and the one reported in the header match in tpm_transmit().
James Bottomley (3):
tpm: split out tpm-dev.c into tpm-dev.c and tpm-common-dev.c
tpm: expose spaces via a device link /dev/tpmrm<n>
tpm2: add session handle context saving and restoring to the space
code
Jarkko Sakkinen (4):
tpm: move length validation to tpm_transmit()
tpm: validate TPM 2.0 commands
tpm: export tpm2_flush_context_cmd
tpm: infrastructure for TPM spaces
drivers/char/tpm/Makefile | 3 +- drivers/char/tpm/tpm-chip.c | 71 ++++- drivers/char/tpm/tpm-dev-common.c | 148 +++++++++++ drivers/char/tpm/tpm-dev.c | 143 +--------- drivers/char/tpm/tpm-dev.h | 27 ++ drivers/char/tpm/tpm-interface.c | 131 +++++++--- drivers/char/tpm/tpm-sysfs.c | 2 +- drivers/char/tpm/tpm.h | 49 +++- drivers/char/tpm/tpm2-cmd.c | 173 +++++++++---- drivers/char/tpm/tpm2-space.c | 532 ++++++++++++++++++++++++++++++++++++++ drivers/char/tpm/tpmrm-dev.c | 65 +++++ 11 files changed, 1123 insertions(+), 221 deletions(-) create mode 100644 drivers/char/tpm/tpm-dev-common.c create mode 100644 drivers/char/tpm/tpm-dev.h create mode 100644 drivers/char/tpm/tpm2-space.c create mode 100644 drivers/char/tpm/tpmrm-dev.c
Signature · 6 lines
2.9.3 ------------------------------------------------------------------------------ Check out the vibrant tech community on one of the world's most engaging tech sites, SlashDot.org! http://sdm.link/slashdot
PATCH v3 1/7 tpm: move length validation to tpm_transmit()
Check that the length matches the length reported by the response header already in tpm_transmit() to improve validation.
--- drivers/char/tpm/tpm-interface.c | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-)
drivers/char/tpm/tpm-interface.c +12 -8
@@ -343,6 +343,7 @@ EXPORT_SYMBOL_GPL(tpm_calc_ordinal_duration);ssize_t tpm_transmit (struct tpm_chip *chip,const u8 *buf,size_t bufsiz,unsigned int flags) { +const struct tpm_output_header *header = (void *)buf;ssize_t rc;u32 count, ordinal;unsigned long stop;
@@ -406,9 +407,18 @@ ssize_t tpm_transmit(struct tpm_chip *chip, const u8 *buf, size_t bufsiz, out_recv: rc = chip->ops->recv (chip, (u8 *) buf, bufsiz); -if (rc <0 ) +if (rc <0 ) {dev_err (&chip->dev,"tpm_transmit: tpm_recv: error %zd\n" , rc); + goto out; + }else if (rc <TPM_HEADER_SIZE ) { + rc = -EFAULT ; + goto out; + } + +if (rc !=be32_to_cpu (header->length)) + goto out; + out:if (chip->dev.parent)pm_runtime_put_sync (chip->dev.parent);
@@ -438,19 +448,13 @@ ssize_t tpm_transmit_cmd(struct tpm_chip *chip, const void *buf, size_t bufsiz, size_t min_rsp_body_length, unsigned int flags, const char *desc) { - const struct tpm_output_header *header; + const struct tpm_output_header *header = buf;int err;ssize_t len; len =tpm_transmit (chip, (const u8 *)buf, bufsiz, flags);if (len <0 )return len; -else if (len <TPM_HEADER_SIZE ) -return -EFAULT ; - - header = buf; -if (len !=be32_to_cpu (header->length)) -return -EFAULT ; err =be32_to_cpu (header->return_code);if (err !=0 && desc)
Signature · 6 lines
2.9.3 ------------------------------------------------------------------------------ Check out the vibrant tech community on one of the world's most engaging tech sites, SlashDot.org! http://sdm.link/slashdot
PATCH v3 2/7 tpm: validate TPM 2.0 commands
In reply to Jarkko SakkinenCheck for every TPM 2.0 command that the command code is supported and the command buffer has at least the length that can contain the header and the handle area.
For ContextSave and FlushContext we mark the body to be part of the handle area. This gives validation for these commands at zero cost, including the body of the command.
The more important reason for this is that we can virtualize these commands in the same way as you would virtualize the handle area of a command.
--- drivers/char/tpm/tpm-interface.c | 38 +++++++++++++++++- drivers/char/tpm/tpm.h | 15 +++++++ drivers/char/tpm/tpm2-cmd.c | 84 ++++++++++++++++++++++++++++++++++++++-- 3 files changed, 132 insertions(+), 5 deletions(-)
drivers/char/tpm/tpm-interface.c +37 -1
@@ -328,6 +328,42 @@ unsigned long tpm_calc_ordinal_duration(struct tpm_chip *chip, }EXPORT_SYMBOL_GPL (tpm_calc_ordinal_duration); +static bool tpm_validate_command (struct tpm_chip *chip,const u8 *cmd, +size_t len) +{ +const struct tpm_input_header *header = (const void *)cmd; +int i; +u32 cc; +u32 attrs; +unsigned int nr_handles; + +if (len <TPM_HEADER_SIZE ) +return false; + +if (chip->flags &TPM_CHIP_FLAG_TPM2 && chip->nr_commands) { + cc =be32_to_cpu (header->ordinal); + + i =tpm2_find_cc (chip, cc); +if (i <0 ) { +dev_dbg (&chip->dev,"0x%04X is an invalid command\n" , + cc); +return false; + } + + attrs = chip->cc_attrs_tbl[i]; + nr_handles = +4 * ((attrs >>TPM2_CC_ATTR_CHANDLES ) &GENMASK (2 ,0 )); +if (len <TPM_HEADER_SIZE +4 * nr_handles) + goto err_len; + } + +return true; +err_len: +dev_dbg (&chip->dev, +"%s: insufficient command length %zu" , __func__, len); +return false; +} +/** * tmp_transmit - Internal kernel interface to transmit TPM commands. *
@@ -348,7 +384,7 @@ ssize_t tpm_transmit(struct tpm_chip *chip, const u8 *buf, size_t bufsiz,u32 count, ordinal;unsigned long stop; -if (bufsiz <TPM_HEADER_SIZE ) +if (!tpm_validate_command (chip, buf, bufsiz))return -EINVAL ;if (bufsiz >TPM_BUFSIZE )
drivers/char/tpm/tpm.h +15 -0
@@ -114,6 +114,7 @@ enum tpm2_command_codes {TPM2_CC_CREATE =0x0153 ,TPM2_CC_LOAD =0x0157 ,TPM2_CC_UNSEAL =0x015E , +TPM2_CC_CONTEXT_SAVE =0x0162 ,TPM2_CC_FLUSH_CONTEXT =0x0165 ,TPM2_CC_GET_CAPABILITY =0x017A , TPM2_CC_GET_RANDOM = 0x017B,
@@ -127,15 +128,25 @@ enum tpm2_permanent_handles { };enum tpm2_capabilities { +TPM2_CAP_COMMANDS =2 ,TPM2_CAP_PCRS =5 ,TPM2_CAP_TPM_PROPERTIES =6 , }; +enum tpm2_properties { +TPM_PT_TOTAL_COMMANDS =0x0129 , +}; +enum tpm2_startup_types {TPM2_SU_CLEAR =0x0000 ,TPM2_SU_STATE =0x0001 , }; +enum tpm2_cc_attrs { +TPM2_CC_ATTR_CHANDLES =25 , +TPM2_CC_ATTR_RHANDLE =28 , +}; +#define TPM_VID_INTEL 0x8086#define TPM_VID_WINBOND 0x1050#define TPM_VID_STM 0x104A
@@ -199,6 +210,9 @@ struct tpm_chip {acpi_handle acpi_dev_handle;char ppi_version[TPM_PPI_VERSION_LEN +1 ];#endif /* CONFIG_ACPI */ + +u32 nr_commands; +u32 *cc_attrs_tbl; };#define to_tpm_chip (d) container_of(d, struct tpm_chip, dev)
@@ -554,4 +568,5 @@ int tpm2_auto_startup(struct tpm_chip *chip);void tpm2_shutdown (struct tpm_chip *chip,u16 shutdown_type);unsigned long tpm2_calc_ordinal_duration (struct tpm_chip *chip,u32 ordinal);int tpm2_probe (struct tpm_chip *chip); +int tpm2_find_cc (struct tpm_chip *chip,u32 cc);#endif
drivers/char/tpm/tpm2-cmd.c +80 -4
104 lines not on this page · raw message
Signature · 6 lines
2.9.3 ------------------------------------------------------------------------------ Check out the vibrant tech community on one of the world's most engaging tech sites, SlashDot.org! http://sdm.link/slashdot
RE: [tpmdd-devel] [PATCH v3 2/7] tpm: validate TPM 2.0 commands
Quoted 3 lines
Check for every TPM 2.0 command that the command code is supported and the command buffer has at least the length that can contain the header and the handle area.
This breaks several use cases for me:
1. I've got a TPM that implements vendor-specific command codes. Those cannot be send to the TPM anymore, but are rejected with EINVAL.
2. When upgrading the firmware on my TPM, it switches to a non-standard communication mode for the upgrade process and does not communicate using TPM2.0 commands during this time. Rejecting non-TPM2.0 commands means upgrading won't be possible anymore.
3. I'd like to use the kernel driver to test my TPM implementation. So for example, I send an invalid command code to the TPM and expect TPM_RC_COMMAND_CODE in response, but now I get EINVAL instead and the TPM never sees the command.
Quoted 1 line
From my point of view, the kernel driver should provide a transparent communication channel to the TPM. Whatever I write to /dev/tpm<n> should arrive at the TPM device, so that the TPM can handle it and return the appropriate response. Otherwise, you'll end up reimplementing all the command handling logic, that is already part of the TPM's job, and as soon as you miss one case and behave differently than the TPM, something relying on this behavior will break.
I see two possible solutions:
1. When the driver does not know a command code, it passes through the command unmodified. This bears the risk of unknown side effects though, so TPM spaces might not be as independent as they should be.
2. Since the command code lookup is only really necessary for TPM spaces, it only gets activated when space != NULL. So the change will not affect /dev/tpm<n>, but only the new /dev/tpmrm<n>. As /dev/tpmrm<n> is not meant to be a transparent interface anyway, rejecting unknown commands is acceptable.
Alexander
????{.n?+???????+%?????????w??{.n?+????{??????????v?^?)????w*jg??????????j????G?????????j:+v???w?j?m????????w?????f???h?????????
Re: [tpmdd-devel] [PATCH v3 2/7] tpm: validate TPM 2.0 commands
Quoted 8 lines · Alexander.Steffen at infineon.com
1. I've got a TPM that implements vendor-specific command codes. Those cannot be send to the TPM anymore, but are rejected with EINVAL.
2. When upgrading the firmware on my TPM, it switches to a non-standard communication mode for the upgrade process and does not communicate using TPM2.0 commands during this time. Rejecting non-TPM2.0 commands means upgrading won't be possible anymore.
How non standard? Is the basic header even there? Are the lengths and status code right?
This might be an argument to add a 'raw' ioctl or something specifically for this special case.
Jason
--
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: [tpmdd-devel] [PATCH v3 2/7] tpm: validate TPM 2.0 commands
Quoted 11 lines
1. I've got a TPM that implements vendor-specific command codes. Those cannot be send to the TPM anymore, but are rejected with EINVAL.
Quoted 4 lines
2. When upgrading the firmware on my TPM, it switches to a non-standard communication mode for the upgrade process and does not communicate using TPM2.0 commands during this time. Rejecting non-TPM2.0 commands means upgrading won't be possible anymore.
How non standard? Is the basic header even there? Are the lengths and status code right?
This might be an argument to add a 'raw' ioctl or something specifically for this special case.
It follows the regular TPM command syntax and looks something like 1.2 commands.
Peter
--
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: [tpmdd-devel] [PATCH v3 2/7] tpm: validate TPM 2.0 commands
Quoted 5 lines
Quoted 5 lines
Quoted 4 lines
2. When upgrading the firmware on my TPM, it switches to a non-standard communication mode for the upgrade process and does not communicate using TPM2.0 commands during this time. Rejecting non-TPM2.0 commands means upgrading won't be possible anymore.
Quoted 8 lines
Quoted 5 lines
How non standard? Is the basic header even there? Are the lengths and status code right?
This might be an argument to add a 'raw' ioctl or something specifically for this special case.
It follows the regular TPM command syntax and looks something like 1.2 commands.
Yep, so most of it already works with the current implementation.
There are a few special cases that need some thought though. For example, it is possible to use an upgrade to switch the TPM family from 1.2 to 2.0 (or vice versa). In this case it seems useful to let the kernel reinitialize the TPM driver, so it uses the correct timeouts for communication, activates the correct features (resource manager or not?), etc., without needing to reboot the system.
Another problem arises when the upgrade process is interrupted, e.g. because power is lost. Then the TPM is stuck in its non-standard upgrade mode, so the kernel does not recognize it as a valid TPM device and does not export /dev/tpm<n>. But without the device node the upgrader is unable to restart the upgrade process, leaving the TPM forever inaccessible.
I'll try to work on those problems in the coming weeks and provide the fixes. Any input is appreciated.
Alexander
????{.n?+???????+%?????????w??{.n?+????{??????????v?^?)????w*jg??????????j????G?????????j:+v???w?j?m????????w?????f???h?????????
Re: [tpmdd-devel] [PATCH v3 2/7] tpm: validate TPM 2.0 commands
Quoted 14 lines · Alexander.Steffen at infineon.com
Quoted 5 lines
Quoted 5 lines
Quoted 4 lines
2. When upgrading the firmware on my TPM, it switches to a non-standard communication mode for the upgrade process and does not communicate using TPM2.0 commands during this time. Rejecting non-TPM2.0 commands means upgrading won't be possible anymore.
Quoted 8 lines
Quoted 5 lines
How non standard? Is the basic header even there? Are the lengths and status code right?
This might be an argument to add a 'raw' ioctl or something specifically for this special case.
It follows the regular TPM command syntax and looks something like 1.2 commands.
Quoted 8 lines
Yep, so most of it already works with the current implementation.
There are a few special cases that need some thought though. For example, it is possible to use an upgrade to switch the TPM family from 1.2 to 2.0 (or vice versa). In this case it seems useful to let the kernel reinitialize the TPM driver, so it uses the correct timeouts for communication, activates the correct features (resource manager or not?), etc., without needing to reboot the system.
It would be nice to do this via plug/unplug with existing sysfs machinery.
Quoted 6 lines
Another problem arises when the upgrade process is interrupted, e.g. because power is lost. Then the TPM is stuck in its non-standard upgrade mode, so the kernel does not recognize it as a valid TPM device and does not export /dev/tpm<n>. But without the device node the upgrader is unable to restart the upgrade process, leaving the TPM forever inaccessible.
I guess you'd have to teach the TPM core about a new chip mode besides 1.2, 2.0 - some kind of 'upgrade' mode.
So the flow would be to send the upgrade command, unplug/replug the driver to switch to 'upgrade' mode (which could happen if there was a reboot?) do the upgrade, then unplug/replug to rediscover the 'new' TPM.
Jason
--
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: [tpmdd-devel] [PATCH v3 2/7] tpm: validate TPM 2.0 commands
In reply to [email protected]Quoted 7 lines · Alexander.Steffen at infineon.com
There are a few special cases that need some thought though. For example, it is possible to use an upgrade to switch the TPM family from 1.2 to 2.0 (or vice versa). In this case it seems useful to let the kernel reinitialize the TPM driver, so it uses the correct timeouts for communication, activates the correct features (resource manager or not?), etc., without needing to reboot the system.
In practice, would a TPM upgrade from TPM 1.2 to TPM 2.0 even occur without a reboot? Is it an important use case?
1 - It would leave the SHA-256 PCRs in the reset state.
2 - It's possible that this upgrade would also require a BIOS upgrade.
--
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: [tpmdd-devel] [PATCH v3 2/7] tpm: validate TPM 2.0 commands
Quoted 7 lines
Quoted 6 lines
There are a few special cases that need some thought though. For example, it is possible to use an upgrade to switch the TPM family from 1.2 to 2.0 (or vice versa). In this case it seems useful to let the kernel reinitialize the TPM driver, so it uses the correct timeouts for communication, activates the correct features (resource manager or not?), etc., without needing to reboot the system.
Quoted 6 lines
In practice, would a TPM upgrade from TPM 1.2 to TPM 2.0 even occur without a reboot? Is it an important use case?
1 - It would leave the SHA-256 PCRs in the reset state.
2 - It's possible that this upgrade would also require a BIOS upgrade.
For a traditional PC and when your goal is platform integrity, a reboot is probably the way to go. But in an embedded environment where there is no BIOS or if you use the TPM more like a smartcard just to store some keys (or generate random numbers), a reboot is unnecessary and it is more comfortable to avoid it.
We probably should inform the kernel before the upgrade anyway, so that it can shut down the TPM gracefully (and maybe switch to the upgrade mode, as Jason suggested). With that infrastructure in place, it does not seem like a lot of effort to also let it switch the TPM back to normal operation mode once the upgrade is complete.
Alexander
????{.n?+???????+%?????????w??{.n?+????{??????????v?^?)????w*jg??????????j????G?????????j:+v???w?j?m????????w?????f???h?????????
Re: [tpmdd-devel] [PATCH v3 2/7] tpm: validate TPM 2.0 commands
In reply to [email protected]Quoted 5 lines · Alexander.Steffen at infineon.com
Quoted 3 lines
Check for every TPM 2.0 command that the command code is supported and the command buffer has at least the length that can contain the header and the handle area.
This breaks several use cases for me:
Thank you for reporting these. This is really great feedback to get.
Quoted 27 lines
1. I've got a TPM that implements vendor-specific command codes. Those cannot be send to the TPM anymore, but are rejected with EINVAL.
2. When upgrading the firmware on my TPM, it switches to a non-standard communication mode for the upgrade process and does not communicate using TPM2.0 commands during this time. Rejecting non-TPM2.0 commands means upgrading won't be possible anymore.
3. I'd like to use the kernel driver to test my TPM implementation. So for example, I send an invalid command code to the TPM and expect
TPM_RC_COMMAND_CODEin response, but now I get EINVAL instead and the TPM never sees the command.From my point of view, the kernel driver should provide a transparent communication channel to the TPM. Whatever I write to /dev/tpm<n> should arrive at the TPM device, so that the TPM can handle it and return the appropriate response. Otherwise, you'll end up reimplementing all the command handling logic, that is already part of the TPM's job, and as soon as you miss one case and behave differently than the TPM, something relying on this behavior will break.
I see two possible solutions:
1. When the driver does not know a command code, it passes through the command unmodified. This bears the risk of unknown side effects though, so TPM spaces might not be as independent as they should be.
Quoted 7 lines
2. Since the command code lookup is only really necessary for TPM spaces, it only gets activated when space != NULL. So the change will not affect /dev/tpm<n>, but only the new /dev/tpmrm<n>. As /dev/tpmrm<n> is not meant to be a transparent interface anyway, rejecting unknown commands is acceptable.
Alexander
I think the most straight-forward way to sort this out would be to limit validation to the resource manager. If I send a fix, would you care to test it? If your issues get sorted, I'll squash it to the existing commits.
Thanks again!
/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: [tpmdd-devel] [PATCH v3 2/7] tpm: validate TPM 2.0 commands
Quoted 2 lines
I think the most straight-forward way to sort this out would be to limit validation to the resource manager.
Sounds good to me.
Quoted 1 line
If I send a fix, would you care to test it?
Sure, will do.
Alexander
????{.n?+???????+%?????????w??{.n?+????{??????????v?^?)????w*jg??????????j????G?????????j:+v???w?j?m????????w?????f???h?????????
Re: [tpmdd-devel] [PATCH v3 2/7] tpm: validate TPM 2.0 commands
Quoted 10 lines · Alexander.Steffen at infineon.com
Quoted 2 lines
I think the most straight-forward way to sort this out would be to limit validation to the resource manager.
Sounds good to me.
Quoted 1 line
If I send a fix, would you care to test it?
Sure, will do.
Alexander
I sent the patch. Please check it out.
/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
PATCH v3 3/7 tpm: export tpm2_flush_context_cmd
In reply to Jarkko Sakkinen--- drivers/char/tpm/tpm.h | 2 ++ drivers/char/tpm/tpm2-cmd.c | 62 +++++++++++++++++++++------------------------ 2 files changed, 31 insertions(+), 33 deletions(-)
drivers/char/tpm/tpm.h +2 -0
@@ -555,6 +555,8 @@ int tpm2_pcr_read(struct tpm_chip *chip, int pcr_idx, u8 *res_buf);int tpm2_pcr_extend (struct tpm_chip *chip,int pcr_idx,u32 count,struct tpm2_digest *digests);int tpm2_get_random (struct tpm_chip *chip,u8 *out,size_t max); +void tpm2_flush_context_cmd (struct tpm_chip *chip,u32 handle, +unsigned int flags);int tpm2_seal_trusted (struct tpm_chip *chip,struct trusted_key_payload *payload,struct trusted_key_options *options);
drivers/char/tpm/tpm2-cmd.c +29 -33
74 lines not on this page · raw message
Signature · 6 lines
2.9.3 ------------------------------------------------------------------------------ Check out the vibrant tech community on one of the world's most engaging tech sites, SlashDot.org! http://sdm.link/slashdot
PATCH v3 4/7 tpm: infrastructure for TPM spaces
In reply to Jarkko SakkinenAdded an ability to virtualize TPM commands into an isolated context that we call a TPM space because the word context is already heavily used in the TPM specification. Both the handle areas and bodies (where necessary) are virtualized.
The mechanism works by adding a new parameter struct tpm_space to the tpm_transmit() function. This new structure contains the list of virtual handles and a buffer of page size (currently) for backing storage.
When tpm_transmit() is called with a struct tpm_space instance it will execute the following sequence:
1. Take locks.
2. Load transient objects from the backing storage by using ContextLoad and map virtual handles to physical handles.
3. Perform the transaction.
4. Save transient objects to backing storage by using ContextSave and map resulting physical handle to virtual handle if there is such.
This commit does not implement virtualization support for hmac and policy sessions.
--- drivers/char/tpm/Makefile | 2 +- drivers/char/tpm/tpm-chip.c | 7 + drivers/char/tpm/tpm-dev.c | 2 +- drivers/char/tpm/tpm-interface.c | 68 +++--- drivers/char/tpm/tpm-sysfs.c | 2 +- drivers/char/tpm/tpm.h | 26 ++- drivers/char/tpm/tpm2-cmd.c | 33 +-- drivers/char/tpm/tpm2-space.c | 431 +++++++++++++++++++++++++++++++++++++++ 8 files changed, 520 insertions(+), 51 deletions(-) create mode 100644 drivers/char/tpm/tpm2-space.c
drivers/char/tpm/Makefile +1 -1
@@ -3,7 +3,7 @@ # obj-$(CONFIG_TCG_TPM) += tpm.o tpm-y := tpm-interface.o tpm-dev.o tpm-sysfs.o tpm-chip.o tpm2-cmd.o \ - tpm1_eventlog.o tpm2_eventlog.o + tpm1_eventlog.o tpm2_eventlog.o tpm2-space.o tpm-$(CONFIG_ACPI) += tpm_ppi.o tpm_acpi.o tpm-$(CONFIG_OF) += tpm_of.o obj-$(CONFIG_TCG_TIS_CORE) += tpm_tis_core.o
drivers/char/tpm/tpm-chip.c +7 -0
@@ -128,6 +128,7 @@ static void tpm_dev_release(struct device *dev)mutex_unlock (&idr_lock);kfree (chip->log.bios_event_log); +kfree (chip->work_space.context_buf);kfree (chip); }
@@ -189,6 +190,12 @@ struct tpm_chip *tpm_chip_alloc(struct device *pdev, chip->cdev.owner =THIS_MODULE ; chip->cdev.kobj.parent = &chip->dev.kobj; + chip->work_space.context_buf =kzalloc (PAGE_SIZE ,GFP_KERNEL ); +if (!chip->work_space.context_buf) { + rc = -ENOMEM ; + goto out; + } +return chip; out:
drivers/char/tpm/tpm-dev.c +1 -1
@@ -147,7 +147,7 @@ static ssize_t tpm_write(struct file *file, const char __user *buf,mutex_unlock (&priv->buffer_mutex);return -EPIPE ; } - out_size =tpm_transmit (priv->chip, priv->data_buffer, + out_size =tpm_transmit (priv->chip,NULL , priv->data_buffer,sizeof (priv->data_buffer),0 );tpm_put_ops (priv->chip);
drivers/char/tpm/tpm-interface.c +40 -28
168 lines not on this page · raw message
drivers/char/tpm/tpm-sysfs.c +1 -1
@@ -40,7 +40,7 @@ static ssize_t pubek_show(struct device *dev, struct device_attribute *attr,struct tpm_chip *chip =to_tpm_chip (dev); tpm_cmd.header.in = tpm_readpubek_header; - err =tpm_transmit_cmd (chip, &tpm_cmd,READ_PUBEK_RESULT_SIZE , + err =tpm_transmit_cmd (chip,NULL , &tpm_cmd,READ_PUBEK_RESULT_SIZE ,READ_PUBEK_RESULT_MIN_BODY_SIZE ,0 ,"attempting to read the PUBEK" );if (err)
drivers/char/tpm/tpm.h +22 -4
@@ -89,10 +89,13 @@ enum tpm2_structures { };enum tpm2_return_codes { +TPM2_RC_SUCCESS =0x0000 ,TPM2_RC_HASH =0x0083 ,/* RC_FMT1 */ +TPM2_RC_HANDLE =0x008B ,TPM2_RC_INITIALIZE =0x0100 ,/* RC_VER1 */ TPM2_RC_DISABLED =0x0120 ,TPM2_RC_TESTING =0x090A ,/* RC_WARN */ +TPM2_RC_REFERENCE_H0 =0x0910 , };enum tpm2_algorithms {
@@ -114,6 +117,7 @@ enum tpm2_command_codes {TPM2_CC_CREATE =0x0153 ,TPM2_CC_LOAD =0x0157 ,TPM2_CC_UNSEAL =0x015E , +TPM2_CC_CONTEXT_LOAD =0x0161 ,TPM2_CC_CONTEXT_SAVE =0x0162 ,TPM2_CC_FLUSH_CONTEXT =0x0165 , TPM2_CC_GET_CAPABILITY = 0x017A,
@@ -128,6 +132,7 @@ enum tpm2_permanent_handles { };enum tpm2_capabilities { +TPM2_CAP_HANDLES =1 ,TPM2_CAP_COMMANDS =2 ,TPM2_CAP_PCRS =5 ,TPM2_CAP_TPM_PROPERTIES =6 ,
@@ -153,6 +158,11 @@ enum tpm2_cc_attrs {#define TPM_PPI_VERSION_LEN 3 +struct tpm_space { +u32 context_tbl[3 ]; +u8 *context_buf; +}; +enum tpm_chip_flags {TPM_CHIP_FLAG_TPM2 =BIT (1 ),TPM_CHIP_FLAG_IRQ =BIT (2 ),
@@ -211,6 +221,7 @@ struct tpm_chip {char ppi_version[TPM_PPI_VERSION_LEN +1 ];#endif /* CONFIG_ACPI */ +struct tpm_space work_space;u32 nr_commands;u32 *cc_attrs_tbl; };
@@ -507,10 +518,11 @@ enum tpm_transmit_flags { TPM_TRANSMIT_UNLOCKED = BIT(0), }; -ssize_t tpm_transmit (struct tpm_chip *chip,const u8 *buf,size_t bufsiz, -unsigned int flags); -ssize_t tpm_transmit_cmd (struct tpm_chip *chip,const void *buf,size_t bufsiz, -size_t min_rsp_body_len,unsigned int flags, +ssize_t tpm_transmit (struct tpm_chip *chip,struct tpm_space *space, +u8 *buf,size_t bufsiz,unsigned int flags); +ssize_t tpm_transmit_cmd (struct tpm_chip *chip,struct tpm_space *space, +const void *buf,size_t bufsiz, +size_t min_rsp_body_length,unsigned int flags,const char *desc);ssize_t tpm_getcap (struct tpm_chip *chip,u32 subcap_id,cap_t *cap,const char *desc,size_t min_cap_length);
@@ -571,4 +583,10 @@ void tpm2_shutdown(struct tpm_chip *chip, u16 shutdown_type);unsigned long tpm2_calc_ordinal_duration (struct tpm_chip *chip,u32 ordinal);int tpm2_probe (struct tpm_chip *chip);int tpm2_find_cc (struct tpm_chip *chip,u32 cc); +int tpm2_init_space (struct tpm_space *space); +void tpm2_del_space (struct tpm_space *space); +int tpm2_prepare_space (struct tpm_chip *chip,struct tpm_space *space,u32 cc, +u8 *cmd); +int tpm2_commit_space (struct tpm_chip *chip,struct tpm_space *space, +u32 cc,u8 *buf,size_t *bufsiz);#endif
drivers/char/tpm/tpm2-cmd.c +17 -16
@@ -266,7 +266,7 @@ int tpm2_pcr_read(struct tpm_chip *chip, int pcr_idx, u8 *res_buf) sizeof(cmd.params.pcrread_in.pcr_select)); cmd.params.pcrread_in.pcr_select[pcr_idx >>3 ] =1 << (pcr_idx &0x7 ); - rc =tpm_transmit_cmd (chip, &cmd,sizeof (cmd), + rc =tpm_transmit_cmd (chip,NULL , &cmd,sizeof (cmd),TPM2_PCR_READ_RESP_BODY_SIZE ,0 ,"attempting to read a pcr value" );if (rc ==0 ) {
@@ -333,7 +333,7 @@ int tpm2_pcr_extend(struct tpm_chip *chip, int pcr_idx, u32 count, } } - rc =tpm_transmit_cmd (chip, buf.data,PAGE_SIZE ,0 ,0 , + rc =tpm_transmit_cmd (chip,NULL , buf.data,PAGE_SIZE ,0 ,0 ,"attempting extend a PCR value" );tpm_buf_destroy (&buf);
@@ -382,7 +382,7 @@ int tpm2_get_random(struct tpm_chip *chip, u8 *out, size_t max) cmd.header.in = tpm2_getrandom_header; cmd.params.getrandom_in.size =cpu_to_be16 (num_bytes); - err =tpm_transmit_cmd (chip, &cmd,sizeof (cmd), + err =tpm_transmit_cmd (chip,NULL , &cmd,sizeof (cmd), offsetof(struct tpm2_get_random_out , buffer),0 ,"attempting get random" );
@@ -441,7 +441,7 @@ void tpm2_flush_context_cmd(struct tpm_chip *chip, u32 handle,tpm_buf_append_u32 (&buf, handle); - (void )tpm_transmit_cmd (chip, buf.data,PAGE_SIZE ,0 , flags, + (void )tpm_transmit_cmd (chip,NULL , buf.data,PAGE_SIZE ,0 , flags,"flushing context" );tpm_buf_destroy (&buf);
@@ -557,7 +557,7 @@ int tpm2_seal_trusted(struct tpm_chip *chip, goto out; } - rc =tpm_transmit_cmd (chip, buf.data,PAGE_SIZE ,4 ,0 , + rc =tpm_transmit_cmd (chip,NULL , buf.data,PAGE_SIZE ,4 ,0 ,"sealing data" );if (rc) goto out;
@@ -641,7 +641,7 @@ static int tpm2_load_cmd(struct tpm_chip *chip, goto out; } - rc =tpm_transmit_cmd (chip, buf.data,PAGE_SIZE ,4 , flags, + rc =tpm_transmit_cmd (chip,NULL , buf.data,PAGE_SIZE ,4 , flags,"loading blob" );if (!rc) *blob_handle = be32_to_cpup(
@@ -693,7 +693,7 @@ static int tpm2_unseal_cmd(struct tpm_chip *chip, options->blobauth/* hmac */ , TPM_DIGEST_SIZE); - rc =tpm_transmit_cmd (chip, buf.data,PAGE_SIZE ,6 , flags, + rc =tpm_transmit_cmd (chip,NULL , buf.data,PAGE_SIZE ,6 , flags,"unsealing" );if (rc >0 ) rc = -EPERM ;
@@ -770,7 +770,7 @@ ssize_t tpm2_get_tpm_pt(struct tpm_chip *chip, u32 property_id, u32 *value, cmd.params.get_tpm_pt_in.property_id =cpu_to_be32 (property_id); cmd.params.get_tpm_pt_in.property_cnt =cpu_to_be32 (1 ); - rc =tpm_transmit_cmd (chip, &cmd,sizeof (cmd), + rc =tpm_transmit_cmd (chip,NULL , &cmd,sizeof (cmd),TPM2_GET_TPM_PT_OUT_BODY_SIZE ,0 , desc);if (!rc) *value =be32_to_cpu (cmd.params.get_tpm_pt_out.value);
@@ -805,7 +805,7 @@ static int tpm2_startup(struct tpm_chip *chip, u16 startup_type) cmd.header.in = tpm2_startup_header; cmd.params.startup_in.startup_type =cpu_to_be16 (startup_type); -return tpm_transmit_cmd (chip, &cmd,sizeof (cmd),0 ,0 , +return tpm_transmit_cmd (chip,NULL , &cmd,sizeof (cmd),0 ,0 ,"attempting to start the TPM" ); }
@@ -834,7 +834,7 @@ void tpm2_shutdown(struct tpm_chip *chip, u16 shutdown_type) cmd.header.in = tpm2_shutdown_header; cmd.params.startup_in.startup_type =cpu_to_be16 (shutdown_type); - rc =tpm_transmit_cmd (chip, &cmd,sizeof (cmd),0 ,0 , + rc =tpm_transmit_cmd (chip,NULL , &cmd,sizeof (cmd),0 ,0 ,"stopping the TPM" );/* In places where shutdown command is sent there's no much we can do
@@ -898,7 +898,7 @@ static int tpm2_start_selftest(struct tpm_chip *chip, bool full) cmd.header.in = tpm2_selftest_header; cmd.params.selftest_in.full_test = full; - rc =tpm_transmit_cmd (chip, &cmd,TPM2_SELF_TEST_IN_SIZE ,0 ,0 , + rc =tpm_transmit_cmd (chip,NULL , &cmd,TPM2_SELF_TEST_IN_SIZE ,0 ,0 ,"continue selftest" );/* At least some prototype chips seem to give RC_TESTING error
@@ -949,7 +949,8 @@ static int tpm2_do_selftest(struct tpm_chip *chip) cmd.params.pcrread_in.pcr_select[1 ] =0x00 ; cmd.params.pcrread_in.pcr_select[2 ] =0x00 ; - rc =tpm_transmit_cmd (chip, &cmd,sizeof (cmd),0 ,0 ,NULL ); + rc =tpm_transmit_cmd (chip,NULL , &cmd,sizeof (cmd),0 ,0 , +NULL );if (rc <0 )break ;
@@ -982,7 +983,7 @@ int tpm2_probe(struct tpm_chip *chip) cmd.params.get_tpm_pt_in.property_id =cpu_to_be32 (0x100 ); cmd.params.get_tpm_pt_in.property_cnt =cpu_to_be32 (1 ); - rc =tpm_transmit_cmd (chip, &cmd,sizeof (cmd),0 ,0 ,NULL ); + rc =tpm_transmit_cmd (chip,NULL , &cmd,sizeof (cmd),0 ,0 ,NULL );if (rc <0 )return rc;
@@ -1020,7 +1021,7 @@ static ssize_t tpm2_get_pcr_allocation(struct tpm_chip *chip)tpm_buf_append_u32 (&buf,0 );tpm_buf_append_u32 (&buf,1 ); - rc =tpm_transmit_cmd (chip, buf.data,PAGE_SIZE ,9 ,0 , + rc =tpm_transmit_cmd (chip,NULL , buf.data,PAGE_SIZE ,9 ,0 ,"get tpm pcr allocation" );if (rc) goto out;
@@ -1092,8 +1093,8 @@ static int tpm2_get_cc_attrs_tbl(struct tpm_chip *chip)tpm_buf_append_u32 (&buf,TPM2_CC_FIRST );tpm_buf_append_u32 (&buf, nr_commands); - rc =tpm_transmit_cmd (chip, buf.data,PAGE_SIZE ,9 +4 * nr_commands, -0 ,NULL ); + rc =tpm_transmit_cmd (chip,NULL , buf.data,PAGE_SIZE , +9 +4 * nr_commands,0 ,NULL );if (rc) {tpm_buf_destroy (&buf); goto out;
drivers/char/tpm/tpm2-space.c new file +431 -0
431 lines not on this page · raw message
Signature · 6 lines
2.9.3 ------------------------------------------------------------------------------ Check out the vibrant tech community on one of the world's most engaging tech sites, SlashDot.org! http://sdm.link/slashdot
RE: [tpmdd-devel] [PATCH v3 4/7] tpm: infrastructure for TPM spaces
Quoted 6 lines
drivers/char/tpm/tpm- renamed from drivers/char/tpm/tpm-interface.c +0
-0
interface.c
index 20b1fe3..db5ffe9 100644
drivers/char/tpm/tpm-interface.c static bool tpm_validate_command(struct · line 381
Quoted 8 lines
drivers/char/tpm/tpm-interface.c +2
-2@@ -376,11 +376,12 @@ static bool tpm_validate_command(structtpm_chip *chip, const u8 *cmd, * 0 when the operation is successful. * A negative number for system errors (errno). */ -ssize_t tpm_transmit (struct tpm_chip *chip,const u8 *buf,size_t bufsiz, -unsigned int flags) +ssize_t tpm_transmit (struct tpm_chip *chip,struct tpm_space *space, +u8 *buf,size_t bufsiz,unsigned int flags)
When adding parameters, please also update the parameter documentation at the top of the function. It is missing for the new parameter "space" here.
Alexander
????{.n?+???????+%?????????w??{.n?+????{??????????v?^?)????w*jg??????????j????G?????????j:+v???w?j?m????????w?????f???h?????????
Re: [tpmdd-devel] [PATCH v3 4/7] tpm: infrastructure for TPM spaces
Quoted 10 lines · Alexander.Steffen at infineon.com
Quoted 10 lines
drivers/char/tpm/tpm- renamed from drivers/char/tpm/tpm-interface.c +0
-0
interface.c
index 20b1fe3..db5ffe9 100644drivers/char/tpm/tpm-interface.c +0
-0@@ -376,11 +376,12 @@ static bool tpm_validate_command(structtpm_chip *chip, const u8 *cmd, * 0 when the operation is successful. * A negative number for system errors (errno). */
Quoted 8 lines
drivers/char/tpm/tpm-interface.c static bool tpm_validate_command(struct tpm_chip *chip, const u8 *cmd, · line 380
Quoted 4 lines
drivers/char/tpm/tpm-interface.c +2
-2-ssize_t tpm_transmit (struct tpm_chip *chip,const u8 *buf,size_t bufsiz, -unsigned int flags) +ssize_t tpm_transmit (struct tpm_chip *chip,struct tpm_space *space, +u8 *buf,size_t bufsiz,unsigned int flags)When adding parameters, please also update the parameter documentation at the top of the function. It is missing for the new parameter "space" here.
I missed that. I'll update the commits with the proper documentation.
Quoted 1 line
Alexander
/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
PATCH v3 5/7 tpm: split out tpm-dev.c into tpm-dev.c and tpm-common-dev.c
In reply to Jarkko SakkinenFrom: James Bottomley <James.Bottomley-d9PhHud1JfjCXq6kfMZ53/[email protected]>
--- drivers/char/tpm/Makefile | 2 +- drivers/char/tpm/tpm-dev-common.c | 148 ++++++++++++++++++++++++++++++++++++++ drivers/char/tpm/tpm-dev.c | 143 ++++-------------------------------- drivers/char/tpm/tpm-dev.h | 27 +++++++ 4 files changed, 190 insertions(+), 130 deletions(-) create mode 100644 drivers/char/tpm/tpm-dev-common.c create mode 100644 drivers/char/tpm/tpm-dev.h
drivers/char/tpm/Makefile +1 -1
@@ -3,7 +3,7 @@ # obj-$(CONFIG_TCG_TPM) += tpm.o tpm-y := tpm-interface.o tpm-dev.o tpm-sysfs.o tpm-chip.o tpm2-cmd.o \ - tpm1_eventlog.o tpm2_eventlog.o tpm2-space.o + tpm-dev-common.o tpm1_eventlog.o tpm2_eventlog.o tpm2-space.o tpm-$(CONFIG_ACPI) += tpm_ppi.o tpm_acpi.o tpm-$(CONFIG_OF) += tpm_of.o obj-$(CONFIG_TCG_TIS_CORE) += tpm_tis_core.o
drivers/char/tpm/tpm-dev-common.c new file +148 -0
148 lines not on this page · raw message
drivers/char/tpm/tpm-dev.c +14 -129
183 lines not on this page · raw message
drivers/char/tpm/tpm-dev.h new file +27 -0
@@ -0,0 +1,27 @@ +#ifndef _TPM_DEV_H +#define _TPM_DEV_H + +#include "tpm.h" + +struct file_priv { +struct tpm_chip *chip; + +/* Data passed to and from the tpm via the read/write calls */ +atomic_t data_pending; +struct mutex buffer_mutex; + +struct timer_list user_read_timer;/* user needs to claim result */ +struct work_struct work; + +u8 data_buffer[TPM_BUFSIZE ]; +}; + +void tpm_common_open (struct file *file,struct tpm_chip *chip, +struct file_priv *priv); +ssize_t tpm_common_read (struct file *file,char __user *buf, +size_t size,loff_t *off); +ssize_t tpm_common_write (struct file *file,const char __user *buf, +size_t size,loff_t *off,struct tpm_space *space); +void tpm_common_release (struct file *file,struct file_priv *priv); + +#endif
Signature · 6 lines
2.9.3 ------------------------------------------------------------------------------ Check out the vibrant tech community on one of the world's most engaging tech sites, SlashDot.org! http://sdm.link/slashdot
PATCH v3 6/7 tpm: expose spaces via a device link /dev/tpmrm<n>
In reply to Jarkko SakkinenFrom: James Bottomley <James.Bottomley-d9PhHud1JfjCXq6kfMZ53/[email protected]>
Currently the tpm spaces are not exposed to userspace. Make this exposure via a separate device, which can now be opened multiple times because each read/write transaction goes separately via the space.
Concurrency is protected by the chip->tpm_mutex for each read/write transaction separately. The TPM is cleared of all transient objects by the time the mutex is dropped, so there should be no interference between the kernel and userspace.
--- drivers/char/tpm/Makefile | 3 +- drivers/char/tpm/tpm-chip.c | 58 ++++++++++++++++++++++++++++++++++- drivers/char/tpm/tpm-interface.c | 13 ++++++-- drivers/char/tpm/tpm.h | 4 +++ drivers/char/tpm/tpmrm-dev.c | 65 ++++++++++++++++++++++++++++++++++++++++ 5 files changed, 139 insertions(+), 4 deletions(-) create mode 100644 drivers/char/tpm/tpmrm-dev.c
drivers/char/tpm/Makefile +2 -1
@@ -3,7 +3,8 @@ # obj-$(CONFIG_TCG_TPM) += tpm.o tpm-y := tpm-interface.o tpm-dev.o tpm-sysfs.o tpm-chip.o tpm2-cmd.o \ - tpm-dev-common.o tpm1_eventlog.o tpm2_eventlog.o tpm2-space.o + tpm-dev-common.o tpmrm-dev.o tpm1_eventlog.o tpm2_eventlog.o \ + tpm2-space.o tpm-$(CONFIG_ACPI) += tpm_ppi.o tpm_acpi.o tpm-$(CONFIG_OF) += tpm_of.o obj-$(CONFIG_TCG_TIS_CORE) += tpm_tis_core.o
drivers/char/tpm/tpm-chip.c +57 -1
121 lines not on this page · raw message
drivers/char/tpm/tpm-interface.c +11 -2
@@ -1257,9 +1257,17 @@ static int __init tpm_init(void)return PTR_ERR (tpm_class); } - rc =alloc_chrdev_region (&tpm_devt,0 ,TPM_NUM_DEVICES ,"tpm" ); + tpmrm_class =class_create (THIS_MODULE ,"tpmrm" ); +if (IS_ERR (tpmrm_class)) { +pr_err ("couldn't create tpmrm class\n" ); +class_destroy (tpm_class); +return PTR_ERR (tpmrm_class); + } + + rc =alloc_chrdev_region (&tpm_devt,0 ,2 *TPM_NUM_DEVICES ,"tpm" );if (rc <0 ) {pr_err ("tpm: failed to allocate char dev region\n" ); +class_destroy (tpmrm_class);class_destroy (tpm_class);return rc; }
@@ -1271,7 +1279,8 @@ static void __exit tpm_exit(void) {idr_destroy (&dev_nums_idr);class_destroy (tpm_class); -unregister_chrdev_region (tpm_devt,TPM_NUM_DEVICES ); +class_destroy (tpmrm_class); +unregister_chrdev_region (tpm_devt,2 *TPM_NUM_DEVICES ); }subsys_initcall (tpm_init);
drivers/char/tpm/tpm.h +4 -0
@@ -182,7 +182,9 @@ struct tpm_chip_seqops {struct tpm_chip {struct device dev; +struct device devs;struct cdev cdev; +struct cdev cdevs;/* A driver callback under ops cannot be run unless ops_sem is held * (sometimes implicitly, eg for the sysfs code). ops becomes null
@@ -510,8 +512,10 @@ static inline void tpm_buf_append_u32(struct tpm_buf *buf, const u32 value) }extern struct class *tpm_class; +extern struct class *tpmrm_class;extern dev_t tpm_devt;extern const struct file_operations tpm_fops; +extern const struct file_operations tpmrm_fops;extern struct idr dev_nums_idr;enum tpm_transmit_flags {
drivers/char/tpm/tpmrm-dev.c new file +65 -0
65 lines not on this page · raw message
Signature · 6 lines
2.9.3 ------------------------------------------------------------------------------ Check out the vibrant tech community on one of the world's most engaging tech sites, SlashDot.org! http://sdm.link/slashdot
PATCH v3 7/7 tpm2: add session handle context saving and restoring to the space code
In reply to Jarkko SakkinenFrom: James Bottomley <James.Bottomley-d9PhHud1JfjCXq6kfMZ53/[email protected]>
Sessions are different from transient objects in that their handles may not be virtualized (because they're used for some hmac calculations). Additionally when a session is context saved, a vestigial memory remains in the TPM and if it is also flushed, that will be lost and the session context will refuse to load next time, so the code is updated to flush only transient objects after a context save. Add a separate array (chip->session_tbl) to save and restore sessions by handle. Use the failure of a context save or load to signal that the session has been flushed from the TPM and we can remove its memory from chip->session_tbl.
Sessions are also isolated during each instance of a tpm space. This means that spaces shouldn't be able to see each other's sessions and is enforced by ensuring that a space user may only refer to sessions handles that are present in their own chip->session_tbl. Finally when a space is closed, all the sessions belonging to it should be flushed so the handles may be re-used by other spaces.
Note that if we get a session save or load error, all sessions are effectively flushed. Even though we restore the session buffer, all the old sessions will refuse to load after the flush and they'll be purged from our session memory. This means that while transient context handling is still soft in the face of errors, session handling is hard (any failure of the model means all sessions are lost).
--- drivers/char/tpm/tpm-chip.c | 6 +++ drivers/char/tpm/tpm.h | 4 +- drivers/char/tpm/tpm2-space.c | 105 +++++++++++++++++++++++++++++++++++++++++- drivers/char/tpm/tpmrm-dev.c | 2 +- 4 files changed, 113 insertions(+), 4 deletions(-)
drivers/char/tpm/tpm-chip.c +6 -0
@@ -130,6 +130,7 @@ static void tpm_dev_release(struct device *dev)kfree (chip->log.bios_event_log);kfree (chip->work_space.context_buf); +kfree (chip->work_space.session_buf);kfree (chip); }
@@ -224,6 +225,11 @@ struct tpm_chip *tpm_chip_alloc(struct device *pdev, rc = -ENOMEM ; goto out; } + chip->work_space.session_buf =kzalloc (PAGE_SIZE ,GFP_KERNEL ); +if (!chip->work_space.session_buf) { + rc = -ENOMEM ; + goto out; + }return chip;
drivers/char/tpm/tpm.h +3 -1
@@ -161,6 +161,8 @@ enum tpm2_cc_attrs {struct tpm_space {u32 context_tbl[3 ];u8 *context_buf; +u32 session_tbl[3 ]; +u8 *session_buf; };enum tpm_chip_flags {
@@ -588,7 +590,7 @@ unsigned long tpm2_calc_ordinal_duration(struct tpm_chip *chip, u32 ordinal);int tpm2_probe (struct tpm_chip *chip);int tpm2_find_cc (struct tpm_chip *chip,u32 cc);int tpm2_init_space (struct tpm_space *space); -void tpm2_del_space (struct tpm_space *space); +void tpm2_del_space (struct tpm_chip *chip,struct tpm_space *space);int tpm2_prepare_space (struct tpm_chip *chip,struct tpm_space *space,u32 cc,u8 *cmd); int tpm2_commit_space(struct tpm_chip *chip, struct tpm_space *space,
drivers/char/tpm/tpm2-space.c +103 -2
181 lines not on this page · raw message
drivers/char/tpm/tpmrm-dev.c +1 -1
@@ -39,7 +39,7 @@ static int tpmrm_release(struct inode *inode, struct file *file) struct tpmrm_priv *priv = container_of(fpriv, struct tpmrm_priv, priv);tpm_common_release (file, fpriv); -tpm2_del_space (&priv->space); +tpm2_del_space (fpriv->chip, &priv->space);kfree (priv);return 0 ;
Signature · 6 lines
2.9.3 ------------------------------------------------------------------------------ Check out the vibrant tech community on one of the world's most engaging tech sites, SlashDot.org! http://sdm.link/slashdot
Quoted 37 lines · Jarkko Sakkinen
This patch set adds support for TPM spaces that provide an isolated execution context for transient objects and HMAC and policy sessions. A space is swapped into TPM volatile memory only when it is used and swapped out after the use.
There's a test script for trying out TPM spaces in
git://git.infradead.org/users/jjs/tpm2-scripts.gitA simple smoke test suite can be run by
sudo python -m unittest -v tpm2_smoke.SpaceTest
v3:
* Reverted back to/dev/tpmrm0that was actually James' original proposal. It's the most pragmatic choice as it cannot be mixed with other TPM 2.0 and kernel idioms easily.v2:
* Substitute virtual handle in ContextSave.
* Substitute virtual handles in GetCapability.
* Validate that the real response length and the one reported in the header match intpm_transmit().James Bottomley (3):
tpm: split outtpm-dev.cintotpm-dev.candtpm-common-dev.c
tpm: expose spaces via a device link /dev/tpmrm<n>
tpm2: add session handle context saving and restoring to the space
codeJarkko Sakkinen (4):
tpm: move length validation totpm_transmit()
tpm: validate TPM 2.0 commands
tpm: exporttpm2_flush_context_cmd
tpm: infrastructure for TPM spaces
Quoted 20 lines
drivers/char/tpm/Makefile | 3 +- drivers/char/tpm/tpm-chip.c | 71 ++++- drivers/char/tpm/tpm-dev-common.c | 148 +++++++++++ drivers/char/tpm/tpm-dev.c | 143 +--------- drivers/char/tpm/tpm-dev.h | 27 ++ drivers/char/tpm/tpm-interface.c | 131 +++++++--- drivers/char/tpm/tpm-sysfs.c | 2 +- drivers/char/tpm/tpm.h | 49 +++- drivers/char/tpm/tpm2-cmd.c | 173 +++++++++---- drivers/char/tpm/tpm2-space.c | 532 ++++++++++++++++++++++++++++++++++++++ drivers/char/tpm/tpmrm-dev.c | 65 +++++ 11 files changed, 1123 insertions(+), 221 deletions(-) create mode 100644 drivers/char/tpm/tpm-dev-common.c create mode 100644 drivers/char/tpm/tpm-dev.h create mode 100644 drivers/char/tpm/tpm2-space.c create mode 100644 drivers/char/tpm/tpmrm-dev.cSignature · 1 line
2.9.3
Should I put this available to linux-next? I would think it would make sense. I'm still looking forward to get more reviewed-by's and tested-by's but that way it might be easier to get those...
/Jarkko
------------------------------------------------------------------------------
Announcing the Oxford Dictionaries API! The API offers world-renowned dictionary content that is easy and intuitive to access. Sign up for an account today to start using our lexical data to power your apps and projects. Get started today and enter our developer competition.
http://sdm.link/oxford
Quoted 37 lines · Jarkko Sakkinen
This patch set adds support for TPM spaces that provide an isolated execution context for transient objects and HMAC and policy sessions. A space is swapped into TPM volatile memory only when it is used and swapped out after the use.
There's a test script for trying out TPM spaces in
git://git.infradead.org/users/jjs/tpm2-scripts.gitA simple smoke test suite can be run by
sudo python -m unittest -v tpm2_smoke.SpaceTest
v3:
* Reverted back to/dev/tpmrm0that was actually James' original proposal. It's the most pragmatic choice as it cannot be mixed with other TPM 2.0 and kernel idioms easily.v2:
* Substitute virtual handle in ContextSave.
* Substitute virtual handles in GetCapability.
* Validate that the real response length and the one reported in the header match intpm_transmit().James Bottomley (3):
tpm: split outtpm-dev.cintotpm-dev.candtpm-common-dev.c
tpm: expose spaces via a device link /dev/tpmrm<n>
tpm2: add session handle context saving and restoring to the space
codeJarkko Sakkinen (4):
tpm: move length validation totpm_transmit()
tpm: validate TPM 2.0 commands
tpm: exporttpm2_flush_context_cmd
tpm: infrastructure for TPM spaces
Quoted 20 lines
drivers/char/tpm/Makefile | 3 +- drivers/char/tpm/tpm-chip.c | 71 ++++- drivers/char/tpm/tpm-dev-common.c | 148 +++++++++++ drivers/char/tpm/tpm-dev.c | 143 +--------- drivers/char/tpm/tpm-dev.h | 27 ++ drivers/char/tpm/tpm-interface.c | 131 +++++++--- drivers/char/tpm/tpm-sysfs.c | 2 +- drivers/char/tpm/tpm.h | 49 +++- drivers/char/tpm/tpm2-cmd.c | 173 +++++++++---- drivers/char/tpm/tpm2-space.c | 532 ++++++++++++++++++++++++++++++++++++++ drivers/char/tpm/tpmrm-dev.c | 65 +++++ 11 files changed, 1123 insertions(+), 221 deletions(-) create mode 100644 drivers/char/tpm/tpm-dev-common.c create mode 100644 drivers/char/tpm/tpm-dev.h create mode 100644 drivers/char/tpm/tpm2-space.c create mode 100644 drivers/char/tpm/tpmrm-dev.cSignature · 1 line
2.9.3
These commits are now in my master and next branches. Tested-by's are still most welcome!
/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