Re: [tpmdd-devel] [PATCH v2 3/4] tpm: reduce tpm_msleep() time in get_burstcount()

2017-09-15 Thread Nayna Jain



On 09/13/2017 06:30 AM, Jarkko Sakkinen wrote:

On Wed, Sep 06, 2017 at 08:56:38AM -0400, Nayna Jain wrote:

Currently, get_burstcount() function sleeps for 5msec in a loop
before retrying for next query to burstcount. However, if it takes
lesser time for TPM to return, this 5 msec delay is longer
than necessary.

This patch replaces the tpm_msleep time from 5msec to 1msec.

After this change, performance on a TPM 1.2 with an 8 byte
burstcount for 1000 extends improved from ~10sec to ~9sec.

Signed-off-by: Nayna Jain <na...@linux.vnet.ibm.com>
Acked-by: Mimi Zohar <zo...@linux.vnet.ibm.com>
---
  drivers/char/tpm/tpm_tis_core.c | 2 +-
  1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/char/tpm/tpm_tis_core.c b/drivers/char/tpm/tpm_tis_core.c
index d1eab29cb447..d710bbc4608b 100644
--- a/drivers/char/tpm/tpm_tis_core.c
+++ b/drivers/char/tpm/tpm_tis_core.c
@@ -169,7 +169,7 @@ static int get_burstcount(struct tpm_chip *chip)
burstcnt = (value >> 8) & 0x;
if (burstcnt)
return burstcnt;
-   tpm_msleep(TPM_TIMEOUT);
+   tpm_msleep(1);
} while (time_before(jiffies, stop));
return -EBUSY;
  }
--
2.13.3

How did you pick 1 ms delay? Should there be a constant defining it?


As per ddwg input, the command may not take more than a few
microseconds. The minimum tpm_msleep() value is 1 msec, so we really
don't have a choice.  (We're working on a patch set to lower this
value even more.)

Thanks & Regards,
- Nayna



/Jarkko




--
Check out the vibrant tech community on one of the world's most
engaging tech sites, Slashdot.org! http://sdm.link/slashdot
___
tpmdd-devel mailing list
tpmdd-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/tpmdd-devel


Re: [tpmdd-devel] [PATCH v2 2/4] tpm: define __wait_for_tpm_stat to specify variable polling sleep time

2017-09-15 Thread Nayna Jain



On 09/13/2017 06:28 AM, Jarkko Sakkinen wrote:

On Wed, Sep 06, 2017 at 08:56:37AM -0400, Nayna Jain wrote:

The existing wait_for_tpm_stat() checks the chip status before
sleeping for 5 msec in a polling loop.  For some functions although
the status isn't ready immediately, the status returns extremely
quickly. Waiting for 5 msec causes an unnecessary delay. An
example is the send() call in the tpms_tis driver.

This patch defines __wait_for_tpm_stat(), allowing the caller
to specify the polling sleep timeout value within the loop.
The existing wait_for_tpm_stat() becomes a wrapper for this
function.

After this change, performance on a TPM 1.2 with an 8 byte
burstcount for 1000 extends improved from ~14sec to ~10sec.

Signed-off-by: Nayna Jain <na...@linux.vnet.ibm.com>
Acked-by: Mimi Zohar <zo...@linux.vnet.ibm.com>

Please get rid of wait_for_tpm_stat() rather than further making it more
complex. It's hardware specific stuff. This function should not exist in
tpm-interface.c.


I think I didn't understand the meaning of "get rid of wait_for_tpm_stat()".
Do you mean to take care of it in driver specific file ?
Can you please elaborate it ?

Thanks & Regards,
    - Nayna



/Jarkko


---
  drivers/char/tpm/tpm-interface.c | 15 ---
  drivers/char/tpm/tpm.h   |  3 +++
  drivers/char/tpm/tpm_tis_core.c  | 11 ++-
  3 files changed, 21 insertions(+), 8 deletions(-)

diff --git a/drivers/char/tpm/tpm-interface.c b/drivers/char/tpm/tpm-interface.c
index 1d6729be4cd6..b23d006243b7 100644
--- a/drivers/char/tpm/tpm-interface.c
+++ b/drivers/char/tpm/tpm-interface.c
@@ -1050,8 +1050,9 @@ static bool wait_for_tpm_stat_cond(struct tpm_chip *chip, 
u8 mask,
return false;
  }
  
-int wait_for_tpm_stat(struct tpm_chip *chip, u8 mask, unsigned long timeout,

- wait_queue_head_t *queue, bool check_cancel)
+int __wait_for_tpm_stat(struct tpm_chip *chip, u8 mask, unsigned long timeout,
+ unsigned int poll_sleep, wait_queue_head_t *queue,
+ bool check_cancel)
  {
unsigned long stop;
long rc;
@@ -1085,7 +1086,7 @@ int wait_for_tpm_stat(struct tpm_chip *chip, u8 mask, 
unsigned long timeout,
}
} else {
do {
-   tpm_msleep(TPM_TIMEOUT);
+   tpm_msleep(poll_sleep);
status = chip->ops->status(chip);
if ((status & mask) == mask)
return 0;
@@ -1093,6 +1094,14 @@ int wait_for_tpm_stat(struct tpm_chip *chip, u8 mask, 
unsigned long timeout,
}
return -ETIME;
  }
+EXPORT_SYMBOL_GPL(__wait_for_tpm_stat);
+
+int wait_for_tpm_stat(struct tpm_chip *chip, u8 mask, unsigned long timeout,
+ wait_queue_head_t *queue, bool check_cancel)
+{
+   return __wait_for_tpm_stat(chip, mask, timeout, TPM_TIMEOUT,
+   queue, check_cancel);
+}
  EXPORT_SYMBOL_GPL(wait_for_tpm_stat);
  
  #define TPM_ORD_SAVESTATE 152

diff --git a/drivers/char/tpm/tpm.h b/drivers/char/tpm/tpm.h
index 2d5466a72e40..eb2f8818eded 100644
--- a/drivers/char/tpm/tpm.h
+++ b/drivers/char/tpm/tpm.h
@@ -525,6 +525,9 @@ int tpm_do_selftest(struct tpm_chip *chip);
  unsigned long tpm_calc_ordinal_duration(struct tpm_chip *chip, u32 ordinal);
  int tpm_pm_suspend(struct device *dev);
  int tpm_pm_resume(struct device *dev);
+int __wait_for_tpm_stat(struct tpm_chip *chip, u8 mask,
+   unsigned long timeout, unsigned int poll_sleep,
+   wait_queue_head_t *queue, bool check_cancel);
  int wait_for_tpm_stat(struct tpm_chip *chip, u8 mask, unsigned long timeout,
  wait_queue_head_t *queue, bool check_cancel);
  
diff --git a/drivers/char/tpm/tpm_tis_core.c b/drivers/char/tpm/tpm_tis_core.c

index 6b9bf4c4d434..d1eab29cb447 100644
--- a/drivers/char/tpm/tpm_tis_core.c
+++ b/drivers/char/tpm/tpm_tis_core.c
@@ -268,8 +268,8 @@ static int tpm_tis_send_data(struct tpm_chip *chip, u8 
*buf, size_t len)
status = tpm_tis_status(chip);
if ((status & TPM_STS_COMMAND_READY) == 0) {
tpm_tis_ready(chip);
-   if (wait_for_tpm_stat
-   (chip, TPM_STS_COMMAND_READY, chip->timeout_b,
+   if (__wait_for_tpm_stat
+   (chip, TPM_STS_COMMAND_READY, chip->timeout_b, 1,
 >int_queue, false) < 0) {
rc = -ETIME;
goto out_err;
@@ -303,7 +303,8 @@ static int tpm_tis_send_data(struct tpm_chip *chip, u8 
*buf, size_t len)
if (ignore_burst_count)
continue;
  
-		if (wait_for_tpm_stat(chip, TPM_STS_VALID, chip->timeout_c,

+   if (__wait_for_tpm_stat(chip, TPM_STS_VALID,
+   chip->timeout_c, 1,
>

Re: [tpmdd-devel] [PATCH v2 1/4] tpm: ignore burstcount to improve tpm_tis send() performance.

2017-09-15 Thread Nayna Jain



On 09/14/2017 04:40 AM, Jarkko Sakkinen wrote:

On Wed, Sep 13, 2017 at 11:39:03AM -0700, Peter Huewe wrote:


Am 12. September 2017 17:45:08 GMT-07:00 schrieb Jarkko Sakkinen 
<jarkko.sakki...@linux.intel.com>:

On Wed, Sep 06, 2017 at 08:56:36AM -0400, Nayna Jain wrote:

The TPM burstcount status indicates the number of bytes that can
be sent to the TPM without causing bus wait states.  Effectively,
it is the number of empty bytes in the command FIFO. Further,
some TPMs have a static burstcount, when the value remains zero
until the entire FIFO is empty.

This patch adds an optimization to check for burstcount only once.
And if it is valid, it writes all the bytes at once, permitting
wait states. The performance of a 34 byte extend on a TPM 1.2 with
an 8 byte burstcount improved from 41 msec to 14 msec.

This functionality is enabled only by passing module
parameter ignore_burst_count=1. By default, this parameter
is disabled.

After this change, performance on a TPM 1.2 with an 8 byte
burstcount for 1000 extends improved from ~41sec to ~14sec.

Suggested-by: Ken Goldman <kg...@linux.vnet.ibm.com> in
conjunction with the TPM Device Driver work group.
Signed-off-by: Nayna Jain <na...@linux.vnet.ibm.com>
Acked-by: Mimi Zohar <zo...@linux.vnet.ibm.com>
---
  Documentation/admin-guide/kernel-parameters.txt |  8 
  drivers/char/tpm/tpm_tis_core.c | 24

+---

  2 files changed, 29 insertions(+), 3 deletions(-)

diff --git a/Documentation/admin-guide/kernel-parameters.txt

b/Documentation/admin-guide/kernel-parameters.txt

index 4e303be83df6..3c59bb91e1ee 100644
--- a/Documentation/admin-guide/kernel-parameters.txt
+++ b/Documentation/admin-guide/kernel-parameters.txt
@@ -1465,6 +1465,14 @@
mode generally follows that for the NaN encoding,
except where unsupported by hardware.
  
+	ignore_burst_count [TPM_TIS_CORE]

+   tpm_tis_core driver queries for the burstcount before
+   every send call in a loop. However, it causes delay to
+   the send command for TPMs with low burstcount value.
+   Setting this value to 1, will make driver to query for
+   burstcount only once in the loop to improve the
+   performance. By default, its value is set to 0.
+
ignore_loglevel [KNL]
Ignore loglevel setting - this will print /all/
kernel messages to the console. Useful for debugging.
diff --git a/drivers/char/tpm/tpm_tis_core.c

b/drivers/char/tpm/tpm_tis_core.c

index 63bc6c3b949e..6b9bf4c4d434 100644
--- a/drivers/char/tpm/tpm_tis_core.c
+++ b/drivers/char/tpm/tpm_tis_core.c
@@ -31,6 +31,11 @@
  #include "tpm.h"
  #include "tpm_tis_core.h"
  
+static bool ignore_burst_count = false;

+module_param(ignore_burst_count, bool, 0444);
+MODULE_PARM_DESC(ignore_burst_count,
+   "Ignore burstcount value while writing data");
+
  /* Before we attempt to access the TPM we must see that the valid

bit is set.

   * The specification says that this bit is 0 at reset and remains 0

until the

   * 'TPM has gone through its self test and initialization and has

established

@@ -256,6 +261,7 @@ static int tpm_tis_send_data(struct tpm_chip

*chip, u8 *buf, size_t len)

  {
struct tpm_tis_data *priv = dev_get_drvdata(>dev);
int rc, status, burstcnt;
+   int sendcnt;
size_t count = 0;
bool itpm = priv->flags & TPM_TIS_ITPM_WORKAROUND;
  
@@ -271,19 +277,31 @@ static int tpm_tis_send_data(struct tpm_chip

*chip, u8 *buf, size_t len)

}
  
  	while (count < len - 1) {

+
+   /*
+* Get the initial burstcount to ensure TPM is ready to
+* accept data, even when waiting for burstcount is disabled.
+*/
burstcnt = get_burstcount(chip);
if (burstcnt < 0) {
dev_err(>dev, "Unable to read burstcount\n");
rc = burstcnt;
goto out_err;
}
-   burstcnt = min_t(int, burstcnt, len - count - 1);
+
+   if (ignore_burst_count)
+   sendcnt = len - 1;
+   else
+   sendcnt = min_t(int, burstcnt, len - count - 1);
+
rc = tpm_tis_write_bytes(priv, TPM_DATA_FIFO(priv->locality),
-burstcnt, buf + count);
+sendcnt, buf + count);
if (rc < 0)
goto out_err;
  
-		count += burstcnt;

+   count += sendcnt;
+   if (ignore_burst_count)
+   continue;
  
  		if (wait_for_tpm_stat(chip, TPM_STS_VALID, chip->timeout_c,


Re: [tpmdd-devel] TPM2.0: No binary_bios_measurements file in securityFS

2017-09-13 Thread Nayna Jain



On 09/12/2017 04:14 AM, Nasim, Kam wrote:


Hi folks,


I am building my TPM 2.0 driver as Kernel modules (tpm.ko, 
tpm_tis_core.ko and tpm_tis.ko).


I noticed that while my /sys/kernel/security directory is created and 
mounted to securityFS, it is empty.


Looking at tpm_bios_log_setup() in tpm1_event.log, I see that this is 
being done during chip registration:


TPM 2.0 binary_bios_measurements event log file support is currently not 
available for ACPI based platform. It is only for device tree based 
platform. And I think you are using ACPI.


Thanks & Regards,
    - Nayna


if (chip->flags & TPM_CHIP_FLAG_TPM2)

chip->bin_log_seqops.seqops =

_binary_b_measurements_seqops;

    else

chip->bin_log_seqops.seqops =

_binary_b_measurements_seqops;

chip->bios_dir[cnt] =

securityfs_create_file("binary_bios_measurements",

   0440, chip->bios_dir[0],

   (void *)>bin_log_seqops,

_bios_measurements_ops);

    if (IS_ERR(chip->bios_dir[cnt]))

    goto err;

My TPM modules are loaded properly and I can interact with TPM using 
userspace TSS2 applications:


$ sudo lsmod | grep tpm

Password:

tpm_crb 6458  0

tpm_tis 5950  0

tpm_tis_core 10054  1 tpm_tis

tpm 48093  3 tpm_crb,tpm_tis,tpm_tis_core

2017-09-08T19:39:16.239 controller-0 kernel: warning [    0.00] 
ACPI: TPM2 7b7c8000 00034 (v03 INTEL   S2600WT 0002 INTL 
0113)


2017-09-08T19:39:16.252 controller-0 kernel: info [    5.457568] 
tpm_tis MSFT0101:00: 2.0 TPM (device-id 0x1A, rev-id 16)


How and when would this file be created? For that matter I don’t even 
have a /sys/devices/pnp0/<pnp#>/pcrs file present


(I am on CentOS 7.3)

Thoughts?

Thanks,

Kam



--
Check out the vibrant tech community on one of the world's most
engaging tech sites, Slashdot.org! http://sdm.link/slashdot


___
tpmdd-devel mailing list
tpmdd-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/tpmdd-devel


--
Check out the vibrant tech community on one of the world's most
engaging tech sites, Slashdot.org! http://sdm.link/slashdot___
tpmdd-devel mailing list
tpmdd-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/tpmdd-devel


Re: [tpmdd-devel] [PATCH 2/4] tpm: define __wait_for_tpm_stat to specify variable polling sleep time

2017-09-06 Thread Nayna
Please ignore these one.. My command took patches recursively from 
directory also.


Sorry for this.

Thanks & Regards,
- Nayna

On 09/06/2017 06:26 PM, Nayna Jain wrote:

The existing wait_for_tpm_stat() checks the chip status before
sleeping for 5 msec in a polling loop.  For some functions although
the status isn't ready immediately, the status returns extremely
quickly. Waiting for 5 msec causes an unnecessary delay. An
example is the send() call in the tpms_tis driver.

This patch defines __wait_for_tpm_stat(), allowing the caller
to specify the polling sleep timeout value within the loop.
The existing wait_for_tpm_stat() becomes a wrapper for this
function.

Signed-off-by: Nayna Jain <na...@linux.vnet.ibm.com>
---
  drivers/char/tpm/tpm-interface.c | 15 ---
  drivers/char/tpm/tpm.h   |  3 +++
  drivers/char/tpm/tpm_tis_core.c  | 11 ++-
  3 files changed, 21 insertions(+), 8 deletions(-)

diff --git a/drivers/char/tpm/tpm-interface.c b/drivers/char/tpm/tpm-interface.c
index 1d6729be4cd6..b23d006243b7 100644
--- a/drivers/char/tpm/tpm-interface.c
+++ b/drivers/char/tpm/tpm-interface.c
@@ -1050,8 +1050,9 @@ static bool wait_for_tpm_stat_cond(struct tpm_chip *chip, 
u8 mask,
return false;
  }

-int wait_for_tpm_stat(struct tpm_chip *chip, u8 mask, unsigned long timeout,
- wait_queue_head_t *queue, bool check_cancel)
+int __wait_for_tpm_stat(struct tpm_chip *chip, u8 mask, unsigned long timeout,
+ unsigned int poll_sleep, wait_queue_head_t *queue,
+ bool check_cancel)
  {
unsigned long stop;
long rc;
@@ -1085,7 +1086,7 @@ int wait_for_tpm_stat(struct tpm_chip *chip, u8 mask, 
unsigned long timeout,
}
} else {
do {
-   tpm_msleep(TPM_TIMEOUT);
+   tpm_msleep(poll_sleep);
status = chip->ops->status(chip);
if ((status & mask) == mask)
return 0;
@@ -1093,6 +1094,14 @@ int wait_for_tpm_stat(struct tpm_chip *chip, u8 mask, 
unsigned long timeout,
}
return -ETIME;
  }
+EXPORT_SYMBOL_GPL(__wait_for_tpm_stat);
+
+int wait_for_tpm_stat(struct tpm_chip *chip, u8 mask, unsigned long timeout,
+ wait_queue_head_t *queue, bool check_cancel)
+{
+   return __wait_for_tpm_stat(chip, mask, timeout, TPM_TIMEOUT,
+   queue, check_cancel);
+}
  EXPORT_SYMBOL_GPL(wait_for_tpm_stat);

  #define TPM_ORD_SAVESTATE 152
diff --git a/drivers/char/tpm/tpm.h b/drivers/char/tpm/tpm.h
index 2d5466a72e40..eb2f8818eded 100644
--- a/drivers/char/tpm/tpm.h
+++ b/drivers/char/tpm/tpm.h
@@ -525,6 +525,9 @@ int tpm_do_selftest(struct tpm_chip *chip);
  unsigned long tpm_calc_ordinal_duration(struct tpm_chip *chip, u32 ordinal);
  int tpm_pm_suspend(struct device *dev);
  int tpm_pm_resume(struct device *dev);
+int __wait_for_tpm_stat(struct tpm_chip *chip, u8 mask,
+   unsigned long timeout, unsigned int poll_sleep,
+   wait_queue_head_t *queue, bool check_cancel);
  int wait_for_tpm_stat(struct tpm_chip *chip, u8 mask, unsigned long timeout,
  wait_queue_head_t *queue, bool check_cancel);

diff --git a/drivers/char/tpm/tpm_tis_core.c b/drivers/char/tpm/tpm_tis_core.c
index 6b9bf4c4d434..d1eab29cb447 100644
--- a/drivers/char/tpm/tpm_tis_core.c
+++ b/drivers/char/tpm/tpm_tis_core.c
@@ -268,8 +268,8 @@ static int tpm_tis_send_data(struct tpm_chip *chip, u8 
*buf, size_t len)
status = tpm_tis_status(chip);
if ((status & TPM_STS_COMMAND_READY) == 0) {
tpm_tis_ready(chip);
-   if (wait_for_tpm_stat
-   (chip, TPM_STS_COMMAND_READY, chip->timeout_b,
+   if (__wait_for_tpm_stat
+   (chip, TPM_STS_COMMAND_READY, chip->timeout_b, 1,
 >int_queue, false) < 0) {
rc = -ETIME;
goto out_err;
@@ -303,7 +303,8 @@ static int tpm_tis_send_data(struct tpm_chip *chip, u8 
*buf, size_t len)
if (ignore_burst_count)
continue;

-   if (wait_for_tpm_stat(chip, TPM_STS_VALID, chip->timeout_c,
+   if (__wait_for_tpm_stat(chip, TPM_STS_VALID,
+   chip->timeout_c, 1,
>int_queue, false) < 0) {
rc = -ETIME;
goto out_err;
@@ -320,8 +321,8 @@ static int tpm_tis_send_data(struct tpm_chip *chip, u8 
*buf, size_t len)
if (rc < 0)
goto out_err;

-   if (wait_for_tpm_stat(chip, TPM_STS_VALID, chip->timeout_c,
-   >int_queue, false) < 0) {
+   if (__wait_for_tpm_stat(chip, TPM_STS_VALID, chip->timeout_c,
+   1, >int_queu

Re: [tpmdd-devel] [PATCH 1/4] tpm: ignore burstcount to improve tpm_tis send() performance.

2017-09-06 Thread Nayna
Please ignore these one.. My command took patches recursively from 
directory also.


Sorry for this.

Thanks & Regards,
   - Nayna

On 09/06/2017 06:26 PM, Nayna Jain wrote:

The TPM burstcount status indicates the number of bytes that can
be sent to the TPM without causing bus wait states.  Effectively,
it is the number of empty bytes in the command FIFO. Further,
some TPMs have a static burstcount, when the value remains zero
until the entire FIFO is empty.

This patch adds an optimization to check for burstcount only once.
And if it is valid, it writes all the bytes at once, permitting
wait states. The performance of a 34 byte extend on a TPM 1.2 with
an 8 byte burstcount improved from 41 msec to 14 msec.

This functionality is enabled only by passing module
parameter ignore_burst_count=1. By default, this parameter
is disabled.

Suggested-by: Ken Goldman <kg...@linux.vnet.ibm.com> in
conjunction with the TPM Device Driver work group.
Signed-off-by: Nayna Jain <na...@linux.vnet.ibm.com>
Acked-by: Mimi Zohar <zo...@linux.vnet.ibm.com>
---
  Documentation/admin-guide/kernel-parameters.txt |  8 
  drivers/char/tpm/tpm_tis_core.c | 24 +---
  2 files changed, 29 insertions(+), 3 deletions(-)

diff --git a/Documentation/admin-guide/kernel-parameters.txt 
b/Documentation/admin-guide/kernel-parameters.txt
index 4e303be83df6..3c59bb91e1ee 100644
--- a/Documentation/admin-guide/kernel-parameters.txt
+++ b/Documentation/admin-guide/kernel-parameters.txt
@@ -1465,6 +1465,14 @@
mode generally follows that for the NaN encoding,
except where unsupported by hardware.

+   ignore_burst_count [TPM_TIS_CORE]
+   tpm_tis_core driver queries for the burstcount before
+   every send call in a loop. However, it causes delay to
+   the send command for TPMs with low burstcount value.
+   Setting this value to 1, will make driver to query for
+   burstcount only once in the loop to improve the
+   performance. By default, its value is set to 0.
+
ignore_loglevel [KNL]
Ignore loglevel setting - this will print /all/
kernel messages to the console. Useful for debugging.
diff --git a/drivers/char/tpm/tpm_tis_core.c b/drivers/char/tpm/tpm_tis_core.c
index 63bc6c3b949e..6b9bf4c4d434 100644
--- a/drivers/char/tpm/tpm_tis_core.c
+++ b/drivers/char/tpm/tpm_tis_core.c
@@ -31,6 +31,11 @@
  #include "tpm.h"
  #include "tpm_tis_core.h"

+static bool ignore_burst_count = false;
+module_param(ignore_burst_count, bool, 0444);
+MODULE_PARM_DESC(ignore_burst_count,
+   "Ignore burstcount value while writing data");
+
  /* Before we attempt to access the TPM we must see that the valid bit is set.
   * The specification says that this bit is 0 at reset and remains 0 until the
   * 'TPM has gone through its self test and initialization and has established
@@ -256,6 +261,7 @@ static int tpm_tis_send_data(struct tpm_chip *chip, u8 
*buf, size_t len)
  {
struct tpm_tis_data *priv = dev_get_drvdata(>dev);
int rc, status, burstcnt;
+   int sendcnt;
size_t count = 0;
bool itpm = priv->flags & TPM_TIS_ITPM_WORKAROUND;

@@ -271,19 +277,31 @@ static int tpm_tis_send_data(struct tpm_chip *chip, u8 
*buf, size_t len)
}

while (count < len - 1) {
+
+   /*
+* Get the initial burstcount to ensure TPM is ready to
+* accept data, even when waiting for burstcount is disabled.
+*/
burstcnt = get_burstcount(chip);
if (burstcnt < 0) {
dev_err(>dev, "Unable to read burstcount\n");
rc = burstcnt;
goto out_err;
}
-   burstcnt = min_t(int, burstcnt, len - count - 1);
+
+   if (ignore_burst_count)
+   sendcnt = len - 1;
+   else
+   sendcnt = min_t(int, burstcnt, len - count - 1);
+
rc = tpm_tis_write_bytes(priv, TPM_DATA_FIFO(priv->locality),
-burstcnt, buf + count);
+sendcnt, buf + count);
if (rc < 0)
goto out_err;

-   count += burstcnt;
+   count += sendcnt;
+   if (ignore_burst_count)
+   continue;

if (wait_for_tpm_stat(chip, TPM_STS_VALID, chip->timeout_c,
>int_queue, false) < 0) {




--
Check out the vibrant tech community on one of the world's most
engaging tech sit

[tpmdd-devel] [PATCH 2/4] tpm: define __wait_for_tpm_stat to specify variable polling sleep time

2017-09-06 Thread Nayna Jain
The existing wait_for_tpm_stat() checks the chip status before
sleeping for 5 msec in a polling loop.  For some functions although
the status isn't ready immediately, the status returns extremely
quickly. Waiting for 5 msec causes an unnecessary delay. An
example is the send() call in the tpms_tis driver.

This patch defines __wait_for_tpm_stat(), allowing the caller
to specify the polling sleep timeout value within the loop.
The existing wait_for_tpm_stat() becomes a wrapper for this
function.

Signed-off-by: Nayna Jain <na...@linux.vnet.ibm.com>
---
 drivers/char/tpm/tpm-interface.c | 15 ---
 drivers/char/tpm/tpm.h   |  3 +++
 drivers/char/tpm/tpm_tis_core.c  | 11 ++-
 3 files changed, 21 insertions(+), 8 deletions(-)

diff --git a/drivers/char/tpm/tpm-interface.c b/drivers/char/tpm/tpm-interface.c
index 1d6729be4cd6..b23d006243b7 100644
--- a/drivers/char/tpm/tpm-interface.c
+++ b/drivers/char/tpm/tpm-interface.c
@@ -1050,8 +1050,9 @@ static bool wait_for_tpm_stat_cond(struct tpm_chip *chip, 
u8 mask,
return false;
 }
 
-int wait_for_tpm_stat(struct tpm_chip *chip, u8 mask, unsigned long timeout,
- wait_queue_head_t *queue, bool check_cancel)
+int __wait_for_tpm_stat(struct tpm_chip *chip, u8 mask, unsigned long timeout,
+ unsigned int poll_sleep, wait_queue_head_t *queue,
+ bool check_cancel)
 {
unsigned long stop;
long rc;
@@ -1085,7 +1086,7 @@ int wait_for_tpm_stat(struct tpm_chip *chip, u8 mask, 
unsigned long timeout,
}
} else {
do {
-   tpm_msleep(TPM_TIMEOUT);
+   tpm_msleep(poll_sleep);
status = chip->ops->status(chip);
if ((status & mask) == mask)
return 0;
@@ -1093,6 +1094,14 @@ int wait_for_tpm_stat(struct tpm_chip *chip, u8 mask, 
unsigned long timeout,
}
return -ETIME;
 }
+EXPORT_SYMBOL_GPL(__wait_for_tpm_stat);
+
+int wait_for_tpm_stat(struct tpm_chip *chip, u8 mask, unsigned long timeout,
+ wait_queue_head_t *queue, bool check_cancel)
+{
+   return __wait_for_tpm_stat(chip, mask, timeout, TPM_TIMEOUT,
+   queue, check_cancel);
+}
 EXPORT_SYMBOL_GPL(wait_for_tpm_stat);
 
 #define TPM_ORD_SAVESTATE 152
diff --git a/drivers/char/tpm/tpm.h b/drivers/char/tpm/tpm.h
index 2d5466a72e40..eb2f8818eded 100644
--- a/drivers/char/tpm/tpm.h
+++ b/drivers/char/tpm/tpm.h
@@ -525,6 +525,9 @@ int tpm_do_selftest(struct tpm_chip *chip);
 unsigned long tpm_calc_ordinal_duration(struct tpm_chip *chip, u32 ordinal);
 int tpm_pm_suspend(struct device *dev);
 int tpm_pm_resume(struct device *dev);
+int __wait_for_tpm_stat(struct tpm_chip *chip, u8 mask,
+   unsigned long timeout, unsigned int poll_sleep,
+   wait_queue_head_t *queue, bool check_cancel);
 int wait_for_tpm_stat(struct tpm_chip *chip, u8 mask, unsigned long timeout,
  wait_queue_head_t *queue, bool check_cancel);
 
diff --git a/drivers/char/tpm/tpm_tis_core.c b/drivers/char/tpm/tpm_tis_core.c
index 6b9bf4c4d434..d1eab29cb447 100644
--- a/drivers/char/tpm/tpm_tis_core.c
+++ b/drivers/char/tpm/tpm_tis_core.c
@@ -268,8 +268,8 @@ static int tpm_tis_send_data(struct tpm_chip *chip, u8 
*buf, size_t len)
status = tpm_tis_status(chip);
if ((status & TPM_STS_COMMAND_READY) == 0) {
tpm_tis_ready(chip);
-   if (wait_for_tpm_stat
-   (chip, TPM_STS_COMMAND_READY, chip->timeout_b,
+   if (__wait_for_tpm_stat
+   (chip, TPM_STS_COMMAND_READY, chip->timeout_b, 1,
 >int_queue, false) < 0) {
rc = -ETIME;
goto out_err;
@@ -303,7 +303,8 @@ static int tpm_tis_send_data(struct tpm_chip *chip, u8 
*buf, size_t len)
if (ignore_burst_count)
continue;
 
-   if (wait_for_tpm_stat(chip, TPM_STS_VALID, chip->timeout_c,
+   if (__wait_for_tpm_stat(chip, TPM_STS_VALID,
+   chip->timeout_c, 1,
>int_queue, false) < 0) {
rc = -ETIME;
goto out_err;
@@ -320,8 +321,8 @@ static int tpm_tis_send_data(struct tpm_chip *chip, u8 
*buf, size_t len)
if (rc < 0)
goto out_err;
 
-   if (wait_for_tpm_stat(chip, TPM_STS_VALID, chip->timeout_c,
-   >int_queue, false) < 0) {
+   if (__wait_for_tpm_stat(chip, TPM_STS_VALID, chip->timeout_c,
+   1, >int_queue, false) < 0) {
rc = -ETIME;
goto out_err;
}
-- 
2.13.3


--
Check o

[tpmdd-devel] [PATCH v2 4/4] tpm: use tpm_msleep() value as max delay

2017-09-06 Thread Nayna Jain
Currently, tpm_msleep() uses delay_msec as the minimum value in
usleep_range. However, that is the maximum time we want to wait.
The function is modified to use the delay_msec as the maximum
value, not the minimum value.

After this change, performance on a TPM 1.2 with an 8 byte
burstcount for 1000 extends improved from ~9sec to ~8sec.

Signed-off-by: Nayna Jain <na...@linux.vnet.ibm.com>
Acked-by: Mimi Zohar <zo...@linux.vnet.ibm.com>
---
 drivers/char/tpm/tpm.h | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/char/tpm/tpm.h b/drivers/char/tpm/tpm.h
index eb2f8818eded..ff5a8b7b80b9 100644
--- a/drivers/char/tpm/tpm.h
+++ b/drivers/char/tpm/tpm.h
@@ -533,8 +533,8 @@ int wait_for_tpm_stat(struct tpm_chip *chip, u8 mask, 
unsigned long timeout,
 
 static inline void tpm_msleep(unsigned int delay_msec)
 {
-   usleep_range(delay_msec * 1000,
-(delay_msec * 1000) + TPM_TIMEOUT_RANGE_US);
+   usleep_range((delay_msec * 1000) - TPM_TIMEOUT_RANGE_US,
+delay_msec * 1000);
 };
 
 struct tpm_chip *tpm_chip_find_get(int chip_num);
-- 
2.13.3


--
Check out the vibrant tech community on one of the world's most
engaging tech sites, Slashdot.org! http://sdm.link/slashdot
___
tpmdd-devel mailing list
tpmdd-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/tpmdd-devel


[tpmdd-devel] [PATCH 1/4] tpm: ignore burstcount to improve tpm_tis send() performance.

2017-09-06 Thread Nayna Jain
The TPM burstcount status indicates the number of bytes that can
be sent to the TPM without causing bus wait states.  Effectively,
it is the number of empty bytes in the command FIFO. Further,
some TPMs have a static burstcount, when the value remains zero
until the entire FIFO is empty.

This patch adds an optimization to check for burstcount only once.
And if it is valid, it writes all the bytes at once, permitting
wait states. The performance of a 34 byte extend on a TPM 1.2 with
an 8 byte burstcount improved from 41 msec to 14 msec.

This functionality is enabled only by passing module
parameter ignore_burst_count=1. By default, this parameter
is disabled.

Suggested-by: Ken Goldman <kg...@linux.vnet.ibm.com> in
conjunction with the TPM Device Driver work group.
Signed-off-by: Nayna Jain <na...@linux.vnet.ibm.com>
Acked-by: Mimi Zohar <zo...@linux.vnet.ibm.com>
---
 Documentation/admin-guide/kernel-parameters.txt |  8 
 drivers/char/tpm/tpm_tis_core.c | 24 +---
 2 files changed, 29 insertions(+), 3 deletions(-)

diff --git a/Documentation/admin-guide/kernel-parameters.txt 
b/Documentation/admin-guide/kernel-parameters.txt
index 4e303be83df6..3c59bb91e1ee 100644
--- a/Documentation/admin-guide/kernel-parameters.txt
+++ b/Documentation/admin-guide/kernel-parameters.txt
@@ -1465,6 +1465,14 @@
mode generally follows that for the NaN encoding,
except where unsupported by hardware.
 
+   ignore_burst_count [TPM_TIS_CORE]
+   tpm_tis_core driver queries for the burstcount before
+   every send call in a loop. However, it causes delay to
+   the send command for TPMs with low burstcount value.
+   Setting this value to 1, will make driver to query for
+   burstcount only once in the loop to improve the
+   performance. By default, its value is set to 0.
+
ignore_loglevel [KNL]
Ignore loglevel setting - this will print /all/
kernel messages to the console. Useful for debugging.
diff --git a/drivers/char/tpm/tpm_tis_core.c b/drivers/char/tpm/tpm_tis_core.c
index 63bc6c3b949e..6b9bf4c4d434 100644
--- a/drivers/char/tpm/tpm_tis_core.c
+++ b/drivers/char/tpm/tpm_tis_core.c
@@ -31,6 +31,11 @@
 #include "tpm.h"
 #include "tpm_tis_core.h"
 
+static bool ignore_burst_count = false;
+module_param(ignore_burst_count, bool, 0444);
+MODULE_PARM_DESC(ignore_burst_count,
+   "Ignore burstcount value while writing data");
+
 /* Before we attempt to access the TPM we must see that the valid bit is set.
  * The specification says that this bit is 0 at reset and remains 0 until the
  * 'TPM has gone through its self test and initialization and has established
@@ -256,6 +261,7 @@ static int tpm_tis_send_data(struct tpm_chip *chip, u8 
*buf, size_t len)
 {
struct tpm_tis_data *priv = dev_get_drvdata(>dev);
int rc, status, burstcnt;
+   int sendcnt;
size_t count = 0;
bool itpm = priv->flags & TPM_TIS_ITPM_WORKAROUND;
 
@@ -271,19 +277,31 @@ static int tpm_tis_send_data(struct tpm_chip *chip, u8 
*buf, size_t len)
}
 
while (count < len - 1) {
+
+   /*
+* Get the initial burstcount to ensure TPM is ready to
+* accept data, even when waiting for burstcount is disabled.
+*/
burstcnt = get_burstcount(chip);
if (burstcnt < 0) {
dev_err(>dev, "Unable to read burstcount\n");
rc = burstcnt;
goto out_err;
}
-   burstcnt = min_t(int, burstcnt, len - count - 1);
+
+   if (ignore_burst_count)
+   sendcnt = len - 1;
+   else
+   sendcnt = min_t(int, burstcnt, len - count - 1);
+
rc = tpm_tis_write_bytes(priv, TPM_DATA_FIFO(priv->locality),
-burstcnt, buf + count);
+sendcnt, buf + count);
if (rc < 0)
goto out_err;
 
-   count += burstcnt;
+   count += sendcnt;
+   if (ignore_burst_count)
+   continue;
 
if (wait_for_tpm_stat(chip, TPM_STS_VALID, chip->timeout_c,
>int_queue, false) < 0) {
-- 
2.13.3


--
Check out the vibrant tech community on one of the world's most
engaging tech sites, Slashdot.org! http://sdm.link/slashdot
___
tpmdd-devel mailing list
tpmdd-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/tpmdd-devel


[tpmdd-devel] [PATCH v2 3/4] tpm: reduce tpm_msleep() time in get_burstcount()

2017-09-06 Thread Nayna Jain
Currently, get_burstcount() function sleeps for 5msec in a loop
before retrying for next query to burstcount. However, if it takes
lesser time for TPM to return, this 5 msec delay is longer
than necessary.

This patch replaces the tpm_msleep time from 5msec to 1msec.

After this change, performance on a TPM 1.2 with an 8 byte
burstcount for 1000 extends improved from ~10sec to ~9sec.

Signed-off-by: Nayna Jain <na...@linux.vnet.ibm.com>
Acked-by: Mimi Zohar <zo...@linux.vnet.ibm.com>
---
 drivers/char/tpm/tpm_tis_core.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/char/tpm/tpm_tis_core.c b/drivers/char/tpm/tpm_tis_core.c
index d1eab29cb447..d710bbc4608b 100644
--- a/drivers/char/tpm/tpm_tis_core.c
+++ b/drivers/char/tpm/tpm_tis_core.c
@@ -169,7 +169,7 @@ static int get_burstcount(struct tpm_chip *chip)
burstcnt = (value >> 8) & 0x;
if (burstcnt)
return burstcnt;
-   tpm_msleep(TPM_TIMEOUT);
+   tpm_msleep(1);
} while (time_before(jiffies, stop));
return -EBUSY;
 }
-- 
2.13.3


--
Check out the vibrant tech community on one of the world's most
engaging tech sites, Slashdot.org! http://sdm.link/slashdot
___
tpmdd-devel mailing list
tpmdd-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/tpmdd-devel


[tpmdd-devel] [PATCH v2 1/4] tpm: ignore burstcount to improve tpm_tis send() performance.

2017-09-06 Thread Nayna Jain
The TPM burstcount status indicates the number of bytes that can
be sent to the TPM without causing bus wait states.  Effectively,
it is the number of empty bytes in the command FIFO. Further,
some TPMs have a static burstcount, when the value remains zero
until the entire FIFO is empty.

This patch adds an optimization to check for burstcount only once.
And if it is valid, it writes all the bytes at once, permitting
wait states. The performance of a 34 byte extend on a TPM 1.2 with
an 8 byte burstcount improved from 41 msec to 14 msec.

This functionality is enabled only by passing module
parameter ignore_burst_count=1. By default, this parameter
is disabled.

After this change, performance on a TPM 1.2 with an 8 byte
burstcount for 1000 extends improved from ~41sec to ~14sec.

Suggested-by: Ken Goldman <kg...@linux.vnet.ibm.com> in
conjunction with the TPM Device Driver work group.
Signed-off-by: Nayna Jain <na...@linux.vnet.ibm.com>
Acked-by: Mimi Zohar <zo...@linux.vnet.ibm.com>
---
 Documentation/admin-guide/kernel-parameters.txt |  8 
 drivers/char/tpm/tpm_tis_core.c | 24 +---
 2 files changed, 29 insertions(+), 3 deletions(-)

diff --git a/Documentation/admin-guide/kernel-parameters.txt 
b/Documentation/admin-guide/kernel-parameters.txt
index 4e303be83df6..3c59bb91e1ee 100644
--- a/Documentation/admin-guide/kernel-parameters.txt
+++ b/Documentation/admin-guide/kernel-parameters.txt
@@ -1465,6 +1465,14 @@
mode generally follows that for the NaN encoding,
except where unsupported by hardware.
 
+   ignore_burst_count [TPM_TIS_CORE]
+   tpm_tis_core driver queries for the burstcount before
+   every send call in a loop. However, it causes delay to
+   the send command for TPMs with low burstcount value.
+   Setting this value to 1, will make driver to query for
+   burstcount only once in the loop to improve the
+   performance. By default, its value is set to 0.
+
ignore_loglevel [KNL]
Ignore loglevel setting - this will print /all/
kernel messages to the console. Useful for debugging.
diff --git a/drivers/char/tpm/tpm_tis_core.c b/drivers/char/tpm/tpm_tis_core.c
index 63bc6c3b949e..6b9bf4c4d434 100644
--- a/drivers/char/tpm/tpm_tis_core.c
+++ b/drivers/char/tpm/tpm_tis_core.c
@@ -31,6 +31,11 @@
 #include "tpm.h"
 #include "tpm_tis_core.h"
 
+static bool ignore_burst_count = false;
+module_param(ignore_burst_count, bool, 0444);
+MODULE_PARM_DESC(ignore_burst_count,
+   "Ignore burstcount value while writing data");
+
 /* Before we attempt to access the TPM we must see that the valid bit is set.
  * The specification says that this bit is 0 at reset and remains 0 until the
  * 'TPM has gone through its self test and initialization and has established
@@ -256,6 +261,7 @@ static int tpm_tis_send_data(struct tpm_chip *chip, u8 
*buf, size_t len)
 {
struct tpm_tis_data *priv = dev_get_drvdata(>dev);
int rc, status, burstcnt;
+   int sendcnt;
size_t count = 0;
bool itpm = priv->flags & TPM_TIS_ITPM_WORKAROUND;
 
@@ -271,19 +277,31 @@ static int tpm_tis_send_data(struct tpm_chip *chip, u8 
*buf, size_t len)
}
 
while (count < len - 1) {
+
+   /*
+* Get the initial burstcount to ensure TPM is ready to
+* accept data, even when waiting for burstcount is disabled.
+*/
burstcnt = get_burstcount(chip);
if (burstcnt < 0) {
dev_err(>dev, "Unable to read burstcount\n");
rc = burstcnt;
goto out_err;
}
-   burstcnt = min_t(int, burstcnt, len - count - 1);
+
+   if (ignore_burst_count)
+   sendcnt = len - 1;
+   else
+   sendcnt = min_t(int, burstcnt, len - count - 1);
+
rc = tpm_tis_write_bytes(priv, TPM_DATA_FIFO(priv->locality),
-burstcnt, buf + count);
+sendcnt, buf + count);
if (rc < 0)
goto out_err;
 
-   count += burstcnt;
+   count += sendcnt;
+   if (ignore_burst_count)
+   continue;
 
if (wait_for_tpm_stat(chip, TPM_STS_VALID, chip->timeout_c,
>int_queue, false) < 0) {
-- 
2.13.3


--
Check out the vibrant tech community on one of the world's most
engaging tech sites, Slashdot.org! http://sdm.link/s

[tpmdd-devel] [PATCH v2 0/4] additional TPM performance improvements

2017-09-06 Thread Nayna Jain
After further discussions with the Device Driver working group (ddwg),
the following changes were made: 

* Check for burstcount at least once to confirm the TPM is ready to accept
the data. Similarly, query for the TPM Expect status as sanity check at
the end.

* Make the sleep for status check during send() in the loop less than
5msec.

* Make the sleep in the loop while querying for burstcount less than
5msec.

Below is the list of patches along with the performance improvements
seen with a TPM 1.2 with an 8 byte burstcount for 1000 extends: 

Patch|Improvement(time in sec)

tpm: ignore burstcount to improve tpm_tis| ~41 - ~14
send() performance.

tpm: define __wait_for_tpm_stat to specify   | ~14 - ~10
variable polling sleep time

tpm: reduce tpm_msleep() time in | ~10 - ~9
get_burstcount()

tpm: modify tpm_msleep() function to have| ~9 - ~8
max range

Changelog v2:

* Add module parameter to handle ignoring of burst count during
tpm tis send() operation.
* Add improvements over sleep time to reduce delays.

Nayna Jain (4):
  tpm: ignore burstcount to improve tpm_tis send() performance.
  tpm: define __wait_for_tpm_stat to specify variable polling sleep time
  tpm: reduce tpm_msleep() time in get_burstcount()
  tpm: use tpm_msleep() value as max delay

 Documentation/admin-guide/kernel-parameters.txt |  8 ++
 drivers/char/tpm/tpm-interface.c| 15 --
 drivers/char/tpm/tpm.h  |  7 +++--
 drivers/char/tpm/tpm_tis_core.c | 37 +++--
 4 files changed, 53 insertions(+), 14 deletions(-)

-- 
2.13.3


--
Check out the vibrant tech community on one of the world's most
engaging tech sites, Slashdot.org! http://sdm.link/slashdot
___
tpmdd-devel mailing list
tpmdd-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/tpmdd-devel


[tpmdd-devel] [PATCH] tpm: improve tpm_tis send() performance by ignoring burstcount

2017-08-07 Thread Nayna Jain
The TPM burstcount status indicates the number of bytes that can
be sent to the TPM without causing bus wait states.  Effectively,
it is the number of empty bytes in the command FIFO. Further,
some TPMs have a static burstcount, when the value remains zero
until the entire FIFO is empty.

This patch ignores burstcount, permitting wait states, and thus
writes the command as fast as the TPM can accept the bytes.
The performance of a 34 byte extend on a TPM 1.2 improved from
52 msec to 11 msec.

Suggested-by: Ken Goldman <kg...@linux.vnet.ibm.com> in
conjunction with the TPM Device Driver work group.
Signed-off-by: Nayna Jain <na...@linux.vnet.ibm.com>
Acked-by: Mimi Zohar <zo...@linux.vnet.ibm.com>
---
 drivers/char/tpm/tpm_tis_core.c | 45 ++---
 1 file changed, 2 insertions(+), 43 deletions(-)

diff --git a/drivers/char/tpm/tpm_tis_core.c b/drivers/char/tpm/tpm_tis_core.c
index b617b2eeb080..478cbc0f61c3 100644
--- a/drivers/char/tpm/tpm_tis_core.c
+++ b/drivers/char/tpm/tpm_tis_core.c
@@ -255,9 +255,7 @@ static int tpm_tis_recv(struct tpm_chip *chip, u8 *buf, 
size_t count)
 static int tpm_tis_send_data(struct tpm_chip *chip, u8 *buf, size_t len)
 {
struct tpm_tis_data *priv = dev_get_drvdata(>dev);
-   int rc, status, burstcnt;
-   size_t count = 0;
-   bool itpm = priv->flags & TPM_TIS_ITPM_WORKAROUND;
+   int rc, status;
 
status = tpm_tis_status(chip);
if ((status & TPM_STS_COMMAND_READY) == 0) {
@@ -270,49 +268,10 @@ static int tpm_tis_send_data(struct tpm_chip *chip, u8 
*buf, size_t len)
}
}
 
-   while (count < len - 1) {
-   burstcnt = get_burstcount(chip);
-   if (burstcnt < 0) {
-   dev_err(>dev, "Unable to read burstcount\n");
-   rc = burstcnt;
-   goto out_err;
-   }
-   burstcnt = min_t(int, burstcnt, len - count - 1);
-   rc = tpm_tis_write_bytes(priv, TPM_DATA_FIFO(priv->locality),
-burstcnt, buf + count);
-   if (rc < 0)
-   goto out_err;
-
-   count += burstcnt;
-
-   if (wait_for_tpm_stat(chip, TPM_STS_VALID, chip->timeout_c,
-   >int_queue, false) < 0) {
-   rc = -ETIME;
-   goto out_err;
-   }
-   status = tpm_tis_status(chip);
-   if (!itpm && (status & TPM_STS_DATA_EXPECT) == 0) {
-   rc = -EIO;
-   goto out_err;
-   }
-   }
-
-   /* write last byte */
-   rc = tpm_tis_write8(priv, TPM_DATA_FIFO(priv->locality), buf[count]);
+   rc = tpm_tis_write_bytes(priv, TPM_DATA_FIFO(priv->locality), len, buf);
if (rc < 0)
goto out_err;
 
-   if (wait_for_tpm_stat(chip, TPM_STS_VALID, chip->timeout_c,
-   >int_queue, false) < 0) {
-   rc = -ETIME;
-   goto out_err;
-   }
-   status = tpm_tis_status(chip);
-   if (!itpm && (status & TPM_STS_DATA_EXPECT) != 0) {
-   rc = -EIO;
-   goto out_err;
-   }
-
return 0;
 
 out_err:
-- 
2.13.3


--
Check out the vibrant tech community on one of the world's most
engaging tech sites, Slashdot.org! http://sdm.link/slashdot
___
tpmdd-devel mailing list
tpmdd-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/tpmdd-devel


Re: [tpmdd-devel] [PATCH] tpm: improve tpm_tis send() performance by ignoring burstcount

2017-08-07 Thread Nayna



On 08/07/2017 05:22 PM, Peter Huewe wrote:



Am 7. August 2017 13:46:32 MESZ schrieb Nayna Jain <na...@linux.vnet.ibm.com>:

The TPM burstcount status indicates the number of bytes that can
be sent to the TPM without causing bus wait states.  Effectively,
it is the number of empty bytes in the command FIFO. Further,
some TPMs have a static burstcount, when the value remains zero
until the entire FIFO is empty.

This patch ignores burstcount, permitting wait states, and thus
writes the command as fast as the TPM can accept the bytes.
The performance of a 34 byte extend on a TPM 1.2 improved from
52 msec to 11 msec.

Suggested-by: Ken Goldman <kg...@linux.vnet.ibm.com> in
conjunction with the TPM Device Driver work group.
Signed-off-by: Nayna Jain <na...@linux.vnet.ibm.com>
Acked-by: Mimi Zohar <zo...@linux.vnet.ibm.com>


Are you sure this is a good idea?
On lpc systems this more or less stalls the bus, including keyboard/mouse (if 
connected via superio lpc).


Thanks Peter for quick response.

I actually meant to post this patch as RFC. Sorry, missed that.
It was meant to be a starting place for the discussion related to 
burst_count.




On which systems have you tested this?
Spi/Lpc? Architecture?


Tested it with LPC on x86.



This might not be noticable for small transfers, but think about much larger 
transfers


I did the following testing:

* Ran a script with 1000 extends. This was to test continuous extends
which are generally in large numbers when IMA is enabled.

* Ran a command to ask TPM to hash big size file like 1MB. This was to
test the long command.

In both of the above cases, I didn't face any tpm specific errors.

Is there any test-script or test-cases which I can try to test the
scenario(stalling the bus, including keyboard/mouse) with the patch ?

Thanks & Regards,
   - Nayna




Imho: NACK from my side.

Thanks,
Peter


---
drivers/char/tpm/tpm_tis_core.c | 45
++---
1 file changed, 2 insertions(+), 43 deletions(-)

diff --git a/drivers/char/tpm/tpm_tis_core.c
b/drivers/char/tpm/tpm_tis_core.c
index b617b2eeb080..478cbc0f61c3 100644
--- a/drivers/char/tpm/tpm_tis_core.c
+++ b/drivers/char/tpm/tpm_tis_core.c
@@ -255,9 +255,7 @@ static int tpm_tis_recv(struct tpm_chip *chip, u8
*buf, size_t count)
static int tpm_tis_send_data(struct tpm_chip *chip, u8 *buf, size_t
len)
{
struct tpm_tis_data *priv = dev_get_drvdata(>dev);
-   int rc, status, burstcnt;
-   size_t count = 0;
-   bool itpm = priv->flags & TPM_TIS_ITPM_WORKAROUND;
+   int rc, status;

status = tpm_tis_status(chip);
if ((status & TPM_STS_COMMAND_READY) == 0) {
@@ -270,49 +268,10 @@ static int tpm_tis_send_data(struct tpm_chip
*chip, u8 *buf, size_t len)
}
}

-   while (count < len - 1) {
-   burstcnt = get_burstcount(chip);
-   if (burstcnt < 0) {
-   dev_err(>dev, "Unable to read burstcount\n");
-   rc = burstcnt;
-   goto out_err;
-   }
-   burstcnt = min_t(int, burstcnt, len - count - 1);
-   rc = tpm_tis_write_bytes(priv, TPM_DATA_FIFO(priv->locality),
-burstcnt, buf + count);
-   if (rc < 0)
-   goto out_err;
-
-   count += burstcnt;
-
-   if (wait_for_tpm_stat(chip, TPM_STS_VALID, chip->timeout_c,
-   >int_queue, false) < 0) {
-   rc = -ETIME;
-   goto out_err;
-   }
-   status = tpm_tis_status(chip);
-   if (!itpm && (status & TPM_STS_DATA_EXPECT) == 0) {
-   rc = -EIO;
-   goto out_err;
-   }
-   }
-
-   /* write last byte */
-   rc = tpm_tis_write8(priv, TPM_DATA_FIFO(priv->locality), buf[count]);
+   rc = tpm_tis_write_bytes(priv, TPM_DATA_FIFO(priv->locality), len,
buf);
if (rc < 0)
goto out_err;

-   if (wait_for_tpm_stat(chip, TPM_STS_VALID, chip->timeout_c,
-   >int_queue, false) < 0) {
-   rc = -ETIME;
-   goto out_err;
-   }
-   status = tpm_tis_status(chip);
-   if (!itpm && (status & TPM_STS_DATA_EXPECT) != 0) {
-   rc = -EIO;
-   goto out_err;
-   }
-
return 0;

out_err:





--
Check out the vibrant tech community on one of the world's most
engaging tech sites, Slashdot.org! http://sdm.link/slashdot
___
tpmdd-devel mailing list
tpmdd-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/tpmdd-devel


Re: [tpmdd-devel] [RFC PATCH] tpm: msleep() delays - replace with usleep_range() in i2c nuvoton driver

2017-04-06 Thread Nayna
We continued analyzing the msleep() behaviour. I tested running msleep() 
(without TPM interactions), by writing a kernel module that runs 
msleep() in a loop for a fixed number of iterations.

Based on these test results, as shown below, the observations are:

1. Non-cascading timers, as introduced by commit 500462a9de65, is 
working as expected, since all the timers expired well within ring 0.
2. However, the minimum delay doubled, causing the average delay to 
increase by ~30%.

CONFIG_HZ = 250:

For 1000 iterations, each of 1 msecs
=

Kernel/Timer |   msleep  |usleep_range  |

4.7  | Min: 4.89, Avg: 8 | Min: 1.12 Avg: 1.58  |
4.10 | Min: 11.9, Avg: 11.19 | Min: 1.31 Avg: 1.36  |


For 3000 iterations, each of 1 msecs.
=

Kernel/Timer |msleep |usleep_range |

4.7  | Min: 6.55, Avg: 8.02  | Min: 1.05 Avg: 1.53 |
4.10 | Min: 11.8, Avg: 12.04 | Min: 1.02 Avg: 1.35 |


Thomas, can the minimum delay be improved ?

Thanks & Regards,
- Nayna



--
Check out the vibrant tech community on one of the world's most
engaging tech sites, Slashdot.org! http://sdm.link/slashdot
___
tpmdd-devel mailing list
tpmdd-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/tpmdd-devel


Re: [tpmdd-devel] [PATCH 0/4] Extend TPM 2.0 PCR banks each with corresponding digest

2017-04-05 Thread Nayna


On 03/30/2017 04:37 PM, Roberto Sassu wrote:
> On 3/30/2017 11:16 AM, Nayna wrote:
>> Why can't we export existing tpm2_pcr_extend() and use that directly ?
>
> tpm2_pcr_extend() requires the tpm_chip structure, which is
> not exposed outside. Translation from chip_num to tpm_chip
> should be done in tpm-interface.c (see tpm_seal_trusted()).

I was thinking why are we not changing tpm2_pcr_extend() itself to 
accept chip_num, but now I see how it is done in tpm_seal_trusted().

Thanks !!

Thanks & Regards,
- Nayna

>
> Roberto
>


--
Check out the vibrant tech community on one of the world's most
engaging tech sites, Slashdot.org! http://sdm.link/slashdot
___
tpmdd-devel mailing list
tpmdd-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/tpmdd-devel


Re: [tpmdd-devel] [PATCH 0/4] Add support for TPM2 log reported via ACPI table

2017-04-03 Thread Nayna


On 03/30/2017 01:43 PM, Petr Vandrovec wrote:
> Nayna wrote:
>>
>>
>> On 03/29/2017 01:13 PM, Petr Vandrovec wrote:
>>> Hi Peter,
>>>
>>> This series of 4 patches adds support for handling TPM2
>>> log when it is reported through ACPI TPM2 table, as
>>> described in latest TPM ACPI draft (Version 1.2, Revision 8,
>>> from February 27th, 2017).
>>>
>>> I've tested patch on x86 only - I do not have PPC64 system
>>> with TPM, and handling of endianness between tpm1_eventlog.c
>>> and tpm2_eventlog.c seems inconsistent: tpm1_eventlog.c uses
>>> be32_to_cpu() for all log fields on PPC64, while
>>> tpm2_eventlog.c uses log uses native endianness. If it
>>> is intentional, and PPC64 has TPM1 logs in big endian
>>
>> Yes, in case of ppc64, the tpm1 code logs are in big endian format.
>
> Thanks.  What about tpm2 logs?  Is first (specid) event in big endian
> format too, or no?

For TPM2 logs, all the events including the first one, are in little endian.

Sorry for delay in response.

Thanks & Regards,
- Nayna

>
>>> while TPM2 logs in native endianness, then 3rd patch
>>> needs to be amended.
>>>
>>> Four patches split task of improving TPM2 support into following
>>> subtasks:
>>>
>>>
>>> 1. Add log start/length fields to TPM2 table
>>>
>>> This patch adds 1.2 rev 8 structures to TPM2 table, and
>>> modifies tpm_tis and tpm_crb to use
>>> offsetofend(tpm2, field_accessed) rather than sizeof(tpm2)
>>> to verify that TPM2 table is big enough.
>>>
>>>
>>> 2. Read TCG log from TPM2 table
>>>
>>> This patch modifies tpm_acpi code to read log start/length
>>> from TPM2 table similar way it does so from TCPA table.
>>>
>>>
>>> 3. Autodetect TCG event log version
>>>
>>> This patch modifies tpm1_eventlog to make decision whether
>>> to use TPM1 or TPM2 format based on log content, rather
>>> than from chip version: on x86 there is dozen of firmwares
>>> that use TPM1 log with TPM2 chip.
>>
>> Do you mean firmware support TPM1 log as only SHA1 log format and not
>> crypto agile log with only SHA1 ?
>
> Yes.  See f.e. 'TPM2 Preboot Event Log' paragraph in
> https://twobit.us/2016/05/tpm2-uefi-measurements-and-event-log/.
>
> If you think there is no need to support such obscure hardware (it does
> not support this year's draft of TPM2 ACPI spec as hardware is few years
> old, so it would matter only if boot loader would pass log address to
> the kernel, and currently there is no support for this in the kernel), I
> can move validation of header event to tpm2_eventlog.c, and simply
> reject any non-specid log with TPM2.
>  Petr
>
>> Thanks & Regards,
>> - Nayna
>>
>>>
>>> Other part of the change is to validate content of specid
>>> event to make sure kernel does not crash when faced with
>>> specid event that claims there is 2^32-1 hashes in the
>>> event list.
>>>
>>>
>>> 4. Improve handling of TPM2 event logs
>>>
>>> Current code does not report any error when digest's hash
>>> is not listed in specid event, or if event reports 2^32-1
>>> digests (which is BIOS bug), or if event has more than
>>> 3 digests (that is kernel bug). Instead it will try to
>>> vmalloc() all available memory when event log is read by
>>> userspace application.
>>>
>>> This patch updates code so that it can handle arbitrary
>>> number of digests, as long as they are all described
>>> in specid event, and stops parsing as soon as any malformed
>>> event is detected.
>>>
>>>
>>> Let me know if there are any improvements I can make to
>>> this patch series.
>>>
>>> Thanks,
>>> Petr Vandrovec
>>>
>>>
>>> --
>>>
>>>
>>> Check out the vibrant tech community on one of the world's most
>>> engaging tech sites, Slashdot.org! http://sdm.link/slashdot
>>> ___
>>> tpmdd-devel mailing list
>>> tpmdd-devel@lists.sourceforge.net
>>> https://lists.sourceforge.net/lists/listinfo/tpmdd-devel
>>>
>>
>


--
Check out the vibrant tech community on one of the world's most
engaging tech sites, Slashdot.org! http://sdm.link/slashdot
___
tpmdd-devel mailing list
tpmdd-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/tpmdd-devel


Re: [tpmdd-devel] [PATCH 0/4] Extend TPM 2.0 PCR banks each with corresponding digest

2017-03-30 Thread Nayna


On 03/29/2017 03:54 PM, Roberto Sassu wrote:
> tpm_pcr_extend() was originally designed to extend a TPM 1.2 PCR with
> a SHA1 digest. With TPM 2.0, multiple hash algorithms can be supported,
> but, at the moment, only one digest can be passed to the function.
>
> Since TCG mandates that all PCR banks must be extended, commit c1f92b4
> (tpm: enhance TPM 2.0 PCR extend to support multiple banks) filled
> the gap by padding the SHA1 digest passed to tpm_pcr_extend(), to extend
> remaining PCR banks.
>
> This patch set adds support for providing a digest for each PCR bank.
>
> The first patch adds an additional check to tpm2_pcr_extend() to ensure
> that all digests have been provided (to meet TCG specs).
>
> The second patch provides a mechanism for TPM users to convert a TPM
> algorithm ID to a crypto ID and vice-versa, so that they can calculate
> the digest of an event data by using the crypto subsystem.
>
> The third patch allows TPM users to know which hash algorithms the TPM
> supports. Since the limit of active banks is fixed (the size of the
> active_banks array in the tpm_chip structure), the new function
> tpm_pcr_algorithms() accepts as input a sized array.
>
> The fourth patch introduces tpm_pcr_extend_digests(), which accepts
> as input a sized array of tpm2_digest structures. Each array element
> contains the algorithm and the digest for a PCR bank.

Why can't we export existing tpm2_pcr_extend() and use that directly ?

Thanks & Regards,
 - Nayna


>
> Roberto Sassu (4):
>tpm: check whether all digests have been provided for TPM 2.0 extend
>tpm: introduce tpm2_pcr_algo_to_crypto() and
>  tpm2_pcr_algo_from_crypto()
>tpm: introduce tpm_pcr_algorithms()
>tpm: introduce tpm_extend_pcr_digests()
>
>   drivers/char/tpm/tpm-interface.c | 121 
> +++
>   drivers/char/tpm/tpm.h   |  19 +-
>   drivers/char/tpm/tpm2-cmd.c  |  65 +++--
>   include/linux/tpm.h  |  44 ++
>   4 files changed, 200 insertions(+), 49 deletions(-)
>


--
Check out the vibrant tech community on one of the world's most
engaging tech sites, Slashdot.org! http://sdm.link/slashdot
___
tpmdd-devel mailing list
tpmdd-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/tpmdd-devel


Re: [tpmdd-devel] [PATCH 0/4] Add support for TPM2 log reported via ACPI table

2017-03-29 Thread Nayna


On 03/29/2017 01:13 PM, Petr Vandrovec wrote:
> Hi Peter,
>
> This series of 4 patches adds support for handling TPM2
> log when it is reported through ACPI TPM2 table, as
> described in latest TPM ACPI draft (Version 1.2, Revision 8,
> from February 27th, 2017).
>
> I've tested patch on x86 only - I do not have PPC64 system
> with TPM, and handling of endianness between tpm1_eventlog.c
> and tpm2_eventlog.c seems inconsistent: tpm1_eventlog.c uses
> be32_to_cpu() for all log fields on PPC64, while
> tpm2_eventlog.c uses log uses native endianness.  If it
> is intentional, and PPC64 has TPM1 logs in big endian

Yes, in case of ppc64, the tpm1 code logs are in big endian format.

> while TPM2 logs in native endianness, then 3rd patch
> needs to be amended.
>
> Four patches split task of improving TPM2 support into following
> subtasks:
>
>
> 1. Add log start/length fields to TPM2 table
>
> This patch adds 1.2 rev 8 structures to TPM2 table, and
> modifies tpm_tis and tpm_crb to use
> offsetofend(tpm2, field_accessed) rather than sizeof(tpm2)
> to verify that TPM2 table is big enough.
>
>
> 2. Read TCG log from TPM2 table
>
> This patch modifies tpm_acpi code to read log start/length
> from TPM2 table similar way it does so from TCPA table.
>
>
> 3. Autodetect TCG event log version
>
> This patch modifies tpm1_eventlog to make decision whether
> to use TPM1 or TPM2 format based on log content, rather
> than from chip version: on x86 there is dozen of firmwares
> that use TPM1 log with TPM2 chip.

Do you mean firmware support TPM1 log as only SHA1 log format and not 
crypto agile log with only SHA1 ?

Thanks & Regards,
- Nayna

>
> Other part of the change is to validate content of specid
> event to make sure kernel does not crash when faced with
> specid event that claims there is 2^32-1 hashes in the
> event list.
>
>
> 4. Improve handling of TPM2 event logs
>
> Current code does not report any error when digest's hash
> is not listed in specid event, or if event reports 2^32-1
> digests (which is BIOS bug), or if event has more than
> 3 digests (that is kernel bug).  Instead it will try to
> vmalloc() all available memory when event log is read by
> userspace application.
>
> This patch updates code so that it can handle arbitrary
> number of digests, as long as they are all described
> in specid event, and stops parsing as soon as any malformed
> event is detected.
>
>
> Let me know if there are any improvements I can make to
> this patch series.
>
> Thanks,
> Petr Vandrovec
>
>
> --
> Check out the vibrant tech community on one of the world's most
> engaging tech sites, Slashdot.org! http://sdm.link/slashdot
> ___
> tpmdd-devel mailing list
> tpmdd-devel@lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/tpmdd-devel
>


--
Check out the vibrant tech community on one of the world's most
engaging tech sites, Slashdot.org! http://sdm.link/slashdot
___
tpmdd-devel mailing list
tpmdd-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/tpmdd-devel


Re: [tpmdd-devel] [PATCH v1 1/2] tpm: msleep() delays - replace with usleep_range() in i2c nuvoton driver

2017-03-15 Thread Nayna


On 03/15/2017 09:22 PM, Jarkko Sakkinen wrote:
> On Fri, Mar 10, 2017 at 01:45:53PM -0500, Nayna Jain wrote:
>> Commit 500462a9de65 "timers: Switch to a non-cascading wheel" replaced
>> the 'classic' timer wheel, which aimed for near 'exact' expiry of the
>> timers.  Their analysis was that the vast majority of timeout timers
>> are used as safeguards, not as real timers, and are cancelled or
>> rearmed before expiration.  The only exception noted to this were
>> networking timers with a small expiry time.
>>
>> Not included in the analysis was the TPM polling timer, which resulted
>> in a longer normal delay and, every so often, a very long delay.  The
>> non-cascading wheel delay is based on CONFIG_HZ.  For a description of
>> the different rings and their delays, refer to the comments in
>> kernel/time/timer.c.
>>
>> Below are the delays given for rings 0 - 2, which explains the longer
>> "normal" delays and the very, long delays as seen on systems with
>> CONFIG_HZ 250.
>>
>> * HZ 1000 steps
>>   * Level Offset  GranularityRange
>>   *  0  0 1 ms0 ms - 63 ms
>>   *  1 64 8 ms   64 ms - 511 ms
>>   *  212864 ms  512 ms - 4095 ms (512ms - ~4s)
>>
>> * HZ  250
>>   * Level Offset  GranularityRange
>>   *  0  0 4 ms0 ms - 255 ms
>>   *  1 6432 ms  256 ms - 2047 ms (256ms - ~2s)
>>   *  2128   256 ms 2048 ms - 16383 ms (~2s - ~16s)
>>
>> Below is a comparison of extending the TPM with 1000 measurements,
>> using msleep() vs. usleep_delay() when configured for 1000 hz vs. 250
>> hz, before and after commit 500462a9de65.
>>
>> linux-4.7 | msleep() usleep_range()
>> 1000 hz: 0m44.628s | 1m34.497s 29.243s
>> 250 hz: 1m28.510s | 4m49.269s 32.386s
>>
>> linux-4.7  | min-max (msleep)  min-max (usleep_range)
>> 1000 hz: 0:017 - 2:760s | 0:015 - 3:967s0:014 - 0:418s
>> 250 hz: 0:028 - 1:954s | 0:040 - 4:096s    0:016 - 0:816s
>>
>> This patch replaces the msleep() with usleep_range() calls in the
>> i2c nuvoton driver with a consistent max range value.
>>
>> Signed-of-by: Mimi Zohar <zo...@linux.vnet.ibm.com>
>> Cc: sta...@vger.kernel.org (linux-4.8)
>> Signed-off-by: Nayna Jain <na...@linux.vnet.ibm.com>
>> ---
>> Changelog v1:
>>
>> - Included Jason's feedbacks related to #defines.
>
> What was changed?
>

Changelog v1:
 >>
 >> - Included Jason's feedbacks related to #defines.

Based on Jason's review:
- Added () in #define
- Replaced hardcoded maximum range value with defined name.

Hmm.. could have included exact details.

Thanks & Regards,
- Nayna

> /Jarkko
>


--
Check out the vibrant tech community on one of the world's most
engaging tech sites, Slashdot.org! http://sdm.link/slashdot
___
tpmdd-devel mailing list
tpmdd-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/tpmdd-devel


[tpmdd-devel] [PATCH v1 1/2] tpm: msleep() delays - replace with usleep_range() in i2c nuvoton driver

2017-03-10 Thread Nayna Jain
Commit 500462a9de65 "timers: Switch to a non-cascading wheel" replaced
the 'classic' timer wheel, which aimed for near 'exact' expiry of the
timers.  Their analysis was that the vast majority of timeout timers
are used as safeguards, not as real timers, and are cancelled or
rearmed before expiration.  The only exception noted to this were
networking timers with a small expiry time.

Not included in the analysis was the TPM polling timer, which resulted
in a longer normal delay and, every so often, a very long delay.  The
non-cascading wheel delay is based on CONFIG_HZ.  For a description of
the different rings and their delays, refer to the comments in
kernel/time/timer.c.

Below are the delays given for rings 0 - 2, which explains the longer
"normal" delays and the very, long delays as seen on systems with
CONFIG_HZ 250.

* HZ 1000 steps
 * Level Offset  GranularityRange
 *  0  0 1 ms0 ms - 63 ms
 *  1 64 8 ms   64 ms - 511 ms
 *  212864 ms  512 ms - 4095 ms (512ms - ~4s)

* HZ  250
 * Level Offset  GranularityRange
 *  0  0 4 ms0 ms - 255 ms
 *  1 6432 ms  256 ms - 2047 ms (256ms - ~2s)
 *  2128   256 ms 2048 ms - 16383 ms (~2s - ~16s)

Below is a comparison of extending the TPM with 1000 measurements,
using msleep() vs. usleep_delay() when configured for 1000 hz vs. 250
hz, before and after commit 500462a9de65.

linux-4.7 | msleep() usleep_range()
1000 hz: 0m44.628s | 1m34.497s 29.243s
250 hz: 1m28.510s | 4m49.269s 32.386s

linux-4.7  | min-max (msleep)  min-max (usleep_range)
1000 hz: 0:017 - 2:760s | 0:015 - 3:967s0:014 - 0:418s
250 hz: 0:028 - 1:954s | 0:040 - 4:096s0:016 - 0:816s

This patch replaces the msleep() with usleep_range() calls in the
i2c nuvoton driver with a consistent max range value.

Signed-of-by: Mimi Zohar <zo...@linux.vnet.ibm.com>
Cc: sta...@vger.kernel.org (linux-4.8)
Signed-off-by: Nayna Jain <na...@linux.vnet.ibm.com>
---
Changelog v1:

- Included Jason's feedbacks related to #defines.

 drivers/char/tpm/tpm_i2c_nuvoton.c | 23 +++
 1 file changed, 15 insertions(+), 8 deletions(-)

diff --git a/drivers/char/tpm/tpm_i2c_nuvoton.c 
b/drivers/char/tpm/tpm_i2c_nuvoton.c
index e3a9155..0c98c42 100644
--- a/drivers/char/tpm/tpm_i2c_nuvoton.c
+++ b/drivers/char/tpm/tpm_i2c_nuvoton.c
@@ -49,9 +49,10 @@
  */
 #define TPM_I2C_MAX_BUF_SIZE   32
 #define TPM_I2C_RETRY_COUNT32
-#define TPM_I2C_BUS_DELAY  1   /* msec */
-#define TPM_I2C_RETRY_DELAY_SHORT  2   /* msec */
-#define TPM_I2C_RETRY_DELAY_LONG   10  /* msec */
+#define TPM_I2C_BUS_DELAY  1000/* usec */
+#define TPM_I2C_RETRY_DELAY_SHORT  (2 * 1000)  /* usec */
+#define TPM_I2C_RETRY_DELAY_LONG   (10 * 1000) /* usec */
+#define TPM_I2C_DELAY_RANGE300 /* usec */
 
 #define OF_IS_TPM2 ((void *)1)
 #define I2C_IS_TPM2 1
@@ -123,7 +124,8 @@ static s32 i2c_nuvoton_write_status(struct i2c_client 
*client, u8 data)
/* this causes the current command to be aborted */
for (i = 0, status = -1; i < TPM_I2C_RETRY_COUNT && status < 0; i++) {
status = i2c_nuvoton_write_buf(client, TPM_STS, 1, );
-   msleep(TPM_I2C_BUS_DELAY);
+   usleep_range(TPM_I2C_BUS_DELAY, TPM_I2C_BUS_DELAY
++ TPM_I2C_DELAY_RANGE);
}
return status;
 }
@@ -160,7 +162,8 @@ static int i2c_nuvoton_get_burstcount(struct i2c_client 
*client,
burst_count = min_t(u8, TPM_I2C_MAX_BUF_SIZE, data);
break;
}
-   msleep(TPM_I2C_BUS_DELAY);
+   usleep_range(TPM_I2C_BUS_DELAY, TPM_I2C_BUS_DELAY
++ TPM_I2C_DELAY_RANGE);
} while (time_before(jiffies, stop));
 
return burst_count;
@@ -203,13 +206,17 @@ static int i2c_nuvoton_wait_for_stat(struct tpm_chip 
*chip, u8 mask, u8 value,
return 0;
 
/* use polling to wait for the event */
-   ten_msec = jiffies + msecs_to_jiffies(TPM_I2C_RETRY_DELAY_LONG);
+   ten_msec = jiffies + usecs_to_jiffies(TPM_I2C_RETRY_DELAY_LONG);
stop = jiffies + timeout;
do {
if (time_before(jiffies, ten_msec))
-   msleep(TPM_I2C_RETRY_DELAY_SHORT);
+   usleep_range(TPM_I2C_RETRY_DELAY_SHORT,
+TPM_I2C_RETRY_DELAY_SHORT
++ TPM_I2C_DELAY_RANGE);
else
-   msleep(TPM_I2C_RETRY_DELAY_LONG);
+  

Re: [tpmdd-devel] [PATCH v2 4/7] tpm: infrastructure for TPM spaces

2017-02-21 Thread Nayna


On 02/17/2017 12:55 AM, Jarkko Sakkinen wrote:
> Added 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.
>

If I have understood discussions correctly, I assume, that kernel TPM 
operations will also be routed via RM. And I think that is not happening 
now with these patches.

Am I missing something ?

Thanks & Regards,
- Nayna


> Signed-off-by: Jarkko Sakkinen <jarkko.sakki...@linux.intel.com>
> ---
>   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
>
> diff --git a/drivers/char/tpm/Makefile b/drivers/char/tpm/Makefile
> index 3d386a8..8f07fcf 100644
> --- a/drivers/char/tpm/Makefile
> +++ b/drivers/char/tpm/Makefile
> @@ -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
> diff --git a/drivers/char/tpm/tpm-chip.c b/drivers/char/tpm/tpm-chip.c
> index c406343..993b9ae 100644
> --- a/drivers/char/tpm/tpm-chip.c
> +++ b/drivers/char/tpm/tpm-chip.c
> @@ -128,6 +128,7 @@ static void tpm_dev_release(struct device *dev)
>   mutex_unlock(_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 = >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:
> diff --git a/drivers/char/tpm/tpm-dev.c b/drivers/char/tpm/tpm-dev.c
> index 02a8850..414553b 100644
> --- a/drivers/char/tpm/tpm-dev.c
> +++ b/drivers/char/tpm/tpm-dev.c
> @@ -147,7 +147,7 @@ static ssize_t tpm_write(struct file *file, const char 
> __user *buf,
>   mutex_unlock(>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);
> diff --git a/drivers/char/tpm/tpm-interface.c 
> b/drivers/char/tpm/tpm-interface.c
> index 20b1fe3..db5ffe9 100644
> --- a/drivers/char/tpm/tpm-interface.c
> +++ b/drivers/char/tpm/tpm-interface.c
> @@ -376,11 +376,12 @@ static bool tpm_validate_command(struct tpm_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)
>   {
> - const struct tpm_output_header *header = (void *)buf;
> - ssize_t rc;
> + struct tpm_output_header *header = (void *)buf;
> + int rc;
> + ssize_t len = 0;
>   u32 count,

Re: [tpmdd-devel] [PATCH] tpm: declare tpm2_get_pcr_allocation() as static

2017-02-20 Thread Nayna


On 02/17/2017 03:54 PM, Jarkko Sakkinen wrote:
> On Wed, Feb 15, 2017 at 08:02:28PM +0200, Jarkko Sakkinen wrote:
>> There's no need to export tpm2_get_pcr_alloation() because it is only
>> a helper function for tpm2_auto_startup(). For the same reason it does
>> not make much sense to maintain documentation for it.
>>
>> Signed-off-by: Jarkko Sakkinen <jarkko.sakki...@linux.intel.com>
>
> Nayna, does this look good to you?

Oops !! I don't know how it is missed. Sorry for that..My internet 
connection wasn't working since my Friday evening and just started 
working yesterday. So, probably somewhere got this missed and saw it today

It is fine and I already see it in PULL request. So, Thanks !!

Thanks & Regards,
- Nayna

>
> /Jarkko
>
>> ---
>>   drivers/char/tpm/tpm.h  |  1 -
>>   drivers/char/tpm/tpm2-cmd.c | 94 
>> ++---
>>   2 files changed, 45 insertions(+), 50 deletions(-)
>>
>> diff --git a/drivers/char/tpm/tpm.h b/drivers/char/tpm/tpm.h
>> index 6b4e7aa..4937b56 100644
>> --- a/drivers/char/tpm/tpm.h
>> +++ b/drivers/char/tpm/tpm.h
>> @@ -554,5 +554,4 @@ 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);
>> -ssize_t tpm2_get_pcr_allocation(struct tpm_chip *chip);
>>   #endif
>> diff --git a/drivers/char/tpm/tpm2-cmd.c b/drivers/char/tpm/tpm2-cmd.c
>> index 10f97e6..881aea9 100644
>> --- a/drivers/char/tpm/tpm2-cmd.c
>> +++ b/drivers/char/tpm/tpm2-cmd.c
>> @@ -997,61 +997,13 @@ int tpm2_probe(struct tpm_chip *chip)
>>   }
>>   EXPORT_SYMBOL_GPL(tpm2_probe);
>>
>> -/**
>> - * tpm2_auto_startup - Perform the standard automatic TPM initialization
>> - * sequence
>> - * @chip: TPM chip to use
>> - *
>> - * Returns 0 on success, < 0 in case of fatal error.
>> - */
>> -int tpm2_auto_startup(struct tpm_chip *chip)
>> -{
>> -int rc;
>> -
>> -rc = tpm_get_timeouts(chip);
>> -if (rc)
>> -goto out;
>> -
>> -rc = tpm2_do_selftest(chip);
>> -if (rc != 0 && rc != TPM2_RC_INITIALIZE) {
>> -dev_err(>dev, "TPM self test failed\n");
>> -goto out;
>> -}
>> -
>> -if (rc == TPM2_RC_INITIALIZE) {
>> -rc = tpm2_startup(chip, TPM2_SU_CLEAR);
>> -if (rc)
>> -goto out;
>> -
>> -rc = tpm2_do_selftest(chip);
>> -if (rc) {
>> -dev_err(>dev, "TPM self test failed\n");
>> -goto out;
>> -}
>> -}
>> -
>> -rc = tpm2_get_pcr_allocation(chip);
>> -
>> -out:
>> -if (rc > 0)
>> -rc = -ENODEV;
>> -return rc;
>> -}
>> -
>>   struct tpm2_pcr_selection {
>>  __be16  hash_alg;
>>  u8  size_of_select;
>>  u8  pcr_select[3];
>>   } __packed;
>>
>> -/**
>> - * tpm2_get_pcr_allocation() - get TPM active PCR banks.
>> - *
>> - * @chip: TPM chip to use.
>> - *
>> - * Return: Same as with tpm_transmit_cmd.
>> - */
>> -ssize_t tpm2_get_pcr_allocation(struct tpm_chip *chip)
>> +static ssize_t tpm2_get_pcr_allocation(struct tpm_chip *chip)
>>   {
>>  struct tpm2_pcr_selection pcr_selection;
>>  struct tpm_buf buf;
>> @@ -1114,3 +1066,47 @@ ssize_t tpm2_get_pcr_allocation(struct tpm_chip *chip)
>>
>>  return rc;
>>   }
>> +
>> +/**
>> + * tpm2_auto_startup - Perform the standard automatic TPM initialization
>> + * sequence
>> + * @chip: TPM chip to use
>> + *
>> + * Initializes timeout values for operation and command durations, conducts
>> + * a self-test and reads the list of active PCR banks.
>> + *
>> + * Return: 0 on success. Otherwise, a system error code is returned.
>> + */
>> +int tpm2_auto_startup(struct tpm_chip *chip)
>> +{
>> +int rc;
>> +
>> +rc = tpm_get_timeouts(chip);
>> +if (rc)
>> +goto out;
>> +
>> +rc = tpm2_do_selftest(chip);
>> +if (rc != 0 && rc != TPM2_RC_INITIALIZE) {
>> +dev_err(>dev, "TPM self test failed\n");
>> +goto out;
>> +}
>> +
>> +if (rc == TPM2_

Re: [tpmdd-devel] [PATCH] tpm: fix type issues in tpm_getcap()

2017-02-03 Thread Nayna


On 02/01/2017 11:23 PM, Jarkko Sakkinen wrote:
> There are two type issues associated with tpm_getcap().
>
> You must not do arithmetic with __be32 or __le32 types because sometimes
> it results incorrect results. Calculations must be done only with data
> that is in CPU byte order. This commit migrates tpm_getcap() to struct
> tpm_buf in order to sort out these issues.
>
> The second issue is with struct cap_t as the size of the type bool is
> assumed to be one byte. This commit sorts out the issue by changing the
> type to u8.
>
> Signed-off-by: Jarkko Sakkinen <jarkko.sakki...@linux.intel.com>
> ---
> v2:
> - Use struct tpm_buf.
> - Merge the type change of 'owned' to this patch.
>   drivers/char/tpm/tpm-interface.c | 33 ++---
>   drivers/char/tpm/tpm.h   | 15 +--
>   2 files changed, 19 insertions(+), 29 deletions(-)
>
> diff --git a/drivers/char/tpm/tpm-interface.c 
> b/drivers/char/tpm/tpm-interface.c
> index 423938e..7af1e8c 100644
> --- a/drivers/char/tpm/tpm-interface.c
> +++ b/drivers/char/tpm/tpm-interface.c
> @@ -480,31 +480,34 @@ static const struct tpm_input_header tpm_getcap_header 
> = {
>   ssize_t tpm_getcap(struct tpm_chip *chip, u32 subcap_id, cap_t *cap,
>  const char *desc, size_t min_cap_length)
>   {
> - struct tpm_cmd_t tpm_cmd;
> + struct tpm_buf buf;
>   int rc;
>
> - tpm_cmd.header.in = tpm_getcap_header;
> + rc = tpm_buf_init(, TPM_TAG_RQU_COMMAND, TPM_ORD_GET_CAP);

I think there is a problem here of twice converting to be32 for both tag 
and ordinal.

Both TPM_ORD_GET_CAP and TPM_TAG_RQU_COMMAND are already defined as:
#define TPM_ORD_GET_CAP cpu_to_be32(101)
#define TPM_TAG_RQU_COMMAND  cpu_to_be16(193)

and again converted to BE in tpm_buf_init().

Thanks & Regards,
- Nayna

> + if (rc)
> + return rc;
> +
>   if (subcap_id == TPM_CAP_VERSION_1_1 ||
>   subcap_id == TPM_CAP_VERSION_1_2) {
> - tpm_cmd.params.getcap_in.cap = cpu_to_be32(subcap_id);
> - /*subcap field not necessary */
> - tpm_cmd.params.getcap_in.subcap_size = cpu_to_be32(0);
> - tpm_cmd.header.in.length -= cpu_to_be32(sizeof(__be32));
> + tpm_buf_append_u32(, subcap_id);
> + tpm_buf_append_u32(, 0);
>   } else {
>   if (subcap_id == TPM_CAP_FLAG_PERM ||
>   subcap_id == TPM_CAP_FLAG_VOL)
> - tpm_cmd.params.getcap_in.cap =
> - cpu_to_be32(TPM_CAP_FLAG);
> + tpm_buf_append_u32(, TPM_CAP_FLAG);
>   else
> - tpm_cmd.params.getcap_in.cap =
> - cpu_to_be32(TPM_CAP_PROP);
> - tpm_cmd.params.getcap_in.subcap_size = cpu_to_be32(4);
> - tpm_cmd.params.getcap_in.subcap = cpu_to_be32(subcap_id);
> + tpm_buf_append_u32(, TPM_CAP_PROP);
> +
> + tpm_buf_append_u32(, 4);
> + tpm_buf_append_u32(, subcap_id);
>   }
> - rc = tpm_transmit_cmd(chip, _cmd, TPM_INTERNAL_RESULT_SIZE,
> -   min_cap_length, 0, desc);
> +
> + rc = tpm_transmit_cmd(chip, buf.data, PAGE_SIZE, min_cap_length, 0,
> +   desc);
>   if (!rc)
> - *cap = tpm_cmd.params.getcap_out.cap;
> + *cap = *(cap_t *)[TPM_HEADER_SIZE + 4];
> +
> + tpm_buf_destroy();
>   return rc;
>   }
>   EXPORT_SYMBOL_GPL(tpm_getcap);
> diff --git a/drivers/char/tpm/tpm.h b/drivers/char/tpm/tpm.h
> index bff37be..709e7d4 100644
> --- a/drivers/char/tpm/tpm.h
> +++ b/drivers/char/tpm/tpm.h
> @@ -281,7 +281,7 @@ struct permanent_flags_t {
>   typedef union {
>   struct  permanent_flags_t perm_flags;
>   struct  stclear_flags_t stclear_flags;
> - boolowned;
> + u8  owned;
>   __be32  num_pcrs;
>   struct  tpm_version_t   tpm_version;
>   struct  tpm_version_1_2_t tpm_version_1_2;
> @@ -307,17 +307,6 @@ enum tpm_sub_capabilities {
>   TPM_CAP_PROP_TIS_DURATION = 0x120,
>   };
>
> -struct   tpm_getcap_params_in {
> - __be32  cap;
> - __be32  subcap_size;
> - __be32  subcap;
> -} __packed;
> -
> -struct   tpm_getcap_params_out {
> - __be32  cap_size;
> - cap_t   cap;
> -} __packed;
> -
>   struct  tpm_readpubek_params_out {
>   u8  algorithm[4];
>   u8  encscheme[2];
> @@ -367,10 +356,8 @@ struct tpm_startup_in {
>   } __packed;
>
>   typedef union {
> - struct  tpm_getcap_params_out getcap_out;
>   struct  tpm_readpubek_params_out readpubek_out;
&g

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

2017-01-31 Thread Nayna


On 02/01/2017 02:20 AM, Jarkko Sakkinen wrote:
> On Wed, Feb 01, 2017 at 12:14:12AM +0530, Nayna wrote:
>>> I already sent my pull request to 4.11 and even today I found something
>>> fishy. You declared a function local array by using a variable in "tpm:
>>> enhance TPM 2.0 PCR extend to support multiple banks" (max_active_banks
>>> or something). And the event log patches have just passed the review.
>>
>> Yes. I have checked using clang and it has passed the clang.. and I also
>> verified there were no complains during build.
>
> What we can deduce from that is that they didn't expose the issue in
> question.
>
> I found this by running sparse with make C=2 M=drives/char/tpm
>
>> What type of problem do you see ?
>
> It is disallowed to do stack allocation in the kernel code even if C
> standard would allow it. Stack is scarce resource so you need to know
> its usage at compile time.
>
> In this case you actually know the allocation because the value is not
> changed during the course of the function but it is still bad. Probably
> compiler will optimize it out. Still it is not a good practice.

Thanks Jarkko for explaining it.

Hmm, do you want me to send a patch for this ?
I think what we want is actually define it just array of size as 7.

>
>> Also, to understand, this is related to multi-bank patchset. I mean how does
>> it affect for event log patchset ?
>
> Well in both cases these have landed fairly late but I asked from James
> whether I'll have to postpone these to 4.12.
>
> Usually when I've sent my release pull request I do not want to make any
> radical changes to the codebase because they always require extra QA and
> thus take extra time.

Thanks again for explaining details.

Thanks & Regards,
- Nayna

>
> /Jarkko
>


--
Check out the vibrant tech community on one of the world's most
engaging tech sites, SlashDot.org! http://sdm.link/slashdot
___
tpmdd-devel mailing list
tpmdd-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/tpmdd-devel


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

2017-01-31 Thread Nayna


On 01/31/2017 11:16 PM, Jarkko Sakkinen wrote:
> On Mon, Jan 30, 2017 at 03:08:42PM +0530, Nayna wrote:
>>
>>> From: "Ken Goldman" <kg...@linux.vnet.ibm.com
>>> <mailto:kg...@linux.vnet.ibm.com>>
>>> Date: 26-Jan-2017 2:53 AM
>>> Subject: Re: [tpmdd-devel] [PATCH v9 2/2] tpm: add securityfs
>>> support,for TPM 2.0 firmware event log
>>> To: <linux-ker...@vger.kernel.org
>>> <mailto:linux-ker...@vger.kernel.org>>,
>>> <linux-security-mod...@vger.kernel.org
>>> <mailto:linux-security-mod...@vger.kernel.org>>,
>>> <tpmdd-devel@lists.sourceforge.net
>>> <mailto:tpmdd-devel@lists.sourceforge.net>>
>>> Cc:
>>>
>>>  You do not need to send a new patch set version as long as this
>>>  one gets peer tested. And it needs to be tested without hacks
>>>  like plumbing TCPA with TPM 2.0 in QEMU. OF code paths needs to
>>>  be peer tested to be more specific.
>>>
>>>  For me the code itself looks good but I simply cannot take it in
>>>  in the current situation.
>>>
>>>  /Jarkko
>>>
>>>
>>> Tested-by: Kenneth Goldman <kg...@linux.vnet.ibm.com
>>> <mailto:kg...@linux.vnet.ibm.com>>
>>>
>>> I validated a firmware event log taken from a Power 8 against PCR 0-7
>>> values for the SHA-1 and SHA-256 banks from a Nuvoton TPM 2.0 chip on
>>> that same platform.
>>>
>>
>> Thank You Ken.
>>
>> Jarkko, I hope now these patches can be accepted for 4.11.
>>
>> Thanks & Regards,
>> - Nayna
>
> I already sent my pull request to 4.11 and even today I found something
> fishy. You declared a function local array by using a variable in "tpm:
> enhance TPM 2.0 PCR extend to support multiple banks" (max_active_banks
> or something). And the event log patches have just passed the review.

Yes. I have checked using clang and it has passed the clang.. and I also 
verified there were no complains during build.

What type of problem do you see ?

Also, to understand, this is related to multi-bank patchset. I mean how 
does it affect for event log patchset ?

Thanks & Regards,
- Nayna

>
> I've applied them to my tree but I'll only include bug fixes for 4.11
> pull requests. You'll have to wait till' 4.12.
>
> /Jarkko
>


--
Check out the vibrant tech community on one of the world's most
engaging tech sites, SlashDot.org! http://sdm.link/slashdot
___
tpmdd-devel mailing list
tpmdd-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/tpmdd-devel


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

2017-01-30 Thread Nayna


On 01/26/2017 03:41 AM, Ken Goldman 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 them.
>>
>> The existing in-kernel interface(tpm_pcr_extend()) expects only a
>> SHA1 digest.  To extend all active PCR banks with differing
>> digest sizes, the SHA1 digest is padded with trailing 0's as needed.
>>
>> This patch reuses the defined digest sizes from the crypto subsystem,
>> adding a dependency on CRYPTO_HASH_INFO module.
>>
>> [1] TPM 2.0 Specification referred here is "TCG PC Client Specific
>> Platform Firmware Profile for TPM 2.0"
>
> Tested-by: Kenneth Goldman <kg...@linux.vnet.ibm.com>
>
> I obtained an IMA event log from a Power platform, along with the PCR 10
> value from both the SHA-1 and SHA-256 banks of its Nuvoton TPM 2.0.  I
> independently validated that the event log matches the TPM PCR values.

Thank You Ken !!

Thanks & Regards,
- Nayna

>
>
> --
> Check out the vibrant tech community on one of the world's most
> engaging tech sites, SlashDot.org! http://sdm.link/slashdot
> ___
> tpmdd-devel mailing list
> tpmdd-devel@lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/tpmdd-devel
>


--
Check out the vibrant tech community on one of the world's most
engaging tech sites, SlashDot.org! http://sdm.link/slashdot
___
tpmdd-devel mailing list
tpmdd-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/tpmdd-devel


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

2017-01-30 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 <na...@linux.vnet.ibm.com>
Reviewed-by: Jarkko Sakkinen <jarkko.sakki...@linux.intel.com>
Tested-by: Kenneth Goldman <kg...@linux.vnet.ibm.com>
---
 drivers/char/tpm/tpm.h  |  5 +++
 drivers/char/tpm/tpm2-cmd.c | 77 +
 2 files changed, 82 insertions(+)

diff --git a/drivers/char/tpm/tpm.h b/drivers/char/tpm/tpm.h
index dbe0c5a..db0398a 100644
--- a/drivers/char/tpm/tpm.h
+++ b/drivers/char/tpm/tpm.h
@@ -97,6 +97,7 @@ enum tpm2_return_codes {
 };
 
 enum tpm2_algorithms {
+   TPM2_ALG_ERROR  = 0x,
TPM2_ALG_SHA1   = 0x0004,
TPM2_ALG_KEYEDHASH  = 0x0008,
TPM2_ALG_SHA256 = 0x000B,
@@ -127,6 +128,7 @@ enum tpm2_permanent_handles {
 };
 
 enum tpm2_capabilities {
+   TPM2_CAP_PCRS   = 5,
TPM2_CAP_TPM_PROPERTIES = 6,
 };
 
@@ -187,6 +189,8 @@ struct tpm_chip {
 
const struct attribute_group *groups[3];
unsigned int groups_cnt;
+
+   u16 active_banks[7];
 #ifdef CONFIG_ACPI
acpi_handle acpi_dev_handle;
char ppi_version[TPM_PPI_VERSION_LEN + 1];
@@ -540,4 +544,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);
+ssize_t tpm2_get_pcr_allocation(struct tpm_chip *chip);
 #endif
diff --git a/drivers/char/tpm/tpm2-cmd.c b/drivers/char/tpm/tpm2-cmd.c
index 42fe3dd..6fbd42c 100644
--- a/drivers/char/tpm/tpm2-cmd.c
+++ b/drivers/char/tpm/tpm2-cmd.c
@@ -1030,3 +1030,80 @@ int tpm2_auto_startup(struct tpm_chip *chip)
rc = -ENODEV;
return rc;
 }
+
+struct tpm2_pcr_selection {
+   __be16  hash_alg;
+   u8  size_of_select;
+   u8  pcr_select[3];
+} __packed;
+
+/**
+ * tpm2_get_pcr_allocation() - get TPM active PCR banks.
+ *
+ * @chip: TPM chip to use.
+ *
+ * Return: Same as with tpm_transmit_cmd.
+ */
+ssize_t tpm2_get_pcr_allocation(struct tpm_chip *chip)
+{
+   struct tpm2_pcr_selection pcr_selection;
+   struct tpm_buf buf;
+   void *marker;
+   void *end;
+   void *pcr_select_offset;
+   unsigned int count;
+   u32 sizeof_pcr_selection;
+   u32 rsp_len;
+   int rc;
+   int i = 0;
+
+   rc = tpm_buf_init(, TPM2_ST_NO_SESSIONS, TPM2_CC_GET_CAPABILITY);
+   if (rc)
+   return rc;
+
+   tpm_buf_append_u32(, TPM2_CAP_PCRS);
+   tpm_buf_append_u32(, 0);
+   tpm_buf_append_u32(, 1);
+
+   rc = tpm_transmit_cmd(chip, buf.data, PAGE_SIZE, 9, 0,
+ "get tpm pcr allocation");
+   if (rc)
+   goto out;
+
+   count = be32_to_cpup(
+   (__be32 *)[TPM_HEADER_SIZE + 5]);
+
+   if (count > ARRAY_SIZE(chip->active_banks)) {
+   rc = -ENODEV;
+   goto out;
+   }
+
+   marker = [TPM_HEADER_SIZE + 9];
+
+   rsp_len = be32_to_cpup((__be32 *)[2]);
+   end = [rsp_len];
+
+   for (i = 0; i < count; i++) {
+   pcr_select_offset = marker +
+   offsetof(struct tpm2_pcr_selection, size_of_select);
+   if (pcr_select_offset >= end) {
+   rc = -EFAULT;
+   break;
+   }
+
+   memcpy(_selection, marker, sizeof(pcr_selection));
+   chip->active_banks[i] = be16_to_cpu(pcr_selection.hash_alg);
+   sizeof_pcr_selection = sizeof(pcr_selection.hash_alg) +
+   sizeof(pcr_selection.size_of_select) +
+   pcr_selection.size_of_select;
+   marker = marker + sizeof_pcr_selection;
+   }
+
+out:
+   if (i < ARRAY_SIZE(chip->active_banks))
+   chip->active_banks[i] = TPM2_ALG_ERROR;
+
+   tpm_buf_destroy();
+
+   return rc;
+}
-- 
2.5.0


--
Check out the vibrant tech community on one of the world's most
engaging tech sites, SlashDot.org! http://sdm.link/slashdot
___
tpmdd-devel mailing list
tpmdd-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/tpmdd-devel


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

2017-01-30 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 prevent malicious users from
setting unused PCR banks with fake measurements and quoting them.
This patch set adds support for extending all active PCR banks,
as recommended.

The first patch implements the TPM 2.0 capability to retrieve
the list of active PCR banks.

The second patch modifies the tpm_pcr_extend() and tpm2_pcr_extend()
interface to support extending multiple PCR banks. The existing
tpm_pcr_extend() interface expects only a SHA1 digest. Hence, to
extend all active PCR banks with differing digest sizes for TPM 2.0,
the SHA1 digest is padded with 0's as needed.

[1] TPM 2.0 Specification referred here is "TCG PC Client Specific
Platform Firmware Profile for TPM 2.0"

Changelog v7:
- Patch "tpm: implement TPM 2.0 capability to get active PCR banks"
 - Fixed missing TPM error handling in tpm2_get_pcr_allocation().
 Thanks Jarkko for noticing it.
 - Included Stefan's suggestion on adding buffer access check.
- Patch "tpm: enchance TPM 2.0 PCR extend to support multiple banks"
 - Moved tpm2_digest and include for hash_info.h in tpm.h. tpm_eventlog.h
 has no modifications now.

Changelog v6:
- Patch "tpm: implement TPM 2.0 capability to get active PCR banks"
  - Fixed the regression - missing tpm_buf_destroy() in
  in tpm2_get_pcr_allocation(). Thanks Jarkko for noticing.
  - Added TPM2_ALG_ERROR = 0x to represent invalid algorithm.

Changelog v5:
- Patch "tpm: implement TPM 2.0 capability to get active PCR banks"
 - Included Jarkko's feedbacks
   - Moved variable declaration to start of function in
   tpm_pcr_extend()


Changelog v4:
- Updated cover letter as per Mimi's feedback.
- Rebased to Jarkko's latest master branch (4064b6b tpm_tis: use
  default timeout value if chip reports it as zero)
- Patch "tpm: implement TPM 2.0 capability to get active PCR banks"
 - Included Jarkko's feedbacks
   - Moved call to tpm2_get_pcr_allocation to Patch 2
   - Renamed struct tpm2_tpms_pcr_selection to struct tpm2_pcr_selection 
   and moved the struct to before tpm2_get_pcr_allocation()
   - Fixed code formatting
- Patch "tpm: enchance TPM 2.0 PCR extend to support multiple banks"
 - Included Jarkkos' feedbacks
   - Updated commit msg to mention dependency on CRYPTO_HASH_INFO
   - Renamed struct tpmt_hash to struct tpm2_digest 
   - Removed struct tpml_digest_values, tpm2_pcr_extend() now accepts
   count and digests list as two separate arguments. Added check for
   count of hashes passed.
 - Cleaned up struct tpm2_pcr_extend_in as not required anymore with
 use of tpm_buf
 - Moved struct tpm2_null_auth_area just before tpm2_pcr_extend() as
 it is the only function using it for now.
 - Fixed code formatting

Changelog v3:
- Rebased to the Jarkko's latest master branch (8e25809 tpm:
  Do not print an error message when doing TPM auto startup)
- Patch "tpm: implement TPM 2.0 capability to get active PCR banks"
  - Included Jarkko's feedbacks
 - Removed getcap_in, getcap_out and used tpm_buf for getting
 capability.
 - Used ARRAY_SIZE in place of TPM_MAX_PCR_BANKS and included
 other feedbacks.
- Patch "tpm: enhance TPM 2.0 PCR extend to support multiple banks"
 - Fixed kbuild errors
   - Fixed buf.data uninitialized warning.
   - Added TCG_TPM dependency on CONFIG_CRYPTO_HASH_INFO in Kconfig.

Changelog v2:

- Patch "tpm: implement TPM 2.0 capability to get active PCR banks"
  - defined structs definition in tpm2-cmd.c.
  - no_of_active_banks field is removed. Instead, constant
  TPM2_MAX_PCR_BANKS is defined.
  - renamed tpm2_get_active_pcr_banks() to tpm2_get_pcr_allocation()
  - removed generic function tpm2_get_capability().

- Patch "tpm: enchance TPM 2.0 PCR extend to support multiple banks"
 - Removed tpm2.h, and defined structs common for extend and event log
  in tpm_eventlog.h
 - uses tpm_buf in tpm2_pcr_extend().

Nayna Jain (2):
  tpm: implement TPM 2.0 capability to get active PCR banks
  tpm: enhance TPM 2.0 PCR extend to support multiple banks

 drivers/char/tpm/Kconfig |   1 +
 drivers/char/tpm/tpm-interface.c |  15 +++-
 drivers/char/tpm/tpm.h   |  14 +++-
 drivers/char/tpm/tpm2-cmd.c  | 168 +--
 4 files changed, 154 insertions(+), 44 deletions(-)

-- 
2.5.0


--
Check out the vibrant tech community on one of the world's most
engaging tech sites, SlashDot.org! http://sdm.link/slashdot
___
tpmdd-devel mailing list
tpmdd-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/tpmdd-devel


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

2017-01-30 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 a
SHA1 digest.  To extend all active PCR banks with differing
digest sizes, the SHA1 digest is padded with trailing 0's as needed.

This patch reuses the defined digest sizes from the crypto subsystem,
adding a dependency on CRYPTO_HASH_INFO module.

[1] TPM 2.0 Specification referred here is "TCG PC Client Specific
Platform Firmware Profile for TPM 2.0"

Signed-off-by: Nayna Jain <na...@linux.vnet.ibm.com>
---
 drivers/char/tpm/Kconfig |  1 +
 drivers/char/tpm/tpm-interface.c | 15 ++-
 drivers/char/tpm/tpm.h   |  9 +++-
 drivers/char/tpm/tpm2-cmd.c  | 91 +---
 4 files changed, 72 insertions(+), 44 deletions(-)

diff --git a/drivers/char/tpm/Kconfig b/drivers/char/tpm/Kconfig
index 277186d..af985cc 100644
--- a/drivers/char/tpm/Kconfig
+++ b/drivers/char/tpm/Kconfig
@@ -6,6 +6,7 @@ menuconfig TCG_TPM
tristate "TPM Hardware Support"
depends on HAS_IOMEM
select SECURITYFS
+   select CRYPTO_HASH_INFO
---help---
  If you have a TPM security chip in your system, which
  implements the Trusted Computing Group's specification,
diff --git a/drivers/char/tpm/tpm-interface.c b/drivers/char/tpm/tpm-interface.c
index 2ea16ab..7fa05a9 100644
--- a/drivers/char/tpm/tpm-interface.c
+++ b/drivers/char/tpm/tpm-interface.c
@@ -789,13 +789,26 @@ int tpm_pcr_extend(u32 chip_num, int pcr_idx, const u8 
*hash)
struct tpm_cmd_t cmd;
int rc;
struct tpm_chip *chip;
+   int max_active_banks = ARRAY_SIZE(chip->active_banks);
+   struct tpm2_digest digest_list[max_active_banks];
+   u32 count = 0;
+   int i;
 
chip = tpm_chip_find_get(chip_num);
if (chip == NULL)
return -ENODEV;
 
if (chip->flags & TPM_CHIP_FLAG_TPM2) {
-   rc = tpm2_pcr_extend(chip, pcr_idx, hash);
+   memset(digest_list, 0, sizeof(digest_list));
+
+   for (i = 0; (chip->active_banks[i] != TPM2_ALG_ERROR) &&
+(i < max_active_banks); i++) {
+   digest_list[i].alg_id = chip->active_banks[i];
+   memcpy(digest_list[i].digest, hash, TPM_DIGEST_SIZE);
+   count++;
+   }
+
+   rc = tpm2_pcr_extend(chip, pcr_idx, count, digest_list);
tpm_put_ops(chip);
return rc;
}
diff --git a/drivers/char/tpm/tpm.h b/drivers/char/tpm/tpm.h
index db0398a..4b7eca9 100644
--- a/drivers/char/tpm/tpm.h
+++ b/drivers/char/tpm/tpm.h
@@ -34,6 +34,7 @@
 #include 
 #include 
 #include 
+#include 
 
 #include "tpm_eventlog.h"
 
@@ -380,6 +381,11 @@ struct tpm_cmd_t {
tpm_cmd_params  params;
 } __packed;
 
+struct tpm2_digest {
+   u16 alg_id;
+   u8 digest[SHA512_DIGEST_SIZE];
+} __packed;
+
 /* A string buffer type for constructing TPM commands. This is based on the
  * ideas of string buffer code in security/keys/trusted.h but is heap based
  * in order to keep the stack usage minimal.
@@ -529,7 +535,8 @@ static inline inline u32 tpm2_rc_value(u32 rc)
 }
 
 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, const u8 *hash);
+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);
 int tpm2_seal_trusted(struct tpm_chip *chip,
  struct trusted_key_payload *payload,
diff --git a/drivers/char/tpm/tpm2-cmd.c b/drivers/char/tpm/tpm2-cmd.c
index 6fbd42c..60042f7 100644
--- a/drivers/char/tpm/tpm2-cmd.c
+++ b/drivers/char/tpm/tpm2-cmd.c
@@ -53,22 +53,6 @@ struct tpm2_pcr_read_out {
u8  digest[TPM_DIGEST_SIZE];
 } __packed;
 
-struct tpm2_null_auth_area {
-   __be32  handle;
-   __be16  nonce_size;
-   u8  attributes;
-   __be16  auth_size;
-} __packed;
-
-struct tpm2_pcr_extend_in {
-   __be32  pcr_idx;
-   __be32  auth_area_size;
-   struct tpm2_null_auth_area  auth_area;
-   __be32  digest_cnt;
-   __be16  hash_alg;
-   u8  digest[TPM_DIGEST_SIZE];
-} __packed;
-
 struct tpm2_get_tpm_pt_in {
__be32  cap_id;
__be32  property_id;
@@ -97,7 +81,6 @@ union tpm2_cmd_params {
struct  tpm2_self_test_in   selftest_in;
struct  tpm2_pcr_read_inpcrread_in;

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

2017-01-30 Thread Nayna

> From: "Ken Goldman" <kg...@linux.vnet.ibm.com
> <mailto:kg...@linux.vnet.ibm.com>>
> Date: 26-Jan-2017 2:53 AM
> Subject: Re: [tpmdd-devel] [PATCH v9 2/2] tpm: add securityfs
> support,for TPM 2.0 firmware event log
> To: <linux-ker...@vger.kernel.org
> <mailto:linux-ker...@vger.kernel.org>>,
> <linux-security-mod...@vger.kernel.org
> <mailto:linux-security-mod...@vger.kernel.org>>,
> <tpmdd-devel@lists.sourceforge.net
> <mailto:tpmdd-devel@lists.sourceforge.net>>
> Cc:
>
> You do not need to send a new patch set version as long as this
> one gets peer tested. And it needs to be tested without hacks
> like plumbing TCPA with TPM 2.0 in QEMU. OF code paths needs to
> be peer tested to be more specific.
>
> For me the code itself looks good but I simply cannot take it in
> in the current situation.
>
> /Jarkko
>
>
> Tested-by: Kenneth Goldman <kg...@linux.vnet.ibm.com
> <mailto:kg...@linux.vnet.ibm.com>>
>
> I validated a firmware event log taken from a Power 8 against PCR 0-7
> values for the SHA-1 and SHA-256 banks from a Nuvoton TPM 2.0 chip on
> that same platform.
>

Thank You Ken.

Jarkko, I hope now these patches can be accepted for 4.11.

Thanks & Regards,
- Nayna


> --
> To unsubscribe from this list: send the line "unsubscribe
> linux-security-module" in
> the body of a message to majord...@vger.kernel.org
> <mailto:majord...@vger.kernel.org>
> More majordomo info at http://vger.kernel.org/majordomo-info.html
> <http://vger.kernel.org/majordomo-info.html>


--
Check out the vibrant tech community on one of the world's most
engaging tech sites, SlashDot.org! http://sdm.link/slashdot
___
tpmdd-devel mailing list
tpmdd-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/tpmdd-devel


Re: [tpmdd-devel] [PATCH] tpm: add buffer access validation in tpm2_get_pcr_allocation()

2017-01-29 Thread Nayna


On 01/30/2017 02:50 AM, Jarkko Sakkinen wrote:
> On Sun, Jan 29, 2017 at 10:48:39PM +0530, Nayna wrote:
>>
>>
>> On 01/29/2017 08:10 PM, Jarkko Sakkinen wrote:
>>> On Fri, Jan 27, 2017 at 10:25:49AM -0500, Nayna Jain wrote:
>>>> This patch add validation in tpm2_get_pcr_allocation to avoid
>>>> access beyond response buffer length.
>>>>
>>>> Suggested-by: Stefan Berger <stef...@linux.vnet.ibm.com>
>>>> Signed-off-by: Nayna Jain <na...@linux.vnet.ibm.com>
>>>
>>> This validation looks broken to me.
>>>
>>>> ---
>>>>drivers/char/tpm/tpm2-cmd.c | 28 +++-
>>>>1 file changed, 23 insertions(+), 5 deletions(-)
>>>>
>>>> diff --git a/drivers/char/tpm/tpm2-cmd.c b/drivers/char/tpm/tpm2-cmd.c
>>>> index 4aad84c..02c1ea7 100644
>>>> --- a/drivers/char/tpm/tpm2-cmd.c
>>>> +++ b/drivers/char/tpm/tpm2-cmd.c
>>>> @@ -1008,9 +1008,13 @@ static ssize_t tpm2_get_pcr_allocation(struct 
>>>> tpm_chip *chip)
>>>>struct tpm2_pcr_selection pcr_selection;
>>>>struct tpm_buf buf;
>>>>void *marker;
>>>> -  unsigned int count = 0;
>>>> +  void *end;
>>>> +  void *pcr_select_offset;
>>>> +  unsigned int count;
>>>> +  u32 sizeof_pcr_selection;
>>>> +  u32 resp_len;
>>>
>>> Very cosmetic but we almos almost universally use the acronym 'rsp' in
>>> the TPM driver.
>>
>> Sure will update.
>>
>>>
>>>>int rc;
>>>> -  int i;
>>>> +  int i = 0;
>>>
>>> Why do you need to initialize it?
>>
>> Because in out: count is replaced with i.
>> And it is replaced because  now for loop can break even before reaching
>> count, because of new buffer checks.
>>>
>>>>
>>>>rc = tpm_buf_init(, TPM2_ST_NO_SESSIONS, 
>>>> TPM2_CC_GET_CAPABILITY);
>>>>if (rc)
>>>> @@ -1034,15 +1038,29 @@ static ssize_t tpm2_get_pcr_allocation(struct 
>>>> tpm_chip *chip)
>>>>}
>>>>
>>>>marker = [TPM_HEADER_SIZE + 9];
>>>> +
>>>> +  resp_len = be32_to_cpup((__be32 *)[2]);
>>>> +  end = [resp_len];
>>>
>>> What if the response contains larger length than the buffer size?
>>
>> Isn't this check need to be done in tpm_transmit_cmd for all responses ?
>> Though, it seems it is not done there as well.
>>
>> And to understand what do we expect max buffer length. PAGE_SIZE or
>> TPM_BUFSIZE ?
>
> Oops. You are correct it is done there:
>
> if (len != be32_to_cpu(header->length))
>   return -EFAULT;
>
> So need to do this.

To be sure, means nothing need to be done in this. Right ?

And guess this was the only thing you meant by broken for this patch.

I will do other two smaller changes as I send the whole new patchset.

Thanks & Regards,
   - Nayna

>
> /Jarkko
>
> /Jarkko
>


--
Check out the vibrant tech community on one of the world's most
engaging tech sites, SlashDot.org! http://sdm.link/slashdot
___
tpmdd-devel mailing list
tpmdd-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/tpmdd-devel


[tpmdd-devel] [PATCH] tpm: add buffer access validation in tpm2_get_pcr_allocation()

2017-01-27 Thread Nayna Jain
This patch add validation in tpm2_get_pcr_allocation to avoid
access beyond response buffer length.

Suggested-by: Stefan Berger <stef...@linux.vnet.ibm.com>
Signed-off-by: Nayna Jain <na...@linux.vnet.ibm.com>
---
 drivers/char/tpm/tpm2-cmd.c | 28 +++-
 1 file changed, 23 insertions(+), 5 deletions(-)

diff --git a/drivers/char/tpm/tpm2-cmd.c b/drivers/char/tpm/tpm2-cmd.c
index 4aad84c..02c1ea7 100644
--- a/drivers/char/tpm/tpm2-cmd.c
+++ b/drivers/char/tpm/tpm2-cmd.c
@@ -1008,9 +1008,13 @@ static ssize_t tpm2_get_pcr_allocation(struct tpm_chip 
*chip)
struct tpm2_pcr_selection pcr_selection;
struct tpm_buf buf;
void *marker;
-   unsigned int count = 0;
+   void *end;
+   void *pcr_select_offset;
+   unsigned int count;
+   u32 sizeof_pcr_selection;
+   u32 resp_len;
int rc;
-   int i;
+   int i = 0;
 
rc = tpm_buf_init(, TPM2_ST_NO_SESSIONS, TPM2_CC_GET_CAPABILITY);
if (rc)
@@ -1034,15 +1038,29 @@ static ssize_t tpm2_get_pcr_allocation(struct tpm_chip 
*chip)
}
 
marker = [TPM_HEADER_SIZE + 9];
+
+   resp_len = be32_to_cpup((__be32 *)[2]);
+   end = [resp_len];
+
for (i = 0; i < count; i++) {
+   pcr_select_offset = marker +
+   offsetof(struct tpm2_pcr_selection, size_of_select);
+   if (pcr_select_offset >= end) {
+   rc = -EFAULT;
+   break;
+   }
+
memcpy(_selection, marker, sizeof(pcr_selection));
chip->active_banks[i] = be16_to_cpu(pcr_selection.hash_alg);
-   marker = marker + sizeof(struct tpm2_pcr_selection);
+   sizeof_pcr_selection = sizeof(pcr_selection.hash_alg) +
+   sizeof(pcr_selection.size_of_select) +
+   sizeof(u8) * pcr_selection.size_of_select;
+   marker = marker + sizeof_pcr_selection;
}
 
 out:
-   if (count < ARRAY_SIZE(chip->active_banks))
-   chip->active_banks[count] = TPM2_ALG_ERROR;
+   if (i < ARRAY_SIZE(chip->active_banks))
+   chip->active_banks[i] = TPM2_ALG_ERROR;
 
tpm_buf_destroy();
 
-- 
2.5.0


--
Check out the vibrant tech community on one of the world's most
engaging tech sites, SlashDot.org! http://sdm.link/slashdot
___
tpmdd-devel mailing list
tpmdd-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/tpmdd-devel


[tpmdd-devel] [PATCH] tpm: fix TPM error handling in tpm2_get_pcr_allocation

2017-01-26 Thread Nayna Jain
Fixes: 75768b4(tpm: enhance TPM 2.0 PCR extend to support
multiple banks)

Signed-off-by: Nayna Jain <na...@linux.vnet.ibm.com>
---
 drivers/char/tpm/tpm2-cmd.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/char/tpm/tpm2-cmd.c b/drivers/char/tpm/tpm2-cmd.c
index 4aad84c..fa52309 100644
--- a/drivers/char/tpm/tpm2-cmd.c
+++ b/drivers/char/tpm/tpm2-cmd.c
@@ -1022,7 +1022,7 @@ static ssize_t tpm2_get_pcr_allocation(struct tpm_chip 
*chip)
 
rc = tpm_transmit_cmd(chip, buf.data, PAGE_SIZE, 9, 0,
  "get tpm pcr allocation");
-   if (rc < 0)
+   if (rc)
goto out;
 
count = be32_to_cpup(
-- 
2.5.0


--
Check out the vibrant tech community on one of the world's most
engaging tech sites, SlashDot.org! http://sdm.link/slashdot
___
tpmdd-devel mailing list
tpmdd-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/tpmdd-devel


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

2017-01-24 Thread Nayna


On 01/24/2017 05:29 PM, Jarkko Sakkinen wrote:
> On Mon, Jan 23, 2017 at 10:11:48PM +0530, Nayna wrote:
>>
>>
>> On 01/23/2017 08:49 PM, Jarkko Sakkinen wrote:
>>> On Fri, Jan 20, 2017 at 12:05:13PM -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 them.
>>>>
>>>> The existing in-kernel interface(tpm_pcr_extend()) expects only a
>>>> SHA1 digest.  To extend all active PCR banks with differing
>>>> digest sizes, the SHA1 digest is padded with trailing 0's as needed.
>>>>
>>>> This patch reuses the defined digest sizes from the crypto subsystem,
>>>> adding a dependency on CRYPTO_HASH_INFO module.
>>>>
>>>> [1] TPM 2.0 Specification referred here is "TCG PC Client Specific
>>>> Platform Firmware Profile for TPM 2.0"
>>>>
>>>> Signed-off-by: Nayna Jain <na...@linux.vnet.ibm.com>
>>>> Reviewed-by: Jarkko Sakkinen <jarkko.sakki...@linux.intel.com>
>>>> ---
>>>>drivers/char/tpm/Kconfig |  1 +
>>>>drivers/char/tpm/tpm-interface.c | 15 ++-
>>>>drivers/char/tpm/tpm.h   |  3 +-
>>>>drivers/char/tpm/tpm2-cmd.c  | 91 
>>>> +---
>>>>drivers/char/tpm/tpm_eventlog.h  |  7 
>>>>5 files changed, 73 insertions(+), 44 deletions(-)
>>>>
>>>> diff --git a/drivers/char/tpm/Kconfig b/drivers/char/tpm/Kconfig
>>>> index 277186d..af985cc 100644
>>>> --- a/drivers/char/tpm/Kconfig
>>>> +++ b/drivers/char/tpm/Kconfig
>>>> @@ -6,6 +6,7 @@ menuconfig TCG_TPM
>>>>tristate "TPM Hardware Support"
>>>>depends on HAS_IOMEM
>>>>select SECURITYFS
>>>> +  select CRYPTO_HASH_INFO
>>>>---help---
>>>>  If you have a TPM security chip in your system, which
>>>>  implements the Trusted Computing Group's specification,
>>>> diff --git a/drivers/char/tpm/tpm-interface.c 
>>>> b/drivers/char/tpm/tpm-interface.c
>>>> index a3461cb..cf959c3 100644
>>>> --- a/drivers/char/tpm/tpm-interface.c
>>>> +++ b/drivers/char/tpm/tpm-interface.c
>>>> @@ -772,13 +772,26 @@ int tpm_pcr_extend(u32 chip_num, int pcr_idx, const 
>>>> u8 *hash)
>>>>struct tpm_cmd_t cmd;
>>>>int rc;
>>>>struct tpm_chip *chip;
>>>> +  int max_active_banks = ARRAY_SIZE(chip->active_banks);
>>>> +  struct tpm2_digest digest_list[max_active_banks];
>>>> +  u32 count = 0;
>>>> +  int i;
>>>>
>>>>chip = tpm_chip_find_get(chip_num);
>>>>if (chip == NULL)
>>>>return -ENODEV;
>>>>
>>>>if (chip->flags & TPM_CHIP_FLAG_TPM2) {
>>>> -  rc = tpm2_pcr_extend(chip, pcr_idx, hash);
>>>> +  memset(digest_list, 0, sizeof(digest_list));
>>>> +
>>>> +  for (i = 0; (chip->active_banks[i] != TPM2_ALG_ERROR) &&
>>>> +   (i < max_active_banks); i++) {
>>>> +  digest_list[i].alg_id = chip->active_banks[i];
>>>> +  memcpy(digest_list[i].digest, hash, TPM_DIGEST_SIZE);
>>>> +  count++;
>>>> +  }
>>>> +
>>>> +  rc = tpm2_pcr_extend(chip, pcr_idx, count, digest_list);
>>>>tpm_put_ops(chip);
>>>>return rc;
>>>>}
>>>> diff --git a/drivers/char/tpm/tpm.h b/drivers/char/tpm/tpm.h
>>>> index c291f19..07a0677 100644
>>>> --- a/drivers/char/tpm/tpm.h
>>>> +++ b/drivers/char/tpm/tpm.h
>>>> @@ -534,7 +534,8 @@ static inline void tpm_add_ppi(struct tpm_chip *chip)
>>>>#endif
>>>>
>>>>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, const u8 *hash);
>>>> +int tpm2_pcr_extend(struct tpm_chip *chip, int pcr_idx, u32 count,
>>>> 

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

2017-01-24 Thread Nayna


On 01/23/2017 08:43 PM, Jarkko Sakkinen wrote:
> On Mon, Jan 23, 2017 at 02:26:27AM -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.0 event log supports a crypto agile format that
>> records multiple digests, which is different from TPM 1.2. This
>> patch enables the tpm_bios_log_setup for TPM 2.0  and adds the
>> event log parser which understand the TPM 2.0 crypto agile format.
>>
>> Signed-off-by: Nayna Jain <na...@linux.vnet.ibm.com>
>> ---
>>   drivers/char/tpm/Makefile  |   2 +-
>>   .../char/tpm/{tpm_eventlog.c => tpm1_eventlog.c}   |  35 ++--
>>   drivers/char/tpm/tpm2_eventlog.c   | 203 
>> +
>>   drivers/char/tpm/tpm_acpi.c|   3 +
>>   drivers/char/tpm/tpm_eventlog.h|  59 ++
>>   5 files changed, 287 insertions(+), 15 deletions(-)
>>   rename drivers/char/tpm/{tpm_eventlog.c => tpm1_eventlog.c} (95%)
>>   create mode 100644 drivers/char/tpm/tpm2_eventlog.c
>>
>> diff --git a/drivers/char/tpm/Makefile b/drivers/char/tpm/Makefile
>> index a05b1eb..3d386a8 100644
>> --- a/drivers/char/tpm/Makefile
>> +++ b/drivers/char/tpm/Makefile
>> @@ -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 \
>> -tpm_eventlog.o
>> +tpm1_eventlog.o tpm2_eventlog.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
>> diff --git a/drivers/char/tpm/tpm_eventlog.c 
>> b/drivers/char/tpm/tpm1_eventlog.c
>> similarity index 95%
>> rename from drivers/char/tpm/tpm_eventlog.c
>> rename to drivers/char/tpm/tpm1_eventlog.c
>> index 11bb113..9a8605e 100644
>> --- a/drivers/char/tpm/tpm_eventlog.c
>> +++ b/drivers/char/tpm/tpm1_eventlog.c
>> @@ -390,9 +390,6 @@ int tpm_bios_log_setup(struct tpm_chip *chip)
>>  unsigned int cnt;
>>  int rc = 0;
>>
>> -if (chip->flags & TPM_CHIP_FLAG_TPM2)
>> -return 0;
>> -
>>  rc = tpm_read_log(chip);
>>  if (rc)
>>  return rc;
>> @@ -407,7 +404,13 @@ int tpm_bios_log_setup(struct tpm_chip *chip)
>>  cnt++;
>>
>>  chip->bin_log_seqops.chip = chip;
>> -chip->bin_log_seqops.seqops = _binary_b_measurements_seqops;
>> +if (chip->flags & TPM_CHIP_FLAG_TPM2)
>> +chip->bin_log_seqops.seqops =
>> +_binary_b_measurements_seqops;
>> +else
>> +chip->bin_log_seqops.seqops =
>> +_binary_b_measurements_seqops;
>> +
>>
>>  chip->bios_dir[cnt] =
>>  securityfs_create_file("binary_bios_measurements",
>> @@ -418,17 +421,21 @@ int tpm_bios_log_setup(struct tpm_chip *chip)
>>  goto err;
>>  cnt++;
>>
>> -chip->ascii_log_seqops.chip = chip;
>> -chip->ascii_log_seqops.seqops = _ascii_b_measurements_seqops;
>> +if (!(chip->flags & TPM_CHIP_FLAG_TPM2)) {
>>
>> -chip->bios_dir[cnt] =
>> -securityfs_create_file("ascii_bios_measurements",
>> -   0440, chip->bios_dir[0],
>> -   (void *)>ascii_log_seqops,
>> -   _bios_measurements_ops);
>> -if (IS_ERR(chip->bios_dir[cnt]))
>> -goto err;
>> -cnt++;
>> +chip->ascii_log_seqops.chip = chip;
>> +chip->ascii_log_seqops.seqops =
>> +_ascii_b_measurements_seqops;
>> +
>> +chip->bios_dir[cnt] =
>> +securityfs_create_file("ascii_bios_measurements",
>> +   0440, chip->bios_dir[0],
>> +   (void *)>ascii_log_seqops,
>> +   _bios_measurements_ops);
>> +if (IS_ERR(chip->bios_dir[cnt]))
>> +goto err;
>> +cnt++;
>> +}
>>
>>  return 0;
>>
>> diff --git a/drivers/char/tpm/tpm2_eventlog.c 
>> b/drivers/char/tpm/tpm2_eventlog.c
>> new file mo

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

2017-01-23 Thread Nayna


On 01/23/2017 08:49 PM, Jarkko Sakkinen wrote:
> On Fri, Jan 20, 2017 at 12:05:13PM -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 them.
>>
>> The existing in-kernel interface(tpm_pcr_extend()) expects only a
>> SHA1 digest.  To extend all active PCR banks with differing
>> digest sizes, the SHA1 digest is padded with trailing 0's as needed.
>>
>> This patch reuses the defined digest sizes from the crypto subsystem,
>> adding a dependency on CRYPTO_HASH_INFO module.
>>
>> [1] TPM 2.0 Specification referred here is "TCG PC Client Specific
>> Platform Firmware Profile for TPM 2.0"
>>
>> Signed-off-by: Nayna Jain <na...@linux.vnet.ibm.com>
>> Reviewed-by: Jarkko Sakkinen <jarkko.sakki...@linux.intel.com>
>> ---
>>   drivers/char/tpm/Kconfig |  1 +
>>   drivers/char/tpm/tpm-interface.c | 15 ++-
>>   drivers/char/tpm/tpm.h   |  3 +-
>>   drivers/char/tpm/tpm2-cmd.c  | 91 
>> +---
>>   drivers/char/tpm/tpm_eventlog.h  |  7 
>>   5 files changed, 73 insertions(+), 44 deletions(-)
>>
>> diff --git a/drivers/char/tpm/Kconfig b/drivers/char/tpm/Kconfig
>> index 277186d..af985cc 100644
>> --- a/drivers/char/tpm/Kconfig
>> +++ b/drivers/char/tpm/Kconfig
>> @@ -6,6 +6,7 @@ menuconfig TCG_TPM
>>  tristate "TPM Hardware Support"
>>  depends on HAS_IOMEM
>>  select SECURITYFS
>> +select CRYPTO_HASH_INFO
>>  ---help---
>>If you have a TPM security chip in your system, which
>>implements the Trusted Computing Group's specification,
>> diff --git a/drivers/char/tpm/tpm-interface.c 
>> b/drivers/char/tpm/tpm-interface.c
>> index a3461cb..cf959c3 100644
>> --- a/drivers/char/tpm/tpm-interface.c
>> +++ b/drivers/char/tpm/tpm-interface.c
>> @@ -772,13 +772,26 @@ int tpm_pcr_extend(u32 chip_num, int pcr_idx, const u8 
>> *hash)
>>  struct tpm_cmd_t cmd;
>>  int rc;
>>  struct tpm_chip *chip;
>> +int max_active_banks = ARRAY_SIZE(chip->active_banks);
>> +struct tpm2_digest digest_list[max_active_banks];
>> +u32 count = 0;
>> +int i;
>>
>>  chip = tpm_chip_find_get(chip_num);
>>  if (chip == NULL)
>>  return -ENODEV;
>>
>>  if (chip->flags & TPM_CHIP_FLAG_TPM2) {
>> -rc = tpm2_pcr_extend(chip, pcr_idx, hash);
>> +memset(digest_list, 0, sizeof(digest_list));
>> +
>> +for (i = 0; (chip->active_banks[i] != TPM2_ALG_ERROR) &&
>> + (i < max_active_banks); i++) {
>> +digest_list[i].alg_id = chip->active_banks[i];
>> +memcpy(digest_list[i].digest, hash, TPM_DIGEST_SIZE);
>> +count++;
>> +}
>> +
>> +rc = tpm2_pcr_extend(chip, pcr_idx, count, digest_list);
>>  tpm_put_ops(chip);
>>  return rc;
>>  }
>> diff --git a/drivers/char/tpm/tpm.h b/drivers/char/tpm/tpm.h
>> index c291f19..07a0677 100644
>> --- a/drivers/char/tpm/tpm.h
>> +++ b/drivers/char/tpm/tpm.h
>> @@ -534,7 +534,8 @@ static inline void tpm_add_ppi(struct tpm_chip *chip)
>>   #endif
>>
>>   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, const u8 *hash);
>> +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);
>>   int tpm2_seal_trusted(struct tpm_chip *chip,
>>struct trusted_key_payload *payload,
>> diff --git a/drivers/char/tpm/tpm2-cmd.c b/drivers/char/tpm/tpm2-cmd.c
>> index 0e000a3..d78adb8 100644
>> --- a/drivers/char/tpm/tpm2-cmd.c
>> +++ b/drivers/char/tpm/tpm2-cmd.c
>> @@ -53,22 +53,6 @@ struct tpm2_pcr_read_out {
>>  u8  digest[TPM_DIGEST_SIZE];
>>   } __packed;
>>
>> -struct tpm2_null_auth_area {
>> -__be32  handle;
>> -__be16  nonce_size;
>> -u8  attributes;
>> -__be16  auth_size;
>> -} __packed;
>> -
>> -struct tpm2_pcr_extend_in {
>> - 

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

2017-01-22 Thread Nayna Jain
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.0 event log supports a crypto agile format that
records multiple digests, which is different from TPM 1.2. This
patch enables the tpm_bios_log_setup for TPM 2.0  and adds the
event log parser which understand the TPM 2.0 crypto agile format.

Signed-off-by: Nayna Jain <na...@linux.vnet.ibm.com>
---
 drivers/char/tpm/Makefile  |   2 +-
 .../char/tpm/{tpm_eventlog.c => tpm1_eventlog.c}   |  35 ++--
 drivers/char/tpm/tpm2_eventlog.c   | 203 +
 drivers/char/tpm/tpm_acpi.c|   3 +
 drivers/char/tpm/tpm_eventlog.h|  59 ++
 5 files changed, 287 insertions(+), 15 deletions(-)
 rename drivers/char/tpm/{tpm_eventlog.c => tpm1_eventlog.c} (95%)
 create mode 100644 drivers/char/tpm/tpm2_eventlog.c

diff --git a/drivers/char/tpm/Makefile b/drivers/char/tpm/Makefile
index a05b1eb..3d386a8 100644
--- a/drivers/char/tpm/Makefile
+++ b/drivers/char/tpm/Makefile
@@ -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 \
-   tpm_eventlog.o
+   tpm1_eventlog.o tpm2_eventlog.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
diff --git a/drivers/char/tpm/tpm_eventlog.c b/drivers/char/tpm/tpm1_eventlog.c
similarity index 95%
rename from drivers/char/tpm/tpm_eventlog.c
rename to drivers/char/tpm/tpm1_eventlog.c
index 11bb113..9a8605e 100644
--- a/drivers/char/tpm/tpm_eventlog.c
+++ b/drivers/char/tpm/tpm1_eventlog.c
@@ -390,9 +390,6 @@ int tpm_bios_log_setup(struct tpm_chip *chip)
unsigned int cnt;
int rc = 0;
 
-   if (chip->flags & TPM_CHIP_FLAG_TPM2)
-   return 0;
-
rc = tpm_read_log(chip);
if (rc)
return rc;
@@ -407,7 +404,13 @@ int tpm_bios_log_setup(struct tpm_chip *chip)
cnt++;
 
chip->bin_log_seqops.chip = chip;
-   chip->bin_log_seqops.seqops = _binary_b_measurements_seqops;
+   if (chip->flags & TPM_CHIP_FLAG_TPM2)
+   chip->bin_log_seqops.seqops =
+   _binary_b_measurements_seqops;
+   else
+   chip->bin_log_seqops.seqops =
+   _binary_b_measurements_seqops;
+
 
chip->bios_dir[cnt] =
securityfs_create_file("binary_bios_measurements",
@@ -418,17 +421,21 @@ int tpm_bios_log_setup(struct tpm_chip *chip)
goto err;
cnt++;
 
-   chip->ascii_log_seqops.chip = chip;
-   chip->ascii_log_seqops.seqops = _ascii_b_measurements_seqops;
+   if (!(chip->flags & TPM_CHIP_FLAG_TPM2)) {
 
-   chip->bios_dir[cnt] =
-   securityfs_create_file("ascii_bios_measurements",
-  0440, chip->bios_dir[0],
-  (void *)>ascii_log_seqops,
-  _bios_measurements_ops);
-   if (IS_ERR(chip->bios_dir[cnt]))
-   goto err;
-   cnt++;
+   chip->ascii_log_seqops.chip = chip;
+   chip->ascii_log_seqops.seqops =
+   _ascii_b_measurements_seqops;
+
+   chip->bios_dir[cnt] =
+   securityfs_create_file("ascii_bios_measurements",
+  0440, chip->bios_dir[0],
+  (void *)>ascii_log_seqops,
+  _bios_measurements_ops);
+   if (IS_ERR(chip->bios_dir[cnt]))
+   goto err;
+   cnt++;
+   }
 
return 0;
 
diff --git a/drivers/char/tpm/tpm2_eventlog.c b/drivers/char/tpm/tpm2_eventlog.c
new file mode 100644
index 000..513897c
--- /dev/null
+++ b/drivers/char/tpm/tpm2_eventlog.c
@@ -0,0 +1,203 @@
+/*
+ * Copyright (C) 2016 IBM Corporation
+ *
+ * Authors:
+ *  Nayna Jain <na...@linux.vnet.ibm.com>
+ *
+ * Access to TPM 2.0 event log as written by Firmware.
+ * It assumes that writer of event log has followed TCG Specification
+ * for Family "2.0" and written the event data in little endian.
+ * With that, it doesn't need any endian conversion for structure
+ * content.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version
+ * 2 of the License, or (at your option) any later version.
+ */
+
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#include "tpm.h"
+#include "tpm_eventlog.h"
+
+/*
+ * ca

[tpmdd-devel] [PATCH v9 1/2] tpm: enhance read_log_of() to support Physical TPM event log

2017-01-22 Thread Nayna Jain
Physical TPMs use Open Firmware Device Tree bindings that are similar
to the IBM Power virtual TPM to support event log. However, these
properties store the values in different endianness for Physical
and Virtual TPM.

This patch fixes the endianness issue by doing appropriate conversion
based on Physical or Virtual TPM.

Signed-off-by: Nayna Jain <na...@linux.vnet.ibm.com>
Reviewed-by: Jarkko Sakkinen <jarkko.sakki...@linux.intel.com>
---
 drivers/char/tpm/tpm_of.c | 27 +++
 1 file changed, 23 insertions(+), 4 deletions(-)

diff --git a/drivers/char/tpm/tpm_of.c b/drivers/char/tpm/tpm_of.c
index 7dee42d7..de57d4a 100644
--- a/drivers/char/tpm/tpm_of.c
+++ b/drivers/char/tpm/tpm_of.c
@@ -27,6 +27,8 @@ int tpm_read_log_of(struct tpm_chip *chip)
const u32 *sizep;
const u64 *basep;
struct tpm_bios_log *log;
+   u32 size;
+   u64 base;
 
log = >log;
if (chip->dev.parent && chip->dev.parent->of_node)
@@ -41,18 +43,35 @@ int tpm_read_log_of(struct tpm_chip *chip)
if (sizep == NULL || basep == NULL)
return -EIO;
 
-   if (*sizep == 0) {
+   /*
+* For both vtpm/tpm, firmware has log addr and log size in big
+* endian format. But in case of vtpm, there is a method called
+* sml-handover which is run during kernel init even before
+* device tree is setup. This sml-handover function takes care
+* of endianness and writes to sml-base and sml-size in little
+* endian format. For this reason, vtpm doesn't need conversion
+* but physical tpm needs the conversion.
+*/
+   if (of_property_match_string(np, "compatible", "IBM,vtpm") < 0) {
+   size = be32_to_cpup(sizep);
+   base = be64_to_cpup(basep);
+   } else {
+   size = *sizep;
+   base = *basep;
+   }
+
+   if (size == 0) {
dev_warn(>dev, "%s: Event log area empty\n", __func__);
return -EIO;
}
 
-   log->bios_event_log = kmalloc(*sizep, GFP_KERNEL);
+   log->bios_event_log = kmalloc(size, GFP_KERNEL);
if (!log->bios_event_log)
return -ENOMEM;
 
-   log->bios_event_log_end = log->bios_event_log + *sizep;
+   log->bios_event_log_end = log->bios_event_log + size;
 
-   memcpy(log->bios_event_log, __va(*basep), *sizep);
+   memcpy(log->bios_event_log, __va(base), size);
 
return 0;
 }
-- 
2.5.0


--
Check out the vibrant tech community on one of the world's most
engaging tech sites, SlashDot.org! http://sdm.link/slashdot
___
tpmdd-devel mailing list
tpmdd-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/tpmdd-devel


[tpmdd-devel] [PATCH v9 0/2] securityfs support for TPM 2.0 firmware event log

2017-01-22 Thread Nayna Jain
The TPM device driver defines ascii and binary methods for
displaying the TPM 1.2 event log via securityfs files, which are
needed for validating a TPM quote. The device driver for TPM 2.0
does not have similar support for displaying the TPM 2.0
event log. This patch set adds the support for displaying
TPM 2.0 event log in binary format.

The parsing mechanism to display the TPM 2.0 event log in binary
format is implemented as defined in the TPM 2.0 TCG specification[1].
If the firmware event log support exists and is successfully read,
the securityfs file is created to provide the event log in binary
format for both the OF device tree and ACPI.

   - Patch 1 adds the device tree bindings support for Physical TPM.
   - Patch 2 adds the support for creating securityfs files and for
 displaying the TPM 2.0 crypto agile event log in binary format.

[1] TCG EFI Protocol Specification, Family "2.0" - Section 5 "Event
Log Structure"

Changelog History

v9:
- Rebased to the Jarkko's latest master branch (9b7f425 tpm: Check size of 
  response before accessing data)
- Patch "tpm: add securityfs support for TPM 2.0 firmware event log" 
  - Renamed struct tpmt_ha to struct tpm2_hash.
  - Removed struct tpml_digest_values.

v8:
- Rebased to the Jarkko's latest master branch (8e25809 tpm:
  Do not print an error message when doing TPM auto startup)
- Patch "tpm: add securityfs support for TPM 2.0 firmware event log" 
  - Added feedbacks from Jarkko
- tpm_read_log_acpi() returns -ENODEV for TPM 2.0.
- Fixed code formatting and comments.

v7:
- Rebased to the Jarkko's latest master branch (b2505f6 tpm/vtpm:
  fix kdoc warnings)
- Included Jarkko's feedbacks on version v6.
- Cleaned up #defines in tpm2_eventlog.c
  - renamed HASH_COUNT to TPM2_ACTIVE_PCR_BANKS
  - deleted MAX_DIGEST_SIZE, used SHA384_DIGEST_SIZE directly from 
  
  - deleted MAX_TPM_LOG_MSG. Redefined event[MAX_TPM_LOG_MSG]
  as event[0].

v6:

- Rebased to the Jarkko's latest master branch (e717b5c:tpm: vtpm_proxy: 
  conditionally call tpm_chip_unregister)
- Retained securityfs setup functions in tpm_eventlog.c
- Renamed tpm_eventlog.c to tpm1_eventlog.c
- Fixed tpm_read_log_of() for NULL check and memcpy function.

v5:

- Upstreamed cleanup and fixes as different patchset
- Rebased to the Jarkko's latest master branch (e5be084 tpm: vtpm_proxy:
  Do not access host's event log)
- Patch "tpm: enhance read_log_of() to support Physical TPM event log
  - New Patch.
- Patch "tpm: add securityfs support for TPM 2.0 firmware event log"
  - Moved the changes in read_log_of() to a different patch
  - TPM 2.0 event log data types are declared in tpm_eventlog.h, tpm2.h
  is removed.
  - Included other feedbacks also from Jarkko on aligment and extra
line

v4:

- Includes feedbacks from Jarkko and Jason.
- Patch "tpm: define a generic open() method for ascii & bios
measurements".
  - Fix indentation issue.
- Patch "tpm: replace the dynamically allocated bios_dir as
  struct dentry array".
  - Continue to use bios_dir_count variable to use is_bad() checks and
to maintain correct order for securityfs_remove() during teardown.
  - Reset chip->bios_dir_count in teardown() function.
- Patch "tpm: validate the eventlog access before tpm_bios_log_setup".
  - Retain TPM2 check which was removed in previous patch.
  - Add tpm_bios_log_setup failure handling.
  - Remove use of private data from v3 version of patch. Add a
  new member to struct tpm_chip to achieve the same purpose.
- Patch "tpm: redefine the read_log method to check for ACPI/OF 
properties sequentially".
  - Move replacement of CONFIG_TCG_IBMVTPM with CONFIG_OF to this
patch from patch 3.
  - Replace -1 error code with -ENODEV.
- Patch "tpm: replace the of_find_node_by_name() with dev of_node
property".
  - Uses chip->dev.parent->of_node.
  - Created separate patch for cleanup of pr_err messages.
- Patch "tpm: remove printk error messages".
  - New Patch.
- Patch "tpm: add the securityfs file support for TPM 2.0 eventlog".
  - Parses event digests using event alg_id rather than event log header
alg_id.
  - Uses of_property_match_string to differentiate tpm/vtpm compatible

v3:

- Includes the review feedbacks as suggested by Jason.
- Split of patches into one patch per idea.
- Generic open() method for ascii/bios measurements.
- Replacement of of **bios_dir with *bios_dir[3].
- Verifying readlog() is successful before creating securityfs entries.
- Generic readlog() to check for ACPI/OF in sequence.
- read_log_of() method now uses of_node propertry rather than
calling find_device_by_name.
- read_log differentiates vtpm/tpm using its compatible property.
- Cleans pr_err with dev_dbg.
- Commit msgs subject line prefixed with tpm.

v2:

- Fixes issues as given in feedback by Jason.
- Adds documentation for device tree.

Nayna Jain (2):
  tp

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

2017-01-20 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 a
SHA1 digest.  To extend all active PCR banks with differing
digest sizes, the SHA1 digest is padded with trailing 0's as needed.

This patch reuses the defined digest sizes from the crypto subsystem,
adding a dependency on CRYPTO_HASH_INFO module.

[1] TPM 2.0 Specification referred here is "TCG PC Client Specific
Platform Firmware Profile for TPM 2.0"

Signed-off-by: Nayna Jain <na...@linux.vnet.ibm.com>
Reviewed-by: Jarkko Sakkinen <jarkko.sakki...@linux.intel.com>
---
 drivers/char/tpm/Kconfig |  1 +
 drivers/char/tpm/tpm-interface.c | 15 ++-
 drivers/char/tpm/tpm.h   |  3 +-
 drivers/char/tpm/tpm2-cmd.c  | 91 +---
 drivers/char/tpm/tpm_eventlog.h  |  7 
 5 files changed, 73 insertions(+), 44 deletions(-)

diff --git a/drivers/char/tpm/Kconfig b/drivers/char/tpm/Kconfig
index 277186d..af985cc 100644
--- a/drivers/char/tpm/Kconfig
+++ b/drivers/char/tpm/Kconfig
@@ -6,6 +6,7 @@ menuconfig TCG_TPM
tristate "TPM Hardware Support"
depends on HAS_IOMEM
select SECURITYFS
+   select CRYPTO_HASH_INFO
---help---
  If you have a TPM security chip in your system, which
  implements the Trusted Computing Group's specification,
diff --git a/drivers/char/tpm/tpm-interface.c b/drivers/char/tpm/tpm-interface.c
index a3461cb..cf959c3 100644
--- a/drivers/char/tpm/tpm-interface.c
+++ b/drivers/char/tpm/tpm-interface.c
@@ -772,13 +772,26 @@ int tpm_pcr_extend(u32 chip_num, int pcr_idx, const u8 
*hash)
struct tpm_cmd_t cmd;
int rc;
struct tpm_chip *chip;
+   int max_active_banks = ARRAY_SIZE(chip->active_banks);
+   struct tpm2_digest digest_list[max_active_banks];
+   u32 count = 0;
+   int i;
 
chip = tpm_chip_find_get(chip_num);
if (chip == NULL)
return -ENODEV;
 
if (chip->flags & TPM_CHIP_FLAG_TPM2) {
-   rc = tpm2_pcr_extend(chip, pcr_idx, hash);
+   memset(digest_list, 0, sizeof(digest_list));
+
+   for (i = 0; (chip->active_banks[i] != TPM2_ALG_ERROR) &&
+(i < max_active_banks); i++) {
+   digest_list[i].alg_id = chip->active_banks[i];
+   memcpy(digest_list[i].digest, hash, TPM_DIGEST_SIZE);
+   count++;
+   }
+
+   rc = tpm2_pcr_extend(chip, pcr_idx, count, digest_list);
tpm_put_ops(chip);
return rc;
}
diff --git a/drivers/char/tpm/tpm.h b/drivers/char/tpm/tpm.h
index c291f19..07a0677 100644
--- a/drivers/char/tpm/tpm.h
+++ b/drivers/char/tpm/tpm.h
@@ -534,7 +534,8 @@ static inline void tpm_add_ppi(struct tpm_chip *chip)
 #endif
 
 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, const u8 *hash);
+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);
 int tpm2_seal_trusted(struct tpm_chip *chip,
  struct trusted_key_payload *payload,
diff --git a/drivers/char/tpm/tpm2-cmd.c b/drivers/char/tpm/tpm2-cmd.c
index 0e000a3..d78adb8 100644
--- a/drivers/char/tpm/tpm2-cmd.c
+++ b/drivers/char/tpm/tpm2-cmd.c
@@ -53,22 +53,6 @@ struct tpm2_pcr_read_out {
u8  digest[TPM_DIGEST_SIZE];
 } __packed;
 
-struct tpm2_null_auth_area {
-   __be32  handle;
-   __be16  nonce_size;
-   u8  attributes;
-   __be16  auth_size;
-} __packed;
-
-struct tpm2_pcr_extend_in {
-   __be32  pcr_idx;
-   __be32  auth_area_size;
-   struct tpm2_null_auth_area  auth_area;
-   __be32  digest_cnt;
-   __be16  hash_alg;
-   u8  digest[TPM_DIGEST_SIZE];
-} __packed;
-
 struct tpm2_get_tpm_pt_in {
__be32  cap_id;
__be32  property_id;
@@ -97,7 +81,6 @@ union tpm2_cmd_params {
struct  tpm2_self_test_in   selftest_in;
struct  tpm2_pcr_read_inpcrread_in;
struct  tpm2_pcr_read_out   pcrread_out;
-   struct  tpm2_pcr_extend_in  pcrextend_in;
struct  tpm2_get_tpm_pt_in  get_tpm_pt_in;
struct  tpm2_get_tpm_pt_out get_tpm_pt_out;
struct  tpm2_get_random_in  getrandom_in;
@@ -290,46 +273,68 @@ int tpm2_pcr_read(struct tpm_chip *chip, int pcr_idx, u8 
*res_buf)
return rc;

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

2017-01-20 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 <na...@linux.vnet.ibm.com>
Reviewed-by: Jarkko Sakkinen <jarkko.sakki...@linux.intel.com>
---
 drivers/char/tpm/tpm.h  |  5 
 drivers/char/tpm/tpm2-cmd.c | 59 +
 2 files changed, 64 insertions(+)

diff --git a/drivers/char/tpm/tpm.h b/drivers/char/tpm/tpm.h
index 1ae9768..c291f19 100644
--- a/drivers/char/tpm/tpm.h
+++ b/drivers/char/tpm/tpm.h
@@ -97,6 +97,7 @@ enum tpm2_return_codes {
 };
 
 enum tpm2_algorithms {
+   TPM2_ALG_ERROR  = 0x,
TPM2_ALG_SHA1   = 0x0004,
TPM2_ALG_KEYEDHASH  = 0x0008,
TPM2_ALG_SHA256 = 0x000B,
@@ -127,6 +128,7 @@ enum tpm2_permanent_handles {
 };
 
 enum tpm2_capabilities {
+   TPM2_CAP_PCRS   = 5,
TPM2_CAP_TPM_PROPERTIES = 6,
 };
 
@@ -187,6 +189,8 @@ struct tpm_chip {
 
const struct attribute_group *groups[3];
unsigned int groups_cnt;
+
+   u16 active_banks[7];
 #ifdef CONFIG_ACPI
acpi_handle acpi_dev_handle;
char ppi_version[TPM_PPI_VERSION_LEN + 1];
@@ -545,4 +549,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);
+ssize_t tpm2_get_pcr_allocation(struct tpm_chip *chip);
 #endif
diff --git a/drivers/char/tpm/tpm2-cmd.c b/drivers/char/tpm/tpm2-cmd.c
index 6eda239..0e000a3 100644
--- a/drivers/char/tpm/tpm2-cmd.c
+++ b/drivers/char/tpm/tpm2-cmd.c
@@ -998,3 +998,62 @@ int tpm2_auto_startup(struct tpm_chip *chip)
rc = -ENODEV;
return rc;
 }
+
+struct tpm2_pcr_selection {
+   __be16  hash_alg;
+   u8  size_of_select;
+   u8  pcr_select[3];
+} __packed;
+
+/**
+ * tpm2_get_pcr_allocation() - get TPM active PCR banks.
+ *
+ * @chip: TPM chip to use.
+ *
+ * Return: Same as with tpm_transmit_cmd.
+ */
+ssize_t tpm2_get_pcr_allocation(struct tpm_chip *chip)
+{
+   struct tpm2_pcr_selection pcr_selection;
+   struct tpm_buf buf;
+   void *marker;
+   unsigned int count = 0;
+   int rc;
+   int i;
+
+   rc = tpm_buf_init(, TPM2_ST_NO_SESSIONS, TPM2_CC_GET_CAPABILITY);
+   if (rc)
+   return rc;
+
+   tpm_buf_append_u32(, TPM2_CAP_PCRS);
+   tpm_buf_append_u32(, 0);
+   tpm_buf_append_u32(, 1);
+
+   rc = tpm_transmit_cmd(chip, buf.data, PAGE_SIZE, 0,
+ "get tpm pcr allocation");
+   if (rc < 0)
+   goto out;
+
+   count = be32_to_cpup(
+   (__be32 *)[TPM_HEADER_SIZE + 5]);
+
+   if (count > ARRAY_SIZE(chip->active_banks)) {
+   rc = -ENODEV;
+   goto out;
+   }
+
+   marker = [TPM_HEADER_SIZE + 9];
+   for (i = 0; i < count; i++) {
+   memcpy(_selection, marker, sizeof(pcr_selection));
+   chip->active_banks[i] = be16_to_cpu(pcr_selection.hash_alg);
+   marker = marker + sizeof(struct tpm2_pcr_selection);
+   }
+
+out:
+   if (count < ARRAY_SIZE(chip->active_banks))
+   chip->active_banks[count] = TPM2_ALG_ERROR;
+
+   tpm_buf_destroy();
+
+   return rc;
+}
-- 
2.5.0


--
Check out the vibrant tech community on one of the world's most
engaging tech sites, SlashDot.org! http://sdm.link/slashdot
___
tpmdd-devel mailing list
tpmdd-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/tpmdd-devel


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

2017-01-19 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 prevent malicious users from
setting unused PCR banks with fake measurements and quoting them.
This patch set adds support for extending all active PCR banks,
as recommended.

The first patch implements the TPM 2.0 capability to retrieve
the list of active PCR banks.

The second patch modifies the tpm_pcr_extend() and tpm2_pcr_extend()
interface to support extending multiple PCR banks. The existing
tpm_pcr_extend() interface expects only a SHA1 digest. Hence, to
extend all active PCR banks with differing digest sizes for TPM 2.0,
the SHA1 digest is padded with 0's as needed.

[1] TPM 2.0 Specification referred here is "TCG PC Client Specific
Platform Firmware Profile for TPM 2.0"

Changelog v5:
- Patch "tpm: implement TPM 2.0 capability to get active PCR banks"
 - Included Jarkko's feedbacks
   - Moved variable declaration to start of function in
   tpm_pcr_extend()


Changelog v4:
- Updated cover letter as per Mimi's feedback.
- Rebased to Jarkko's latest master branch (4064b6b tpm_tis: use
  default timeout value if chip reports it as zero)
- Patch "tpm: implement TPM 2.0 capability to get active PCR banks"
 - Included Jarkko's feedbacks
   - Moved call to tpm2_get_pcr_allocation to Patch 2
   - Renamed struct tpm2_tpms_pcr_selection to struct tpm2_pcr_selection 
   and moved the struct to before tpm2_get_pcr_allocation()
   - Fixed code formatting
- Patch "tpm: enchance TPM 2.0 PCR extend to support multiple banks"
 - Included Jarkkos' feedbacks
   - Updated commit msg to mention dependency on CRYPTO_HASH_INFO
   - Renamed struct tpmt_hash to struct tpm2_digest 
   - Removed struct tpml_digest_values, tpm2_pcr_extend() now accepts
   count and digests list as two separate arguments. Added check for
   count of hashes passed.
 - Cleaned up struct tpm2_pcr_extend_in as not required anymore with
 use of tpm_buf
 - Moved struct tpm2_null_auth_area just before tpm2_pcr_extend() as
 it is the only function using it for now.
 - Fixed code formatting

Changelog v3:
- Rebased to the Jarkko's latest master branch (8e25809 tpm:
  Do not print an error message when doing TPM auto startup)
- Patch "tpm: implement TPM 2.0 capability to get active PCR banks"
  - Included Jarkko's feedbacks
 - Removed getcap_in, getcap_out and used tpm_buf for getting
 capability.
 - Used ARRAY_SIZE in place of TPM_MAX_PCR_BANKS and included
 other feedbacks.
- Patch "tpm: enhance TPM 2.0 PCR extend to support multiple banks"
 - Fixed kbuild errors
   - Fixed buf.data uninitialized warning.
   - Added TCG_TPM dependency on CONFIG_CRYPTO_HASH_INFO in Kconfig.

Changelog v2:

- Patch "tpm: implement TPM 2.0 capability to get active PCR banks"
  - defined structs definition in tpm2-cmd.c.
  - no_of_active_banks field is removed. Instead, constant
  TPM2_MAX_PCR_BANKS is defined.
  - renamed tpm2_get_active_pcr_banks() to tpm2_get_pcr_allocation()
  - removed generic function tpm2_get_capability().

- Patch "tpm: enchance TPM 2.0 PCR extend to support multiple banks"
 - Removed tpm2.h, and defined structs common for extend and event log
  in tpm_eventlog.h
 - uses tpm_buf in tpm2_pcr_extend().

Nayna Jain (2):
  tpm: implement TPM 2.0 capability to get active PCR banks
  tpm: enhance TPM 2.0 PCR extend to support multiple banks

 drivers/char/tpm/Kconfig |   1 +
 drivers/char/tpm/tpm-interface.c |  15 +++-
 drivers/char/tpm/tpm.h   |   7 +-
 drivers/char/tpm/tpm2-cmd.c  | 148 ---
 drivers/char/tpm/tpm_eventlog.h  |   7 ++
 5 files changed, 134 insertions(+), 44 deletions(-)

-- 
2.5.0


--
Check out the vibrant tech community on one of the world's most
engaging tech sites, SlashDot.org! http://sdm.link/slashdot
___
tpmdd-devel mailing list
tpmdd-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/tpmdd-devel


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

2017-01-18 Thread Nayna


On 01/18/2017 07:15 PM, Jarkko Sakkinen wrote:
> On Wed, Jan 18, 2017 at 03:44:49AM -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 Jain <na...@linux.vnet.ibm.com>
>> ---
>>   drivers/char/tpm/tpm.h  |  4 
>>   drivers/char/tpm/tpm2-cmd.c | 57 
>> +
>>   2 files changed, 61 insertions(+)
>>
>> diff --git a/drivers/char/tpm/tpm.h b/drivers/char/tpm/tpm.h
>> index 1ae9768..573 100644
>> --- a/drivers/char/tpm/tpm.h
>> +++ b/drivers/char/tpm/tpm.h
>> @@ -127,6 +127,7 @@ enum tpm2_permanent_handles {
>>   };
>>
>>   enum tpm2_capabilities {
>> +TPM2_CAP_PCRS   = 5,
>>  TPM2_CAP_TPM_PROPERTIES = 6,
>>   };
>>
>> @@ -187,6 +188,8 @@ struct tpm_chip {
>>
>>  const struct attribute_group *groups[3];
>>  unsigned int groups_cnt;
>> +
>> +u16 active_banks[7];
>>   #ifdef CONFIG_ACPI
>>  acpi_handle acpi_dev_handle;
>>  char ppi_version[TPM_PPI_VERSION_LEN + 1];
>> @@ -545,4 +548,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);
>> +ssize_t tpm2_get_pcr_allocation(struct tpm_chip *chip);
>>   #endif
>> diff --git a/drivers/char/tpm/tpm2-cmd.c b/drivers/char/tpm/tpm2-cmd.c
>> index 6eda239..75a7546 100644
>> --- a/drivers/char/tpm/tpm2-cmd.c
>> +++ b/drivers/char/tpm/tpm2-cmd.c
>> @@ -998,3 +998,60 @@ int tpm2_auto_startup(struct tpm_chip *chip)
>>  rc = -ENODEV;
>>  return rc;
>>   }
>> +
>> +struct tpm2_pcr_selection {
>> +__be16  hash_alg;
>> +u8  size_of_select;
>> +u8  pcr_select[3];
>> +} __packed;
>> +
>> +/**
>> + * tpm2_get_pcr_allocation() - get TPM active PCR banks.
>> + *
>> + * @chip: TPM chip to use.
>> + *
>> + * Return: Same as with tpm_transmit_cmd.
>> + */
>> +ssize_t tpm2_get_pcr_allocation(struct tpm_chip *chip)
>> +{
>> +struct tpm2_pcr_selection pcr_selection;
>> +struct tpm_buf buf;
>> +void *marker;
>> +unsigned int count = 0;
>
> You shouldn't initialize 'count'.

It is initialized for reason below:

>
>> +int rc;
>> +int i;
>> +
>> +rc = tpm_buf_init(, TPM2_ST_NO_SESSIONS, TPM2_CC_GET_CAPABILITY);
>> +if (rc)
>> +return rc;
>> +
>> +tpm_buf_append_u32(, TPM2_CAP_PCRS);
>> +tpm_buf_append_u32(, 0);
>> +tpm_buf_append_u32(, 1);
>> +
>> +rc = tpm_transmit_cmd(chip, buf.data, PAGE_SIZE, 0,
>> +  "get tpm pcr allocation");
>> +if (rc < 0)
>> +goto out;

if  tpm_transmit_cmd()fails, it jumps to out:
where count is used in if(..).

Thanks & Regards,
- Nayna

>> +
>> +count = be32_to_cpup(
>> +(__be32 *)[TPM_HEADER_SIZE + 5]);
>> +
>> +if (count > ARRAY_SIZE(chip->active_banks))
>> +return -ENODEV;
>> +
>> +marker = [TPM_HEADER_SIZE + 9];
>> +for (i = 0; i < count; i++) {
>> +memcpy(_selection, marker, sizeof(pcr_selection));
>> +chip->active_banks[i] = be16_to_cpu(pcr_selection.hash_alg);
>> +marker = marker + sizeof(struct tpm2_pcr_selection);
>> +}
>> +
>> +out:
>> +if (count < ARRAY_SIZE(chip->active_banks))
>> +chip->active_banks[count] = 0;
>> +
>> +tpm_buf_destroy();
>> +
>> +return rc;
>> +}
>> --
>> 2.5.0
>
> Otherwise,
>
> Reviewed-by: Jarkko Sakkinen <jarkko.sakk...@linux.intel.com>
>
> /Jarkko
>


--
Check out the vibrant tech community on one of the world's most
engaging tech sites, SlashDot.org! http://sdm.link/slashdot
___
tpmdd-devel mailing list
tpmdd-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/tpmdd-devel


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

2017-01-18 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 <na...@linux.vnet.ibm.com>
---
 drivers/char/tpm/tpm.h  |  4 
 drivers/char/tpm/tpm2-cmd.c | 57 +
 2 files changed, 61 insertions(+)

diff --git a/drivers/char/tpm/tpm.h b/drivers/char/tpm/tpm.h
index 1ae9768..573 100644
--- a/drivers/char/tpm/tpm.h
+++ b/drivers/char/tpm/tpm.h
@@ -127,6 +127,7 @@ enum tpm2_permanent_handles {
 };
 
 enum tpm2_capabilities {
+   TPM2_CAP_PCRS   = 5,
TPM2_CAP_TPM_PROPERTIES = 6,
 };
 
@@ -187,6 +188,8 @@ struct tpm_chip {
 
const struct attribute_group *groups[3];
unsigned int groups_cnt;
+
+   u16 active_banks[7];
 #ifdef CONFIG_ACPI
acpi_handle acpi_dev_handle;
char ppi_version[TPM_PPI_VERSION_LEN + 1];
@@ -545,4 +548,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);
+ssize_t tpm2_get_pcr_allocation(struct tpm_chip *chip);
 #endif
diff --git a/drivers/char/tpm/tpm2-cmd.c b/drivers/char/tpm/tpm2-cmd.c
index 6eda239..75a7546 100644
--- a/drivers/char/tpm/tpm2-cmd.c
+++ b/drivers/char/tpm/tpm2-cmd.c
@@ -998,3 +998,60 @@ int tpm2_auto_startup(struct tpm_chip *chip)
rc = -ENODEV;
return rc;
 }
+
+struct tpm2_pcr_selection {
+   __be16  hash_alg;
+   u8  size_of_select;
+   u8  pcr_select[3];
+} __packed;
+
+/**
+ * tpm2_get_pcr_allocation() - get TPM active PCR banks.
+ *
+ * @chip: TPM chip to use.
+ *
+ * Return: Same as with tpm_transmit_cmd.
+ */
+ssize_t tpm2_get_pcr_allocation(struct tpm_chip *chip)
+{
+   struct tpm2_pcr_selection pcr_selection;
+   struct tpm_buf buf;
+   void *marker;
+   unsigned int count = 0;
+   int rc;
+   int i;
+
+   rc = tpm_buf_init(, TPM2_ST_NO_SESSIONS, TPM2_CC_GET_CAPABILITY);
+   if (rc)
+   return rc;
+
+   tpm_buf_append_u32(, TPM2_CAP_PCRS);
+   tpm_buf_append_u32(, 0);
+   tpm_buf_append_u32(, 1);
+
+   rc = tpm_transmit_cmd(chip, buf.data, PAGE_SIZE, 0,
+ "get tpm pcr allocation");
+   if (rc < 0)
+   goto out;
+
+   count = be32_to_cpup(
+   (__be32 *)[TPM_HEADER_SIZE + 5]);
+
+   if (count > ARRAY_SIZE(chip->active_banks))
+   return -ENODEV;
+
+   marker = [TPM_HEADER_SIZE + 9];
+   for (i = 0; i < count; i++) {
+   memcpy(_selection, marker, sizeof(pcr_selection));
+   chip->active_banks[i] = be16_to_cpu(pcr_selection.hash_alg);
+   marker = marker + sizeof(struct tpm2_pcr_selection);
+   }
+
+out:
+   if (count < ARRAY_SIZE(chip->active_banks))
+   chip->active_banks[count] = 0;
+
+   tpm_buf_destroy();
+
+   return rc;
+}
-- 
2.5.0


--
Check out the vibrant tech community on one of the world's most
engaging tech sites, SlashDot.org! http://sdm.link/slashdot
___
tpmdd-devel mailing list
tpmdd-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/tpmdd-devel


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

2017-01-18 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 prevent malicious users from
setting unused PCR banks with fake measurements and quoting them.
This patch set adds support for extending all active PCR banks,
as recommended.

The first patch implements the TPM 2.0 capability to retrieve
the list of active PCR banks.

The second patch modifies the tpm_pcr_extend() and tpm2_pcr_extend()
interface to support extending multiple PCR banks. The existing
tpm_pcr_extend() interface expects only a SHA1 digest. Hence, to
extend all active PCR banks with differing digest sizes for TPM 2.0,
the SHA1 digest is padded with 0's as needed.

[1] TPM 2.0 Specification referred here is "TCG PC Client Specific
Platform Firmware Profile for TPM 2.0"

Changelog v4:
- Updated cover letter as per Mimi's feedback.
- Rebased to Jarkko's latest master branch (4064b6b tpm_tis: use
  default timeout value if chip reports it as zero)
- Patch "tpm: implement TPM 2.0 capability to get active PCR banks"
 - Included Jarkko's feedbacks
   - Moved call to tpm2_get_pcr_allocation to Patch 2
   - Renamed struct tpm2_tpms_pcr_selection to struct tpm2_pcr_selection 
   and moved the struct to before tpm2_get_pcr_allocation()
   - Fixed code formatting
- Patch "tpm: enchance TPM 2.0 PCR extend to support multiple banks"
 - Included Jarkkos' feedbacks
   - Updated commit msg to mention dependency on CRYPTO_HASH_INFO
   - Renamed struct tpmt_hash to struct tpm2_digest 
   - Removed struct tpml_digest_values, tpm2_pcr_extend() now accepts
   count and digests list as two separate arguments. Added check for
   count of hashes passed.
 - Cleaned up struct tpm2_pcr_extend_in as not required anymore with
 use of tpm_buf
 - Moved struct tpm2_null_auth_area just before tpm2_pcr_extend() as
 it is the only function using it for now.
 - Fixed code formatting

Changelog v3:
- Rebased to the Jarkko's latest master branch (8e25809 tpm:
  Do not print an error message when doing TPM auto startup)
- Patch "tpm: implement TPM 2.0 capability to get active PCR banks"
  - Included Jarkko's feedbacks
 - Removed getcap_in, getcap_out and used tpm_buf for getting
 capability.
 - Used ARRAY_SIZE in place of TPM_MAX_PCR_BANKS and included
 other feedbacks.
- Patch "tpm: enhance TPM 2.0 PCR extend to support multiple banks"
 - Fixed kbuild errors
   - Fixed buf.data uninitialized warning.
   - Added TCG_TPM dependency on CONFIG_CRYPTO_HASH_INFO in Kconfig.

Changelog v2:

- Patch "tpm: implement TPM 2.0 capability to get active PCR banks"
  - defined structs definition in tpm2-cmd.c.
  - no_of_active_banks field is removed. Instead, constant
  TPM2_MAX_PCR_BANKS is defined.
  - renamed tpm2_get_active_pcr_banks() to tpm2_get_pcr_allocation()
  - removed generic function tpm2_get_capability().

- Patch "tpm: enchance TPM 2.0 PCR extend to support multiple banks"
 - Removed tpm2.h, and defined structs common for extend and event log
  in tpm_eventlog.h
 - uses tpm_buf in tpm2_pcr_extend().

Nayna Jain (2):
  tpm: implement TPM 2.0 capability to get active PCR banks
  tpm: enhance TPM 2.0 PCR extend to support multiple banks

 drivers/char/tpm/Kconfig |   1 +
 drivers/char/tpm/tpm-interface.c |  15 +++-
 drivers/char/tpm/tpm.h   |   7 +-
 drivers/char/tpm/tpm2-cmd.c  | 148 ---
 drivers/char/tpm/tpm_eventlog.h  |   7 ++
 5 files changed, 134 insertions(+), 44 deletions(-)

-- 
2.5.0


--
Check out the vibrant tech community on one of the world's most
engaging tech sites, SlashDot.org! http://sdm.link/slashdot
___
tpmdd-devel mailing list
tpmdd-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/tpmdd-devel


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

2017-01-16 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 unused PCR banks with
>> fake measurements and quoting them.
>>
>> The existing in-kernel interface(tpm_pcr_extend()) expects only a
>> SHA1 digest.  To extend all active PCR banks with differing
>> digest sizes, the SHA1 digest is padded with trailing 0's as needed.
>>
>> [1] TPM 2.0 Specification referred here is "TCG PC Client Specific
>> Platform Firmware Profile for TPM 2.0"
>>
>> Signed-off-by: Nayna Jain <na...@linux.vnet.ibm.com>
>> ---
>>   drivers/char/tpm/Kconfig |  1 +
>>   drivers/char/tpm/tpm-interface.c | 16 +-
>>   drivers/char/tpm/tpm.h   |  3 +-
>>   drivers/char/tpm/tpm2-cmd.c  | 68 
>> +++-
>>   drivers/char/tpm/tpm_eventlog.h  | 18 +++
>>   5 files changed, 75 insertions(+), 31 deletions(-)
>>
>> diff --git a/drivers/char/tpm/Kconfig b/drivers/char/tpm/Kconfig
>> index 277186d..af985cc 100644
>> --- a/drivers/char/tpm/Kconfig
>> +++ b/drivers/char/tpm/Kconfig
>> @@ -6,6 +6,7 @@ menuconfig TCG_TPM
>>  tristate "TPM Hardware Support"
>>  depends on HAS_IOMEM
>>  select SECURITYFS
>> +select CRYPTO_HASH_INFO
>
> In the commit message you did not mention this.
>
>>  ---help---
>>If you have a TPM security chip in your system, which
>>implements the Trusted Computing Group's specification,
>> diff --git a/drivers/char/tpm/tpm-interface.c 
>> b/drivers/char/tpm/tpm-interface.c
>> index fecdd3f..e037dd2 100644
>> --- a/drivers/char/tpm/tpm-interface.c
>> +++ b/drivers/char/tpm/tpm-interface.c
>> @@ -7,6 +7,7 @@
>>* Dave Safford <saff...@watson.ibm.com>
>>* Reiner Sailer <sai...@watson.ibm.com>
>>* Kylene Hall <kjh...@us.ibm.com>
>> + * Nayna Jain <na...@linux.vnet.ibm.com>
>
> Remove.
>
>>*
>>* Maintained by: <tpmdd-devel@lists.sourceforge.net>
>>*
>> @@ -759,6 +760,7 @@ static const struct tpm_input_header pcrextend_header = {
>>   int tpm_pcr_extend(u32 chip_num, int pcr_idx, const u8 *hash)
>>   {
>>  struct tpm_cmd_t cmd;
>> +int i;
>>  int rc;
>>  struct tpm_chip *chip;
>>
>> @@ -767,7 +769,19 @@ int tpm_pcr_extend(u32 chip_num, int pcr_idx, const u8 
>> *hash)
>>  return -ENODEV;
>>
>>  if (chip->flags & TPM_CHIP_FLAG_TPM2) {
>> -rc = tpm2_pcr_extend(chip, pcr_idx, hash);
>> +struct tpml_digest_values d_values;
>> +
>> +memset(_values, 0, sizeof(d_values));
>> +
>> +for (i = 0; (chip->active_banks[i] != 0) &&
>> + (i < ARRAY_SIZE(chip->active_banks)); i++) {
>> +d_values.digests[i].alg_id = chip->active_banks[i];
>> +memcpy(d_values.digests[i].digest, hash,
>> +   TPM_DIGEST_SIZE);
>> +d_values.count++;
>> +}
>> +
>> +rc = tpm2_pcr_extend(chip, pcr_idx, _values);
>>  tpm_put_ops(chip);
>>  return rc;
>>  }
>> diff --git a/drivers/char/tpm/tpm.h b/drivers/char/tpm/tpm.h
>> index 573..dd82d58 100644
>> --- a/drivers/char/tpm/tpm.h
>> +++ b/drivers/char/tpm/tpm.h
>> @@ -533,7 +533,8 @@ static inline void tpm_add_ppi(struct tpm_chip *chip)
>>   #endif
>>
>>   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, const u8 *hash);
>> +int tpm2_pcr_extend(struct tpm_chip *chip, int pcr_idx,
>> +struct tpml_digest_values *digests);
>>   int tpm2_get_random(struct tpm_chip *chip, u8 *out, size_t max);
>>   int tpm2_seal_trusted(struct tpm_chip *chip,
>>struct trusted_key_payload *payload,
>> diff --git a/drivers/char/tpm/tpm2-cmd.c b/drivers/char/tpm/tpm2-cmd.c
>> index 87388921..5027a54 100644
>> --- a/drivers/char/tpm/tpm2-cmd.c
>> +++ b/drivers/char/tpm/tpm2-cmd.c
>> @@ -64,9 +64,7 @@ struct tpm2_pcr_extend_in {
>>  __be32  pcr_idx;
>>  __be32  auth_area_size;
>>  struct tpm2_null

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 2.0
>> TCG Specification.
>>
>> Signed-off-by: Nayna Jain <na...@linux.vnet.ibm.com>
>> ---
>>   drivers/char/tpm/tpm.h  |  4 +++
>>   drivers/char/tpm/tpm2-cmd.c | 59 
>> +
>>   2 files changed, 63 insertions(+)
>>
>> diff --git a/drivers/char/tpm/tpm.h b/drivers/char/tpm/tpm.h
>> index 1ae9768..573 100644
>> --- a/drivers/char/tpm/tpm.h
>> +++ b/drivers/char/tpm/tpm.h
>> @@ -127,6 +127,7 @@ enum tpm2_permanent_handles {
>>   };
>>
>>   enum tpm2_capabilities {
>> +TPM2_CAP_PCRS   = 5,
>>  TPM2_CAP_TPM_PROPERTIES = 6,
>>   };
>>
>> @@ -187,6 +188,8 @@ struct tpm_chip {
>>
>>  const struct attribute_group *groups[3];
>>  unsigned int groups_cnt;
>> +
>> +u16 active_banks[7];
>>   #ifdef CONFIG_ACPI
>>  acpi_handle acpi_dev_handle;
>>  char ppi_version[TPM_PPI_VERSION_LEN + 1];
>> @@ -545,4 +548,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);
>> +ssize_t tpm2_get_pcr_allocation(struct tpm_chip *chip);
>>   #endif
>> diff --git a/drivers/char/tpm/tpm2-cmd.c b/drivers/char/tpm/tpm2-cmd.c
>> index 6eda239..87388921 100644
>> --- a/drivers/char/tpm/tpm2-cmd.c
>> +++ b/drivers/char/tpm/tpm2-cmd.c
>> @@ -83,6 +83,12 @@ struct tpm2_get_tpm_pt_out {
>>  __be32  value;
>>   } __packed;
>>
>> +struct tpm2_tpms_pcr_selection {
>> +__be16  hash_alg;
>> +u8  size_of_select;
>> +u8  pcr_select[3];
>> +} __packed;
>
> Please move this right before tpm2_get_pcr_allocation.
> Drop 'tpms_'.

Sure, will do this. But didn't understand why. I think all structs are 
defined in start of file..

Thanks & Regards,
- Nayna

>
>> +
>>   struct tpm2_get_random_in {
>>  __be16  size;
>>   } __packed;
>> @@ -993,8 +999,61 @@ int tpm2_auto_startup(struct tpm_chip *chip)
>>  }
>>  }
>>
>> +rc = tpm2_get_pcr_allocation(chip);
>> +
>
> Please have this call in the commit where you actually use it
> Does not make any sense here
>
>>   out:
>>  if (rc > 0)
>>  rc = -ENODEV;
>>  return rc;
>>   }
>> +
>> +/**
>> + * tpm2_get_pcr_allocation() - get TPM active PCR banks.
>> + *
>> + * @chip: TPM chip to use.
>> + *
>> + * Return: Same as with tpm_transmit_cmd.
>> + */
>> +ssize_t tpm2_get_pcr_allocation(struct tpm_chip *chip)
>> +{
>> +struct tpm2_tpms_pcr_selection pcr_selection;
>> +struct tpm_buf buf;
>> +void *marker;
>> +unsigned int count = 0;
>> +int rc;
>> +int i;
>> +
>> +rc = tpm_buf_init(, TPM2_ST_NO_SESSIONS, TPM2_CC_GET_CAPABILITY);
>> +if (rc)
>> +return rc;
>> +
>> +tpm_buf_append_u32(, TPM2_CAP_PCRS);
>> +tpm_buf_append_u32(, 0);
>> +tpm_buf_append_u32(, 1);
>> +
>> +rc = tpm_transmit_cmd(chip, buf.data, PAGE_SIZE, 0,
>> +  "get tpm pcr allocation");
>> +if (rc < 0)
>> +goto out;
>> +
>> +count = be32_to_cpup(
>> +(__be32 *) [TPM_HEADER_SIZE + 5]);
>
> Please do not add a space after cast. This has been an issue in your
> previous patches too so try to do it right next time.
>
>> +
>> +if (count > ARRAY_SIZE(chip->active_banks))
>> +return -ENODEV;
>> +
>> +marker = [TPM_HEADER_SIZE + 9];
>> +for (i = 0; i < count; i++) {
>> +memcpy(_selection, marker, sizeof(pcr_selection));
>> +chip->active_banks[i] = be16_to_cpu(pcr_selection.hash_alg);
>> +marker = marker + sizeof(struct tpm2_tpms_pcr_selection);
>> +}
>> +
>> +out:
>> +if (count < ARRAY_SIZE(chip->active_banks))
>> +chip->active_banks[count] = 0;
>> +
>> +tpm_buf_destroy();
>> +
>> +return rc;
>> +}
>> --
>> 2.5.0
>>
>
> /Jarkko
>


--
Developer Access Program for Intel Xeon Phi Processors
Access to Intel Xeon Phi processor-based developer platforms.
With one year of Intel Parallel Studio XE.
Training and support from Colfax.
Order your platform today. http://sdm.link/xeonphi
___
tpmdd-devel mailing list
tpmdd-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/tpmdd-devel


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 unused PCR banks with
>> fake measurements and quoting them.
>>
>> The existing in-kernel interface(tpm_pcr_extend()) expects only a
>> SHA1 digest.  To extend all active PCR banks with differing
>> digest sizes, the SHA1 digest is padded with trailing 0's as needed.
>>
>> [1] TPM 2.0 Specification referred here is "TCG PC Client Specific
>> Platform Firmware Profile for TPM 2.0"
>>
>> Signed-off-by: Nayna Jain <na...@linux.vnet.ibm.com>
>> ---
>>   drivers/char/tpm/Kconfig |  1 +
>>   drivers/char/tpm/tpm-interface.c | 16 +-
>>   drivers/char/tpm/tpm.h   |  3 +-
>>   drivers/char/tpm/tpm2-cmd.c  | 68 
>> +++-
>>   drivers/char/tpm/tpm_eventlog.h  | 18 +++
>>   5 files changed, 75 insertions(+), 31 deletions(-)
>>
>> diff --git a/drivers/char/tpm/Kconfig b/drivers/char/tpm/Kconfig
>> index 277186d..af985cc 100644
>> --- a/drivers/char/tpm/Kconfig
>> +++ b/drivers/char/tpm/Kconfig
>> @@ -6,6 +6,7 @@ menuconfig TCG_TPM
>>  tristate "TPM Hardware Support"
>>  depends on HAS_IOMEM
>>  select SECURITYFS
>> +select CRYPTO_HASH_INFO
>
> In the commit message you did not mention this.
>
>>  ---help---
>>If you have a TPM security chip in your system, which
>>implements the Trusted Computing Group's specification,
>> diff --git a/drivers/char/tpm/tpm-interface.c 
>> b/drivers/char/tpm/tpm-interface.c
>> index fecdd3f..e037dd2 100644
>> --- a/drivers/char/tpm/tpm-interface.c
>> +++ b/drivers/char/tpm/tpm-interface.c
>> @@ -7,6 +7,7 @@
>>* Dave Safford <saff...@watson.ibm.com>
>>* Reiner Sailer <sai...@watson.ibm.com>
>>* Kylene Hall <kjh...@us.ibm.com>
>> + * Nayna Jain <na...@linux.vnet.ibm.com>
>
> Remove.
>
>>*
>>* Maintained by: <tpmdd-devel@lists.sourceforge.net>
>>*
>> @@ -759,6 +760,7 @@ static const struct tpm_input_header pcrextend_header = {
>>   int tpm_pcr_extend(u32 chip_num, int pcr_idx, const u8 *hash)
>>   {
>>  struct tpm_cmd_t cmd;
>> +int i;
>>  int rc;
>>  struct tpm_chip *chip;
>>
>> @@ -767,7 +769,19 @@ int tpm_pcr_extend(u32 chip_num, int pcr_idx, const u8 
>> *hash)
>>  return -ENODEV;
>>
>>  if (chip->flags & TPM_CHIP_FLAG_TPM2) {
>> -rc = tpm2_pcr_extend(chip, pcr_idx, hash);
>> +struct tpml_digest_values d_values;
>> +
>> +memset(_values, 0, sizeof(d_values));
>> +
>> +for (i = 0; (chip->active_banks[i] != 0) &&
>> + (i < ARRAY_SIZE(chip->active_banks)); i++) {
>> +d_values.digests[i].alg_id = chip->active_banks[i];
>> +memcpy(d_values.digests[i].digest, hash,
>> +   TPM_DIGEST_SIZE);
>> +d_values.count++;
>> +}
>> +
>> +rc = tpm2_pcr_extend(chip, pcr_idx, _values);
>>  tpm_put_ops(chip);
>>  return rc;
>>  }
>> diff --git a/drivers/char/tpm/tpm.h b/drivers/char/tpm/tpm.h
>> index 573..dd82d58 100644
>> --- a/drivers/char/tpm/tpm.h
>> +++ b/drivers/char/tpm/tpm.h
>> @@ -533,7 +533,8 @@ static inline void tpm_add_ppi(struct tpm_chip *chip)
>>   #endif
>>
>>   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, const u8 *hash);
>> +int tpm2_pcr_extend(struct tpm_chip *chip, int pcr_idx,
>> +struct tpml_digest_values *digests);
>>   int tpm2_get_random(struct tpm_chip *chip, u8 *out, size_t max);
>>   int tpm2_seal_trusted(struct tpm_chip *chip,
>>struct trusted_key_payload *payload,
>> diff --git a/drivers/char/tpm/tpm2-cmd.c b/drivers/char/tpm/tpm2-cmd.c
>> index 87388921..5027a54 100644
>> --- a/drivers/char/tpm/tpm2-cmd.c
>> +++ b/drivers/char/tpm/tpm2-cmd.c
>> @@ -64,9 +64,7 @@ struct tpm2_pcr_extend_in {
>>  __be32  pcr_idx;
>>  __be32  auth_area_size;
>>  struct tpm2_null

[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 a
SHA1 digest.  To extend all active PCR banks with differing
digest sizes, the SHA1 digest is padded with trailing 0's as needed.

[1] TPM 2.0 Specification referred here is "TCG PC Client Specific
Platform Firmware Profile for TPM 2.0"

Signed-off-by: Nayna Jain <na...@linux.vnet.ibm.com>
---
 drivers/char/tpm/Kconfig |  1 +
 drivers/char/tpm/tpm-interface.c | 16 +-
 drivers/char/tpm/tpm.h   |  3 +-
 drivers/char/tpm/tpm2-cmd.c  | 68 +++-
 drivers/char/tpm/tpm_eventlog.h  | 18 +++
 5 files changed, 75 insertions(+), 31 deletions(-)

diff --git a/drivers/char/tpm/Kconfig b/drivers/char/tpm/Kconfig
index 277186d..af985cc 100644
--- a/drivers/char/tpm/Kconfig
+++ b/drivers/char/tpm/Kconfig
@@ -6,6 +6,7 @@ menuconfig TCG_TPM
tristate "TPM Hardware Support"
depends on HAS_IOMEM
select SECURITYFS
+   select CRYPTO_HASH_INFO
---help---
  If you have a TPM security chip in your system, which
  implements the Trusted Computing Group's specification,
diff --git a/drivers/char/tpm/tpm-interface.c b/drivers/char/tpm/tpm-interface.c
index fecdd3f..e037dd2 100644
--- a/drivers/char/tpm/tpm-interface.c
+++ b/drivers/char/tpm/tpm-interface.c
@@ -7,6 +7,7 @@
  * Dave Safford <saff...@watson.ibm.com>
  * Reiner Sailer <sai...@watson.ibm.com>
  * Kylene Hall <kjh...@us.ibm.com>
+ * Nayna Jain <na...@linux.vnet.ibm.com>
  *
  * Maintained by: <tpmdd-devel@lists.sourceforge.net>
  *
@@ -759,6 +760,7 @@ static const struct tpm_input_header pcrextend_header = {
 int tpm_pcr_extend(u32 chip_num, int pcr_idx, const u8 *hash)
 {
struct tpm_cmd_t cmd;
+   int i;
int rc;
struct tpm_chip *chip;
 
@@ -767,7 +769,19 @@ int tpm_pcr_extend(u32 chip_num, int pcr_idx, const u8 
*hash)
return -ENODEV;
 
if (chip->flags & TPM_CHIP_FLAG_TPM2) {
-   rc = tpm2_pcr_extend(chip, pcr_idx, hash);
+   struct tpml_digest_values d_values;
+
+   memset(_values, 0, sizeof(d_values));
+
+   for (i = 0; (chip->active_banks[i] != 0) &&
+(i < ARRAY_SIZE(chip->active_banks)); i++) {
+   d_values.digests[i].alg_id = chip->active_banks[i];
+   memcpy(d_values.digests[i].digest, hash,
+  TPM_DIGEST_SIZE);
+   d_values.count++;
+   }
+
+   rc = tpm2_pcr_extend(chip, pcr_idx, _values);
tpm_put_ops(chip);
return rc;
}
diff --git a/drivers/char/tpm/tpm.h b/drivers/char/tpm/tpm.h
index 573..dd82d58 100644
--- a/drivers/char/tpm/tpm.h
+++ b/drivers/char/tpm/tpm.h
@@ -533,7 +533,8 @@ static inline void tpm_add_ppi(struct tpm_chip *chip)
 #endif
 
 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, const u8 *hash);
+int tpm2_pcr_extend(struct tpm_chip *chip, int pcr_idx,
+   struct tpml_digest_values *digests);
 int tpm2_get_random(struct tpm_chip *chip, u8 *out, size_t max);
 int tpm2_seal_trusted(struct tpm_chip *chip,
  struct trusted_key_payload *payload,
diff --git a/drivers/char/tpm/tpm2-cmd.c b/drivers/char/tpm/tpm2-cmd.c
index 87388921..5027a54 100644
--- a/drivers/char/tpm/tpm2-cmd.c
+++ b/drivers/char/tpm/tpm2-cmd.c
@@ -64,9 +64,7 @@ struct tpm2_pcr_extend_in {
__be32  pcr_idx;
__be32  auth_area_size;
struct tpm2_null_auth_area  auth_area;
-   __be32  digest_cnt;
-   __be16  hash_alg;
-   u8  digest[TPM_DIGEST_SIZE];
+   struct tpml_digest_values   digests;
 } __packed;
 
 struct tpm2_get_tpm_pt_in {
@@ -296,46 +294,58 @@ int tpm2_pcr_read(struct tpm_chip *chip, int pcr_idx, u8 
*res_buf)
return rc;
 }
 
-#define TPM2_GET_PCREXTEND_IN_SIZE \
-   (sizeof(struct tpm_input_header) + \
-sizeof(struct tpm2_pcr_extend_in))
-
-static const struct tpm_input_header tpm2_pcrextend_header = {
-   .tag = cpu_to_be16(TPM2_ST_SESSIONS),
-   .length = cpu_to_be32(TPM2_GET_PCREXTEND_IN_SIZE),
-   .ordinal = cpu_to_be32(TPM2_CC_PCR_EXTEND)
-};
-
 /**
  * tpm2_pcr_extend() - extend a PCR value
  *
  * @chip:  TPM chip to use.
  * @pcr_idx:   index of the PCR.
- * @hash:  hash value to use for the extend operation.
+ * @digests:   list of pcr banks and corresponding hash values to be extend

[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 prevent malicious users from
setting unused PCR banks with fake measurements and quoting them.
This patch set adds support for extending all active PCR banks,
as recommended.

The first patch implements the TPM 2.0 capability to retrieve
the list of active PCR banks.

The second patch modifies the tpm_pcr_extend() and tpm2_pcr_extend()
interface to support extending multiple PCR banks. The existing
tpm_pcr_extend() interface expects only a SHA1 digest. Hence, to
extend all active PCR banks with differing digest sizes for TPM 2.0,
the SHA1 digest is padded with 0's as needed.

This approach is taken to maintain backwards compatibility for IMA
in order to continue working with both TPM 1.2 and TPM 2.0 without
any changes and still comply with TCG TPM 2.0 Specification[1].

[1] TPM 2.0 Specification referred here is "TCG PC Client Specific
Platform Firmware Profile for TPM 2.0"

Changelog v3:
- Rebased to the Jarkko's latest master branch (8e25809 tpm:
  Do not print an error message when doing TPM auto startup)
- Patch "tpm: implement TPM 2.0 capability to get active PCR banks"
  - Included Jarkko's feedbacks
 - Removed getcap_in, getcap_out and used tpm_buf for getting
 capability.
 - Used ARRAY_SIZE in place of TPM_MAX_PCR_BANKS and included
 other feedbacks.
- Patch "tpm: enhance TPM 2.0 PCR extend to support multiple banks"
 - Fixed kbuild errors
   - Fixed buf.data uninitialized warning.
   - Added TCG_TPM dependency on CONFIG_CRYPTO_HASH_INFO in Kconfig.

Changelog v2:

- Patch "tpm: implement TPM 2.0 capability to get active PCR banks"
  - defined structs definition in tpm2-cmd.c.
  - no_of_active_banks field is removed. Instead, constant
  TPM2_MAX_PCR_BANKS is defined.
  - renamed tpm2_get_active_pcr_banks() to tpm2_get_pcr_allocation()
  - removed generic function tpm2_get_capability().

- Patch "tpm: enchance TPM 2.0 PCR extend to support multiple banks"
 - Removed tpm2.h, and defined structs common for extend and event log
  in tpm_eventlog.h
 - uses tpm_buf in tpm2_pcr_extend().

Nayna Jain (2):
  tpm: implement TPM 2.0 capability to get active PCR banks
  tpm: enhance TPM 2.0 PCR extend to support multiple banks

 drivers/char/tpm/Kconfig |   1 +
 drivers/char/tpm/tpm-interface.c |  16 -
 drivers/char/tpm/tpm.h   |   7 ++-
 drivers/char/tpm/tpm2-cmd.c  | 127 ++-
 drivers/char/tpm/tpm_eventlog.h  |  18 ++
 5 files changed, 138 insertions(+), 31 deletions(-)

-- 
2.5.0


--
Developer Access Program for Intel Xeon Phi Processors
Access to Intel Xeon Phi processor-based developer platforms.
With one year of Intel Parallel Studio XE.
Training and support from Colfax.
Order your platform today. http://sdm.link/xeonphi
___
tpmdd-devel mailing list
tpmdd-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/tpmdd-devel


[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 <na...@linux.vnet.ibm.com>
---
 drivers/char/tpm/tpm.h  |  4 +++
 drivers/char/tpm/tpm2-cmd.c | 59 +
 2 files changed, 63 insertions(+)

diff --git a/drivers/char/tpm/tpm.h b/drivers/char/tpm/tpm.h
index 1ae9768..573 100644
--- a/drivers/char/tpm/tpm.h
+++ b/drivers/char/tpm/tpm.h
@@ -127,6 +127,7 @@ enum tpm2_permanent_handles {
 };
 
 enum tpm2_capabilities {
+   TPM2_CAP_PCRS   = 5,
TPM2_CAP_TPM_PROPERTIES = 6,
 };
 
@@ -187,6 +188,8 @@ struct tpm_chip {
 
const struct attribute_group *groups[3];
unsigned int groups_cnt;
+
+   u16 active_banks[7];
 #ifdef CONFIG_ACPI
acpi_handle acpi_dev_handle;
char ppi_version[TPM_PPI_VERSION_LEN + 1];
@@ -545,4 +548,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);
+ssize_t tpm2_get_pcr_allocation(struct tpm_chip *chip);
 #endif
diff --git a/drivers/char/tpm/tpm2-cmd.c b/drivers/char/tpm/tpm2-cmd.c
index 6eda239..87388921 100644
--- a/drivers/char/tpm/tpm2-cmd.c
+++ b/drivers/char/tpm/tpm2-cmd.c
@@ -83,6 +83,12 @@ struct tpm2_get_tpm_pt_out {
__be32  value;
 } __packed;
 
+struct tpm2_tpms_pcr_selection {
+   __be16  hash_alg;
+   u8  size_of_select;
+   u8  pcr_select[3];
+} __packed;
+
 struct tpm2_get_random_in {
__be16  size;
 } __packed;
@@ -993,8 +999,61 @@ int tpm2_auto_startup(struct tpm_chip *chip)
}
}
 
+   rc = tpm2_get_pcr_allocation(chip);
+
 out:
if (rc > 0)
rc = -ENODEV;
return rc;
 }
+
+/**
+ * tpm2_get_pcr_allocation() - get TPM active PCR banks.
+ *
+ * @chip: TPM chip to use.
+ *
+ * Return: Same as with tpm_transmit_cmd.
+ */
+ssize_t tpm2_get_pcr_allocation(struct tpm_chip *chip)
+{
+   struct tpm2_tpms_pcr_selection pcr_selection;
+   struct tpm_buf buf;
+   void *marker;
+   unsigned int count = 0;
+   int rc;
+   int i;
+
+   rc = tpm_buf_init(, TPM2_ST_NO_SESSIONS, TPM2_CC_GET_CAPABILITY);
+   if (rc)
+   return rc;
+
+   tpm_buf_append_u32(, TPM2_CAP_PCRS);
+   tpm_buf_append_u32(, 0);
+   tpm_buf_append_u32(, 1);
+
+   rc = tpm_transmit_cmd(chip, buf.data, PAGE_SIZE, 0,
+ "get tpm pcr allocation");
+   if (rc < 0)
+   goto out;
+
+   count = be32_to_cpup(
+   (__be32 *) [TPM_HEADER_SIZE + 5]);
+
+   if (count > ARRAY_SIZE(chip->active_banks))
+   return -ENODEV;
+
+   marker = [TPM_HEADER_SIZE + 9];
+   for (i = 0; i < count; i++) {
+   memcpy(_selection, marker, sizeof(pcr_selection));
+   chip->active_banks[i] = be16_to_cpu(pcr_selection.hash_alg);
+   marker = marker + sizeof(struct tpm2_tpms_pcr_selection);
+   }
+
+out:
+   if (count < ARRAY_SIZE(chip->active_banks))
+   chip->active_banks[count] = 0;
+
+   tpm_buf_destroy();
+
+   return rc;
+}
-- 
2.5.0


--
Developer Access Program for Intel Xeon Phi Processors
Access to Intel Xeon Phi processor-based developer platforms.
With one year of Intel Parallel Studio XE.
Training and support from Colfax.
Order your platform today. http://sdm.link/xeonphi
___
tpmdd-devel mailing list
tpmdd-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/tpmdd-devel


[tpmdd-devel] [PATCH v8 0/2] securityfs support for TPM 2.0 firmware event log

2017-01-10 Thread Nayna Jain
The TPM device driver defines ascii and binary methods for
displaying the TPM 1.2 event log via securityfs files, which are
needed for validating a TPM quote. The device driver for TPM 2.0
does not have similar support for displaying the TPM 2.0
event log. This patch set adds the support for displaying
TPM 2.0 event log in binary format.

The parsing mechanism to display the TPM 2.0 event log in binary
format is implemented as defined in the TPM 2.0 TCG specification[1].
If the firmware event log support exists and is successfully read,
the securityfs file is created to provide the event log in binary
format for both the OF device tree and ACPI.

   - Patch 1 adds the device tree bindings support for Physical TPM.
   - Patch 2 adds the support for creating securityfs files and for
 displaying the TPM 2.0 crypto agile event log in binary format.

[1] TCG EFI Protocol Specification, Family "2.0" - Section 5 "Event
Log Structure"

Changelog History

v8:
- Rebased to the Jarkko's latest master branch (8e25809 tpm:
  Do not print an error message when doing TPM auto startup)
- Patch "tpm: add securityfs support for TPM 2.0 firmware event log" 
  - Added feedbacks from Jarkko
- tpm_read_log_acpi() returns -ENODEV for TPM 2.0.
- Fixed code formatting and comments.

v7:
- Rebased to the Jarkko's latest master branch (b2505f6 tpm/vtpm:
  fix kdoc warnings)
- Included Jarkko's feedbacks on version v6.
- Cleaned up #defines in tpm2_eventlog.c
  - renamed HASH_COUNT to TPM2_ACTIVE_PCR_BANKS
  - deleted MAX_DIGEST_SIZE, used SHA384_DIGEST_SIZE directly from 
  
  - deleted MAX_TPM_LOG_MSG. Redefined event[MAX_TPM_LOG_MSG]
  as event[0].

v6:

- Rebased to the Jarkko's latest master branch (e717b5c:tpm: vtpm_proxy: 
  conditionally call tpm_chip_unregister)
- Retained securityfs setup functions in tpm_eventlog.c
- Renamed tpm_eventlog.c to tpm1_eventlog.c
- Fixed tpm_read_log_of() for NULL check and memcpy function.

v5:

- Upstreamed cleanup and fixes as different patchset
- Rebased to the Jarkko's latest master branch (e5be084 tpm: vtpm_proxy:
  Do not access host's event log)
- Patch "tpm: enhance read_log_of() to support Physical TPM event log
  - New Patch.
- Patch "tpm: add securityfs support for TPM 2.0 firmware event log"
  - Moved the changes in read_log_of() to a different patch
  - TPM 2.0 event log data types are declared in tpm_eventlog.h, tpm2.h
  is removed.
  - Included other feedbacks also from Jarkko on aligment and extra
line

v4:

- Includes feedbacks from Jarkko and Jason.
- Patch "tpm: define a generic open() method for ascii & bios
measurements".
  - Fix indentation issue.
- Patch "tpm: replace the dynamically allocated bios_dir as
  struct dentry array".
  - Continue to use bios_dir_count variable to use is_bad() checks and
to maintain correct order for securityfs_remove() during teardown.
  - Reset chip->bios_dir_count in teardown() function.
- Patch "tpm: validate the eventlog access before tpm_bios_log_setup".
  - Retain TPM2 check which was removed in previous patch.
  - Add tpm_bios_log_setup failure handling.
  - Remove use of private data from v3 version of patch. Add a
  new member to struct tpm_chip to achieve the same purpose.
- Patch "tpm: redefine the read_log method to check for ACPI/OF 
properties sequentially".
  - Move replacement of CONFIG_TCG_IBMVTPM with CONFIG_OF to this
patch from patch 3.
  - Replace -1 error code with -ENODEV.
- Patch "tpm: replace the of_find_node_by_name() with dev of_node
property".
  - Uses chip->dev.parent->of_node.
  - Created separate patch for cleanup of pr_err messages.
- Patch "tpm: remove printk error messages".
  - New Patch.
- Patch "tpm: add the securityfs file support for TPM 2.0 eventlog".
  - Parses event digests using event alg_id rather than event log header
alg_id.
  - Uses of_property_match_string to differentiate tpm/vtpm compatible

v3:

- Includes the review feedbacks as suggested by Jason.
- Split of patches into one patch per idea.
- Generic open() method for ascii/bios measurements.
- Replacement of of **bios_dir with *bios_dir[3].
- Verifying readlog() is successful before creating securityfs entries.
- Generic readlog() to check for ACPI/OF in sequence.
- read_log_of() method now uses of_node propertry rather than
calling find_device_by_name.
- read_log differentiates vtpm/tpm using its compatible property.
- Cleans pr_err with dev_dbg.
- Commit msgs subject line prefixed with tpm.

v2:

- Fixes issues as given in feedback by Jason.
- Adds documentation for device tree.

Nayna Jain (2):
  tpm: enhance read_log_of() to support Physical TPM event log
  tpm: add securityfs support for TPM 2.0 firmware event log

 drivers/char/tpm/Makefile  |   2 +-
 .../char/tpm/{tpm_eventlog.c => tpm1_eventlog.c}   |  35 ++--
 drivers/char/tpm/tpm2_eventlog.c

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

2017-01-10 Thread Nayna Jain
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.0 event log supports a crypto agile format that
records multiple digests, which is different from TPM 1.2. This
patch enables the tpm_bios_log_setup for TPM 2.0  and adds the
event log parser which understand the TPM 2.0 crypto agile format.

Signed-off-by: Nayna Jain <na...@linux.vnet.ibm.com>
---
 drivers/char/tpm/Makefile  |   2 +-
 .../char/tpm/{tpm_eventlog.c => tpm1_eventlog.c}   |  35 ++--
 drivers/char/tpm/tpm2_eventlog.c   | 203 +
 drivers/char/tpm/tpm_acpi.c|   3 +
 drivers/char/tpm/tpm_eventlog.h|  63 +++
 5 files changed, 291 insertions(+), 15 deletions(-)
 rename drivers/char/tpm/{tpm_eventlog.c => tpm1_eventlog.c} (95%)
 create mode 100644 drivers/char/tpm/tpm2_eventlog.c

diff --git a/drivers/char/tpm/Makefile b/drivers/char/tpm/Makefile
index a05b1eb..3d386a8 100644
--- a/drivers/char/tpm/Makefile
+++ b/drivers/char/tpm/Makefile
@@ -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 \
-   tpm_eventlog.o
+   tpm1_eventlog.o tpm2_eventlog.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
diff --git a/drivers/char/tpm/tpm_eventlog.c b/drivers/char/tpm/tpm1_eventlog.c
similarity index 95%
rename from drivers/char/tpm/tpm_eventlog.c
rename to drivers/char/tpm/tpm1_eventlog.c
index 11bb113..9a8605e 100644
--- a/drivers/char/tpm/tpm_eventlog.c
+++ b/drivers/char/tpm/tpm1_eventlog.c
@@ -390,9 +390,6 @@ int tpm_bios_log_setup(struct tpm_chip *chip)
unsigned int cnt;
int rc = 0;
 
-   if (chip->flags & TPM_CHIP_FLAG_TPM2)
-   return 0;
-
rc = tpm_read_log(chip);
if (rc)
return rc;
@@ -407,7 +404,13 @@ int tpm_bios_log_setup(struct tpm_chip *chip)
cnt++;
 
chip->bin_log_seqops.chip = chip;
-   chip->bin_log_seqops.seqops = _binary_b_measurements_seqops;
+   if (chip->flags & TPM_CHIP_FLAG_TPM2)
+   chip->bin_log_seqops.seqops =
+   _binary_b_measurements_seqops;
+   else
+   chip->bin_log_seqops.seqops =
+   _binary_b_measurements_seqops;
+
 
chip->bios_dir[cnt] =
securityfs_create_file("binary_bios_measurements",
@@ -418,17 +421,21 @@ int tpm_bios_log_setup(struct tpm_chip *chip)
goto err;
cnt++;
 
-   chip->ascii_log_seqops.chip = chip;
-   chip->ascii_log_seqops.seqops = _ascii_b_measurements_seqops;
+   if (!(chip->flags & TPM_CHIP_FLAG_TPM2)) {
 
-   chip->bios_dir[cnt] =
-   securityfs_create_file("ascii_bios_measurements",
-  0440, chip->bios_dir[0],
-  (void *)>ascii_log_seqops,
-  _bios_measurements_ops);
-   if (IS_ERR(chip->bios_dir[cnt]))
-   goto err;
-   cnt++;
+   chip->ascii_log_seqops.chip = chip;
+   chip->ascii_log_seqops.seqops =
+   _ascii_b_measurements_seqops;
+
+   chip->bios_dir[cnt] =
+   securityfs_create_file("ascii_bios_measurements",
+  0440, chip->bios_dir[0],
+  (void *)>ascii_log_seqops,
+  _bios_measurements_ops);
+   if (IS_ERR(chip->bios_dir[cnt]))
+   goto err;
+   cnt++;
+   }
 
return 0;
 
diff --git a/drivers/char/tpm/tpm2_eventlog.c b/drivers/char/tpm/tpm2_eventlog.c
new file mode 100644
index 000..1063b09
--- /dev/null
+++ b/drivers/char/tpm/tpm2_eventlog.c
@@ -0,0 +1,203 @@
+/*
+ * Copyright (C) 2016 IBM Corporation
+ *
+ * Authors:
+ *  Nayna Jain <na...@linux.vnet.ibm.com>
+ *
+ * Access to TPM 2.0 event log as written by Firmware.
+ * It assumes that writer of event log has followed TCG Specification
+ * for Family "2.0" and written the event data in little endian.
+ * With that, it doesn't need any endian conversion for structure
+ * content.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version
+ * 2 of the License, or (at your option) any later version.
+ */
+
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#include "tpm.h"
+#include "tpm_eventlog.h"
+
+/*
+ * ca

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

2017-01-04 Thread Nayna


On 01/03/2017 07:03 PM, Jarkko Sakkinen wrote:
> On Tue, Jan 03, 2017 at 01:09:18PM +0530, Nayna wrote:
>>
>>
>> On 01/03/2017 03:42 AM, Jarkko Sakkinen wrote:
>>> On Sun, Dec 11, 2016 at 12:35:33AM -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.0 event log supports a crypto agile format that
>>>> records multiple digests, which is different from TPM 1.2. This
>>>> patch enables the tpm_bios_log_setup for TPM 2.0  and adds the
>>>> event log parser which understand the TPM 2.0 crypto agile format.
>>>>
>>>> Signed-off-by: Nayna Jain <na...@linux.vnet.ibm.com>
>>>
>>> There is something fundamentally wrong in this commit.
>>>
>>> You must not allow this feature unless CONFIG_OF is set. It is the only
>>> interface where the supply path of the event log is well defined on
>>> platforms that include a TPM 2.0 chip.
>>
>> As per current implementation, if ACPI with TPM 2.0 doesn't support event
>> log, tpm_read_log_acpi() is expected to return rc and tpm_bios_log_setup
>> will not create securityfs. This is inline with our design for TPM 1.2 event
>> log.
>
> At minimum you must have a check for TPM_CHIP_FLAG_TPM2 in the beginning
> of tpm_read_log_acpi. It is wrong to even try to open TCPA in this case.

Sure, will add this check and return -ENODEV if check passes.

Thanks & Regards,
 - Nayna

>
> /Jarkko
>


--
Check out the vibrant tech community on one of the world's most 
engaging tech sites, SlashDot.org! http://sdm.link/slashdot
___
tpmdd-devel mailing list
tpmdd-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/tpmdd-devel


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

2017-01-02 Thread Nayna


On 01/03/2017 03:42 AM, Jarkko Sakkinen wrote:
> On Sun, Dec 11, 2016 at 12:35:33AM -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.0 event log supports a crypto agile format that
>> records multiple digests, which is different from TPM 1.2. This
>> patch enables the tpm_bios_log_setup for TPM 2.0  and adds the
>> event log parser which understand the TPM 2.0 crypto agile format.
>>
>> Signed-off-by: Nayna Jain <na...@linux.vnet.ibm.com>
>
> There is something fundamentally wrong in this commit.
>
> You must not allow this feature unless CONFIG_OF is set. It is the only
> interface where the supply path of the event log is well defined on
> platforms that include a TPM 2.0 chip.

As per current implementation, if ACPI with TPM 2.0 doesn't support 
event log, tpm_read_log_acpi() is expected to return rc and 
tpm_bios_log_setup will not create securityfs. This is inline with our 
design for TPM 1.2 event log.

>
> There's buch casts in the form '(char *) foo'. They should be
> '(char *)foo'.

Will fix these and other comments.

Thanks & Regards,
 - Nayna

>
>> ---
>>   drivers/char/tpm/Makefile  |   2 +-
>>   .../char/tpm/{tpm_eventlog.c => tpm1_eventlog.c}   |  35 ++--
>>   drivers/char/tpm/tpm2_eventlog.c   | 203 
>> +
>>   drivers/char/tpm/tpm_eventlog.h|  70 +++
>>   4 files changed, 295 insertions(+), 15 deletions(-)
>>   rename drivers/char/tpm/{tpm_eventlog.c => tpm1_eventlog.c} (95%)
>>   create mode 100644 drivers/char/tpm/tpm2_eventlog.c
>>
>> diff --git a/drivers/char/tpm/Makefile b/drivers/char/tpm/Makefile
>> index a05b1eb..3d386a8 100644
>> --- a/drivers/char/tpm/Makefile
>> +++ b/drivers/char/tpm/Makefile
>> @@ -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 \
>> -tpm_eventlog.o
>> +tpm1_eventlog.o tpm2_eventlog.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
>> diff --git a/drivers/char/tpm/tpm_eventlog.c 
>> b/drivers/char/tpm/tpm1_eventlog.c
>> similarity index 95%
>> rename from drivers/char/tpm/tpm_eventlog.c
>> rename to drivers/char/tpm/tpm1_eventlog.c
>> index 11bb113..9a8605e 100644
>> --- a/drivers/char/tpm/tpm_eventlog.c
>> +++ b/drivers/char/tpm/tpm1_eventlog.c
>> @@ -390,9 +390,6 @@ int tpm_bios_log_setup(struct tpm_chip *chip)
>>  unsigned int cnt;
>>  int rc = 0;
>>
>> -if (chip->flags & TPM_CHIP_FLAG_TPM2)
>> -return 0;
>> -
>>  rc = tpm_read_log(chip);
>>  if (rc)
>>  return rc;
>> @@ -407,7 +404,13 @@ int tpm_bios_log_setup(struct tpm_chip *chip)
>>  cnt++;
>>
>>  chip->bin_log_seqops.chip = chip;
>> -chip->bin_log_seqops.seqops = _binary_b_measurements_seqops;
>> +if (chip->flags & TPM_CHIP_FLAG_TPM2)
>> +chip->bin_log_seqops.seqops =
>> +_binary_b_measurements_seqops;
>> +else
>> +chip->bin_log_seqops.seqops =
>> +_binary_b_measurements_seqops;
>> +
>>
>>  chip->bios_dir[cnt] =
>>  securityfs_create_file("binary_bios_measurements",
>> @@ -418,17 +421,21 @@ int tpm_bios_log_setup(struct tpm_chip *chip)
>>  goto err;
>>  cnt++;
>>
>> -chip->ascii_log_seqops.chip = chip;
>> -chip->ascii_log_seqops.seqops = _ascii_b_measurements_seqops;
>> +if (!(chip->flags & TPM_CHIP_FLAG_TPM2)) {
>>
>> -chip->bios_dir[cnt] =
>> -securityfs_create_file("ascii_bios_measurements",
>> -   0440, chip->bios_dir[0],
>> -   (void *)>ascii_log_seqops,
>> -   _bios_measurements_ops);
>> -if (IS_ERR(chip->bios_dir[cnt]))
>> -goto err;
>> -cnt++;
>> +chip->ascii_log_seqops.chip = chip;
>> +chip->ascii_log_seqops.seqops =
>> +_ascii_b_measurements_seqops;
>> +
>> +chip->bios_dir[cnt] =
>> +security

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

2016-12-30 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 <na...@linux.vnet.ibm.com>
---
 drivers/char/tpm/tpm.h  |  5 +++
 drivers/char/tpm/tpm2-cmd.c | 79 +
 2 files changed, 84 insertions(+)

diff --git a/drivers/char/tpm/tpm.h b/drivers/char/tpm/tpm.h
index 1ae9768..3d8121e 100644
--- a/drivers/char/tpm/tpm.h
+++ b/drivers/char/tpm/tpm.h
@@ -43,6 +43,7 @@ enum tpm_const {
TPM_NUM_DEVICES = 65536,
TPM_RETRY = 50, /* 5 seconds */
TPM_NUM_EVENT_LOG_FILES = 3,
+   TPM2_MAX_PCR_BANKS = 7,
 };
 
 enum tpm_timeout {
@@ -127,6 +128,7 @@ enum tpm2_permanent_handles {
 };
 
 enum tpm2_capabilities {
+   TPM2_CAP_PCRS   = 5,
TPM2_CAP_TPM_PROPERTIES = 6,
 };
 
@@ -187,6 +189,8 @@ struct tpm_chip {
 
const struct attribute_group *groups[3];
unsigned int groups_cnt;
+
+   enum tpm2_algorithms active_banks[TPM2_MAX_PCR_BANKS];
 #ifdef CONFIG_ACPI
acpi_handle acpi_dev_handle;
char ppi_version[TPM_PPI_VERSION_LEN + 1];
@@ -545,4 +549,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);
+ssize_t tpm2_get_pcr_allocation(struct tpm_chip *chip);
 #endif
diff --git a/drivers/char/tpm/tpm2-cmd.c b/drivers/char/tpm/tpm2-cmd.c
index 6eda239..dd03fd8 100644
--- a/drivers/char/tpm/tpm2-cmd.c
+++ b/drivers/char/tpm/tpm2-cmd.c
@@ -83,6 +83,25 @@ struct tpm2_get_tpm_pt_out {
__be32  value;
 } __packed;
 
+struct tpm2_tpms_pcr_selection {
+   __be16  hash_alg;
+   u8  size_of_select;
+   u8  pcr_select[3];
+} __packed;
+
+struct tpm2_getcap_in {
+   __be32  cap_id;
+   __be32  property_id;
+   __be32  property_cnt;
+} __packed;
+
+struct tpm2_getcap_out {
+   u8  more_data;
+   __be32  subcap_id;
+   __be32  count;
+   charcap_data[0];
+} __packed;
+
 struct tpm2_get_random_in {
__be16  size;
 } __packed;
@@ -100,6 +119,8 @@ union tpm2_cmd_params {
struct  tpm2_pcr_extend_in  pcrextend_in;
struct  tpm2_get_tpm_pt_in  get_tpm_pt_in;
struct  tpm2_get_tpm_pt_out get_tpm_pt_out;
+   struct  tpm2_getcap_in  getcap_in;
+   struct  tpm2_getcap_out getcap_out;
struct  tpm2_get_random_in  getrandom_in;
struct  tpm2_get_random_out getrandom_out;
 };
@@ -993,8 +1014,66 @@ int tpm2_auto_startup(struct tpm_chip *chip)
}
}
 
+   rc = tpm2_get_pcr_allocation(chip);
+
 out:
if (rc > 0)
rc = -ENODEV;
return rc;
 }
+
+#define TPM2_GETCAP_IN_SIZE \
+   (sizeof(struct tpm_input_header) + sizeof(struct tpm2_getcap_in))
+
+static const struct tpm_input_header tpm2_getcap_header = {
+   .tag = cpu_to_be16(TPM2_ST_NO_SESSIONS),
+   .length = cpu_to_be32(TPM2_GETCAP_IN_SIZE),
+   .ordinal = cpu_to_be32(TPM2_CC_GET_CAPABILITY)
+};
+
+/**
+ * tpm2_get_pcr_allocation() - get TPM active PCR banks.
+ *
+ * @chip: TPM chip to use.
+ *
+ * Return: Same as with tpm_transmit_cmd.
+ */
+ssize_t tpm2_get_pcr_allocation(struct tpm_chip *chip)
+{
+   struct tpm2_cmd cmd;
+   struct tpm2_tpms_pcr_selection pcr_selection;
+   void *marker;
+   unsigned int count = 0;
+   int rc;
+   int i;
+
+   cmd.header.in = tpm2_getcap_header;
+   cmd.params.getcap_in.cap_id = cpu_to_be32(TPM2_CAP_PCRS);
+   cmd.params.getcap_in.property_id = cpu_to_be32(0);
+   cmd.params.getcap_in.property_cnt = cpu_to_be32(1);
+
+   rc = tpm_transmit_cmd(chip, , sizeof(cmd), 0,
+ "get tpm pcr allocation");
+   if (rc < 0)
+   goto out;
+
+   count = be32_to_cpu(cmd.params.getcap_out.count);
+   if (count > TPM2_MAX_PCR_BANKS) {
+   dev_err(>dev,
+   "%s: Error: Invalid active PCR banks count\n",
+   __func__);
+   return -ENODEV;
+   }
+
+   marker = _out.cap_data;
+   for (i = 0; i < count; i++) {
+   memcpy(_selection, marker, sizeof(pcr_selection));
+   chip->active_banks[i] = be16_to_cpu(pcr_selection.hash_alg);
+   marker = marker + sizeof(struct tpm2_tpms_pcr_selection);
+   }
+
+out:
+   if (count < TPM2_MAX_PCR_BANKS)
+   chip->active_banks[count] = 0;
+   return rc;
+}
-- 
2.5.0


--
Check out the vibrant tech community on one of the world's most 
engaging tech sites, SlashDot.org! http://sdm.link/slashdot

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

2016-12-30 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 prevent malicious users from
setting unused PCR banks with fake measurements and quoting them.
This patch set adds support for extending all active PCR banks,
as recommended.

The first patch implements the TPM 2.0 capability to retrieve
the list of active PCR banks.

The second patch modifies the tpm_pcr_extend() and tpm2_pcr_extend()
interface to support extending multiple PCR banks. The existing
tpm_pcr_extend() interface expects only a SHA1 digest. Hence, to
extend all active PCR banks with differing digest sizes for TPM 2.0,
the SHA1 digest is padded with 0's as needed.

This approach is taken to maintain backwards compatibility for IMA
in order to continue working with both TPM 1.2 and TPM 2.0 without
any changes and still comply with TCG TPM 2.0 Specification[1].

[1] TPM 2.0 Specification referred here is "TCG PC Client Specific
Platform Firmware Profile for TPM 2.0"

Changelog v2:

- Patch "tpm: implement TPM 2.0 capability to get active PCR banks"
  - defined structs definition in tpm2-cmd.c.
  - no_of_active_banks field is removed. Instead, constant
  TPM2_MAX_PCR_BANKS is defined.
  - renamed tpm2_get_active_pcr_banks() to tpm2_get_pcr_allocation()
  - removed generic function tpm2_get_capability().

- Patch "tpm: enchance TPM 2.0 PCR extend to support multiple banks"
 - Removed tpm2.h, and defined structs common for extend and event log
  in tpm_eventlog.h
 - uses tpm_buf in tpm2_pcr_extend().

Nayna Jain (2):
  tpm: implement TPM 2.0 capability to get active PCR banks
  tpm: enhance TPM 2.0 PCR extend to support multiple banks

 drivers/char/tpm/tpm-interface.c |  16 -
 drivers/char/tpm/tpm.h   |   8 ++-
 drivers/char/tpm/tpm2-cmd.c  | 146 +++
 drivers/char/tpm/tpm_eventlog.h  |  15 
 4 files changed, 153 insertions(+), 32 deletions(-)

-- 
2.5.0


--
Check out the vibrant tech community on one of the world's most 
engaging tech sites, SlashDot.org! http://sdm.link/slashdot
___
tpmdd-devel mailing list
tpmdd-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/tpmdd-devel


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

2016-12-10 Thread Nayna Jain
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.0 event log supports a crypto agile format that
records multiple digests, which is different from TPM 1.2. This
patch enables the tpm_bios_log_setup for TPM 2.0  and adds the
event log parser which understand the TPM 2.0 crypto agile format.

Signed-off-by: Nayna Jain <na...@linux.vnet.ibm.com>
---
 drivers/char/tpm/Makefile  |   2 +-
 .../char/tpm/{tpm_eventlog.c => tpm1_eventlog.c}   |  35 ++--
 drivers/char/tpm/tpm2_eventlog.c   | 203 +
 drivers/char/tpm/tpm_eventlog.h|  70 +++
 4 files changed, 295 insertions(+), 15 deletions(-)
 rename drivers/char/tpm/{tpm_eventlog.c => tpm1_eventlog.c} (95%)
 create mode 100644 drivers/char/tpm/tpm2_eventlog.c

diff --git a/drivers/char/tpm/Makefile b/drivers/char/tpm/Makefile
index a05b1eb..3d386a8 100644
--- a/drivers/char/tpm/Makefile
+++ b/drivers/char/tpm/Makefile
@@ -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 \
-   tpm_eventlog.o
+   tpm1_eventlog.o tpm2_eventlog.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
diff --git a/drivers/char/tpm/tpm_eventlog.c b/drivers/char/tpm/tpm1_eventlog.c
similarity index 95%
rename from drivers/char/tpm/tpm_eventlog.c
rename to drivers/char/tpm/tpm1_eventlog.c
index 11bb113..9a8605e 100644
--- a/drivers/char/tpm/tpm_eventlog.c
+++ b/drivers/char/tpm/tpm1_eventlog.c
@@ -390,9 +390,6 @@ int tpm_bios_log_setup(struct tpm_chip *chip)
unsigned int cnt;
int rc = 0;
 
-   if (chip->flags & TPM_CHIP_FLAG_TPM2)
-   return 0;
-
rc = tpm_read_log(chip);
if (rc)
return rc;
@@ -407,7 +404,13 @@ int tpm_bios_log_setup(struct tpm_chip *chip)
cnt++;
 
chip->bin_log_seqops.chip = chip;
-   chip->bin_log_seqops.seqops = _binary_b_measurements_seqops;
+   if (chip->flags & TPM_CHIP_FLAG_TPM2)
+   chip->bin_log_seqops.seqops =
+   _binary_b_measurements_seqops;
+   else
+   chip->bin_log_seqops.seqops =
+   _binary_b_measurements_seqops;
+
 
chip->bios_dir[cnt] =
securityfs_create_file("binary_bios_measurements",
@@ -418,17 +421,21 @@ int tpm_bios_log_setup(struct tpm_chip *chip)
goto err;
cnt++;
 
-   chip->ascii_log_seqops.chip = chip;
-   chip->ascii_log_seqops.seqops = _ascii_b_measurements_seqops;
+   if (!(chip->flags & TPM_CHIP_FLAG_TPM2)) {
 
-   chip->bios_dir[cnt] =
-   securityfs_create_file("ascii_bios_measurements",
-  0440, chip->bios_dir[0],
-  (void *)>ascii_log_seqops,
-  _bios_measurements_ops);
-   if (IS_ERR(chip->bios_dir[cnt]))
-   goto err;
-   cnt++;
+   chip->ascii_log_seqops.chip = chip;
+   chip->ascii_log_seqops.seqops =
+   _ascii_b_measurements_seqops;
+
+   chip->bios_dir[cnt] =
+   securityfs_create_file("ascii_bios_measurements",
+  0440, chip->bios_dir[0],
+  (void *)>ascii_log_seqops,
+  _bios_measurements_ops);
+   if (IS_ERR(chip->bios_dir[cnt]))
+   goto err;
+   cnt++;
+   }
 
return 0;
 
diff --git a/drivers/char/tpm/tpm2_eventlog.c b/drivers/char/tpm/tpm2_eventlog.c
new file mode 100644
index 000..63690d3
--- /dev/null
+++ b/drivers/char/tpm/tpm2_eventlog.c
@@ -0,0 +1,203 @@
+/*
+ * Copyright (C) 2016 IBM Corporation
+ *
+ * Authors:
+ *  Nayna Jain <na...@linux.vnet.ibm.com>
+ *
+ * Access to TPM 2.0 event log as written by Firmware.
+ * It assumes that writer of event log has followed TCG Specification
+ * for Family "2.0" and written the event data in little endian.
+ * With that, it doesn't need any endian conversion for structure
+ * content.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version
+ * 2 of the License, or (at your option) any later version.
+ */
+
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#include "tpm.h"
+#include "tpm_eventlog.h"
+
+static int calc_tpm2_event_size(struct tcg_pcr_event2 *eve

[tpmdd-devel] [PATCH v7 1/2] tpm: enhance read_log_of() to support Physical TPM event log

2016-12-10 Thread Nayna Jain
Physical TPMs use Open Firmware Device Tree bindings that are similar
to the IBM Power virtual TPM to support event log. However, these
properties store the values in different endianness for Physical
and Virtual TPM.

This patch fixes the endianness issue by doing appropriate conversion
based on Physical or Virtual TPM.

Signed-off-by: Nayna Jain <na...@linux.vnet.ibm.com>
---
 drivers/char/tpm/tpm_of.c | 27 +++
 1 file changed, 23 insertions(+), 4 deletions(-)

diff --git a/drivers/char/tpm/tpm_of.c b/drivers/char/tpm/tpm_of.c
index 7dee42d7..de57d4a 100644
--- a/drivers/char/tpm/tpm_of.c
+++ b/drivers/char/tpm/tpm_of.c
@@ -27,6 +27,8 @@ int tpm_read_log_of(struct tpm_chip *chip)
const u32 *sizep;
const u64 *basep;
struct tpm_bios_log *log;
+   u32 size;
+   u64 base;
 
log = >log;
if (chip->dev.parent && chip->dev.parent->of_node)
@@ -41,18 +43,35 @@ int tpm_read_log_of(struct tpm_chip *chip)
if (sizep == NULL || basep == NULL)
return -EIO;
 
-   if (*sizep == 0) {
+   /*
+* For both vtpm/tpm, firmware has log addr and log size in big
+* endian format. But in case of vtpm, there is a method called
+* sml-handover which is run during kernel init even before
+* device tree is setup. This sml-handover function takes care
+* of endianness and writes to sml-base and sml-size in little
+* endian format. For this reason, vtpm doesn't need conversion
+* but physical tpm needs the conversion.
+*/
+   if (of_property_match_string(np, "compatible", "IBM,vtpm") < 0) {
+   size = be32_to_cpup(sizep);
+   base = be64_to_cpup(basep);
+   } else {
+   size = *sizep;
+   base = *basep;
+   }
+
+   if (size == 0) {
dev_warn(>dev, "%s: Event log area empty\n", __func__);
return -EIO;
}
 
-   log->bios_event_log = kmalloc(*sizep, GFP_KERNEL);
+   log->bios_event_log = kmalloc(size, GFP_KERNEL);
if (!log->bios_event_log)
return -ENOMEM;
 
-   log->bios_event_log_end = log->bios_event_log + *sizep;
+   log->bios_event_log_end = log->bios_event_log + size;
 
-   memcpy(log->bios_event_log, __va(*basep), *sizep);
+   memcpy(log->bios_event_log, __va(base), size);
 
return 0;
 }
-- 
2.5.0


--
Developer Access Program for Intel Xeon Phi Processors
Access to Intel Xeon Phi processor-based developer platforms.
With one year of Intel Parallel Studio XE.
Training and support from Colfax.
Order your platform today.http://sdm.link/xeonphi
___
tpmdd-devel mailing list
tpmdd-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/tpmdd-devel


[tpmdd-devel] [PATCH v7 0/2] securityfs support for TPM 2.0 firmware event log

2016-12-10 Thread Nayna Jain
The TPM device driver defines ascii and binary methods for
displaying the TPM 1.2 event log via securityfs files, which are
needed for validating a TPM quote. The device driver for TPM 2.0
does not have similar support for displaying the TPM 2.0
event log. This patch set adds the support for displaying
TPM 2.0 event log in binary format.

The parsing mechanism to display the TPM 2.0 event log in binary
format is implemented as defined in the TPM 2.0 TCG specification[1].
If the firmware event log support exists and is successfully read,
the securityfs file is created to provide the event log in binary
format for both the OF device tree and ACPI.

   - Patch 1 adds the device tree bindings support for Physical TPM.
   - Patch 2 adds the support for creating securityfs files and for
 displaying the TPM 2.0 crypto agile event log in binary format.

[1] TCG EFI Protocol Specification, Family "2.0" - Section 5 "Event
Log Structure"

Changelog History

v7:
- Rebased to the Jarkko's latest master branch (b2505f6 tpm/vtpm:
  fix kdoc warnings)
- Included Jarkko's feedbacks on version v6.
- Cleaned up #defines in tpm2_eventlog.c
  - renamed HASH_COUNT to TPM2_ACTIVE_PCR_BANKS
  - deleted MAX_DIGEST_SIZE, used SHA384_DIGEST_SIZE directly from 
  
  - deleted MAX_TPM_LOG_MSG. Redefined event[MAX_TPM_LOG_MSG]
  as event[0].

v6:

- Rebased to the Jarkko's latest master branch (e717b5c:tpm: vtpm_proxy: 
  conditionally call tpm_chip_unregister)
- Retained securityfs setup functions in tpm_eventlog.c
- Renamed tpm_eventlog.c to tpm1_eventlog.c
- Fixed tpm_read_log_of() for NULL check and memcpy function.

v5:

- Upstreamed cleanup and fixes as different patchset
- Rebased to the Jarkko's latest master branch (e5be084 tpm: vtpm_proxy:
  Do not access host's event log)
- Patch "tpm: enhance read_log_of() to support Physical TPM event log
  - New Patch.
- Patch "tpm: add securityfs support for TPM 2.0 firmware event log"
  - Moved the changes in read_log_of() to a different patch
  - TPM 2.0 event log data types are declared in tpm_eventlog.h, tpm2.h
  is removed.
  - Included other feedbacks also from Jarkko on aligment and extra
line

v4:

- Includes feedbacks from Jarkko and Jason.
- Patch "tpm: define a generic open() method for ascii & bios
measurements".
  - Fix indentation issue.
- Patch "tpm: replace the dynamically allocated bios_dir as
  struct dentry array".
  - Continue to use bios_dir_count variable to use is_bad() checks and
to maintain correct order for securityfs_remove() during teardown.
  - Reset chip->bios_dir_count in teardown() function.
- Patch "tpm: validate the eventlog access before tpm_bios_log_setup".
  - Retain TPM2 check which was removed in previous patch.
  - Add tpm_bios_log_setup failure handling.
  - Remove use of private data from v3 version of patch. Add a
  new member to struct tpm_chip to achieve the same purpose.
- Patch "tpm: redefine the read_log method to check for ACPI/OF 
properties sequentially".
  - Move replacement of CONFIG_TCG_IBMVTPM with CONFIG_OF to this
patch from patch 3.
  - Replace -1 error code with -ENODEV.
- Patch "tpm: replace the of_find_node_by_name() with dev of_node
property".
  - Uses chip->dev.parent->of_node.
  - Created separate patch for cleanup of pr_err messages.
- Patch "tpm: remove printk error messages".
  - New Patch.
- Patch "tpm: add the securityfs file support for TPM 2.0 eventlog".
  - Parses event digests using event alg_id rather than event log header
alg_id.
  - Uses of_property_match_string to differentiate tpm/vtpm compatible

v3:

- Includes the review feedbacks as suggested by Jason.
- Split of patches into one patch per idea.
- Generic open() method for ascii/bios measurements.
- Replacement of of **bios_dir with *bios_dir[3].
- Verifying readlog() is successful before creating securityfs entries.
- Generic readlog() to check for ACPI/OF in sequence.
- read_log_of() method now uses of_node propertry rather than
calling find_device_by_name.
- read_log differentiates vtpm/tpm using its compatible property.
- Cleans pr_err with dev_dbg.
- Commit msgs subject line prefixed with tpm.

v2:

- Fixes issues as given in feedback by Jason.
- Adds documentation for device tree.

Nayna Jain (2):
  tpm: enhance read_log_of() to support Physical TPM event log
  tpm: add securityfs support for TPM 2.0 firmware event log

 drivers/char/tpm/Makefile  |   2 +-
 .../char/tpm/{tpm_eventlog.c => tpm1_eventlog.c}   |  35 ++--
 drivers/char/tpm/tpm2_eventlog.c   | 203 +
 drivers/char/tpm/tpm_eventlog.h|  70 +++
 drivers/char/tpm/tpm_of.c  |  27 ++-
 5 files changed, 318 insertions(+), 19 deletions(-)
 rename drivers/char/tpm/{tpm_eventlog.c => tpm1_eventlog.c} (95%)
 create mode 100644 drivers/char/tpm/tpm2_eve

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

2016-12-06 Thread Nayna


On 11/30/2016 10:29 PM, Nayna wrote:
>
>
> On 11/26/2016 09:17 PM, Jarkko Sakkinen wrote:
>> On Sat, Nov 26, 2016 at 07:45:39AM -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.0 event log supports a crypto agile format that
>>> records multiple digests, which is different from TPM 1.2. This
>>> patch enables the tpm_bios_log_setup for TPM 2.0  and adds the
>>> event log parser which understand the TPM 2.0 crypto agile format.
>>>
>>> Signed-off-by: Nayna Jain <na...@linux.vnet.ibm.com>

>>> diff --git a/drivers/char/tpm/tpm_eventlog.h 
>>> b/drivers/char/tpm/tpm_eventlog.h
>>> index 1660d74..7e33b90 100644
>>> --- a/drivers/char/tpm/tpm_eventlog.h
>>> +++ b/drivers/char/tpm/tpm_eventlog.h
>>> @@ -5,6 +5,9 @@
>>>#define TCG_EVENT_NAME_LEN_MAX   255
>>>#define MAX_TEXT_EVENT   1000/* Max event string length */
>>>#define ACPI_TCPA_SIG"TCPA"  /* 0x41504354 /'TCPA' */
>>> +#define HASH_COUNT 3
>>> +#define MAX_TPM_LOG_MSG128
>>> +#define MAX_DIGEST_SIZE64
>>
>> Where have been the values for these constants derived? You should
>> anyway prefix them with TPM_.
>
> HASH_COUNT is to represent multiple active banks at a time, where SHA1
> and SHA256 are the ones, I kept it 3 with assumption of SHA384/SHA512.
> And with that, I kept MAX_DIGEST_SIZE as 64.
>
> MAX_TPM_LOG_MSG was an assumption by me. I think TCG Spec says max value
> can be 1MB.
>
> I would actually like to know the views on this.

I would like to know your and Jason views on the above given reasoning 
related to how values for these constants are derived.

Thanks & Regards,
- Nayna

>
>>
>>>#ifdef CONFIG_PPC64
>>>#define do_endian_conversion(x) be32_to_cpu(x)
>>> @@ -73,6 +76,73 @@ enum tcpa_pc_event_ids {
>>> HOST_TABLE_OF_DEVICES,
>>>};
>>>
>>> +/*
>>> + * All the structures related to TPM 2.0 Event Log are taken from TCG EFIi
>>> + * Protocol * Specification, Family "2.0". Document is available on link
>>> + * http://www.trustedcomputinggroup.org/tcg-efi-protocol-specification/
>>> + * Information is also available on TCG PC Client Platform Firmware Profile
>>> + * Specification, Family "2.0"
>>> + * Detailed digest structures for TPM 2.0 are defined in document
>>> + * Trusted Platform Module Library Part 2: Structures, Family "2.0".
>>> + */
>>> +
>>> +/* TPM 2.0 Event log header algorithm spec. */
>>> +struct tcg_efi_specid_event_algs {
>>> +   u16 alg_id;
>>> +   u16 digest_size;
>>> +} __packed;
>>> +
>>> +/* TPM 2.0 Event log header data. */
>>> +struct tcg_efi_specid_event {
>>> +   u8  signature[16];
>>> +   u32 platform_class;
>>> +   u8  spec_version_minor;
>>> +   u8  spec_version_major;
>>> +   u8  spec_errata;
>>> +   u8  uintnsize;
>>> +   u32 num_algs;
>>> +   struct tcg_efi_specid_event_algs   digest_sizes[HASH_COUNT];
>>> +   u8  vendor_info_size;
>>> +   u8  vendor_info[0];
>>> +} __packed;
>>> +
>>> +/* TPM 2.0 Event Log Header. */
>>> +struct tcg_pcr_event {
>>> +   u32 pcr_idx;
>>> +   u32 event_type;
>>> +   u8  digest[20];
>>> +   u32 event_size;
>>> +   u8  event[MAX_TPM_LOG_MSG];
>>> +} __packed;
>>> +
>>> +/* TPM 2.0 Crypto agile algorithm and respective digest. */
>>> +struct tpmt_ha {
>>> +   u16 alg_id;
>>> +   u8  digest[MAX_DIGEST_SIZE];
>>> +} __packed;
>>> +
>>> +/* TPM 2.0 Crypto agile digests list. */
>>> +struct tpml_digest_values {
>>> +   u32 count;
>>> +   struct tpmt_ha  digests[HASH_COUNT];
>>> +} __packed;
>>> +
>>> +/* TPM 2.0 Event field structure. */
>>> +struct tcg_event_field {
>>> +   u32 event_size;
>>> +   u8  event[MAX_TPM_LOG_MSG];
>>> +} __packed;
>>> +
>>> +/* TPM 2.0 Crypto agile log entry format. */
>>> +struct tcg_pcr_event2 {
>>> +   u32 pcr_idx;
>>> +   u32 event_t

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

2016-12-02 Thread Nayna


On 12/01/2016 05:13 PM, Jarkko Sakkinen wrote:
> On Wed, Nov 30, 2016 at 10:29:00PM +0530, Nayna wrote:
>>
>>
>> On 11/26/2016 09:17 PM, Jarkko Sakkinen wrote:
>>> On Sat, Nov 26, 2016 at 07:45:39AM -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.0 event log supports a crypto agile format that
>>>> records multiple digests, which is different from TPM 1.2. This
>>>> patch enables the tpm_bios_log_setup for TPM 2.0  and adds the
>>>> event log parser which understand the TPM 2.0 crypto agile format.
>>>>
>>>> Signed-off-by: Nayna Jain <na...@linux.vnet.ibm.com>
>>>
>>> I would not rush with new patch set versions as long as the testing is
>>> almost completely lacking. I didn't even have time to read the previous
>>> version properly before this came out.
>>
>> Sure Jarkko. My apologies for multiple versions. I will wait for testing,
>> before posting my next version.
>
> You could send now a new version because probably anyone who wants
> to review your patches has had a chance to look at it. My point was
> that you wait for at least few days.

Sure Jarkko. Thanks !!

Also Jarkko/Jason, please let me know your views on #defines in 
tpm_eventlog.h for TPM 2.0 event log support. I have responded to the 
related and other feedbacks in my previous mail sent on 30th Nov.

Thanks & Regards,
- Nayna

>
> Maybe Jason could help testing your patches. I don't know when I have
> time to setup environment. He had OF environment available.
>
> /Jarkko
>


--
Check out the vibrant tech community on one of the world's most 
engaging tech sites, SlashDot.org! http://sdm.link/slashdot
___
tpmdd-devel mailing list
tpmdd-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/tpmdd-devel


Re: [tpmdd-devel] [PATCH v6 1/2] tpm: enhance read_log_of() to support Physical TPM event log

2016-11-29 Thread Nayna


On 11/26/2016 09:45 PM, Jarkko Sakkinen wrote:
> On Sat, Nov 26, 2016 at 07:45:38AM -0500, Nayna Jain wrote:
>> Physical TPMs use Open Firmware Device Tree bindings that are similar
>> to the IBM Power virtual TPM to support event log. However, these
>> properties store the values in different endianness for Physical
>> and Virtual TPM.
>>
>> This patch fixes the endianness issue by doing appropriate conversion
>> based on Physical or Virtual TPM.
>>
>> Signed-off-by: Nayna Jain <na...@linux.vnet.ibm.com>
>> ---
>>   drivers/char/tpm/tpm_of.c | 27 +++
>>   1 file changed, 23 insertions(+), 4 deletions(-)
>>
>> diff --git a/drivers/char/tpm/tpm_of.c b/drivers/char/tpm/tpm_of.c
>> index 7dee42d7..4b0d5e6 100644
>> --- a/drivers/char/tpm/tpm_of.c
>> +++ b/drivers/char/tpm/tpm_of.c
>> @@ -27,6 +27,8 @@ int tpm_read_log_of(struct tpm_chip *chip)
>>  const u32 *sizep;
>>  const u64 *basep;
>>  struct tpm_bios_log *log;
>> +u32 log_size;
>> +u64 log_base;
>
> Maybe just base and size?

Hmm.. okay to keep names short, I can change to base/size. And since 
they are used within log function, probably it is implicit that, these 
refer to Log  base address and size.

>
>>
>>  log = >log;
>>  if (chip->dev.parent && chip->dev.parent->of_node)
>> @@ -41,18 +43,35 @@ int tpm_read_log_of(struct tpm_chip *chip)
>>  if (sizep == NULL || basep == NULL)
>>  return -EIO;
>>
>> -if (*sizep == 0) {
>> +/*
>> + * For both vtpm/tpm, firmware has log addr and log size in big
>> + * endian format. But in case of vtpm, there is a method called
>> + * sml-handover which is run during kernel init even before
>> + * device tree is setup. This sml-handover function takes care
>> + * of endianness and writes to sml-base and sml-size in little
>> + * endian format. For this reason, vtpm doesn't need conversion
>> + * but physical tpm needs the conversion.
>> + */
>> +if (of_property_match_string(np, "compatible", "IBM,vtpm") < 0) {
>> +log_size = be32_to_cpup(sizep);
>> +log_base = be64_to_cpup(basep);
>> +} else {
>> +log_size = *sizep;
>> +log_base = *basep;
>> +}
>> +
>> +if (log_size == 0) {
>>  dev_warn(>dev, "%s: Event log area empty\n", __func__);
>>  return -EIO;
>>  }
>>
>> -log->bios_event_log = kmalloc(*sizep, GFP_KERNEL);
>> +log->bios_event_log = kmalloc(log_size, GFP_KERNEL);
>>  if (!log->bios_event_log)
>>  return -ENOMEM;
>>
>> -log->bios_event_log_end = log->bios_event_log + *sizep;
>> +log->bios_event_log_end = log->bios_event_log + log_size;
>>
>> -memcpy(log->bios_event_log, __va(*basep), *sizep);
>> +memcpy(chip->log.bios_event_log, __va(log_base), log_size);
>
> Why did you change the first parameter?

Hmm.. yeah..shouldn't be.  Sorry, I think while redoing, I mixed up with 
my previous versions. Will change it.
Thanks for noticing it.

Thanks & Regards,
- Nayna

>
>>
>>  return 0;
>>   }
>> --
>> 2.5.0
>>
>
> /Jarkko
>


--
___
tpmdd-devel mailing list
tpmdd-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/tpmdd-devel


[tpmdd-devel] [PATCH v6 0/2] securityfs support for TPM 2.0 firmware event log

2016-11-26 Thread Nayna Jain
The TPM device driver defines ascii and binary methods for
displaying the TPM 1.2 event log via securityfs files, which are
needed for validating a TPM quote. The device driver for TPM 2.0
does not have similar support for displaying the TPM 2.0
event log. This patch set adds the support for displaying
TPM 2.0 event log in binary format.

The parsing mechanism to display the TPM 2.0 event log in binary
format is implemented as defined in the TPM 2.0 TCG specification[1].
If the firmware event log support exists and is successfully read,
the securityfs file is created to provide the event log in binary
format for both the OF device tree and ACPI.

   - Patch 1 adds the device tree bindings support for Physical TPM.
   - Patch 2 adds the support for creating securityfs files and for
 displaying the TPM 2.0 crypto agile event log in binary format.

[1] TCG EFI Protocol Specification, Family "2.0" - Section 5 "Event
Log Structure"

Changelog History

v6:

- Rebased to the Jarkko's latest master branch (e717b5c:tpm: vtpm_proxy: 
  conditionally call tpm_chip_unregister)
- Retained securityfs setup functions in tpm_eventlog.c
- Renamed tpm_eventlog.c to tpm1_eventlog.c
- Fixed tpm_read_log_of() for NULL check and memcpy function.

v5:

- Upstreamed cleanup and fixes as different patchset
- Rebased to the Jarkko's latest master branch (e5be084 tpm: vtpm_proxy:
  Do not access host's event log)
- Patch "tpm: enhance read_log_of() to support Physical TPM event log
  - New Patch.
- Patch "tpm: add securityfs support for TPM 2.0 firmware event log"
  - Moved the changes in read_log_of() to a different patch
  - TPM 2.0 event log data types are declared in tpm_eventlog.h, tpm2.h
  is removed.
  - Included other feedbacks also from Jarkko on aligment and extra
line

v4:

- Includes feedbacks from Jarkko and Jason.
- Patch "tpm: define a generic open() method for ascii & bios
measurements".
  - Fix indentation issue.
- Patch "tpm: replace the dynamically allocated bios_dir as
  struct dentry array".
  - Continue to use bios_dir_count variable to use is_bad() checks and
to maintain correct order for securityfs_remove() during teardown.
  - Reset chip->bios_dir_count in teardown() function.
- Patch "tpm: validate the eventlog access before tpm_bios_log_setup".
  - Retain TPM2 check which was removed in previous patch.
  - Add tpm_bios_log_setup failure handling.
  - Remove use of private data from v3 version of patch. Add a
  new member to struct tpm_chip to achieve the same purpose.
- Patch "tpm: redefine the read_log method to check for ACPI/OF 
properties sequentially".
  - Move replacement of CONFIG_TCG_IBMVTPM with CONFIG_OF to this
patch from patch 3.
  - Replace -1 error code with -ENODEV.
- Patch "tpm: replace the of_find_node_by_name() with dev of_node
property".
  - Uses chip->dev.parent->of_node.
  - Created separate patch for cleanup of pr_err messages.
- Patch "tpm: remove printk error messages".
  - New Patch.
- Patch "tpm: add the securityfs file support for TPM 2.0 eventlog".
  - Parses event digests using event alg_id rather than event log header
alg_id.
  - Uses of_property_match_string to differentiate tpm/vtpm compatible

v3:

- Includes the review feedbacks as suggested by Jason.
- Split of patches into one patch per idea.
- Generic open() method for ascii/bios measurements.
- Replacement of of **bios_dir with *bios_dir[3].
- Verifying readlog() is successful before creating securityfs entries.
- Generic readlog() to check for ACPI/OF in sequence.
- read_log_of() method now uses of_node propertry rather than
calling find_device_by_name.
- read_log differentiates vtpm/tpm using its compatible property.
- Cleans pr_err with dev_dbg.
- Commit msgs subject line prefixed with tpm.

v2:

- Fixes issues as given in feedback by Jason.
- Adds documentation for device tree.

Nayna Jain (2):
  tpm: enhance read_log_of() to support Physical TPM event log
  tpm: add securityfs support for TPM 2.0 firmware event log

 drivers/char/tpm/Makefile  |   2 +-
 .../char/tpm/{tpm_eventlog.c => tpm1_eventlog.c}   |  35 ++--
 drivers/char/tpm/tpm2_eventlog.c   | 214 +
 drivers/char/tpm/tpm_eventlog.h|  70 +++
 drivers/char/tpm/tpm_of.c  |  27 ++-
 5 files changed, 329 insertions(+), 19 deletions(-)
 rename drivers/char/tpm/{tpm_eventlog.c => tpm1_eventlog.c} (95%)
 create mode 100644 drivers/char/tpm/tpm2_eventlog.c

-- 
2.5.0


--
___
tpmdd-devel mailing list
tpmdd-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/tpmdd-devel


Re: [tpmdd-devel] [PATCH v5 1/3] tpm: move event log init functions to tpm_eventlog_init.c

2016-11-24 Thread Nayna


On 11/24/2016 10:13 PM, Jason Gunthorpe wrote:
> On Thu, Nov 24, 2016 at 01:31:03PM +0530, Nayna wrote:
>
>>>> Since the initialization functions are common with the TPM 2.0 event
>>>> log support, this patch splits tpm_eventlog.c to have only TPM 1.2
>>>> event log parsing logic and moves the init functions into
>>>> tpm_eventlog_init.c.
>>>
>>> I think I'd rather see a tpm_eventlog1.c/tpm_eventlog2.c than this
>>> _init thing..
>>
>> Do you mean tpm_eventlog1.c for TPM 1.2 and tpm_eventlog2.c for TPM 2.0
>> event log specific parsing ?
>>
>> And if so, then which one should have the common functions for TPM 1.2 and
>> TPM 2.0?
>
> Leave them in tpm_eventlog.c ..

Sure. I am fine with that. I just feel that it bit of mixed up the scope 
of tpm_eventlog.c file, where it now also refers to TPM2, but have 
corresponding seq functions in separate file.

Thanks & Regards,
- Nayna

>
> Jason
>


--
___
tpmdd-devel mailing list
tpmdd-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/tpmdd-devel


Re: [tpmdd-devel] [PATCH v5 1/3] tpm: move event log init functions to tpm_eventlog_init.c

2016-11-24 Thread Nayna


On 11/24/2016 01:08 AM, Jason Gunthorpe wrote:
> On Wed, Nov 23, 2016 at 12:27:35PM -0500, Nayna Jain wrote:
>> The device driver code for the event log has the init functions and
>> TPM 1.2 parsing logic both defined in same file(tpm_eventlog.c).
>>
>> Since the initialization functions are common with the TPM 2.0 event
>> log support, this patch splits tpm_eventlog.c to have only TPM 1.2
>> event log parsing logic and moves the init functions into
>> tpm_eventlog_init.c.
>
> I think I'd rather see a tpm_eventlog1.c/tpm_eventlog2.c than this
> _init thing..

Do you mean tpm_eventlog1.c for TPM 1.2 and tpm_eventlog2.c for TPM 2.0 
  event log specific parsing ?

And if so, then which one should have the common functions for TPM 1.2 
and TPM 2.0 ?

Thanks & Regards,
- Nayna

>
> Jason
>


--
___
tpmdd-devel mailing list
tpmdd-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/tpmdd-devel


Re: [tpmdd-devel] [PATCH v5 2/3] tpm: enhance read_log_of() to support Physical TPM event log

2016-11-23 Thread Nayna


On 11/24/2016 01:07 AM, Jason Gunthorpe wrote:
> On Wed, Nov 23, 2016 at 12:27:36PM -0500, Nayna Jain wrote:
>>  sizep = of_get_property(np, "linux,sml-size", NULL);
>> +if (of_property_match_string(np, "compatible", "IBM,vtpm") < 0)
>> +log_size = be32_to_cpup(sizep);
>> +else
>> +log_size = *sizep;
>> +
>
> Uh, no, sizep can be null at this point:

Oops !! Missed the basic. Will fix it. Sorry, and Thanks for noticing.

>
>>  basep = of_get_property(np, "linux,sml-base", NULL);
>>  if (sizep == NULL && basep == NULL)
>>  return -ENODEV;
>>  if (sizep == NULL || basep == NULL)
>>  return -EIO;
>
> Move the if here.

Yeah..

>
>> -if (*sizep == 0) {
>> +if (log_size == 0) {
>>  dev_warn(>dev, "%s: Event log area empty\n", __func__);
>>  return -EIO;
>>  }
>>
>> -log->bios_event_log = kmalloc(*sizep, GFP_KERNEL);
>> +log->bios_event_log = kmalloc(log_size, GFP_KERNEL);
>>  if (!log->bios_event_log)
>>  return -ENOMEM;
>>
>> -log->bios_event_log_end = log->bios_event_log + *sizep;
>> +log->bios_event_log_end = log->bios_event_log + log_size;
>>
>> -memcpy(log->bios_event_log, __va(*basep), *sizep);
>> +if (of_property_match_string(np, "compatible", "IBM,vtpm") < 0)
>> +memcpy(chip->log.bios_event_log, __va(be64_to_cpup(basep)),
>> +   log_size);
>> +else
>> +memcpy(chip->log.bios_event_log, __va(*basep),
>> log_size);
>
> And move the conditional swap of basep up to be along side sizep as
> well (ie get rid of the second of_property_match_string)
>

Yeah.. true.. Will fix this also.

Thanks & Regards,
- Nayna

> Jason
>


--
___
tpmdd-devel mailing list
tpmdd-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/tpmdd-devel


Re: [tpmdd-devel] [PATCH v6 4/9] tpm: drop tpm1_chip_register(/unregister)

2016-11-23 Thread Nayna


On 11/22/2016 10:12 PM, Jason Gunthorpe wrote:
> On Tue, Nov 22, 2016 at 01:22:00PM +0200, Jarkko Sakkinen wrote:
>> On Mon, Nov 14, 2016 at 05:00:51AM -0500, Nayna Jain wrote:
>>> Check for TPM2 chip in tpm_sysfs_add_device, tpm_bios_log_setup and
>>> tpm_bios_log_teardown in order to make code flow cleaner and to enable
>>> to implement TPM 2.0 support later on. This is partially derived from
>>> the commit by Nayna Jain with the extension that also tpm1_chip_register
>>> is dropped.
>>>
>>> Signed-off-by: Jarkko Sakkinen <jarkko.sakki...@linux.intel.com>
>>
>> This commit remains unreviewed and tested. I'm in the author role here
>> so I cannot help with this. If that does not happen soon I cannot put
>> this into the pull request.
>
> I tested it on my ARM system when I tested your branch.
>
> I think it looks better this way..
>
> Reviewed-by: Jason Gunthorpe <jguntho...@obsidianresearch.com>
>
> Jason
>

 From my side also, as part of testing the whole patchset, I have tested 
this patch.

Tested-by: Nayna Jain <na...@linux.vnet.ibm.com>
Reviewed-by: Nayna Jain <na...@linux.vnet.ibm.com>

Thanks & Regards,
   - Nayna


--
___
tpmdd-devel mailing list
tpmdd-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/tpmdd-devel


[tpmdd-devel] [PATCH v5 3/3] tpm: add securityfs support for TPM 2.0 firmware event log

2016-11-23 Thread Nayna Jain
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.0 event log supports a crypto agile format that
records multiple digests, which is different from TPM 1.2. This
patch enables the tpm_bios_log_setup for TPM 2.0  and adds the
event log parser which understand the TPM 2.0 crypto agile format.

Signed-off-by: Nayna Jain <na...@linux.vnet.ibm.com>
---
 drivers/char/tpm/Makefile|   2 +-
 drivers/char/tpm/tpm2_eventlog.c | 214 +++
 drivers/char/tpm/tpm_eventlog.h  |  69 +++
 drivers/char/tpm/tpm_eventlog_init.c |  43 +++
 4 files changed, 308 insertions(+), 20 deletions(-)
 create mode 100644 drivers/char/tpm/tpm2_eventlog.c

diff --git a/drivers/char/tpm/Makefile b/drivers/char/tpm/Makefile
index 1dc2671..f185a6a5 100644
--- a/drivers/char/tpm/Makefile
+++ b/drivers/char/tpm/Makefile
@@ -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 \
-   tpm_eventlog.o tpm_eventlog_init.o
+   tpm_eventlog.o tpm_eventlog_init.o tpm2_eventlog.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
diff --git a/drivers/char/tpm/tpm2_eventlog.c b/drivers/char/tpm/tpm2_eventlog.c
new file mode 100644
index 000..865e70e
--- /dev/null
+++ b/drivers/char/tpm/tpm2_eventlog.c
@@ -0,0 +1,214 @@
+/*
+ * Copyright (C) 2016 IBM Corporation
+ *
+ * Authors:
+ *  Nayna Jain <na...@linux.vnet.ibm.com>
+ *
+ * Access to TPM 2.0 event log as written by Firmware.
+ * It assumes that writer of event log has followed TCG Spec 2.0
+ * has written the event struct data in little endian. With that,
+ * it doesn't need any endian conversion for structure content.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version
+ * 2 of the License, or (at your option) any later version.
+ */
+
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#include "tpm.h"
+#include "tpm_eventlog.h"
+
+static int calc_tpm2_event_size(struct tcg_pcr_event2 *event,
+   struct tcg_pcr_event *event_header)
+{
+   struct tcg_efi_specid_event *efispecid;
+   struct tcg_event_field *event_field;
+   void *marker, *marker_start;
+   int i, j;
+   u16 halg;
+   u32 halg_size;
+   size_t size = 0;
+
+   /*
+* NOTE: TPM 2.0 supports extend to multiple PCR Banks. This implies
+* event log also has multiple digest values, one for each PCR Bank.
+* This is called Crypto Agile Log Entry Format.
+* TCG EFI Protocol Specification defines the procedure to parse
+* the event log. Below code implements this procedure to parse
+* correctly the Crypto agile log entry format.
+* Example of Crypto Agile Log Digests Format :
+* digest_values.count = 2;
+* digest_values.digest[0].alg_id = sha1;
+* digest_values.digest[0].digest.sha1 = {20 bytes raw data};
+* digest_values.digest[1].alg_id = sha256;
+* digest_values.digest[1].digest.sha256 = {32 bytes raw data};
+* Offset of eventsize is sizeof(count) + sizeof(alg_id) + 20
+*  + sizeof(alg_id) + 32;
+*
+* Since, offset of event_size can vary based on digests count, offset
+* has to be calculated at run time. void *marker is used to traverse
+* the dynamic structure and calculate the offset of event_size.
+*/
+
+   marker = event;
+   marker_start = marker;
+   marker = marker + sizeof(event->pcr_idx) + sizeof(event->event_type)
+   + sizeof(event->digests.count);
+
+   efispecid = (struct tcg_efi_specid_event *) event_header->event;
+
+   for (i = 0; (i < event->digests.count) && (i < HASH_COUNT); i++) {
+   halg_size = sizeof(event->digests.digests[i].alg_id);
+   memcpy(, marker, halg_size);
+   marker = marker + halg_size;
+   for (j = 0; (j < efispecid->num_algs); j++) {
+   if (halg == efispecid->digest_sizes[j].alg_id) {
+   marker = marker +
+   efispecid->digest_sizes[j].digest_size;
+   break;
+   }
+   }
+   }
+
+   event_field = (struct tcg_event_field *) marker;
+   marker = marker + sizeof(event_field->event_size)
+   + event_field->event_size;
+   size = marker - marker_start;
+
+   if ((event->event_type == 0) && (even

[tpmdd-devel] [PATCH v5 0/3] tpm: securityfs support for TPM 2.0 firmware event log

2016-11-23 Thread Nayna Jain
The TPM device driver defines ascii and binary methods for
displaying the TPM 1.2 event log via securityfs files, which are
needed for validating a TPM quote. The device driver for TPM 2.0
does not have similar support for displaying the TPM 2.0
event log. This patch set adds the support for displaying
TPM 2.0 event log in binary format.

The parsing mechanism to display the TPM 2.0 event log in binary
format is implemented as defined in the TPM 2.0 TCG specification[1].
If the firmware event log support exists and is successfully read,
the securityfs file is created to provide the event log in binary
format for both the OF device tree and ACPI.

   - Patch 1 moves the common TPM 1.2 and 2.0 event log initialization
 functions to a new file named tpm_eventlog_init.c.
   - Patch 2 adds the device tree bindings support for Physical TPM.
   - Patch 3 adds the support for creating securityfs files and for
 displaying the TPM 2.0 crypto agile event log in binary format.

With that, this patch set splits the event log functionality into
initialization functions, TPM 1.2 event log parsing and TPM 2.0 event
log parsing.

[1] TCG EFI Protocol Specification, Family "2.0" - Section 5 "Event
Log Structure"

Changelog History

v5:

- Upstreamed cleanup and fixes as different patchset
- Rebased to the Jarkko's latest master branch (e5be084 tpm: vtpm_proxy:
  Do not access host's event log)
- Patch "tpm: enhance read_log_of() to support Physical TPM event log
  - New Patch.
- Patch "tpm: add securityfs support for TPM 2.0 firmware event log"
  - Moved the changes in read_log_of() to a different patch
  - TPM 2.0 event log data types are declared in tpm_eventlog.h, tpm2.h
  is removed.
  - Included other feedbacks also from Jarkko on aligment and extra
line

v4:

- Includes feedbacks from Jarkko and Jason.
- Patch "tpm: define a generic open() method for ascii & bios
measurements".
  - Fix indentation issue.
- Patch "tpm: replace the dynamically allocated bios_dir as
  struct dentry array".
  - Continue to use bios_dir_count variable to use is_bad() checks and
to maintain correct order for securityfs_remove() during teardown.
  - Reset chip->bios_dir_count in teardown() function.
- Patch "tpm: validate the eventlog access before tpm_bios_log_setup".
  - Retain TPM2 check which was removed in previous patch.
  - Add tpm_bios_log_setup failure handling.
  - Remove use of private data from v3 version of patch. Add a
  new member to struct tpm_chip to achieve the same purpose.
- Patch "tpm: redefine the read_log method to check for ACPI/OF 
properties sequentially".
  - Move replacement of CONFIG_TCG_IBMVTPM with CONFIG_OF to this
patch from patch 3.
  - Replace -1 error code with -ENODEV.
- Patch "tpm: replace the of_find_node_by_name() with dev of_node
property".
  - Uses chip->dev.parent->of_node.
  - Created separate patch for cleanup of pr_err messages.
- Patch "tpm: remove printk error messages".
  - New Patch.
- Patch "tpm: add the securityfs file support for TPM 2.0 eventlog".
  - Parses event digests using event alg_id rather than event log header
alg_id.
  - Uses of_property_match_string to differentiate tpm/vtpm compatible

v3:

- Includes the review feedbacks as suggested by Jason.
- Split of patches into one patch per idea.
- Generic open() method for ascii/bios measurements.
- Replacement of of **bios_dir with *bios_dir[3].
- Verifying readlog() is successful before creating securityfs entries.
- Generic readlog() to check for ACPI/OF in sequence.
- read_log_of() method now uses of_node propertry rather than
calling find_device_by_name.
- read_log differentiates vtpm/tpm using its compatible property.
- Cleans pr_err with dev_dbg.
- Commit msgs subject line prefixed with tpm.

v2:

- Fixes issues as given in feedback by Jason.
- Adds documentation for device tree.

Nayna Jain (3):
  tpm: move event log init functions to tpm_eventlog_init.c
  tpm: enhance read_log_of() to support Physical TPM event log
  tpm: add securityfs support for TPM 2.0 firmware event log

 drivers/char/tpm/Makefile|   2 +-
 drivers/char/tpm/tpm2_eventlog.c | 214 +++
 drivers/char/tpm/tpm_eventlog.c  | 165 +--
 drivers/char/tpm/tpm_eventlog.h  |  72 
 drivers/char/tpm/tpm_eventlog_init.c | 194 +++
 drivers/char/tpm/tpm_of.c|  27 -
 6 files changed, 508 insertions(+), 166 deletions(-)
 create mode 100644 drivers/char/tpm/tpm2_eventlog.c
 create mode 100644 drivers/char/tpm/tpm_eventlog_init.c

-- 
2.5.0


--
___
tpmdd-devel mailing list
tpmdd-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/tpmdd-devel


[tpmdd-devel] [PATCH v5 2/3] tpm: enhance read_log_of() to support Physical TPM event log

2016-11-23 Thread Nayna Jain
Physical TPMs use Open Firmware Device Tree bindings that are similar
to the IBM Power virtual TPM to support event log. However, these
properties store the values in different endianness for Physical
and Virtual TPM.

This patch fixes the endianness issue by doing appropriate conversion
based on Physical or Virtual TPM.

Signed-off-by: Nayna Jain <na...@linux.vnet.ibm.com>
---
 drivers/char/tpm/tpm_of.c | 27 +++
 1 file changed, 23 insertions(+), 4 deletions(-)

diff --git a/drivers/char/tpm/tpm_of.c b/drivers/char/tpm/tpm_of.c
index 7dee42d7..646aec1 100644
--- a/drivers/char/tpm/tpm_of.c
+++ b/drivers/char/tpm/tpm_of.c
@@ -27,6 +27,7 @@ int tpm_read_log_of(struct tpm_chip *chip)
const u32 *sizep;
const u64 *basep;
struct tpm_bios_log *log;
+   u32 log_size;
 
log = >log;
if (chip->dev.parent && chip->dev.parent->of_node)
@@ -34,25 +35,43 @@ int tpm_read_log_of(struct tpm_chip *chip)
else
return -ENODEV;
 
+   /*
+* For both vtpm/tpm, firmware has log addr and log size in big
+* endian format. But in case of vtpm, there is a method called
+* sml-handover which is run during kernel init even before
+* device tree is setup. This sml-handover function takes care
+* of endianness and writes to sml-base and sml-size in little
+* endian format. For this reason, vtpm doesn't need conversion
+* but physical tpm needs the conversion.
+*/
sizep = of_get_property(np, "linux,sml-size", NULL);
+   if (of_property_match_string(np, "compatible", "IBM,vtpm") < 0)
+   log_size = be32_to_cpup(sizep);
+   else
+   log_size = *sizep;
+
basep = of_get_property(np, "linux,sml-base", NULL);
if (sizep == NULL && basep == NULL)
return -ENODEV;
if (sizep == NULL || basep == NULL)
return -EIO;
 
-   if (*sizep == 0) {
+   if (log_size == 0) {
dev_warn(>dev, "%s: Event log area empty\n", __func__);
return -EIO;
}
 
-   log->bios_event_log = kmalloc(*sizep, GFP_KERNEL);
+   log->bios_event_log = kmalloc(log_size, GFP_KERNEL);
if (!log->bios_event_log)
return -ENOMEM;
 
-   log->bios_event_log_end = log->bios_event_log + *sizep;
+   log->bios_event_log_end = log->bios_event_log + log_size;
 
-   memcpy(log->bios_event_log, __va(*basep), *sizep);
+   if (of_property_match_string(np, "compatible", "IBM,vtpm") < 0)
+   memcpy(chip->log.bios_event_log, __va(be64_to_cpup(basep)),
+  log_size);
+   else
+   memcpy(chip->log.bios_event_log, __va(*basep), log_size);
 
return 0;
 }
-- 
2.5.0


--
___
tpmdd-devel mailing list
tpmdd-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/tpmdd-devel


Re: [tpmdd-devel] [PATCH v6 3/9] tpm: replace dynamically allocated bios_dir with a static array

2016-11-22 Thread Nayna


On 11/22/2016 04:53 PM, Jarkko Sakkinen wrote:
> On Mon, Nov 14, 2016 at 05:00:50AM -0500, Nayna Jain wrote:
>> This commit is based on a commit by Nayna Jain. Replaced dynamically
>> allocated bios_dir with a static array as the size is always constant.
>>
>> Suggested-by: Jason Gunthorpe <jguntho...@obsidianresearch.com>
>> Signed-off-by: Nayna Jain <na...@linux.vnet.ibm.com>
>> Signed-off-by: Jarkko Sakkinen <jarkko.sakki...@linux.intel.com>
>
> This commit remains unreviewed and tested. I'm in the author role here
> so I cannot help with this. If that does not happen soon I cannot put
> this into the pull request.

Tested-By: Nayna Jain <na...@linux.vnet.ibm.com>

Thanks & Regards,
   - Nayna

>
> /Jarkko
>
>
>> ---
>>   drivers/char/tpm/tpm-chip.c |  9 ---
>>   drivers/char/tpm/tpm.h  |  3 ++-
>>   drivers/char/tpm/tpm_eventlog.c | 59 
>> ++---
>>   drivers/char/tpm/tpm_eventlog.h | 10 +++
>>   4 files changed, 38 insertions(+), 43 deletions(-)
>>
>> diff --git a/drivers/char/tpm/tpm-chip.c b/drivers/char/tpm/tpm-chip.c
>> index 836f056..d0c1872 100644
>> --- a/drivers/char/tpm/tpm-chip.c
>> +++ b/drivers/char/tpm/tpm-chip.c
>> @@ -278,14 +278,16 @@ static void tpm_del_char_device(struct tpm_chip *chip)
>>
>>   static int tpm1_chip_register(struct tpm_chip *chip)
>>   {
>> +int rc;
>> +
>>  if (chip->flags & TPM_CHIP_FLAG_TPM2)
>>  return 0;
>>
>>  tpm_sysfs_add_device(chip);
>>
>> -chip->bios_dir = tpm_bios_log_setup(dev_name(>dev));
>> +rc = tpm_bios_log_setup(chip);
>>
>> -return 0;
>> +return rc;
>>   }
>>
>>   static void tpm1_chip_unregister(struct tpm_chip *chip)
>> @@ -293,8 +295,7 @@ 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);
>> +tpm_bios_log_teardown(chip);
>>   }
>>
>>   static void tpm_del_legacy_sysfs(struct tpm_chip *chip)
>> diff --git a/drivers/char/tpm/tpm.h b/drivers/char/tpm/tpm.h
>> index f9401ca..9d69580 100644
>> --- a/drivers/char/tpm/tpm.h
>> +++ b/drivers/char/tpm/tpm.h
>> @@ -40,6 +40,7 @@ enum tpm_const {
>>  TPM_BUFSIZE = 4096,
>>  TPM_NUM_DEVICES = 65536,
>>  TPM_RETRY = 50, /* 5 seconds */
>> +TPM_NUM_EVENT_LOG_FILES = 3,
>>   };
>>
>>   enum tpm_timeout {
>> @@ -171,7 +172,7 @@ struct tpm_chip {
>>  unsigned long duration[3]; /* jiffies */
>>  bool duration_adjusted;
>>
>> -struct dentry **bios_dir;
>> +struct dentry *bios_dir[TPM_NUM_EVENT_LOG_FILES];
>>
>>  const struct attribute_group *groups[3];
>>  unsigned int groups_cnt;
>> diff --git a/drivers/char/tpm/tpm_eventlog.c 
>> b/drivers/char/tpm/tpm_eventlog.c
>> index 9467e31..62e9da6 100644
>> --- a/drivers/char/tpm/tpm_eventlog.c
>> +++ b/drivers/char/tpm/tpm_eventlog.c
>> @@ -368,54 +368,47 @@ static int is_bad(void *p)
>>  return 0;
>>   }
>>
>> -struct dentry **tpm_bios_log_setup(const char *name)
>> +int tpm_bios_log_setup(struct tpm_chip *chip)
>>   {
>> -struct dentry **ret = NULL, *tpm_dir, *bin_file, *ascii_file;
>> +const char *name = dev_name(>dev);
>> +unsigned int cnt;
>>
>> -tpm_dir = securityfs_create_dir(name, NULL);
>> -if (is_bad(tpm_dir))
>> -goto out;
>> +cnt = 0;
>> +chip->bios_dir[cnt] = securityfs_create_dir(name, NULL);
>> +if (is_bad(chip->bios_dir[cnt]))
>> +goto err;
>> +cnt++;
>>
>> -bin_file =
>> +chip->bios_dir[cnt] =
>>  securityfs_create_file("binary_bios_measurements",
>> -   0440, tpm_dir,
>> +   0440, chip->bios_dir[0],
>> (void *)_binary_b_measurements_seqops,
>> _bios_measurements_ops);
>> -if (is_bad(bin_file))
>> -goto out_tpm;
>> +if (is_bad(chip->bios_dir[cnt]))
>> +goto err;
>> +cnt++;
>>
>> -ascii_file =
>> +chip->bios_dir[cnt] =
>>  securityfs_create_file("ascii_bios_measurements",
>> -   0440, tpm_dir,
>> 

Re: [tpmdd-devel] [PATCH] tpm: use test_bit() to check TPM2 flag in eventlog and sysfs code

2016-11-22 Thread Nayna


On 11/22/2016 04:29 PM, Jarkko Sakkinen wrote:
> On Tue, Nov 22, 2016 at 02:32:00PM +0530, Nayna wrote:
>>
>>
>> On 11/22/2016 01:25 AM, Jarkko Sakkinen wrote:
>>> On Mon, Nov 21, 2016 at 03:03:51AM -0500, Nayna Jain wrote:
>>>> There is change done to introduce atomic bitops to set and test
>>>> chip->flags.
>>>> This patch fixes tpm_bios_log_setup() and tpm_sysfs_add_device()
>>>> to use test_bit() to check for TPM_CHIP_FLAG_TPM2 flag.
>>>>
>>>> Signed-off-by: Nayna Jain <na...@linux.vnet.ibm.com>
>>>
>>> I'm bit lost of the purpose of this patch.
>>
>> I was using tabrm branch which has changes related to using bitops for
>> chip->flags, but it was failing for TPM2 check in tpm_bios_log_setup() with
>> the existing way of checking. Replacing existing one with test_bit() check
>> makes it work. Same in case of tpm_sysfs_add_device().
>
> Why didn't you just response to the thread with a review comment
> especially as the patch is not applied to the master branch?

Oh!! Ok.. Sorry, I should have done that.
Will take care next time.

So basically it needs to be fixed as part of that patch.

Thanks & Regards,
- Nayna

>
> /Jarkko
>


--
___
tpmdd-devel mailing list
tpmdd-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/tpmdd-devel


Re: [tpmdd-devel] [PATCH 2/2] tpm: Fix error code handling after tpm_bios_log_setup

2016-11-22 Thread Nayna


On 11/21/2016 10:45 PM, Jason Gunthorpe wrote:
> On Mon, Nov 21, 2016 at 12:06:20AM +0530, Nayna wrote:
>>> rc = tpm_bios_log_setup(chip);
>>> -   if (rc == -ENODEV)
>>> +   if (rc != 0 && rc != -ENODEV)
>>> return rc;
>>
>> This will return in case of -EFAULT as well, where the check is that log is
>> already initialized. Do we want to fail the probe here as well ?
>>
>> -EFAULT is returned from tpm_read_log() as below:
>
> That is fine, we should never read the log twice.
>
>>> index fb603a74cbd29e..2a15b866ac257a 100644
>>> +++ b/drivers/char/tpm/tpm_eventlog.c
>>> @@ -377,14 +377,21 @@ static int tpm_read_log(struct tpm_chip *chip)
>>> }
>>>
>>> rc = tpm_read_log_acpi(chip);
>>
>> This is to understand..
>> It can return -ENOMEM error here, contd below...
>>
>>> -   if ((rc == 0) || (rc == -ENOMEM))
>>> +   if (rc != -ENODEV)
>>> return rc;
>>>
>>> -   rc = tpm_read_log_of(chip);
>>> -
>>> -   return rc;
>>> +   return tpm_read_log_of(chip);
>>
>> So, in ACPI if -ENOMEM error is returned, it will continue to
>> tpm_read_log_of(chip), which will return -ENODEV. So, -ENOMEM error is now
>> masked with -ENODEV error.
>
> No, if acpi is -ENOMEM then 'if (rc != -ENODEV)' is true and it
> returns -ENOMEM.

Yeah, I missed it. Sorry.
>
>>> sizep = of_get_property(np, "linux,sml-size", NULL);
>>> -   if (sizep == NULL)
>>> +   basep = of_get_property(np, "linux,sml-base", NULL);
>>> +   if (sizep == NULL && basep == NULL)
>>> +   return -ENODEV;
>>> +   if (sizep == NULL || basep == NULL)
>>> return -EIO;
>>
>> To confirm my understanding,
>>
>> For -ENODEV, it means that both properties are not supported, so event log
>> is not supported.
>
> Yes
>
>> For -EIO , it means that event log is supported but there is some failure in
>> getting one of them, so should fail the probe.
>> Is my understanding right ?
>
> Yes

Thanks for explaining. Looks good now.

Thanks & Regards,
   - Nayna

>
> Jason
>


--
___
tpmdd-devel mailing list
tpmdd-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/tpmdd-devel


[tpmdd-devel] [PATCH] tpm: use test_bit() to check TPM2 flag in eventlog and sysfs code

2016-11-21 Thread Nayna Jain
There is change done to introduce atomic bitops to set and test
chip->flags.
This patch fixes tpm_bios_log_setup() and tpm_sysfs_add_device()
to use test_bit() to check for TPM_CHIP_FLAG_TPM2 flag.

Signed-off-by: Nayna Jain <na...@linux.vnet.ibm.com>
---
 drivers/char/tpm/tpm-sysfs.c| 2 +-
 drivers/char/tpm/tpm_eventlog.c | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/char/tpm/tpm-sysfs.c b/drivers/char/tpm/tpm-sysfs.c
index 82298e51..9a37c26 100644
--- a/drivers/char/tpm/tpm-sysfs.c
+++ b/drivers/char/tpm/tpm-sysfs.c
@@ -284,7 +284,7 @@ static const struct attribute_group tpm_dev_group = {
 
 void tpm_sysfs_add_device(struct tpm_chip *chip)
 {
-   if (chip->flags & TPM_CHIP_FLAG_TPM2)
+   if (test_bit(TPM_CHIP_FLAG_TPM2, >flags))
return;
 
/* The sysfs routines rely on an implicit tpm_try_get_ops, device_del
diff --git a/drivers/char/tpm/tpm_eventlog.c b/drivers/char/tpm/tpm_eventlog.c
index ebec4ac..dede2ec 100644
--- a/drivers/char/tpm/tpm_eventlog.c
+++ b/drivers/char/tpm/tpm_eventlog.c
@@ -391,7 +391,7 @@ int tpm_bios_log_setup(struct tpm_chip *chip)
unsigned int cnt;
int rc = 0;
 
-   if (chip->flags & TPM_CHIP_FLAG_TPM2)
+   if (test_bit(TPM_CHIP_FLAG_TPM2, >flags))
return 0;
 
rc = tpm_read_log(chip);
-- 
2.5.0


--
___
tpmdd-devel mailing list
tpmdd-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/tpmdd-devel


Re: [tpmdd-devel] [PATCH RFC 2/2] tpm: refactor tpm2_get_tpm_pt to tpm2_getcap_cmd

2016-11-18 Thread Nayna


On 11/17/2016 11:12 PM, Jarkko Sakkinen wrote:
> On Thu, Nov 17, 2016 at 05:20:36PM +0530, Nayna wrote:
>
>> I tested this for capability TPM2_CAP_PCRS. It seems TPM2_CAP_PCRS
>> capability always returns full PCR allocation, and more_data as 0, So, I
>> think the idea of looping over based on more_data may not work for this
>> capability.
>
> You can always request one value at a time until there's no more.
>
> If you request N values, depending on the hardware, the hardware returns
> to you anything from 1 to N values. If you implement a function that
> requests N values in the command, you *must* handle the case where
> moreData is 1 even if the hardware you are testing that never happens.
>
> That's the reason why I would start with a function that you request one
> property of one capability and optimize it in future if it doesn't scale
> for some workload.
>
> Do you have a workload where it doesn't scale?

Thanks Jarkko for explaining in detail.

If I understood correctly, the idea is to request for one property at a 
time, and if we need multiple properties, then to request for each of 
them in a loop. In case of TPM2_CAP_PCRS, property is always zero. This 
is how I am calling getcap_cmd for TPM2_CAP_PCRS.

tpm2_getcap_cmd(chip, TPM2_CAP_PCRS, 0, _data, "get active pcr 
banks");

Output :

[   17.081665] tpm: cap id to receive value is 2
[   17.081666] tpm: TPM2_CAP_COMMANDS: more data 1
[   17.081667] tpm: 2
[   17.081668] tpm: tpm2_get_active_banks  ---> cap is TPM2_CAP_PCRS
[   17.171665] tpm: cap id to receive value is 5
[   17.171666] tpm: TPM2_CAP_PCRS: more data 0 ---> more data is zero.
[   17.171666] tpm: TPM2_CAP_PCRS: more data 0
[   17.171667] tpm: count pcr banks is 2 --> count of active pcr 
banks information returned

more_data is always zero here, so am not sure how to handle more_data in 
this case ?
Since property_id is always zero, I am not able to request for one 
property at a time.
and response_buffer returns the details for both active banks.

This is the expected behavior defined in TCG 2.0 Part 3 Commands 
Specification (Section 30.2.1):

"TPM_CAP_PCRS – Returns the current allocation of PCR in a 
TPML_PCR_SELECTION. The property parameter shall be zero. The TPM will 
always respond to this command with the full PCR allocation and moreData 
will be NO."

Please let me know, if I am missing something.

Thanks & Regards,
- Nayna


>
> /Jarkko
>


--
___
tpmdd-devel mailing list
tpmdd-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/tpmdd-devel


Re: [tpmdd-devel] [PATCH RFC 2/2] tpm: refactor tpm2_get_tpm_pt to tpm2_getcap_cmd

2016-11-17 Thread Nayna


On 11/12/2016 05:32 AM, Jarkko Sakkinen wrote:
> On Fri, Nov 11, 2016 at 09:51:45AM +0530, Nayna wrote:
>>
>>
>> On 10/09/2016 03:44 PM, Jarkko Sakkinen wrote:
>>> Refactored tpm2_get_tpm_pt to tpm2_getcap_cmd, which means that it also
>>> takes capability ID as input. This is required to access
>>> TPM_CAP_HANDLES, which contains metadata needed for swapping transient
>>> data.
>>>
>>> Signed-off-by: Jarkko Sakkinen <jarkko.sakki...@linux.intel.com>
>>> ---
>>>drivers/char/tpm/tpm.h  |  6 +++-
>>>drivers/char/tpm/tpm2-cmd.c | 64 
>>> -
>>>drivers/char/tpm/tpm_tis_core.c |  3 +-
>>>3 files changed, 38 insertions(+), 35 deletions(-)
>>>
>>> diff --git a/drivers/char/tpm/tpm.h b/drivers/char/tpm/tpm.h
>>> index 0fab6d5..8176f42 100644
>>> --- a/drivers/char/tpm/tpm.h
>>> +++ b/drivers/char/tpm/tpm.h
>>> @@ -85,6 +85,10 @@ enum tpm2_capabilities {
>>> TPM2_CAP_TPM_PROPERTIES = 6,
>>>};
>>>
>>> +enum tpm2_properties {
>>> +   TPM2_PT_FAMILY_INDICATOR= 0x100,
>>> +};
>>> +
>>>enum tpm2_startup_types {
>>> TPM2_SU_CLEAR   = 0x,
>>> TPM2_SU_STATE   = 0x0001,
>>> @@ -485,7 +489,7 @@ int tpm2_seal_trusted(struct tpm_chip *chip,
>>>int tpm2_unseal_trusted(struct tpm_chip *chip,
>>> struct trusted_key_payload *payload,
>>> struct trusted_key_options *options);
>>> -ssize_t tpm2_get_tpm_pt(struct tpm_chip *chip, u32 property_id,
>>> +ssize_t tpm2_getcap_cmd(struct tpm_chip *chip, u32 cap_id, u32 property_id,
>>> u32 *value, const char *desc);
>>>
>>>int tpm2_auto_startup(struct tpm_chip *chip);
>>> diff --git a/drivers/char/tpm/tpm2-cmd.c b/drivers/char/tpm/tpm2-cmd.c
>>> index 2900e18..fcf3d86 100644
>>> --- a/drivers/char/tpm/tpm2-cmd.c
>>> +++ b/drivers/char/tpm/tpm2-cmd.c
>>> @@ -111,13 +111,13 @@ struct tpm2_pcr_extend_in {
>>> u8  digest[TPM_DIGEST_SIZE];
>>>} __packed;
>>>
>>> -struct tpm2_get_tpm_pt_in {
>>> +struct tpm2_getcap_in {
>>> __be32  cap_id;
>>> __be32  property_id;
>>> __be32  property_cnt;
>>>} __packed;
>>>
>>> -struct tpm2_get_tpm_pt_out {
>>> +struct tpm2_getcap_out {
>>> u8  more_data;
>>> __be32  subcap_id;
>>> __be32  property_cnt;
>>> @@ -140,8 +140,8 @@ union tpm2_cmd_params {
>>> struct  tpm2_pcr_read_inpcrread_in;
>>> struct  tpm2_pcr_read_out   pcrread_out;
>>> struct  tpm2_pcr_extend_in  pcrextend_in;
>>> -   struct  tpm2_get_tpm_pt_in  get_tpm_pt_in;
>>> -   struct  tpm2_get_tpm_pt_out get_tpm_pt_out;
>>> +   struct  tpm2_getcap_in  getcap_in;
>>> +   struct  tpm2_getcap_out getcap_out;
>>> struct  tpm2_get_random_in  getrandom_in;
>>> struct  tpm2_get_random_out getrandom_out;
>>>};
>>> @@ -435,16 +435,6 @@ int tpm2_get_random(struct tpm_chip *chip, u8 *out, 
>>> size_t max)
>>> return total ? total : -EIO;
>>>}
>>>
>>> -#define TPM2_GET_TPM_PT_IN_SIZE \
>>> -   (sizeof(struct tpm_input_header) + \
>>> -sizeof(struct tpm2_get_tpm_pt_in))
>>> -
>>> -static const struct tpm_input_header tpm2_get_tpm_pt_header = {
>>> -   .tag = cpu_to_be16(TPM2_ST_NO_SESSIONS),
>>> -   .length = cpu_to_be32(TPM2_GET_TPM_PT_IN_SIZE),
>>> -   .ordinal = cpu_to_be32(TPM2_CC_GET_CAPABILITY)
>>> -};
>>> -
>>>/**
>>> * Append TPMS_AUTH_COMMAND to the buffer. The buffer must be allocated 
>>> with
>>> * tpm_buf_alloc().
>>> @@ -750,35 +740,43 @@ out:
>>> return rc;
>>>}
>>>
>>> +#define TPM2_GETCAP_IN_SIZE \
>>> +   (sizeof(struct tpm_input_header) + sizeof(struct tpm2_getcap_in))
>>> +
>>> +static const struct tpm_input_header tpm2_getcap_header = {
>>> +   .tag = cpu_to_be16(TPM2_ST_NO_SESSIONS),
>>> +   .length = cpu_to_be32(TPM2_GETCAP_IN_SIZE),
>>> +   .ordinal = cpu_to_be32(TPM2_CC_GET_CAPABILITY)
>>> +};
>>> +
>>>/**
>>> - * tpm2_get_tpm_pt() - get value of a TPM_CAP_TPM_PROPERTIES type property
>>> - * @chip:  TPM

Re: [tpmdd-devel] [PATCH] tpm: Check the bios_dir entry for NULL before accessing it

2016-11-16 Thread Nayna


On 11/16/2016 07:26 PM, Stefan Berger wrote:
> Check the bios_dir entry for NULL before accessing it. Currently
> this crashes the driver when a TPM 2 is attached and the entries
> are NULL.

Thanks Stefan !! I think it would be good to also add Fixes in commit 
description here.

Fixes: d660a91a1b9d (tpm: adds NULL check for securityfs pseudo files)

Thanks & Regards,
   - Nayna

>
> Signed-off-by: Stefan Berger <stef...@linux.vnet.ibm.com>
> ---
>   drivers/char/tpm/tpm_eventlog.c | 12 +++-
>   1 file changed, 7 insertions(+), 5 deletions(-)
>
> diff --git a/drivers/char/tpm/tpm_eventlog.c b/drivers/char/tpm/tpm_eventlog.c
> index ebec4ac..fb603a7 100644
> --- a/drivers/char/tpm/tpm_eventlog.c
> +++ b/drivers/char/tpm/tpm_eventlog.c
> @@ -455,10 +455,12 @@ void tpm_bios_log_teardown(struct tpm_chip *chip)
>* This design ensures that open() either safely gets kref or fails.
>*/
>   for (i = (TPM_NUM_EVENT_LOG_FILES - 1); i >= 0; i--) {
> - inode = d_inode(chip->bios_dir[i]);
> - inode_lock(inode);
> - inode->i_private = NULL;
> - inode_unlock(inode);
> - securityfs_remove(chip->bios_dir[i]);
> + if (chip->bios_dir[i]) {
> + inode = d_inode(chip->bios_dir[i]);
> + inode_lock(inode);
> + inode->i_private = NULL;
> + inode_unlock(inode);
> + securityfs_remove(chip->bios_dir[i]);
> + }
>   }
>   }
>


--
___
tpmdd-devel mailing list
tpmdd-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/tpmdd-devel


Re: [tpmdd-devel] [PATCH v6 0/9] tpm: cleanup/fixes in existing event log support

2016-11-14 Thread Nayna


On 11/15/2016 07:45 AM, Jarkko Sakkinen wrote:
> On Mon, Nov 14, 2016 at 04:25:14PM -0800, Jarkko Sakkinen wrote:
>> On Mon, Nov 14, 2016 at 02:33:23PM -0800, Jarkko Sakkinen wrote:
>>> On Mon, Nov 14, 2016 at 05:00:47AM -0500, Nayna Jain wrote:
>>>> This patch set includes the cleanup and bug fixes patches, previously
>>>> part of the "tpm: add the securityfs pseudo files support for TPM 2.0
>>>> firmware event log" patch set, in order to upstream them more quickly.
>>>
>>> I applied the patches. I'm not yet sure whether these are part of the
>>> 4.10 pull request or whether I postpone to 4.11 (my preference would be
>>> 4.10 but I do not want to close that right now). I'll do testing next
>>> week before doing pull request.
>>>
>>> I hope that the commits gets some reviews and testing now that they are
>>> easily testable in my master branch.
>>
>> Event log still works and they do not seem to break TPM 2.0 (tried both
>> machine with tpm_crb and tpm_tis).
>>
>> Stefan: would you mind check that these do not break your TPM 1.2
>> environment? I already tried wih TPM 1.2 machine but probably would
>> make sense to peer test.
>
> I'm dropping commits 8/9 and 9/9 from my tree and *will not* include
> them to my 4.10 pull request.

Will fix this and resend the patch 8/9 and 9/9 again.

Thanks & Regards,
- Nayna

>
> /Jarkko
>


--
___
tpmdd-devel mailing list
tpmdd-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/tpmdd-devel


[tpmdd-devel] [PATCH v6 5/9] tpm: have event log use the tpm_chip

2016-11-14 Thread Nayna Jain
Move the backing memory for the event log into tpm_chip and push
the tpm_chip into read_log. This optimizes read_log processing by
only doing it once and prepares things for the next patches in the
series which require the tpm_chip to locate the event log via
ACPI and OF handles instead of searching.

This is straightfoward except for the issue of passing a kref through
i_private with securityfs. Since securityfs_remove does not have any
removal fencing like sysfs we use the inode lock to safely get a
kref on the tpm_chip.

Suggested-by: Jason Gunthorpe <jguntho...@obsidianresearch.com>
Signed-off-by: Nayna Jain <na...@linux.vnet.ibm.com>
---
 drivers/char/tpm/tpm-chip.c |  3 +-
 drivers/char/tpm/tpm.h  | 11 ++
 drivers/char/tpm/tpm_acpi.c | 15 +--
 drivers/char/tpm/tpm_eventlog.c | 88 ++---
 drivers/char/tpm/tpm_eventlog.h |  2 +-
 drivers/char/tpm/tpm_of.c   |  4 +-
 6 files changed, 85 insertions(+), 38 deletions(-)

diff --git a/drivers/char/tpm/tpm-chip.c b/drivers/char/tpm/tpm-chip.c
index 250a651..3f27753 100644
--- a/drivers/char/tpm/tpm-chip.c
+++ b/drivers/char/tpm/tpm-chip.c
@@ -127,6 +127,7 @@ static void tpm_dev_release(struct device *dev)
idr_remove(_nums_idr, chip->dev_num);
mutex_unlock(_lock);
 
+   kfree(chip->log.bios_event_log);
kfree(chip);
 }
 
@@ -345,7 +346,7 @@ int tpm_chip_register(struct tpm_chip *chip)
tpm_sysfs_add_device(chip);
 
rc = tpm_bios_log_setup(chip);
-   if (rc)
+   if (rc == -ENODEV)
return rc;
 
tpm_add_ppi(chip);
diff --git a/drivers/char/tpm/tpm.h b/drivers/char/tpm/tpm.h
index 9d69580..1ae9768 100644
--- a/drivers/char/tpm/tpm.h
+++ b/drivers/char/tpm/tpm.h
@@ -35,6 +35,8 @@
 #include 
 #include 
 
+#include "tpm_eventlog.h"
+
 enum tpm_const {
TPM_MINOR = 224,/* officially assigned */
TPM_BUFSIZE = 4096,
@@ -146,6 +148,11 @@ enum tpm_chip_flags {
TPM_CHIP_FLAG_HAVE_TIMEOUTS = BIT(4),
 };
 
+struct tpm_chip_seqops {
+   struct tpm_chip *chip;
+   const struct seq_operations *seqops;
+};
+
 struct tpm_chip {
struct device dev;
struct cdev cdev;
@@ -157,6 +164,10 @@ struct tpm_chip {
struct rw_semaphore ops_sem;
const struct tpm_class_ops *ops;
 
+   struct tpm_bios_log log;
+   struct tpm_chip_seqops bin_log_seqops;
+   struct tpm_chip_seqops ascii_log_seqops;
+
unsigned int flags;
 
int dev_num;/* /dev/tpm# */
diff --git a/drivers/char/tpm/tpm_acpi.c b/drivers/char/tpm/tpm_acpi.c
index 565a947..01dfb35 100644
--- a/drivers/char/tpm/tpm_acpi.c
+++ b/drivers/char/tpm/tpm_acpi.c
@@ -9,7 +9,7 @@
  *
  * Maintained by: <tpmdd-devel@lists.sourceforge.net>
  *
- * Access to the eventlog extended by the TCG BIOS of PC platform
+ * Access to the event log extended by the TCG BIOS of PC platform
  *
  * This program is free software; you can redistribute it and/or
  * modify it under the terms of the GNU General Public License
@@ -45,13 +45,15 @@ struct acpi_tcpa {
 };
 
 /* read binary bios log */
-int read_log(struct tpm_bios_log *log)
+int read_log(struct tpm_chip *chip)
 {
struct acpi_tcpa *buff;
acpi_status status;
void __iomem *virt;
u64 len, start;
+   struct tpm_bios_log *log;
 
+   log = >log;
if (log->bios_event_log != NULL) {
printk(KERN_ERR
   "%s: ERROR - Eventlog already initialized\n",
@@ -97,13 +99,18 @@ int read_log(struct tpm_bios_log *log)
 
virt = acpi_os_map_iomem(start, len);
if (!virt) {
-   kfree(log->bios_event_log);
printk("%s: ERROR - Unable to map memory\n", __func__);
-   return -EIO;
+   goto err;
}
 
memcpy_fromio(log->bios_event_log, virt, len);
 
acpi_os_unmap_iomem(virt, len);
return 0;
+
+err:
+   kfree(log->bios_event_log);
+   log->bios_event_log = NULL;
+   return -EIO;
+
 }
diff --git a/drivers/char/tpm/tpm_eventlog.c b/drivers/char/tpm/tpm_eventlog.c
index 57ac862..f8c42fe 100644
--- a/drivers/char/tpm/tpm_eventlog.c
+++ b/drivers/char/tpm/tpm_eventlog.c
@@ -11,7 +11,7 @@
  *
  * Maintained by: <tpmdd-devel@lists.sourceforge.net>
  *
- * Access to the eventlog created by a system's firmware / BIOS
+ * Access to the event log created by a system's firmware / BIOS
  *
  * This program is free software; you can redistribute it and/or
  * modify it under the terms of the GNU General Public License
@@ -73,7 +73,8 @@ static const char* tcpa_pc_event_id_strings[] = {
 static void *tpm_bios_measurements_start(struct seq_file *m, loff_t *pos)
 {
loff_t i;
-   struct tpm_bios_log *log = m->private;
+   struct tpm_chip *chip = m->private;
+   struct tpm_bios_log *log = >log;
void *ad

[tpmdd-devel] [PATCH v6 6/9] tpm: fix the missing .owner in tpm_bios_measurements_ops

2016-11-14 Thread Nayna Jain
This patch fixes the missing .owner field in
tpm_bios_measurements_ops definition.

Suggested-by: Jason Gunthorpe <jguntho...@obsidianresearch.com>
Signed-off-by: Nayna Jain <na...@linux.vnet.ibm.com>
---
 drivers/char/tpm/tpm_eventlog.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/drivers/char/tpm/tpm_eventlog.c b/drivers/char/tpm/tpm_eventlog.c
index f8c42fe..5575ffc 100644
--- a/drivers/char/tpm/tpm_eventlog.c
+++ b/drivers/char/tpm/tpm_eventlog.c
@@ -349,6 +349,7 @@ static int tpm_bios_measurements_open(struct inode *inode,
 }
 
 static const struct file_operations tpm_bios_measurements_ops = {
+   .owner = THIS_MODULE,
.open = tpm_bios_measurements_open,
.read = seq_read,
.llseek = seq_lseek,
-- 
2.5.0


--
Developer Access Program for Intel Xeon Phi Processors
Access to Intel Xeon Phi processor-based developer platforms.
With one year of Intel Parallel Studio XE.
Training and support from Colfax.
Order your platform today. http://sdm.link/xeonphi
___
tpmdd-devel mailing list
tpmdd-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/tpmdd-devel


[tpmdd-devel] [PATCH v6 9/9] tpm: cleanup of printk error messages

2016-11-14 Thread Nayna Jain
This patch removes the unnecessary error messages on failing to
allocate memory and replaces pr_err/printk with dev_dbg/dev_info
as applicable.

Suggested-by: Jason Gunthorpe <jguntho...@obsidianresearch.com>
Signed-off-by: Nayna Jain <na...@linux.vnet.ibm.com>
---
 drivers/char/tpm/tpm_acpi.c | 16 
 drivers/char/tpm/tpm_of.c   | 29 +
 2 files changed, 13 insertions(+), 32 deletions(-)

diff --git a/drivers/char/tpm/tpm_acpi.c b/drivers/char/tpm/tpm_acpi.c
index fa30c969..ddbaef2 100644
--- a/drivers/char/tpm/tpm_acpi.c
+++ b/drivers/char/tpm/tpm_acpi.c
@@ -60,11 +60,8 @@ int read_log_acpi(struct tpm_chip *chip)
status = acpi_get_table(ACPI_SIG_TCPA, 1,
(struct acpi_table_header **));
 
-   if (ACPI_FAILURE(status)) {
-   printk(KERN_ERR "%s: ERROR - Could not get TCPA table\n",
-  __func__);
+   if (ACPI_FAILURE(status))
return -EIO;
-   }
 
switch(buff->platform_class) {
case BIOS_SERVER:
@@ -78,25 +75,20 @@ int read_log_acpi(struct tpm_chip *chip)
break;
}
if (!len) {
-   printk(KERN_ERR "%s: ERROR - TCPA log area empty\n", __func__);
+   dev_warn(>dev, "%s: TCPA log area empty\n", __func__);
return -EIO;
}
 
/* malloc EventLog space */
log->bios_event_log = kmalloc(len, GFP_KERNEL);
-   if (!log->bios_event_log) {
-   printk("%s: ERROR - Not enough  Memory for BIOS measurements\n",
-   __func__);
+   if (!log->bios_event_log)
return -ENOMEM;
-   }
 
log->bios_event_log_end = log->bios_event_log + len;
 
virt = acpi_os_map_iomem(start, len);
-   if (!virt) {
-   printk("%s: ERROR - Unable to map memory\n", __func__);
+   if (!virt)
goto err;
-   }
 
memcpy_fromio(log->bios_event_log, virt, len);
 
diff --git a/drivers/char/tpm/tpm_of.c b/drivers/char/tpm/tpm_of.c
index 22b8f81..3af829f 100644
--- a/drivers/char/tpm/tpm_of.c
+++ b/drivers/char/tpm/tpm_of.c
@@ -31,40 +31,29 @@ int read_log_of(struct tpm_chip *chip)
log = >log;
if (chip->dev.parent->of_node)
np = chip->dev.parent->of_node;
-   if (!np) {
-   pr_err("%s: ERROR - IBMVTPM not supported\n", __func__);
+   if (!np)
return -ENODEV;
-   }
 
sizep = of_get_property(np, "linux,sml-size", NULL);
-   if (sizep == NULL) {
-   pr_err("%s: ERROR - SML size not found\n", __func__);
-   goto cleanup_eio;
-   }
+   if (sizep == NULL)
+   return -EIO;
+
if (*sizep == 0) {
-   pr_err("%s: ERROR - event log area empty\n", __func__);
-   goto cleanup_eio;
+   dev_warn(>dev, "%s: Event log area empty\n", __func__);
+   return -EIO;
}
 
basep = of_get_property(np, "linux,sml-base", NULL);
-   if (basep == NULL) {
-   pr_err("%s: ERROR - SML not found\n", __func__);
-   goto cleanup_eio;
-   }
+   if (basep == NULL)
+   return -EIO;
 
log->bios_event_log = kmalloc(*sizep, GFP_KERNEL);
-   if (!log->bios_event_log) {
-   pr_err("%s: ERROR - Not enough memory for BIOS measurements\n",
-  __func__);
+   if (!log->bios_event_log)
return -ENOMEM;
-   }
 
log->bios_event_log_end = log->bios_event_log + *sizep;
 
memcpy(log->bios_event_log, __va(*basep), *sizep);
 
return 0;
-
-cleanup_eio:
-   return -EIO;
 }
-- 
2.5.0


--
Developer Access Program for Intel Xeon Phi Processors
Access to Intel Xeon Phi processor-based developer platforms.
With one year of Intel Parallel Studio XE.
Training and support from Colfax.
Order your platform today. http://sdm.link/xeonphi
___
tpmdd-devel mailing list
tpmdd-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/tpmdd-devel


[tpmdd-devel] [PATCH v6 8/9] tpm: replace of_find_node_by_name() with dev of_node property

2016-11-14 Thread Nayna Jain
Using the device of_node property is a better way to refer to the
device tree node rather than of_find_node_by_name().

Suggested-by: Jason Gunthorpe <jguntho...@obsidianresearch.com>
Signed-off-by: Nayna Jain <na...@linux.vnet.ibm.com>
Reviewed-by: Jarkko Sakkinen <jarkko.sakki...@linux.intel.com>
---
 drivers/char/tpm/tpm_of.c | 6 ++
 1 file changed, 2 insertions(+), 4 deletions(-)

diff --git a/drivers/char/tpm/tpm_of.c b/drivers/char/tpm/tpm_of.c
index 7c30752..22b8f81 100644
--- a/drivers/char/tpm/tpm_of.c
+++ b/drivers/char/tpm/tpm_of.c
@@ -29,7 +29,8 @@ int read_log_of(struct tpm_chip *chip)
struct tpm_bios_log *log;
 
log = >log;
-   np = of_find_node_by_name(NULL, "vtpm");
+   if (chip->dev.parent->of_node)
+   np = chip->dev.parent->of_node;
if (!np) {
pr_err("%s: ERROR - IBMVTPM not supported\n", __func__);
return -ENODEV;
@@ -55,18 +56,15 @@ int read_log_of(struct tpm_chip *chip)
if (!log->bios_event_log) {
pr_err("%s: ERROR - Not enough memory for BIOS measurements\n",
   __func__);
-   of_node_put(np);
return -ENOMEM;
}
 
log->bios_event_log_end = log->bios_event_log + *sizep;
 
memcpy(log->bios_event_log, __va(*basep), *sizep);
-   of_node_put(np);
 
return 0;
 
 cleanup_eio:
-   of_node_put(np);
return -EIO;
 }
-- 
2.5.0


--
Developer Access Program for Intel Xeon Phi Processors
Access to Intel Xeon Phi processor-based developer platforms.
With one year of Intel Parallel Studio XE.
Training and support from Colfax.
Order your platform today. http://sdm.link/xeonphi
___
tpmdd-devel mailing list
tpmdd-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/tpmdd-devel


[tpmdd-devel] [PATCH v6 7/9] tpm: redefine read_log() to handle ACPI/OF at runtime

2016-11-14 Thread Nayna Jain
Currently, read_log() has two implementations: one for ACPI platforms
and the other for device tree(OF) based platforms. The proper one is
selected at compile time using Kconfig and #ifdef in the Makefile,
which is not the recommended approach.

This patch removes the #ifdef in the Makefile by defining a single
read_log() method, which checks for ACPI/OF event log properties at
runtime.

Suggested-by: Jason Gunthorpe <jguntho...@obsidianresearch.com>
Signed-off-by: Nayna Jain <na...@linux.vnet.ibm.com>
Reviewed-by: Jason Gunthorpe <jguntho...@obsidianresearch.com>
Reviewed-by: Jarkko Sakkinen <jarkko.sakki...@linux.intel.com>
---
 drivers/char/tpm/Makefile   | 14 --
 drivers/char/tpm/tpm_acpi.c |  9 ++---
 drivers/char/tpm/tpm_eventlog.c | 20 
 drivers/char/tpm/tpm_eventlog.h | 22 +-
 drivers/char/tpm/tpm_of.c   |  8 ++--
 5 files changed, 41 insertions(+), 32 deletions(-)

diff --git a/drivers/char/tpm/Makefile b/drivers/char/tpm/Makefile
index a385fb8..a05b1eb 100644
--- a/drivers/char/tpm/Makefile
+++ b/drivers/char/tpm/Makefile
@@ -2,16 +2,10 @@
 # Makefile for the kernel tpm device drivers.
 #
 obj-$(CONFIG_TCG_TPM) += tpm.o
-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
-else
-ifdef CONFIG_TCG_IBMVTPM
-   tpm-y += tpm_eventlog.o tpm_of.o
-endif
-endif
+tpm-y := tpm-interface.o tpm-dev.o tpm-sysfs.o tpm-chip.o tpm2-cmd.o \
+   tpm_eventlog.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
 obj-$(CONFIG_TCG_TIS) += tpm_tis.o
 obj-$(CONFIG_TCG_TIS_SPI) += tpm_tis_spi.o
diff --git a/drivers/char/tpm/tpm_acpi.c b/drivers/char/tpm/tpm_acpi.c
index 01dfb35..fa30c969 100644
--- a/drivers/char/tpm/tpm_acpi.c
+++ b/drivers/char/tpm/tpm_acpi.c
@@ -6,6 +6,7 @@
  * Stefan Berger <stef...@us.ibm.com>
  * Reiner Sailer <sai...@watson.ibm.com>
  * Kylene Hall <kjh...@us.ibm.com>
+ * Nayna Jain <na...@linux.vnet.ibm.com>
  *
  * Maintained by: <tpmdd-devel@lists.sourceforge.net>
  *
@@ -45,7 +46,7 @@ struct acpi_tcpa {
 };
 
 /* read binary bios log */
-int read_log(struct tpm_chip *chip)
+int read_log_acpi(struct tpm_chip *chip)
 {
struct acpi_tcpa *buff;
acpi_status status;
@@ -54,12 +55,6 @@ int read_log(struct tpm_chip *chip)
struct tpm_bios_log *log;
 
log = >log;
-   if (log->bios_event_log != NULL) {
-   printk(KERN_ERR
-  "%s: ERROR - Eventlog already initialized\n",
-  __func__);
-   return -EFAULT;
-   }
 
/* Find TCPA entry in RSDT (ACPI_LOGICAL_ADDRESSING) */
status = acpi_get_table(ACPI_SIG_TCPA, 1,
diff --git a/drivers/char/tpm/tpm_eventlog.c b/drivers/char/tpm/tpm_eventlog.c
index 5575ffc..cce679b 100644
--- a/drivers/char/tpm/tpm_eventlog.c
+++ b/drivers/char/tpm/tpm_eventlog.c
@@ -365,6 +365,26 @@ static int is_bad(void *p)
return 0;
 }
 
+int read_log(struct tpm_chip *chip)
+{
+   int rc;
+
+   if (chip->log.bios_event_log != NULL) {
+   dev_dbg(>dev,
+   "%s: ERROR - event log already initialized\n",
+   __func__);
+   return -EFAULT;
+   }
+
+   rc = read_log_acpi(chip);
+   if ((rc == 0) || (rc == -ENOMEM))
+   return rc;
+
+   rc = read_log_of(chip);
+
+   return rc;
+}
+
 int tpm_bios_log_setup(struct tpm_chip *chip)
 {
const char *name = dev_name(>dev);
diff --git a/drivers/char/tpm/tpm_eventlog.h b/drivers/char/tpm/tpm_eventlog.h
index 6df2f8e..be529ad 100644
--- a/drivers/char/tpm/tpm_eventlog.h
+++ b/drivers/char/tpm/tpm_eventlog.h
@@ -73,20 +73,24 @@ enum tcpa_pc_event_ids {
HOST_TABLE_OF_DEVICES,
 };
 
-int read_log(struct tpm_chip *chip);
-
-#if defined(CONFIG_TCG_IBMVTPM) || defined(CONFIG_TCG_IBMVTPM_MODULE) || \
-   defined(CONFIG_ACPI)
-extern int tpm_bios_log_setup(struct tpm_chip *chip);
-extern void tpm_bios_log_teardown(struct tpm_chip *chip);
+#if defined(CONFIG_ACPI)
+int read_log_acpi(struct tpm_chip *chip);
 #else
-static inline int tpm_bios_log_setup(struct tpm_chip *chip)
+static inline int read_log_acpi(struct tpm_chip *chip)
 {
-   return 0;
+   return -ENODEV;
 }
-static inline void tpm_bios_log_teardown(struct tpm_chip *chip)
+#endif
+#if defined(CONFIG_OF)
+int read_log_of(struct tpm_chip *chip);
+#else
+static inline int read_log_of(struct tpm_chip *chip)
 {
+   return -ENODEV;
 }
 #endif
 
+int tpm_bios_log_setup(struct tpm_chip *chip);
+void tpm_bios_log_teardown(struct tpm_chip *chip);
+
 #endif
diff --git a/drivers/char/tpm/tpm_of.c b/drivers/char/tpm/tpm_of.c
index 68d891a..7c30752 100644
--- a/drivers/char/tpm/tp

[tpmdd-devel] [PATCH v6 0/9] tpm: cleanup/fixes in existing event log support

2016-11-14 Thread Nayna Jain
This patch set includes the cleanup and bug fixes patches, previously
part of the "tpm: add the securityfs pseudo files support for TPM 2.0
firmware event log" patch set, in order to upstream them more quickly.

Changelog History:

v6:

- Patch "tpm: replace symbolic permission with octal for securityfs files"
  - New Patch.
- Patch "tpm: have event log use the tpm_chip"
  - Changed commit description as per Jason's suggestion.
  - Fixed bug related to kfree() for bios_event_log.
  - Moved inode_unlock() just after get_device() in open().
  - Returned -ENODEV for read_log() ENOMEM error and other errors as it is.
  - Added comment in tpm_bios_log_teardown() to explain inode_lock()/unlock
reasoning.
  - Splitted .owner into different patch.
- Patch "tpm: fix the missing .owner in tpm_bios_measurements_ops"
  - New Patch.
- Patch "tpm: cleanup of printk error messages"
  - Replaced dev_info() with dev_warn().
  - Updated commit description subject line.

v5:

- Moved cleanup/fixes patches into this patch set.
- Patch "fix the race condition between event log access and chip
getting unregistered"
  - updated subject line and commit description.
  - modified fops code to use chip kref.
  - modified fops to lock inode before accessing inode private data.
  - renamed tpm_securityfs_data to tpm_chip_seqops, as it no more
  holds bios log, but associates seqops with respective chip. For
  the same reason, moved it to tpm.h
- Patch "replace or remove printk error messages"
  - cleaned up dev_dbg and used dev_info as applicable.

v4:

- Includes feedbacks from Jarkko and Jason.
- Patch "tpm: define a generic open() method for ascii & bios
measurements".
  - Fix indentation issue.
- Patch "tpm: replace the dynamically allocated bios_dir as
  struct dentry array". 
  - Continue to use bios_dir_count variable to use is_bad() checks and
  to maintain correct order for securityfs_remove() during teardown.
  - Reset chip->bios_dir_count in teardown() function.
- Patch "tpm: validate the event log access before tpm_bios_log_setup".
  - Retain TPM2 check which was removed in previous patch.
  - Add tpm_bios_log_setup failure handling.
  - Remove use of private data from v3 version of patch. Add a new
  member to struct tpm_chip to achieve the same purpose.
- Patch "tpm: redefine the read_log method to check for ACPI/OF 
properties sequentially".
  - Move replacement of CONFIG_TCG_IBMVTPM with CONFIG_OF to
  this patch from patch 3.
  - Replace -1 error code with -ENODEV.
- Patch "tpm: replace the of_find_node_by_name() with dev of_node
property".
 - Uses chip->dev.parent->of_node.
 - Created separate patch for cleanup of pr_err messages.
- Patch "tpm: remove printk error messages".
 - New Patch.
- Patch "tpm: add the securityfs file support for TPM 2.0 event log".
 - Parses event digests using event alg_id rather than event log header
 alg_id.
 - Uses of_property_match_string to differentiate tpm/vtpm compatible
 property.
 - Adds the comment for difference in tpm/vtpm endianness.

v3:

- Includes the review feedbacks as suggested by Jason.
- Split of patches into one patch per idea.
- Generic open() method for ascii/bios measurements.
- Replacement of of **bios_dir with *bios_dir[3].
- Verifying readlog() is successful before creating securityfs entries.
- Generic readlog() to check for ACPI/OF in sequence.
- read_log_of() method now uses of_node propertry rather than
calling find_device_by_name.
- read_log differentiates vtpm/tpm using its compatible property.
- Cleans pr_err with dev_dbg.
- Commit msgs subject line prefixed with tpm.

v2:

- Fixes issues as given in feedback by Jason.
- Adds documentation for device tree.

Nayna Jain (9):
  tpm: define a generic open() method for ascii & bios measurements
  tpm: replace symbolic permission with octal for securityfs files
  tpm: replace dynamically allocated bios_dir with a static array
  tpm: drop tpm1_chip_register(/unregister)
  tpm: have event log use the tpm_chip
  tpm: fix the missing .owner in tpm_bios_measurements_ops
  tpm: redefine read_log() to handle ACPI/OF at runtime
  tpm: replace of_find_node_by_name() with dev of_node property
  tpm: cleanup of printk error messages

 drivers/char/tpm/Makefile   |  14 +--
 drivers/char/tpm/tpm-chip.c |  33 ++
 drivers/char/tpm/tpm-sysfs.c|   3 +
 drivers/char/tpm/tpm.h  |  14 ++-
 drivers/char/tpm/tpm_acpi.c |  38 +++
 drivers/char/tpm/tpm_eventlog.c | 222 +---
 drivers/char/tpm/tpm_eventlog.h |  22 ++--
 drivers/char/tpm/tpm_of.c   |  45 +++-
 8 files changed, 187 insertions(+), 204 deletions(-)

-- 
2.5.0


--
Developer Access Program for Intel Xeon Phi Processors
Access to Intel Xeon Phi process

[tpmdd-devel] [PATCH v6 4/9] tpm: drop tpm1_chip_register(/unregister)

2016-11-14 Thread Nayna Jain
Check for TPM2 chip in tpm_sysfs_add_device, tpm_bios_log_setup and
tpm_bios_log_teardown in order to make code flow cleaner and to enable
to implement TPM 2.0 support later on. This is partially derived from
the commit by Nayna Jain with the extension that also tpm1_chip_register
is dropped.

Signed-off-by: Jarkko Sakkinen <jarkko.sakki...@linux.intel.com>
---
 drivers/char/tpm/tpm-chip.c | 31 +--
 drivers/char/tpm/tpm-sysfs.c|  3 +++
 drivers/char/tpm/tpm_eventlog.c |  3 +++
 3 files changed, 11 insertions(+), 26 deletions(-)

diff --git a/drivers/char/tpm/tpm-chip.c b/drivers/char/tpm/tpm-chip.c
index d0c1872..250a651 100644
--- a/drivers/char/tpm/tpm-chip.c
+++ b/drivers/char/tpm/tpm-chip.c
@@ -276,28 +276,6 @@ static void tpm_del_char_device(struct tpm_chip *chip)
up_write(>ops_sem);
 }
 
-static int tpm1_chip_register(struct tpm_chip *chip)
-{
-   int rc;
-
-   if (chip->flags & TPM_CHIP_FLAG_TPM2)
-   return 0;
-
-   tpm_sysfs_add_device(chip);
-
-   rc = tpm_bios_log_setup(chip);
-
-   return rc;
-}
-
-static void tpm1_chip_unregister(struct tpm_chip *chip)
-{
-   if (chip->flags & TPM_CHIP_FLAG_TPM2)
-   return;
-
-   tpm_bios_log_teardown(chip);
-}
-
 static void tpm_del_legacy_sysfs(struct tpm_chip *chip)
 {
struct attribute **i;
@@ -364,7 +342,9 @@ int tpm_chip_register(struct tpm_chip *chip)
return rc;
}
 
-   rc = tpm1_chip_register(chip);
+   tpm_sysfs_add_device(chip);
+
+   rc = tpm_bios_log_setup(chip);
if (rc)
return rc;
 
@@ -372,7 +352,7 @@ int tpm_chip_register(struct tpm_chip *chip)
 
rc = tpm_add_char_device(chip);
if (rc) {
-   tpm1_chip_unregister(chip);
+   tpm_bios_log_teardown(chip);
return rc;
}
 
@@ -402,8 +382,7 @@ EXPORT_SYMBOL_GPL(tpm_chip_register);
 void tpm_chip_unregister(struct tpm_chip *chip)
 {
tpm_del_legacy_sysfs(chip);
-
-   tpm1_chip_unregister(chip);
+   tpm_bios_log_teardown(chip);
tpm_del_char_device(chip);
 }
 EXPORT_SYMBOL_GPL(tpm_chip_unregister);
diff --git a/drivers/char/tpm/tpm-sysfs.c b/drivers/char/tpm/tpm-sysfs.c
index 59a1ead..848ad65 100644
--- a/drivers/char/tpm/tpm-sysfs.c
+++ b/drivers/char/tpm/tpm-sysfs.c
@@ -284,6 +284,9 @@ static const struct attribute_group tpm_dev_group = {
 
 void tpm_sysfs_add_device(struct tpm_chip *chip)
 {
+   if (chip->flags & TPM_CHIP_FLAG_TPM2)
+   return;
+
/* The sysfs routines rely on an implicit tpm_try_get_ops, device_del
 * is called before ops is null'd and the sysfs core synchronizes this
 * removal so that no callbacks are running or can run again
diff --git a/drivers/char/tpm/tpm_eventlog.c b/drivers/char/tpm/tpm_eventlog.c
index 62e9da6..57ac862 100644
--- a/drivers/char/tpm/tpm_eventlog.c
+++ b/drivers/char/tpm/tpm_eventlog.c
@@ -373,6 +373,9 @@ int tpm_bios_log_setup(struct tpm_chip *chip)
const char *name = dev_name(>dev);
unsigned int cnt;
 
+   if (chip->flags & TPM_CHIP_FLAG_TPM2)
+   return 0;
+
cnt = 0;
chip->bios_dir[cnt] = securityfs_create_dir(name, NULL);
if (is_bad(chip->bios_dir[cnt]))
-- 
2.5.0


--
Developer Access Program for Intel Xeon Phi Processors
Access to Intel Xeon Phi processor-based developer platforms.
With one year of Intel Parallel Studio XE.
Training and support from Colfax.
Order your platform today. http://sdm.link/xeonphi
___
tpmdd-devel mailing list
tpmdd-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/tpmdd-devel


[tpmdd-devel] [PATCH v6 2/9] tpm: replace symbolic permission with octal for securityfs files

2016-11-14 Thread Nayna Jain
checkpatch.pl flags warning for symbolic permissions and suggests
to replace with octal value.

This patch changes securityfs pseudo files permission
to octal values in tpm_bios_log_setup().

Signed-off-by: Nayna Jain <na...@linux.vnet.ibm.com>
---
 drivers/char/tpm/tpm_eventlog.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/char/tpm/tpm_eventlog.c b/drivers/char/tpm/tpm_eventlog.c
index 42b49c4..9467e31 100644
--- a/drivers/char/tpm/tpm_eventlog.c
+++ b/drivers/char/tpm/tpm_eventlog.c
@@ -378,7 +378,7 @@ struct dentry **tpm_bios_log_setup(const char *name)
 
bin_file =
securityfs_create_file("binary_bios_measurements",
-  S_IRUSR | S_IRGRP, tpm_dir,
+  0440, tpm_dir,
   (void *)_binary_b_measurements_seqops,
   _bios_measurements_ops);
if (is_bad(bin_file))
@@ -386,7 +386,7 @@ struct dentry **tpm_bios_log_setup(const char *name)
 
ascii_file =
securityfs_create_file("ascii_bios_measurements",
-  S_IRUSR | S_IRGRP, tpm_dir,
+  0440, tpm_dir,
   (void *)_ascii_b_measurements_seqops,
   _bios_measurements_ops);
if (is_bad(ascii_file))
-- 
2.5.0


--
Developer Access Program for Intel Xeon Phi Processors
Access to Intel Xeon Phi processor-based developer platforms.
With one year of Intel Parallel Studio XE.
Training and support from Colfax.
Order your platform today. http://sdm.link/xeonphi
___
tpmdd-devel mailing list
tpmdd-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/tpmdd-devel


[tpmdd-devel] [PATCH v6 3/9] tpm: replace dynamically allocated bios_dir with a static array

2016-11-14 Thread Nayna Jain
This commit is based on a commit by Nayna Jain. Replaced dynamically
allocated bios_dir with a static array as the size is always constant.

Suggested-by: Jason Gunthorpe <jguntho...@obsidianresearch.com>
Signed-off-by: Nayna Jain <na...@linux.vnet.ibm.com>
Signed-off-by: Jarkko Sakkinen <jarkko.sakki...@linux.intel.com>
---
 drivers/char/tpm/tpm-chip.c |  9 ---
 drivers/char/tpm/tpm.h  |  3 ++-
 drivers/char/tpm/tpm_eventlog.c | 59 ++---
 drivers/char/tpm/tpm_eventlog.h | 10 +++
 4 files changed, 38 insertions(+), 43 deletions(-)

diff --git a/drivers/char/tpm/tpm-chip.c b/drivers/char/tpm/tpm-chip.c
index 836f056..d0c1872 100644
--- a/drivers/char/tpm/tpm-chip.c
+++ b/drivers/char/tpm/tpm-chip.c
@@ -278,14 +278,16 @@ static void tpm_del_char_device(struct tpm_chip *chip)
 
 static int tpm1_chip_register(struct tpm_chip *chip)
 {
+   int rc;
+
if (chip->flags & TPM_CHIP_FLAG_TPM2)
return 0;
 
tpm_sysfs_add_device(chip);
 
-   chip->bios_dir = tpm_bios_log_setup(dev_name(>dev));
+   rc = tpm_bios_log_setup(chip);
 
-   return 0;
+   return rc;
 }
 
 static void tpm1_chip_unregister(struct tpm_chip *chip)
@@ -293,8 +295,7 @@ 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);
+   tpm_bios_log_teardown(chip);
 }
 
 static void tpm_del_legacy_sysfs(struct tpm_chip *chip)
diff --git a/drivers/char/tpm/tpm.h b/drivers/char/tpm/tpm.h
index f9401ca..9d69580 100644
--- a/drivers/char/tpm/tpm.h
+++ b/drivers/char/tpm/tpm.h
@@ -40,6 +40,7 @@ enum tpm_const {
TPM_BUFSIZE = 4096,
TPM_NUM_DEVICES = 65536,
TPM_RETRY = 50, /* 5 seconds */
+   TPM_NUM_EVENT_LOG_FILES = 3,
 };
 
 enum tpm_timeout {
@@ -171,7 +172,7 @@ struct tpm_chip {
unsigned long duration[3]; /* jiffies */
bool duration_adjusted;
 
-   struct dentry **bios_dir;
+   struct dentry *bios_dir[TPM_NUM_EVENT_LOG_FILES];
 
const struct attribute_group *groups[3];
unsigned int groups_cnt;
diff --git a/drivers/char/tpm/tpm_eventlog.c b/drivers/char/tpm/tpm_eventlog.c
index 9467e31..62e9da6 100644
--- a/drivers/char/tpm/tpm_eventlog.c
+++ b/drivers/char/tpm/tpm_eventlog.c
@@ -368,54 +368,47 @@ static int is_bad(void *p)
return 0;
 }
 
-struct dentry **tpm_bios_log_setup(const char *name)
+int tpm_bios_log_setup(struct tpm_chip *chip)
 {
-   struct dentry **ret = NULL, *tpm_dir, *bin_file, *ascii_file;
+   const char *name = dev_name(>dev);
+   unsigned int cnt;
 
-   tpm_dir = securityfs_create_dir(name, NULL);
-   if (is_bad(tpm_dir))
-   goto out;
+   cnt = 0;
+   chip->bios_dir[cnt] = securityfs_create_dir(name, NULL);
+   if (is_bad(chip->bios_dir[cnt]))
+   goto err;
+   cnt++;
 
-   bin_file =
+   chip->bios_dir[cnt] =
securityfs_create_file("binary_bios_measurements",
-  0440, tpm_dir,
+  0440, chip->bios_dir[0],
   (void *)_binary_b_measurements_seqops,
   _bios_measurements_ops);
-   if (is_bad(bin_file))
-   goto out_tpm;
+   if (is_bad(chip->bios_dir[cnt]))
+   goto err;
+   cnt++;
 
-   ascii_file =
+   chip->bios_dir[cnt] =
securityfs_create_file("ascii_bios_measurements",
-  0440, tpm_dir,
+  0440, chip->bios_dir[0],
   (void *)_ascii_b_measurements_seqops,
   _bios_measurements_ops);
-   if (is_bad(ascii_file))
-   goto out_bin;
+   if (is_bad(chip->bios_dir[cnt]))
+   goto err;
+   cnt++;
 
-   ret = kmalloc(3 * sizeof(struct dentry *), GFP_KERNEL);
-   if (!ret)
-   goto out_ascii;
-
-   ret[0] = ascii_file;
-   ret[1] = bin_file;
-   ret[2] = tpm_dir;
-
-   return ret;
+   return 0;
 
-out_ascii:
-   securityfs_remove(ascii_file);
-out_bin:
-   securityfs_remove(bin_file);
-out_tpm:
-   securityfs_remove(tpm_dir);
-out:
-   return NULL;
+err:
+   chip->bios_dir[cnt] = NULL;
+   tpm_bios_log_teardown(chip);
+   return -EIO;
 }
 
-void tpm_bios_log_teardown(struct dentry **lst)
+void tpm_bios_log_teardown(struct tpm_chip *chip)
 {
int i;
 
-   for (i = 0; i < 3; i++)
-   securityfs_remove(lst[i]);
+   for (i = (TPM_NUM_EVENT_LOG_FILES - 1); i >= 0; i--)
+   securityfs_remove(chip->bios_dir[i]);
 }
diff --git a/drivers/char/tpm/tpm_eventlog.h b/drivers/char/tpm/tp

[tpmdd-devel] [PATCH v6 1/9] tpm: define a generic open() method for ascii & bios measurements

2016-11-14 Thread Nayna Jain
open() method for event log ascii and binary bios measurements file
operations are very similar. This patch refactors the code into a
single open() call by passing seq_operations as i_node->private data.

Suggested-by: Jason Gunthorpe <jguntho...@obsidianresearch.com>
Signed-off-by: Nayna Jain <na...@linux.vnet.ibm.com>
Reviewed-by: Jarkko Sakkinen <jarkko.sakki...@linux.intel.com>
Reviewed-by: Jason Gunthorpe <jguntho...@obsidianresearch.com>
Tested-by: Jarkko Sakkinen <jarkko.sakki...@linux.intel.com>
Signed-off-by: Jarkko Sakkinen <jarkko.sakki...@linux.intel.com>
---
 drivers/char/tpm/tpm_eventlog.c | 63 ++---
 1 file changed, 15 insertions(+), 48 deletions(-)

diff --git a/drivers/char/tpm/tpm_eventlog.c b/drivers/char/tpm/tpm_eventlog.c
index e722886..42b49c4 100644
--- a/drivers/char/tpm/tpm_eventlog.c
+++ b/drivers/char/tpm/tpm_eventlog.c
@@ -7,6 +7,7 @@
  * Stefan Berger <stef...@us.ibm.com>
  * Reiner Sailer <sai...@watson.ibm.com>
  * Kylene Hall <kjh...@us.ibm.com>
+ * Nayna Jain <na...@linux.vnet.ibm.com>
  *
  * Maintained by: <tpmdd-devel@lists.sourceforge.net>
  *
@@ -304,26 +305,28 @@ static int tpm_ascii_bios_measurements_show(struct 
seq_file *m, void *v)
return 0;
 }
 
-static const struct seq_operations tpm_ascii_b_measurments_seqops = {
+static const struct seq_operations tpm_ascii_b_measurements_seqops = {
.start = tpm_bios_measurements_start,
.next = tpm_bios_measurements_next,
.stop = tpm_bios_measurements_stop,
.show = tpm_ascii_bios_measurements_show,
 };
 
-static const struct seq_operations tpm_binary_b_measurments_seqops = {
+static const struct seq_operations tpm_binary_b_measurements_seqops = {
.start = tpm_bios_measurements_start,
.next = tpm_bios_measurements_next,
.stop = tpm_bios_measurements_stop,
.show = tpm_binary_bios_measurements_show,
 };
 
-static int tpm_ascii_bios_measurements_open(struct inode *inode,
+static int tpm_bios_measurements_open(struct inode *inode,
struct file *file)
 {
int err;
struct tpm_bios_log *log;
struct seq_file *seq;
+   const struct seq_operations *seqops =
+   (const struct seq_operations *)inode->i_private;
 
log = kzalloc(sizeof(struct tpm_bios_log), GFP_KERNEL);
if (!log)
@@ -333,7 +336,7 @@ static int tpm_ascii_bios_measurements_open(struct inode 
*inode,
goto out_free;
 
/* now register seq file */
-   err = seq_open(file, _ascii_b_measurments_seqops);
+   err = seq_open(file, seqops);
if (!err) {
seq = file->private_data;
seq->private = log;
@@ -349,46 +352,8 @@ static int tpm_ascii_bios_measurements_open(struct inode 
*inode,
goto out;
 }
 
-static const struct file_operations tpm_ascii_bios_measurements_ops = {
-   .open = tpm_ascii_bios_measurements_open,
-   .read = seq_read,
-   .llseek = seq_lseek,
-   .release = tpm_bios_measurements_release,
-};
-
-static int tpm_binary_bios_measurements_open(struct inode *inode,
-struct file *file)
-{
-   int err;
-   struct tpm_bios_log *log;
-   struct seq_file *seq;
-
-   log = kzalloc(sizeof(struct tpm_bios_log), GFP_KERNEL);
-   if (!log)
-   return -ENOMEM;
-
-   if ((err = read_log(log)))
-   goto out_free;
-
-   /* now register seq file */
-   err = seq_open(file, _binary_b_measurments_seqops);
-   if (!err) {
-   seq = file->private_data;
-   seq->private = log;
-   } else {
-   goto out_free;
-   }
-
-out:
-   return err;
-out_free:
-   kfree(log->bios_event_log);
-   kfree(log);
-   goto out;
-}
-
-static const struct file_operations tpm_binary_bios_measurements_ops = {
-   .open = tpm_binary_bios_measurements_open,
+static const struct file_operations tpm_bios_measurements_ops = {
+   .open = tpm_bios_measurements_open,
.read = seq_read,
.llseek = seq_lseek,
.release = tpm_bios_measurements_release,
@@ -413,15 +378,17 @@ struct dentry **tpm_bios_log_setup(const char *name)
 
bin_file =
securityfs_create_file("binary_bios_measurements",
-  S_IRUSR | S_IRGRP, tpm_dir, NULL,
-  _binary_bios_measurements_ops);
+  S_IRUSR | S_IRGRP, tpm_dir,
+  (void *)_binary_b_measurements_seqops,
+  _bios_measurements_ops);
if (is_bad(bin_file))
goto out_tpm;
 
ascii_file =
securityfs_create_file("ascii_bios_measurements",
-

Re: [tpmdd-devel] [PATCH RFC 0/2] Generalize tpm2_get_tpm_pt to tpm2_get_cap

2016-11-10 Thread Nayna


On 11/04/2016 12:58 PM, Jarkko Sakkinen wrote:
> Nayna,
>
> I've already sent these earlier this month as we had this discussion.
> Please look up your emails. I can apply these if they look good for
> you. Please review them.

Sure, I replied just now. I am sorry if delay in response. I was off 
early this week and still going through all mails.

Thanks & Regards,
   - Nayna

>
> /Jarkko
>
> On Sun, Oct 09, 2016 at 01:14:14PM +0300, Jarkko Sakkinen wrote:
>> We need to generalize tpm2_get_tpm_pt to tpm2_get_cap in order to it be
>> suitable for grabbing handles, PCR banks and so forth.
>>
>> Jarkko Sakkinen (2):
>>tpm: move TPM 2.0 command and response constants to tpm2-cmd.c
>>tpm: refactor tpm2_get_tpm_pt to tpm2_getcap_cmd
>>
>>   drivers/char/tpm/tpm.h  |  48 ++
>>   drivers/char/tpm/tpm2-cmd.c | 106 
>> +++-
>>   drivers/char/tpm/tpm_tis_core.c |   3 +-
>>   3 files changed, 80 insertions(+), 77 deletions(-)
>>
>> --
>> 2.7.4
>>
>


--
Developer Access Program for Intel Xeon Phi Processors
Access to Intel Xeon Phi processor-based developer platforms.
With one year of Intel Parallel Studio XE.
Training and support from Colfax.
Order your platform today. http://sdm.link/xeonphi
___
tpmdd-devel mailing list
tpmdd-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/tpmdd-devel


Re: [tpmdd-devel] [PATCH RFC 2/2] tpm: refactor tpm2_get_tpm_pt to tpm2_getcap_cmd

2016-11-10 Thread Nayna
 *desc)

This function currently returns single value "u32 *value" as output data.

Some calling function expect list of values from capabilities output.
For eg., get_active_banks() use TPM_CAP_PCRS capability to retrieve list 
of active banks. And this capability returns array of pcr 
selections(which is a struct representing each active PCR bank)

I was thinking, can we define output parameter as struct of cap_id and 
union of expected cap_data ?

struct cap_out {
   u32 cap_id;
   union cap_data {
  struct tpml_pcr_selection assignedPCR;
  struct tpml_tagged_tpm_property tpmProperties;
  struct tpml_handle handles;
   }
}

And then the calling function, map union to the cap_data expected as per 
id, and parse it.

Thanks & Regards,
   - Nayna


>   {
>   struct tpm2_cmd cmd;
>   int rc;
>
> - cmd.header.in = tpm2_get_tpm_pt_header;
> - cmd.params.get_tpm_pt_in.cap_id = cpu_to_be32(TPM2_CAP_TPM_PROPERTIES);
> - 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);
> + cmd.header.in = tpm2_getcap_header;
> + cmd.params.getcap_in.cap_id = cpu_to_be32(cap_id);
> + cmd.params.getcap_in.property_id = cpu_to_be32(property_id);
> + cmd.params.getcap_in.property_cnt = cpu_to_be32(1);
>
>   rc = tpm_transmit_cmd(chip, , sizeof(cmd), 0, desc);
>   if (!rc)
> - *value = be32_to_cpu(cmd.params.get_tpm_pt_out.value);
> + *value = be32_to_cpu(cmd.params.getcap_out.value);
>
>   return rc;
>   }
> -EXPORT_SYMBOL_GPL(tpm2_get_tpm_pt);
> +EXPORT_SYMBOL_GPL(tpm2_getcap_cmd);
>
>   #define TPM2_STARTUP_IN_SIZE \
>   (sizeof(struct tpm_input_header) + \
> @@ -978,10 +976,10 @@ int tpm2_probe(struct tpm_chip *chip)
>   struct tpm2_cmd cmd;
>   int rc;
>
> - cmd.header.in = tpm2_get_tpm_pt_header;
> - cmd.params.get_tpm_pt_in.cap_id = cpu_to_be32(TPM2_CAP_TPM_PROPERTIES);
> - cmd.params.get_tpm_pt_in.property_id = cpu_to_be32(0x100);
> - cmd.params.get_tpm_pt_in.property_cnt = cpu_to_be32(1);
> + cmd.header.in = tpm2_getcap_header;
> + cmd.params.getcap_in.cap_id = cpu_to_be32(TPM2_CAP_TPM_PROPERTIES);
> + cmd.params.getcap_in.property_id = 
> cpu_to_be32(TPM2_PT_FAMILY_INDICATOR);
> + cmd.params.getcap_in.property_cnt = cpu_to_be32(1);
>
>   rc = tpm_transmit_cmd(chip, , sizeof(cmd),  0, NULL);
>   if (rc <  0)
> diff --git a/drivers/char/tpm/tpm_tis_core.c b/drivers/char/tpm/tpm_tis_core.c
> index e3bf31b..792ccd1 100644
> --- a/drivers/char/tpm/tpm_tis_core.c
> +++ b/drivers/char/tpm/tpm_tis_core.c
> @@ -528,7 +528,8 @@ static int tpm_tis_gen_interrupt(struct tpm_chip *chip)
>   cap_t cap;
>
>   if (chip->flags & TPM_CHIP_FLAG_TPM2)
> - return tpm2_get_tpm_pt(chip, 0x100, , desc);
> + return tpm2_getcap_cmd(chip, TPM2_CAP_TPM_PROPERTIES,
> +TPM2_PT_FAMILY_INDICATOR, , desc);
>   else
>   return tpm_getcap(chip, TPM_CAP_PROP_TIS_TIMEOUT, , desc);
>   }
>


--
Developer Access Program for Intel Xeon Phi Processors
Access to Intel Xeon Phi processor-based developer platforms.
With one year of Intel Parallel Studio XE.
Training and support from Colfax.
Order your platform today. http://sdm.link/xeonphi
___
tpmdd-devel mailing list
tpmdd-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/tpmdd-devel


Re: [tpmdd-devel] [PATCH v5 7/7] tpm: replace or remove printk error messages

2016-10-27 Thread Nayna


On 10/27/2016 07:23 PM, Jarkko Sakkinen wrote:
> On Wed, Oct 26, 2016 at 11:01:00PM +0530, Nayna wrote:
>>
>>
>> On 10/26/2016 04:26 PM, Jarkko Sakkinen wrote:
>>> On Wed, Oct 26, 2016 at 07:52:53AM +0530, Nayna wrote:
>>>>
>>>>
>>>> On 10/21/2016 08:32 PM, Jarkko Sakkinen wrote:
>>>>> On Fri, Oct 21, 2016 at 08:52:14AM +0530, Nayna wrote:
>>>>>>
>>>>>>
>>>>>> On 10/20/2016 04:54 PM, Jarkko Sakkinen wrote:
>>>>>>> On Thu, Oct 20, 2016 at 07:34:37AM +, Winkler, Tomas wrote:
>>>>>>>>> On Tue, Oct 18, 2016 at 08:49:45PM -0400, Nayna Jain wrote:
>>>>>>>>>> This patch removes the unnecessary error messages on failing to
>>>>>>>>>> allocate memory and replaces pr_err/printk with dev_dbg/dev_info as
>>>>>>>>>> applicable.
>>>>>>>>>>
>>>>>>>>>> Suggested-by: Jason Gunthorpe <jguntho...@obsidianresearch.com>
>>>>>>>>>> Signed-off-by: Nayna Jain <na...@linux.vnet.ibm.com>
>>>>>>>>>
>>>>>>>>> Reviewed-by: Jarkko Sakkinen <jarkko.sakki...@linux.intel.com>
>>>>>>>>>
>>>>>>>>> /Jarkko
>>>>>>>>>
>>>>>>>>>> ---
>>>>>>>>>>  drivers/char/tpm/tpm_acpi.c | 17 +
>>>>>>>>>>  drivers/char/tpm/tpm_of.c   | 30 ++
>>>>>>>>>>  2 files changed, 15 insertions(+), 32 deletions(-)
>>>>>>>>>>
>>>>>>>>>> diff --git a/drivers/char/tpm/tpm_acpi.c 
>>>>>>>>>> b/drivers/char/tpm/tpm_acpi.c
>>>>>>>>>> index 859bdba..22e42da 100644
>>>>>>>>>> --- a/drivers/char/tpm/tpm_acpi.c
>>>>>>>>>> +++ b/drivers/char/tpm/tpm_acpi.c
>>>>>>>>>> @@ -60,11 +60,8 @@ int read_log_acpi(struct tpm_chip *chip)
>>>>>>>>>>  status = acpi_get_table(ACPI_SIG_TCPA, 1,
>>>>>>>>>>  (struct acpi_table_header 
>>>>>>>>>> **));
>>>>>>>>>>
>>>>>>>>>> -if (ACPI_FAILURE(status)) {
>>>>>>>>>> -printk(KERN_ERR "%s: ERROR - Could not get TCPA 
>>>>>>>>>> table\n",
>>>>>>>>>> -   __func__);
>>>>>>>>>> +if (ACPI_FAILURE(status))
>>>>>>>>>>  return -EIO;
>>>>>>>>>> -}
>>>>>>>>>>
>>>>>>>>>>  switch(buff->platform_class) {
>>>>>>>>>>  case BIOS_SERVER:
>>>>>>>>>> @@ -78,25 +75,21 @@ int read_log_acpi(struct tpm_chip *chip)
>>>>>>>>>>  break;
>>>>>>>>>>  }
>>>>>>>>>>  if (!len) {
>>>>>>>>>> -printk(KERN_ERR "%s: ERROR - TCPA log area empty\n",
>>>>>>>>> __func__);
>>>>>>>>>> +    dev_dbg(>dev, "%s: ERROR - TCPA log area empty\n",
>>>>>>>>>> +__func__);
>>>>>>>>
>>>>>>>>
>>>>>>>> Why to keep __func__ here, dev_dbg already does it for you.
>>>>>>>
>>>>>>> Good catch. I would actually consider also changing this to
>>>>>>>
>>>>>>> dev_err(dev, FW_BUG "TCPA log area empty\n");
>>>>>>>
>>>>>>> If TCPA exists but it's empty, that's most likely a FW bug.
>>>>>>
>>>>>> If it can be possibly a FW bug, should it fail the probe also just like
>>>>>> -ENOMEM error ?
>>>>>
>>>>> I think so but I hold for second opinion on this. I mean wouldn't
>>>>> it seem like a bit broken situation where TCPA tabe would exist but
>>>>> would also be empty?
>>>>
>>>> Hmm, is it possible for this to be firmware implementation dependent ?
>>>
>>> Let me put it this way. Why would anyone expose TCPA to the user space
>>> that is empty? What would be the point?
>>
>> If I understand correctly,  the reserved memory for event log would be
>> allocated much earlier and firmware would directly write to this allocated
>> memory. So, if there is a firmware bug, and events are not recorded, it will
>> get exposed to userspace as empty event log and this might also help
>> applications to know that it is broken.  Is there any wrong assumption here
>> ?
>
> I think the right question to ask is can event log be legally empty?

No

> If not, then FW_BUG should be used here.
Ok. yeah. and then I think we would want it to fail the probe ?

Thanks & Regards,
- Nayna

>
> /Jarkko
>


--
The Command Line: Reinvented for Modern Developers
Did the resurgence of CLI tooling catch you by surprise?
Reconnect with the command line and become more productive. 
Learn the new .NET and ASP.NET CLI. Get your free copy!
http://sdm.link/telerik
___
tpmdd-devel mailing list
tpmdd-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/tpmdd-devel


Re: [tpmdd-devel] [PATCH v5 7/7] tpm: replace or remove printk error messages

2016-10-26 Thread Nayna


On 10/26/2016 04:26 PM, Jarkko Sakkinen wrote:
> On Wed, Oct 26, 2016 at 07:52:53AM +0530, Nayna wrote:
>>
>>
>> On 10/21/2016 08:32 PM, Jarkko Sakkinen wrote:
>>> On Fri, Oct 21, 2016 at 08:52:14AM +0530, Nayna wrote:
>>>>
>>>>
>>>> On 10/20/2016 04:54 PM, Jarkko Sakkinen wrote:
>>>>> On Thu, Oct 20, 2016 at 07:34:37AM +0000, Winkler, Tomas wrote:
>>>>>>> On Tue, Oct 18, 2016 at 08:49:45PM -0400, Nayna Jain wrote:
>>>>>>>> This patch removes the unnecessary error messages on failing to
>>>>>>>> allocate memory and replaces pr_err/printk with dev_dbg/dev_info as
>>>>>>>> applicable.
>>>>>>>>
>>>>>>>> Suggested-by: Jason Gunthorpe <jguntho...@obsidianresearch.com>
>>>>>>>> Signed-off-by: Nayna Jain <na...@linux.vnet.ibm.com>
>>>>>>>
>>>>>>> Reviewed-by: Jarkko Sakkinen <jarkko.sakki...@linux.intel.com>
>>>>>>>
>>>>>>> /Jarkko
>>>>>>>
>>>>>>>> ---
>>>>>>>> drivers/char/tpm/tpm_acpi.c | 17 +
>>>>>>>> drivers/char/tpm/tpm_of.c   | 30 ++
>>>>>>>> 2 files changed, 15 insertions(+), 32 deletions(-)
>>>>>>>>
>>>>>>>> diff --git a/drivers/char/tpm/tpm_acpi.c b/drivers/char/tpm/tpm_acpi.c
>>>>>>>> index 859bdba..22e42da 100644
>>>>>>>> --- a/drivers/char/tpm/tpm_acpi.c
>>>>>>>> +++ b/drivers/char/tpm/tpm_acpi.c
>>>>>>>> @@ -60,11 +60,8 @@ int read_log_acpi(struct tpm_chip *chip)
>>>>>>>>status = acpi_get_table(ACPI_SIG_TCPA, 1,
>>>>>>>>(struct acpi_table_header **));
>>>>>>>>
>>>>>>>> -  if (ACPI_FAILURE(status)) {
>>>>>>>> -  printk(KERN_ERR "%s: ERROR - Could not get TCPA 
>>>>>>>> table\n",
>>>>>>>> - __func__);
>>>>>>>> +  if (ACPI_FAILURE(status))
>>>>>>>>return -EIO;
>>>>>>>> -  }
>>>>>>>>
>>>>>>>>switch(buff->platform_class) {
>>>>>>>>case BIOS_SERVER:
>>>>>>>> @@ -78,25 +75,21 @@ int read_log_acpi(struct tpm_chip *chip)
>>>>>>>>break;
>>>>>>>>}
>>>>>>>>if (!len) {
>>>>>>>> -  printk(KERN_ERR "%s: ERROR - TCPA log area empty\n",
>>>>>>> __func__);
>>>>>>>> +  dev_dbg(>dev, "%s: ERROR - TCPA log area empty\n",
>>>>>>>> +  __func__);
>>>>>>
>>>>>>
>>>>>> Why to keep __func__ here, dev_dbg already does it for you.
>>>>>
>>>>> Good catch. I would actually consider also changing this to
>>>>>
>>>>> dev_err(dev, FW_BUG "TCPA log area empty\n");
>>>>>
>>>>> If TCPA exists but it's empty, that's most likely a FW bug.
>>>>
>>>> If it can be possibly a FW bug, should it fail the probe also just like
>>>> -ENOMEM error ?
>>>
>>> I think so but I hold for second opinion on this. I mean wouldn't
>>> it seem like a bit broken situation where TCPA tabe would exist but
>>> would also be empty?
>>
>> Hmm, is it possible for this to be firmware implementation dependent ?
>
> Let me put it this way. Why would anyone expose TCPA to the user space
> that is empty? What would be the point?

If I understand correctly,  the reserved memory for event log would be 
allocated much earlier and firmware would directly write to this 
allocated memory. So, if there is a firmware bug, and events are not 
recorded, it will get exposed to userspace as empty event log and this 
might also help applications to know that it is broken.  Is there any 
wrong assumption here ?

Thanks & Regards,
- Nayna

>
> /Jarkko
>


--
The Command Line: Reinvented for Modern Developers
Did the resurgence of CLI tooling catch you by surprise?
Reconnect with the command line and become more productive. 
Learn the new .NET and ASP.NET CLI. Get your free copy!
http://sdm.link/telerik
___
tpmdd-devel mailing list
tpmdd-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/tpmdd-devel


[tpmdd-devel] [PATCH v3 1/2] Documentation: tpm: add the IBM Virtual TPM device tree binding documentation

2016-10-26 Thread Nayna Jain
Virtual TPM, which is being used on IBM POWER7+ and POWER8 systems running
POWERVM, is currently supported by tpm device driver but lacks the
documentation. This patch adds the missing documentation for the existing
support.

Suggested-by: Jason Gunthorpe <jguntho...@obsidianresearch.com>
Signed-off-by: Nayna Jain <na...@linux.vnet.ibm.com>
---
Changelog v3:

- No changes done.

Changelog v2:

- New Patch.

 .../devicetree/bindings/security/tpm/ibmvtpm.txt   | 41 ++
 1 file changed, 41 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/security/tpm/ibmvtpm.txt

diff --git a/Documentation/devicetree/bindings/security/tpm/ibmvtpm.txt 
b/Documentation/devicetree/bindings/security/tpm/ibmvtpm.txt
new file mode 100644
index 000..d89f999
--- /dev/null
+++ b/Documentation/devicetree/bindings/security/tpm/ibmvtpm.txt
@@ -0,0 +1,41 @@
+* Device Tree Bindings for IBM Virtual Trusted Platform Module(vtpm)
+
+Required properties:
+
+- compatible: property name that conveys the platform architecture
+  identifiers, as 'IBM,vtpm'
+- device_type   : specifies type of virtual device
+- interrupts: property specifying the interrupt source number and
+  sense code associated with this virtual I/O Adapters
+- ibm,my-drc-index  : integer index for the connector between the device
+  and its parent - present only if Dynamic
+  Reconfiguration(DR) Connector is enabled
+- ibm,#dma-address-cells: specifies the number of cells that are used to
+  encode the physical address field of dma-window
+  properties
+- ibm,#dma-size-cells   : specifies the number of cells that are used to
+  encode the size field of dma-window properties
+- ibm,my-dma-window : specifies DMA window associated with this virtual
+  IOA
+- ibm,loc-code  : specifies the unique and persistent location code
+  associated with this virtual I/O Adapters
+- linux,sml-base: 64-bit base address of the reserved memory allocated
+  for the firmware event log
+- linux,sml-size: size of the memory allocated for the firmware event 
log
+
+Example (IBM Virtual Trusted Platform Module)
+-
+
+vtpm@3003 {
+ibm,#dma-size-cells = <0x2>;
+compatible = "IBM,vtpm";
+device_type = "IBM,vtpm";
+ibm,my-drc-index = <0x3003>;
+ibm,#dma-address-cells = <0x2>;
+linux,sml-base = <0xc60e 0x0>;
+interrupts = <0xa0003 0x0>;
+ibm,my-dma-window = <0x1003 0x0 0x0 0x0 
0x1000>;
+ibm,loc-code = "U8286.41A.10082DV-V3-C3";
+reg = <0x3003>;
+linux,sml-size = <0xbce10200>;
+};
-- 
2.5.0


--
The Command Line: Reinvented for Modern Developers
Did the resurgence of CLI tooling catch you by surprise?
Reconnect with the command line and become more productive. 
Learn the new .NET and ASP.NET CLI. Get your free copy!
http://sdm.link/telerik
___
tpmdd-devel mailing list
tpmdd-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/tpmdd-devel


Re: [tpmdd-devel] [PATCH v5 7/7] tpm: replace or remove printk error messages

2016-10-25 Thread Nayna


On 10/21/2016 08:32 PM, Jarkko Sakkinen wrote:
> On Fri, Oct 21, 2016 at 08:52:14AM +0530, Nayna wrote:
>>
>>
>> On 10/20/2016 04:54 PM, Jarkko Sakkinen wrote:
>>> On Thu, Oct 20, 2016 at 07:34:37AM +, Winkler, Tomas wrote:
>>>>> On Tue, Oct 18, 2016 at 08:49:45PM -0400, Nayna Jain wrote:
>>>>>> This patch removes the unnecessary error messages on failing to
>>>>>> allocate memory and replaces pr_err/printk with dev_dbg/dev_info as
>>>>>> applicable.
>>>>>>
>>>>>> Suggested-by: Jason Gunthorpe <jguntho...@obsidianresearch.com>
>>>>>> Signed-off-by: Nayna Jain <na...@linux.vnet.ibm.com>
>>>>>
>>>>> Reviewed-by: Jarkko Sakkinen <jarkko.sakki...@linux.intel.com>
>>>>>
>>>>> /Jarkko
>>>>>
>>>>>> ---
>>>>>>drivers/char/tpm/tpm_acpi.c | 17 +
>>>>>>drivers/char/tpm/tpm_of.c   | 30 ++
>>>>>>2 files changed, 15 insertions(+), 32 deletions(-)
>>>>>>
>>>>>> diff --git a/drivers/char/tpm/tpm_acpi.c b/drivers/char/tpm/tpm_acpi.c
>>>>>> index 859bdba..22e42da 100644
>>>>>> --- a/drivers/char/tpm/tpm_acpi.c
>>>>>> +++ b/drivers/char/tpm/tpm_acpi.c
>>>>>> @@ -60,11 +60,8 @@ int read_log_acpi(struct tpm_chip *chip)
>>>>>>  status = acpi_get_table(ACPI_SIG_TCPA, 1,
>>>>>>  (struct acpi_table_header **));
>>>>>>
>>>>>> -if (ACPI_FAILURE(status)) {
>>>>>> -printk(KERN_ERR "%s: ERROR - Could not get TCPA 
>>>>>> table\n",
>>>>>> -   __func__);
>>>>>> +if (ACPI_FAILURE(status))
>>>>>>  return -EIO;
>>>>>> -}
>>>>>>
>>>>>>  switch(buff->platform_class) {
>>>>>>  case BIOS_SERVER:
>>>>>> @@ -78,25 +75,21 @@ int read_log_acpi(struct tpm_chip *chip)
>>>>>>  break;
>>>>>>  }
>>>>>>  if (!len) {
>>>>>> -printk(KERN_ERR "%s: ERROR - TCPA log area empty\n",
>>>>> __func__);
>>>>>> +dev_dbg(>dev, "%s: ERROR - TCPA log area empty\n",
>>>>>> +__func__);
>>>>
>>>>
>>>> Why to keep __func__ here, dev_dbg already does it for you.
>>>
>>> Good catch. I would actually consider also changing this to
>>>
>>> dev_err(dev, FW_BUG "TCPA log area empty\n");
>>>
>>> If TCPA exists but it's empty, that's most likely a FW bug.
>>
>> If it can be possibly a FW bug, should it fail the probe also just like
>> -ENOMEM error ?
>
> I think so but I hold for second opinion on this. I mean wouldn't
> it seem like a bit broken situation where TCPA tabe would exist but
> would also be empty?

Hmm, is it possible for this to be firmware implementation dependent ?

Thanks & Regards,
- Nayna
>
> /Jarkko
>


--
The Command Line: Reinvented for Modern Developers
Did the resurgence of CLI tooling catch you by surprise?
Reconnect with the command line and become more productive. 
Learn the new .NET and ASP.NET CLI. Get your free copy!
http://sdm.link/telerik
___
tpmdd-devel mailing list
tpmdd-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/tpmdd-devel


Re: [tpmdd-devel] [PATCH v5 7/7] tpm: replace or remove printk error messages

2016-10-20 Thread Nayna


On 10/20/2016 04:54 PM, Jarkko Sakkinen wrote:
> On Thu, Oct 20, 2016 at 07:34:37AM +, Winkler, Tomas wrote:
>>> On Tue, Oct 18, 2016 at 08:49:45PM -0400, Nayna Jain wrote:
>>>> This patch removes the unnecessary error messages on failing to
>>>> allocate memory and replaces pr_err/printk with dev_dbg/dev_info as
>>>> applicable.
>>>>
>>>> Suggested-by: Jason Gunthorpe <jguntho...@obsidianresearch.com>
>>>> Signed-off-by: Nayna Jain <na...@linux.vnet.ibm.com>
>>>
>>> Reviewed-by: Jarkko Sakkinen <jarkko.sakki...@linux.intel.com>
>>>
>>> /Jarkko
>>>
>>>> ---
>>>>   drivers/char/tpm/tpm_acpi.c | 17 +
>>>>   drivers/char/tpm/tpm_of.c   | 30 ++
>>>>   2 files changed, 15 insertions(+), 32 deletions(-)
>>>>
>>>> diff --git a/drivers/char/tpm/tpm_acpi.c b/drivers/char/tpm/tpm_acpi.c
>>>> index 859bdba..22e42da 100644
>>>> --- a/drivers/char/tpm/tpm_acpi.c
>>>> +++ b/drivers/char/tpm/tpm_acpi.c
>>>> @@ -60,11 +60,8 @@ int read_log_acpi(struct tpm_chip *chip)
>>>>status = acpi_get_table(ACPI_SIG_TCPA, 1,
>>>>(struct acpi_table_header **));
>>>>
>>>> -  if (ACPI_FAILURE(status)) {
>>>> -  printk(KERN_ERR "%s: ERROR - Could not get TCPA table\n",
>>>> - __func__);
>>>> +  if (ACPI_FAILURE(status))
>>>>return -EIO;
>>>> -  }
>>>>
>>>>switch(buff->platform_class) {
>>>>case BIOS_SERVER:
>>>> @@ -78,25 +75,21 @@ int read_log_acpi(struct tpm_chip *chip)
>>>>break;
>>>>}
>>>>if (!len) {
>>>> -  printk(KERN_ERR "%s: ERROR - TCPA log area empty\n",
>>> __func__);
>>>> +  dev_dbg(>dev, "%s: ERROR - TCPA log area empty\n",
>>>> +  __func__);
>>
>>
>> Why to keep __func__ here, dev_dbg already does it for you.
>
> Good catch. I would actually consider also changing this to
>
> dev_err(dev, FW_BUG "TCPA log area empty\n");
>
> If TCPA exists but it's empty, that's most likely a FW bug.

If it can be possibly a FW bug, should it fail the probe also just like 
-ENOMEM error ?

Thanks & Regards,
 - Nayna

>
> /Jarkko
>


--
Check out the vibrant tech community on one of the world's most 
engaging tech sites, SlashDot.org! http://sdm.link/slashdot
___
tpmdd-devel mailing list
tpmdd-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/tpmdd-devel


Re: [tpmdd-devel] [PATCH v4 3/8] tpm: validate event log access before tpm_bios_log_setup

2016-10-18 Thread Nayna


On 10/14/2016 12:21 AM, Nayna wrote:
>
>
> On 10/01/2016 05:31 PM, Jarkko Sakkinen wrote:
>> On Wed, Sep 28, 2016 at 04:34:37AM -0400, Nayna Jain wrote:
>>> Currently, the securityfs pseudo files for obtaining the firmware
>>> event log are created whether the event log properties exist or not.
>>> This patch creates ascii and bios measurements pseudo files
>>> only if read_log() is successful.
>>
>> Re-reviewing this. The commit message should mention about preventing
>> a race condition.
>>
>> I think Jason was right. It makes code much more manageable with a
>> small price of memory consumption.
>>
>>> Suggested-by: Jason Gunthorpe <jguntho...@obsidianresearch.com>
>>> Signed-off-by: Nayna Jain <na...@linux.vnet.ibm.com>
>>> ---
>>>drivers/char/tpm/tpm.h  |  6 +
>>>drivers/char/tpm/tpm_acpi.c | 12 +++---
>>>drivers/char/tpm/tpm_eventlog.c | 53 
>>> +++--
>>>drivers/char/tpm/tpm_eventlog.h |  7 +-
>>>drivers/char/tpm/tpm_of.c   |  4 +++-
>>>5 files changed, 48 insertions(+), 34 deletions(-)
>>>
>>> diff --git a/drivers/char/tpm/tpm.h b/drivers/char/tpm/tpm.h
>>> index b5866bb..68630cd 100644
>>> --- a/drivers/char/tpm/tpm.h
>>> +++ b/drivers/char/tpm/tpm.h
>>> @@ -35,6 +35,8 @@
>>>#include 
>>>#include 
>>>
>>> +#include "tpm_eventlog.h"
>>> +
>>>enum tpm_const {
>>> TPM_MINOR = 224,/* officially assigned */
>>> TPM_BUFSIZE = 4096,
>>> @@ -156,6 +158,10 @@ struct tpm_chip {
>>> struct rw_semaphore ops_sem;
>>> const struct tpm_class_ops *ops;
>>>
>>> +   struct tpm_bios_log log;
>>
>> struct tpm_bios_log should be renamed as struct tpm_event_log in some
>> commit of this patch set as tpm_bios_log is a misleading name.
>
> My understanding is that other event log functions are also named in
> consistent with tpm_bios_log naming.. for eg..
> tpm_bios_log_setup(/teardown), tpm_bios_measurements_open,etc. So,
> wanted to understand if idea is only to change the struct name to
> tpm_event_log ?
>
> Thanks & Regards,
> - Nayna

I have not modified the tpm_bios_log naming in my new patch set for the 
above reason. But if we think that it is appropriate to change the data 
type (and functions ?) naming, I will post it as separate single patch.

Thanks & Regards,
- Nayna

>
>>
>>> +   struct tpm_securityfs_data bin_sfs_data;
>>> +   struct tpm_securityfs_data ascii_sfs_data;
>>
>> I think this is otherwise right but the struct name is very clunky.
>> First of all it doesn't own the data and IMHO now it kind of implies
>> of owning.
>>
>> Maybe something like tpm_event_log_fd would a better name. It's a
>> description of the event log file essentially.
>>
>>> +
>>> unsigned int flags;
>>>
>>> int dev_num;/* /dev/tpm# */
>>> diff --git a/drivers/char/tpm/tpm_acpi.c b/drivers/char/tpm/tpm_acpi.c
>>> index 565a947..4d6c2d7 100644
>>> --- a/drivers/char/tpm/tpm_acpi.c
>>> +++ b/drivers/char/tpm/tpm_acpi.c
>>> @@ -45,13 +45,15 @@ struct acpi_tcpa {
>>>};
>>>
>>>/* read binary bios log */
>>> -int read_log(struct tpm_bios_log *log)
>>> +int read_log(struct tpm_chip *chip)
>>>{
>>> struct acpi_tcpa *buff;
>>> acpi_status status;
>>> void __iomem *virt;
>>> u64 len, start;
>>> +   struct tpm_bios_log *log;
>>>
>>> +   log = >log;
>>> if (log->bios_event_log != NULL) {
>>> printk(KERN_ERR
>>>"%s: ERROR - Eventlog already initialized\n",
>>> @@ -97,13 +99,17 @@ int read_log(struct tpm_bios_log *log)
>>>
>>> virt = acpi_os_map_iomem(start, len);
>>> if (!virt) {
>>> -   kfree(log->bios_event_log);
>>> printk("%s: ERROR - Unable to map memory\n", __func__);
>>> -   return -EIO;
>>> +   goto err;
>>> }
>>>
>>> memcpy_fromio(log->bios_event_log, virt, len);
>>>
>>> acpi_os_unmap_iomem(virt, len);
>>> return 0;
>>> +
>>> +err:
>>> +   kfree(log->bios_event_log);
>>> +   return -EIO;
>>> +
>>>}
>>> diff --git a/d

[tpmdd-devel] [PATCH v5 5/7] tpm: redefine read_log() to handle ACPI/OF at runtime

2016-10-18 Thread Nayna Jain
Currently, read_log() has two implementations: one for ACPI platforms
and the other for device tree(OF) based platforms. The proper one is
selected at compile time using Kconfig and #ifdef in the Makefile,
which is not the recommended approach.

This patch removes the #ifdef in the Makefile by defining a single
read_log() method, which checks for ACPI/OF event log properties at
runtime.

Suggested-by: Jason Gunthorpe <jguntho...@obsidianresearch.com>
Signed-off-by: Nayna Jain <na...@linux.vnet.ibm.com>
Reviewed-by: Jason Gunthorpe <jguntho...@obsidianresearch.com>
---
 drivers/char/tpm/Makefile   | 14 --
 drivers/char/tpm/tpm_acpi.c |  9 ++---
 drivers/char/tpm/tpm_eventlog.c | 18 ++
 drivers/char/tpm/tpm_eventlog.h | 22 +-
 drivers/char/tpm/tpm_of.c   |  8 ++--
 5 files changed, 39 insertions(+), 32 deletions(-)

diff --git a/drivers/char/tpm/Makefile b/drivers/char/tpm/Makefile
index a385fb8..a05b1eb 100644
--- a/drivers/char/tpm/Makefile
+++ b/drivers/char/tpm/Makefile
@@ -2,16 +2,10 @@
 # Makefile for the kernel tpm device drivers.
 #
 obj-$(CONFIG_TCG_TPM) += tpm.o
-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
-else
-ifdef CONFIG_TCG_IBMVTPM
-   tpm-y += tpm_eventlog.o tpm_of.o
-endif
-endif
+tpm-y := tpm-interface.o tpm-dev.o tpm-sysfs.o tpm-chip.o tpm2-cmd.o \
+   tpm_eventlog.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
 obj-$(CONFIG_TCG_TIS) += tpm_tis.o
 obj-$(CONFIG_TCG_TIS_SPI) += tpm_tis_spi.o
diff --git a/drivers/char/tpm/tpm_acpi.c b/drivers/char/tpm/tpm_acpi.c
index 4d6c2d7..859bdba 100644
--- a/drivers/char/tpm/tpm_acpi.c
+++ b/drivers/char/tpm/tpm_acpi.c
@@ -6,6 +6,7 @@
  * Stefan Berger <stef...@us.ibm.com>
  * Reiner Sailer <sai...@watson.ibm.com>
  * Kylene Hall <kjh...@us.ibm.com>
+ * Nayna Jain <na...@linux.vnet.ibm.com>
  *
  * Maintained by: <tpmdd-devel@lists.sourceforge.net>
  *
@@ -45,7 +46,7 @@ struct acpi_tcpa {
 };
 
 /* read binary bios log */
-int read_log(struct tpm_chip *chip)
+int read_log_acpi(struct tpm_chip *chip)
 {
struct acpi_tcpa *buff;
acpi_status status;
@@ -54,12 +55,6 @@ int read_log(struct tpm_chip *chip)
struct tpm_bios_log *log;
 
log = >log;
-   if (log->bios_event_log != NULL) {
-   printk(KERN_ERR
-  "%s: ERROR - Eventlog already initialized\n",
-  __func__);
-   return -EFAULT;
-   }
 
/* Find TCPA entry in RSDT (ACPI_LOGICAL_ADDRESSING) */
status = acpi_get_table(ACPI_SIG_TCPA, 1,
diff --git a/drivers/char/tpm/tpm_eventlog.c b/drivers/char/tpm/tpm_eventlog.c
index bb142f2..b60c028 100644
--- a/drivers/char/tpm/tpm_eventlog.c
+++ b/drivers/char/tpm/tpm_eventlog.c
@@ -365,6 +365,24 @@ static int is_bad(void *p)
return 0;
 }
 
+int read_log(struct tpm_chip *chip)
+{
+   int rc;
+
+   if (chip->log.bios_event_log != NULL) {
+   dev_dbg(>dev, "%s: ERROR - Eventlog already 
initialized\n",
+   __func__);
+   return -EFAULT;
+   }
+
+   rc = read_log_acpi(chip);
+   if ((rc == 0) || (rc == -ENOMEM))
+   return rc;
+   rc = read_log_of(chip);
+   return rc;
+
+}
+
 int tpm_bios_log_setup(struct tpm_chip *chip)
 {
const char *name = dev_name(>dev);
diff --git a/drivers/char/tpm/tpm_eventlog.h b/drivers/char/tpm/tpm_eventlog.h
index 6df2f8e..be529ad 100644
--- a/drivers/char/tpm/tpm_eventlog.h
+++ b/drivers/char/tpm/tpm_eventlog.h
@@ -73,20 +73,24 @@ enum tcpa_pc_event_ids {
HOST_TABLE_OF_DEVICES,
 };
 
-int read_log(struct tpm_chip *chip);
-
-#if defined(CONFIG_TCG_IBMVTPM) || defined(CONFIG_TCG_IBMVTPM_MODULE) || \
-   defined(CONFIG_ACPI)
-extern int tpm_bios_log_setup(struct tpm_chip *chip);
-extern void tpm_bios_log_teardown(struct tpm_chip *chip);
+#if defined(CONFIG_ACPI)
+int read_log_acpi(struct tpm_chip *chip);
 #else
-static inline int tpm_bios_log_setup(struct tpm_chip *chip)
+static inline int read_log_acpi(struct tpm_chip *chip)
 {
-   return 0;
+   return -ENODEV;
 }
-static inline void tpm_bios_log_teardown(struct tpm_chip *chip)
+#endif
+#if defined(CONFIG_OF)
+int read_log_of(struct tpm_chip *chip);
+#else
+static inline int read_log_of(struct tpm_chip *chip)
 {
+   return -ENODEV;
 }
 #endif
 
+int tpm_bios_log_setup(struct tpm_chip *chip);
+void tpm_bios_log_teardown(struct tpm_chip *chip);
+
 #endif
diff --git a/drivers/char/tpm/tpm_of.c b/drivers/char/tpm/tpm_of.c
index 68d891a..7c30752 100644
--- a/drivers/char/tpm/tpm_of.c
+++ b/drivers/char/tpm/tpm_of.c
@@ -2,6 +2,7 @@
  * Copyright 2012 IBM Corporation
  *
  * Author:

[tpmdd-devel] [PATCH v5 1/7] tpm: define a generic open() method for ascii & bios measurements

2016-10-18 Thread Nayna Jain
open() method for event log ascii and binary bios measurements file
operations are very similar. This patch refactors the code into a
single open() call by passing seq_operations as i_node->private data.

Suggested-by: Jason Gunthorpe <jguntho...@obsidianresearch.com>
Signed-off-by: Nayna Jain <na...@linux.vnet.ibm.com>
Reviewed-by: Jarkko Sakkinen <jarkko.sakki...@linux.intel.com>
Reviewed-by: Jason Gunthorpe <jguntho...@obsidianresearch.com>
Tested-by: Jarkko Sakkinen <jarkko.sakki...@linux.intel.com>
---
 drivers/char/tpm/tpm_eventlog.c | 59 +
 1 file changed, 13 insertions(+), 46 deletions(-)

diff --git a/drivers/char/tpm/tpm_eventlog.c b/drivers/char/tpm/tpm_eventlog.c
index e722886..75e6644 100644
--- a/drivers/char/tpm/tpm_eventlog.c
+++ b/drivers/char/tpm/tpm_eventlog.c
@@ -7,6 +7,7 @@
  * Stefan Berger <stef...@us.ibm.com>
  * Reiner Sailer <sai...@watson.ibm.com>
  * Kylene Hall <kjh...@us.ibm.com>
+ * Nayna Jain <na...@linux.vnet.ibm.com>
  *
  * Maintained by: <tpmdd-devel@lists.sourceforge.net>
  *
@@ -318,12 +319,14 @@ static const struct seq_operations 
tpm_binary_b_measurments_seqops = {
.show = tpm_binary_bios_measurements_show,
 };
 
-static int tpm_ascii_bios_measurements_open(struct inode *inode,
+static int tpm_bios_measurements_open(struct inode *inode,
struct file *file)
 {
int err;
struct tpm_bios_log *log;
struct seq_file *seq;
+   const struct seq_operations *seqops =
+   (const struct seq_operations *)inode->i_private;
 
log = kzalloc(sizeof(struct tpm_bios_log), GFP_KERNEL);
if (!log)
@@ -333,7 +336,7 @@ static int tpm_ascii_bios_measurements_open(struct inode 
*inode,
goto out_free;
 
/* now register seq file */
-   err = seq_open(file, _ascii_b_measurments_seqops);
+   err = seq_open(file, seqops);
if (!err) {
seq = file->private_data;
seq->private = log;
@@ -349,46 +352,8 @@ out_free:
goto out;
 }
 
-static const struct file_operations tpm_ascii_bios_measurements_ops = {
-   .open = tpm_ascii_bios_measurements_open,
-   .read = seq_read,
-   .llseek = seq_lseek,
-   .release = tpm_bios_measurements_release,
-};
-
-static int tpm_binary_bios_measurements_open(struct inode *inode,
-struct file *file)
-{
-   int err;
-   struct tpm_bios_log *log;
-   struct seq_file *seq;
-
-   log = kzalloc(sizeof(struct tpm_bios_log), GFP_KERNEL);
-   if (!log)
-   return -ENOMEM;
-
-   if ((err = read_log(log)))
-   goto out_free;
-
-   /* now register seq file */
-   err = seq_open(file, _binary_b_measurments_seqops);
-   if (!err) {
-   seq = file->private_data;
-   seq->private = log;
-   } else {
-   goto out_free;
-   }
-
-out:
-   return err;
-out_free:
-   kfree(log->bios_event_log);
-   kfree(log);
-   goto out;
-}
-
-static const struct file_operations tpm_binary_bios_measurements_ops = {
-   .open = tpm_binary_bios_measurements_open,
+static const struct file_operations tpm_bios_measurements_ops = {
+   .open = tpm_bios_measurements_open,
.read = seq_read,
.llseek = seq_lseek,
.release = tpm_bios_measurements_release,
@@ -413,15 +378,17 @@ struct dentry **tpm_bios_log_setup(const char *name)
 
bin_file =
securityfs_create_file("binary_bios_measurements",
-  S_IRUSR | S_IRGRP, tpm_dir, NULL,
-  _binary_bios_measurements_ops);
+  S_IRUSR | S_IRGRP, tpm_dir,
+  (void *)_binary_b_measurments_seqops,
+  _bios_measurements_ops);
if (is_bad(bin_file))
goto out_tpm;
 
ascii_file =
securityfs_create_file("ascii_bios_measurements",
-  S_IRUSR | S_IRGRP, tpm_dir, NULL,
-  _ascii_bios_measurements_ops);
+  S_IRUSR | S_IRGRP, tpm_dir,
+  (void *)_ascii_b_measurments_seqops,
+  _bios_measurements_ops);
if (is_bad(ascii_file))
goto out_bin;
 
-- 
2.5.0


--
Check out the vibrant tech community on one of the world's most 
engaging tech sites, SlashDot.org! http://sdm.link/slashdot
___
tpmdd-devel mailing list
tpmdd-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/tpmdd-devel


  1   2   >