Re: [tpmdd-devel] [PATCH v2] tpm: Check size of response before accessing data

2017-01-12 Thread Jarkko Sakkinen
On Tue, Jan 10, 2017 at 03:15:41PM -0500, Stefan Berger wrote: > Make sure that we have not received less bytes than what is indicated > in the header of the TPM response. Also, check the number of bytes in > the response before accessing its data. > > Signed-off-by: Stefan Berger I'm not going

Re: [tpmdd-devel] [PATCH 01/10] tpm: Check received number of bytes against length indicator in header

2017-01-12 Thread Jarkko Sakkinen
On Tue, Jan 10, 2017 at 09:18:11AM -0500, Stefan Berger wrote: > Make sure that we have not received less bytes than what is indicated > in the header of the TPM response. > > Signed-off-by: Stefan Berger NAK for the whole patch set as it is missing the cover letter. Also you should pick my val

[tpmdd-devel] TPM 2.0 RM getcapability #1

2017-01-12 Thread Ken Goldman
Question 1 of 2: The RM is virtualizing transient handles. When getcapability returns TPM handles, they have to be mapped to the virtual handles. Where should the mapping occur? RM vs. user space TSS? - The RM sees the TPM physical handles, and knows the mapping to virtual handles for that p

[tpmdd-devel] TPM 2.0 RM getcapability #2

2017-01-12 Thread Ken Goldman
The result of getcapability for transient objects should normally be virtual handles that the application sees, not the TPM handles. However, there is a corner case - auditing the getcapability command. Audit is a TPM function that maintains a hash of commands and responses, and

[tpmdd-devel] [PATCH v3 1/2] tpm: implement TPM 2.0 capability to get active PCR banks

2017-01-12 Thread Nayna Jain
This patch implements the TPM 2.0 capability TPM_CAP_PCRS to retrieve the active PCR banks from the TPM. This is needed to enable extending all active banks as recommended by TPM 2.0 TCG Specification. Signed-off-by: Nayna Jain --- drivers/char/tpm/tpm.h | 4 +++ drivers/char/tpm/tpm2-cmd.

[tpmdd-devel] [PATCH v3 0/2] tpm: enhance TPM 2.0 extend function to support multiple PCR banks

2017-01-12 Thread Nayna Jain
IMA extends its hash measurements in the TPM PCRs, based on policy. The existing in-kernel TPM extend function extends only the SHA1 PCR bank. TPM 2.0 defines multiple PCR banks, to support different hash algorithms. The TCG TPM 2.0 Specification[1] recommends extending all active PCR banks to prev

[tpmdd-devel] [PATCH v3 2/2] tpm: enhance TPM 2.0 PCR extend to support multiple banks

2017-01-12 Thread Nayna Jain
The current TPM 2.0 device driver extends only the SHA1 PCR bank but the TCG Specification[1] recommends extending all active PCR banks, to prevent malicious users from setting unused PCR banks with fake measurements and quoting them. The existing in-kernel interface(tpm_pcr_extend()) expects only

Re: [tpmdd-devel] [PATCH v2] tpm: Check size of response before accessing data

2017-01-12 Thread Jason Gunthorpe
On Thu, Jan 12, 2017 at 04:43:21PM +0200, Jarkko Sakkinen wrote: > On Tue, Jan 10, 2017 at 03:15:41PM -0500, Stefan Berger wrote: > > Make sure that we have not received less bytes than what is indicated > > in the header of the TPM response. Also, check the number of bytes in > > the response befo

Re: [tpmdd-devel] [PATCH v2] tpm: Check size of response before accessing data

2017-01-12 Thread Jarkko Sakkinen
On Thu, Jan 12, 2017 at 10:18:39AM -0700, Jason Gunthorpe wrote: > On Thu, Jan 12, 2017 at 04:43:21PM +0200, Jarkko Sakkinen wrote: > > On Tue, Jan 10, 2017 at 03:15:41PM -0500, Stefan Berger wrote: > > > Make sure that we have not received less bytes than what is indicated > > > in the header of t

Re: [tpmdd-devel] [PATCH v3] tpm: Check size of response before accessing data

2017-01-12 Thread Jarkko Sakkinen
On Tue, Jan 10, 2017 at 05:04:04PM -0500, Stefan Berger wrote: > Make sure that we have not received less bytes than what is indicated > in the header of the TPM response. Also, check the number of bytes in > the response before accessing its data. > > Signed-off-by: Stefan Berger This patch has

Re: [tpmdd-devel] [PATCH v8 2/2] tpm: add securityfs support for TPM 2.0 firmware event log

2017-01-12 Thread Jarkko Sakkinen
On Wed, Jan 11, 2017 at 02:54:22AM -0500, Nayna Jain wrote: > Unlike the device driver support for TPM 1.2, the TPM 2.0 does > not support the securityfs pseudo files for displaying the > firmware event log. > > This patch enables support for providing the TPM 2.0 event log in > binary form. TPM 2

[tpmdd-devel] [PATCH RFC v2 3/5] tpm: infrastructure for TPM spaces

2017-01-12 Thread Jarkko Sakkinen
Added ability to tpm_transmit() to supply a TPM space that contains mapping from virtual handles to physical handles and backing storage for swapping transient objects. TPM space is isolated from other users of the TPM. Signed-off-by: Jarkko Sakkinen --- drivers/char/tpm/Makefile| 2 +-

[tpmdd-devel] [PATCH RFC v2 4/5] tpm: split out tpm-dev.c into tpm-dev.c and tpm-common-dev.c

2017-01-12 Thread Jarkko Sakkinen
From: James Bottomley Signed-off-by: James Bottomley --- drivers/char/tpm/Makefile | 2 +- drivers/char/tpm/tpm-dev-common.c | 145 ++ drivers/char/tpm/tpm-dev.c| 141 drivers/char/tpm/tpm-dev.h|

[tpmdd-devel] [PATCH RFC v2 5/5] tpm2: expose resource manager via a device link /dev/tpms

2017-01-12 Thread Jarkko Sakkinen
From: James Bottomley Currently the Resource Manager (RM) is 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 RM. Concurrency is protected by the chip->tpm_mutex for each read/w

[tpmdd-devel] [PATCH RFC v2 1/5] tpm: validate TPM 2.0 commands

2017-01-12 Thread Jarkko Sakkinen
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. Signed-off-by: Jarkko Sakkinen --- drivers/char/tpm/tpm-interface.c | 32 - drivers/char/tpm/tpm.h

[tpmdd-devel] [PATCH RFC v2 0/5] RFC: in-kernel resource manager

2017-01-12 Thread Jarkko Sakkinen
This patch set adds support for TPM spaces that provide a context for isolating and swapping transient objects. This patch set does not yet include support for isolating policy and HMAC sessions but it is trivial to add once the basic approach is settled (and that's why I created an RFC patch set).

[tpmdd-devel] [PATCH RFC v2 2/5] tpm: export tpm2_flush_context_cmd

2017-01-12 Thread Jarkko Sakkinen
Signed-off-by: Jarkko Sakkinen --- drivers/char/tpm/tpm.h | 2 ++ drivers/char/tpm/tpm2-cmd.c | 65 ++--- 2 files changed, 34 insertions(+), 33 deletions(-) diff --git a/drivers/char/tpm/tpm.h b/drivers/char/tpm/tpm.h index 80fa606..c87c221 100644 --

[tpmdd-devel] [PATCH] tpm_tis: override reported C and D timeouts for Atmel 3203

2017-01-12 Thread Maciej S. Szmigiero
Since commit 1107d065fdf1 ("tpm_tis: Introduce intermediate layer for TPM access") Atmel 3203 TPM on ThinkPad X61S (TPM firmware version 13.9) no longer works. It turns out the initialization proceeds fine until we get and start using chip-reported timeouts - and the chip reports C and D timeouts o

[tpmdd-devel] [PATCH] tpm_tis: fix iTPM probe via probe_itpm() function

2017-01-12 Thread Maciej S. Szmigiero
probe_itpm() function is supposed to send command without an itpm flag set and if this fails to repeat it, this time with the itpm flag set. However, commit 41a5e1cf1fe15 ("tpm/tpm_tis: Split tpm_tis driver into a core and TCG TIS compliant phy") moved the itpm flag from an "itpm" variable to a TP

Re: [tpmdd-devel] [PATCH v3 2/2] tpm: enhance TPM 2.0 PCR extend to support multiple banks

2017-01-12 Thread Jarkko Sakkinen
On Thu, Jan 12, 2017 at 11:58:10AM -0500, Nayna Jain wrote: > The current TPM 2.0 device driver extends only the SHA1 PCR bank > but the TCG Specification[1] recommends extending all active PCR > banks, to prevent malicious users from setting unused PCR banks with > fake measurements and quoting th

Re: [tpmdd-devel] [PATCH v3 1/2] tpm: implement TPM 2.0 capability to get active PCR banks

2017-01-12 Thread Jarkko Sakkinen
On Thu, Jan 12, 2017 at 11:58:09AM -0500, Nayna Jain wrote: > This patch implements the TPM 2.0 capability TPM_CAP_PCRS to > retrieve the active PCR banks from the TPM. This is needed > to enable extending all active banks as recommended by TPM 2.0 > TCG Specification. > > Signed-off-by: Nayna Jai

Re: [tpmdd-devel] [PATCH RFC v2 3/5] tpm: infrastructure for TPM spaces

2017-01-12 Thread James Bottomley
On Thu, 2017-01-12 at 19:46 +0200, Jarkko Sakkinen wrote: > @@ -435,17 +440,23 @@ ssize_t tpm_transmit(struct tpm_chip *chip, > const u8 *buf, size_t bufsiz, > goto out; > > out_recv: > - rc = chip->ops->recv(chip, (u8 *) buf, bufsiz); > - if (rc < 0) > + len = chip->ops

Re: [tpmdd-devel] [PATCH RFC v2 5/5] tpm2: expose resource manager via a device link /dev/tpms

2017-01-12 Thread Jason Gunthorpe
On Thu, Jan 12, 2017 at 07:46:08PM +0200, Jarkko Sakkinen wrote: > struct tpm_chip { > - struct device dev; > - struct cdev cdev; > + struct device dev, devrm; Hum.. devrm adds a new kref but doesn't do anything with the release function, so that is going to use after free, ie here:

Re: [tpmdd-devel] [PATCH] tpm_tis: override reported C and D timeouts for Atmel 3203

2017-01-12 Thread Jason Gunthorpe
On Thu, Jan 12, 2017 at 07:08:53PM +0100, Maciej S. Szmigiero wrote: > Since commit 1107d065fdf1 ("tpm_tis: Introduce intermediate layer for TPM > access") Atmel 3203 TPM on ThinkPad X61S (TPM firmware version 13.9) no > longer works. > It turns out the initialization proceeds fine until we get and

Re: [tpmdd-devel] [PATCH] tpm_tis: fix iTPM probe via probe_itpm() function

2017-01-12 Thread Jason Gunthorpe
On Thu, Jan 12, 2017 at 07:12:06PM +0100, Maciej S. Szmigiero wrote: > probe_itpm() function is supposed to send command without an itpm flag set > and if this fails to repeat it, this time with the itpm flag set. > > However, commit 41a5e1cf1fe15 ("tpm/tpm_tis: Split tpm_tis driver into a > core

Re: [tpmdd-devel] [PATCH RFC v2 5/5] tpm2: expose resource manager via a device link /dev/tpms

2017-01-12 Thread James Bottomley
On Thu, 2017-01-12 at 19:46 +0200, Jarkko Sakkinen wrote: > From: James Bottomley > > Currently the Resource Manager (RM) is 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 t

Re: [tpmdd-devel] [PATCH] tpm_tis: override reported C and D timeouts for Atmel 3203

2017-01-12 Thread Maciej S. Szmigiero
Hi Jason, On 12.01.2017 19:42, Jason Gunthorpe wrote: > On Thu, Jan 12, 2017 at 07:08:53PM +0100, Maciej S. Szmigiero wrote: >> Since commit 1107d065fdf1 ("tpm_tis: Introduce intermediate layer for TPM >> access") Atmel 3203 TPM on ThinkPad X61S (TPM firmware version 13.9) no >> longer works. >> I

Re: [tpmdd-devel] [PATCH] tpm_tis: fix iTPM probe via probe_itpm() function

2017-01-12 Thread Maciej S. Szmigiero
On 12.01.2017 19:50, Jason Gunthorpe wrote: > On Thu, Jan 12, 2017 at 07:12:06PM +0100, Maciej S. Szmigiero wrote: >> probe_itpm() function is supposed to send command without an itpm flag set >> and if this fails to repeat it, this time with the itpm flag set. >> >> However, commit 41a5e1cf1fe15 (

Re: [tpmdd-devel] [PATCH] tpm_tis: override reported C and D timeouts for Atmel 3203

2017-01-12 Thread Jason Gunthorpe
On Thu, Jan 12, 2017 at 09:09:33PM +0100, Maciej S. Szmigiero wrote: > Hmm, I dug in history of tpm-interface.c and the code had actually rejected > zero timeouts until commit 8e54caf407b98e (this is the commit that > introduced the Atmel 3204 workaround) and let default timeout values remain > in

Re: [tpmdd-devel] [PATCH] tpm_tis: override reported C and D timeouts for Atmel 3203

2017-01-12 Thread Jarkko Sakkinen
On Thu, Jan 12, 2017 at 09:09:33PM +0100, Maciej S. Szmigiero wrote: > Hi Jason, > > On 12.01.2017 19:42, Jason Gunthorpe wrote: > > On Thu, Jan 12, 2017 at 07:08:53PM +0100, Maciej S. Szmigiero wrote: > >> Since commit 1107d065fdf1 ("tpm_tis: Introduce intermediate layer for TPM > >> access") Atm

Re: [tpmdd-devel] [PATCH RFC v2 3/5] tpm: infrastructure for TPM spaces

2017-01-12 Thread Jarkko Sakkinen
On Thu, Jan 12, 2017 at 10:38:30AM -0800, James Bottomley wrote: > On Thu, 2017-01-12 at 19:46 +0200, Jarkko Sakkinen wrote: > > @@ -435,17 +440,23 @@ ssize_t tpm_transmit(struct tpm_chip *chip, > > const u8 *buf, size_t bufsiz, > > goto out; > > > > out_recv: > > - rc = chip->ops->

Re: [tpmdd-devel] [PATCH RFC v2 1/5] tpm: validate TPM 2.0 commands

2017-01-12 Thread Jarkko Sakkinen
On Thu, Jan 12, 2017 at 07:46:04PM +0200, Jarkko Sakkinen wrote: > 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. > > Signed-off-by: Jarkko Sakkinen I think this could be bundl

Re: [tpmdd-devel] [PATCH] tpm_tis: fix iTPM probe via probe_itpm() function

2017-01-12 Thread Jarkko Sakkinen
On Thu, Jan 12, 2017 at 07:12:06PM +0100, Maciej S. Szmigiero wrote: > probe_itpm() function is supposed to send command without an itpm flag set > and if this fails to repeat it, this time with the itpm flag set. > > However, commit 41a5e1cf1fe15 ("tpm/tpm_tis: Split tpm_tis driver into a > core

Re: [tpmdd-devel] [PATCH RFC v2 3/5] tpm: infrastructure for TPM spaces

2017-01-12 Thread James Bottomley
On Thu, 2017-01-12 at 19:46 +0200, Jarkko Sakkinen wrote: > +static int tpm2_map_response(struct tpm_chip *chip, u32 cc, u8 *rsp, > size_t len) > +{ > + struct tpm_space *space = &chip->work_space; > + u32 phandle; > + u32 vhandle; > + u32 attrs; > + int i; > + i

Re: [tpmdd-devel] [PATCH v3] tpm: Check size of response before accessing data

2017-01-12 Thread Jarkko Sakkinen
On Thu, Jan 12, 2017 at 07:40:43PM +0200, Jarkko Sakkinen wrote: > On Tue, Jan 10, 2017 at 05:04:04PM -0500, Stefan Berger wrote: > > Make sure that we have not received less bytes than what is indicated > > in the header of the TPM response. Also, check the number of bytes in > > the response befo

Re: [tpmdd-devel] [PATCH RFC v2 3/5] tpm: infrastructure for TPM spaces

2017-01-12 Thread Jarkko Sakkinen
On Thu, Jan 12, 2017 at 07:46:06PM +0200, Jarkko Sakkinen wrote: > Added ability to tpm_transmit() to supply a TPM space that contains > mapping from virtual handles to physical handles and backing storage for > swapping transient objects. TPM space is isolated from other users of > the TPM. > > S

Re: [tpmdd-devel] [PATCH RFC v2 5/5] tpm2: expose resource manager via a device link /dev/tpms

2017-01-12 Thread Jarkko Sakkinen
On Thu, Jan 12, 2017 at 07:46:08PM +0200, Jarkko Sakkinen wrote: > From: James Bottomley > > Currently the Resource Manager (RM) is 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 v

Re: [tpmdd-devel] [PATCH] tpm_tis: override reported C and D timeouts for Atmel 3203

2017-01-12 Thread Maciej S. Szmigiero
On 12.01.2017 21:20, Jarkko Sakkinen wrote: > On Thu, Jan 12, 2017 at 09:09:33PM +0100, Maciej S. Szmigiero wrote: >> Hi Jason, >> >> On 12.01.2017 19:42, Jason Gunthorpe wrote: (..) >>> Can you also add a check for 0 timeouts in the core code and print a >>> FW_BUG :\ >> >> Hmm, I dug in history o

[tpmdd-devel] [PATCH] tpm_tis: rename TPM_TIS_ITPM_POSSIBLE to TPM_TIS_ITPM_WORKAROUND

2017-01-12 Thread Maciej S. Szmigiero
Rename TPM_TIS_ITPM_POSSIBLE to TPM_TIS_ITPM_WORKAROUND since it gives a better idea what this flag actually does. Suggested-by: Jason Gunthorpe Signed-off-by: Maciej S. Szmigiero --- This needs "tpm_tis: fix iTPM probe via probe_itpm() function" applied first. drivers/char/tpm/tpm_tis.c

Re: [tpmdd-devel] [PATCH RFC v2 3/5] tpm: infrastructure for TPM spaces

2017-01-12 Thread James Bottomley
On Thu, 2017-01-12 at 19:46 +0200, Jarkko Sakkinen wrote: > @@ -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

[tpmdd-devel] [PATCH v4] tpm: Check size of response before accessing data

2017-01-12 Thread Stefan Berger
Make sure that we have not received less bytes than what is indicated in the header of the TPM response. Also, check the number of bytes in the response before accessing its data. Signed-off-by: Stefan Berger --- drivers/char/tpm/tpm-interface.c | 59 +-- drivers/char

Re: [tpmdd-devel] [PATCH v3] tpm: Check size of response before accessing data

2017-01-12 Thread Stefan Berger
On 01/12/2017 03:39 PM, Jarkko Sakkinen wrote: > On Thu, Jan 12, 2017 at 07:40:43PM +0200, Jarkko Sakkinen wrote: >> On Tue, Jan 10, 2017 at 05:04:04PM -0500, Stefan Berger wrote: >>> Make sure that we have not received less bytes than what is indicated >>> in the header of the TPM response. Also,

Re: [tpmdd-devel] [PATCH v3 2/2] tpm: enhance TPM 2.0 PCR extend to support multiple banks

2017-01-12 Thread Nayna
On 01/12/2017 11:50 PM, Jarkko Sakkinen wrote: > On Thu, Jan 12, 2017 at 11:58:10AM -0500, Nayna Jain wrote: >> The current TPM 2.0 device driver extends only the SHA1 PCR bank >> but the TCG Specification[1] recommends extending all active PCR >> banks, to prevent malicious users from setting un

Re: [tpmdd-devel] [PATCH v3 1/2] tpm: implement TPM 2.0 capability to get active PCR banks

2017-01-12 Thread Nayna
On 01/12/2017 11:55 PM, Jarkko Sakkinen wrote: > On Thu, Jan 12, 2017 at 11:58:09AM -0500, Nayna Jain wrote: >> This patch implements the TPM 2.0 capability TPM_CAP_PCRS to >> retrieve the active PCR banks from the TPM. This is needed >> to enable extending all active banks as recommended by TPM