linux-integrity.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v2 0/2] tpm/eventlog/tpm1: Small fixes
@ 2019-01-11  8:59 Jia Zhang
  2019-01-11  8:59 ` [PATCH 1/2] tpm/eventlog/tpm1: Simplify walking over *pos measurements Jia Zhang
  2019-01-11  8:59 ` [PATCH 2/2] tpm/eventlog/tpm1: Fix off-by-1 when reading binary_bios_measurements Jia Zhang
  0 siblings, 2 replies; 11+ messages in thread
From: Jia Zhang @ 2019-01-11  8:59 UTC (permalink / raw)
  To: jarkko.sakkinen, peterhuewe, jgg, tweek
  Cc: linux-integrity, linux-kernel, zhang.jia

Change since V1:

- Add test results with LTP.
- Rewrite patch 1's commit header.

Here is the test result with LTP testcase ima_tpm.sh which is used
to verify binary_bios_measurements.

ima_tpm 1 TINFO: timeout per run is 0h 5m 0s
ima_tpm 1 TINFO: /proc/cmdline: BOOT_IMAGE=/boot/vmlinuz-5.0.0-rc1+ root=UUID=c665e92c-736d-4b08-9143-a57396f935f3 ro rootwait crashkernel=auto console=tty0 console=ttyS0,115200 reboot=efi ima_hash=sha1
ima_tpm 1 TINFO: verify boot aggregate
ima_tpm 1 TPASS: bios aggregate matches IMA boot aggregate
ima_tpm 2 TINFO: verify PCR values
ima_tpm 2 TINFO: evmctl version: evmctl 1.1
ima_tpm 2 TCONF: TPM Hardware Support not enabled in kernel or no TPM chip found

Summary:
passed   1
failed   0   
skipped  1   
warnings 0

Note:
The 2nd test in ima_tpm requires /sys/class/tpm/tpm0/device/pcrs but this
interface is not available if TPM2 device used. So the test result showed
above is expected.

Jia

^ permalink raw reply	[flat|nested] 11+ messages in thread
* [PATCH 1/2] tpm/eventlog/tpm1: Simplify walking over *pos measurements
@ 2019-01-06  7:23 Jia Zhang
  2019-01-10 17:32 ` Jarkko Sakkinen
  0 siblings, 1 reply; 11+ messages in thread
From: Jia Zhang @ 2019-01-06  7:23 UTC (permalink / raw)
  To: jarkko.sakkinen, peterhuewe, jgg, tweek
  Cc: linux-integrity, linux-kernel, zhang.jia

The sanity check would be easier, especially for the first read
of binary_bios_measurements from the beginning.

Signed-off-by: Jia Zhang <zhang.jia@linux.alibaba.com>
---
 drivers/char/tpm/eventlog/tpm1.c | 37 ++++++++++++++-----------------------
 1 file changed, 14 insertions(+), 23 deletions(-)

diff --git a/drivers/char/tpm/eventlog/tpm1.c b/drivers/char/tpm/eventlog/tpm1.c
index 58c8478..4cf8303 100644
--- a/drivers/char/tpm/eventlog/tpm1.c
+++ b/drivers/char/tpm/eventlog/tpm1.c
@@ -74,7 +74,7 @@
 /* returns pointer to start of pos. entry of tcg log */
 static void *tpm1_bios_measurements_start(struct seq_file *m, loff_t *pos)
 {
-	loff_t i;
+	loff_t i = 0;
 	struct tpm_chip *chip = m->private;
 	struct tpm_bios_log *log = &chip->log;
 	void *addr = log->bios_event_log;
@@ -83,38 +83,29 @@ static void *tpm1_bios_measurements_start(struct seq_file *m, loff_t *pos)
 	u32 converted_event_size;
 	u32 converted_event_type;
 
-
 	/* read over *pos measurements */
-	for (i = 0; i < *pos; i++) {
+	do {
 		event = addr;
 
+		/* check if current entry is valid */
+		if (addr + sizeof(struct tcpa_event) >= limit)
+			return NULL;
+
 		converted_event_size =
 		    do_endian_conversion(event->event_size);
 		converted_event_type =
 		    do_endian_conversion(event->event_type);
 
-		if ((addr + sizeof(struct tcpa_event)) < limit) {
-			if ((converted_event_type == 0) &&
-			    (converted_event_size == 0))
-				return NULL;
-			addr += (sizeof(struct tcpa_event) +
-				 converted_event_size);
-		}
-	}
-
-	/* now check if current entry is valid */
-	if ((addr + sizeof(struct tcpa_event)) >= limit)
-		return NULL;
-
-	event = addr;
+		if (((converted_event_type == 0) && (converted_event_size == 0))
+		    || ((addr + sizeof(struct tcpa_event) + converted_event_size)
+			>= limit))
+			return NULL;
 
-	converted_event_size = do_endian_conversion(event->event_size);
-	converted_event_type = do_endian_conversion(event->event_type);
+		if (i++ == *pos)
+			break;
 
-	if (((converted_event_type == 0) && (converted_event_size == 0))
-	    || ((addr + sizeof(struct tcpa_event) + converted_event_size)
-		>= limit))
-		return NULL;
+		addr += (sizeof(struct tcpa_event) + converted_event_size);
+	} while (1);
 
 	return addr;
 }
-- 
1.8.3.1


^ permalink raw reply related	[flat|nested] 11+ messages in thread

end of thread, other threads:[~2019-01-19  7:48 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-01-11  8:59 [PATCH v2 0/2] tpm/eventlog/tpm1: Small fixes Jia Zhang
2019-01-11  8:59 ` [PATCH 1/2] tpm/eventlog/tpm1: Simplify walking over *pos measurements Jia Zhang
2019-01-16 22:09   ` Jarkko Sakkinen
2019-01-17  1:32     ` Jia Zhang
2019-01-18 15:18       ` Jarkko Sakkinen
2019-01-19  7:48         ` Jia Zhang
2019-01-11  8:59 ` [PATCH 2/2] tpm/eventlog/tpm1: Fix off-by-1 when reading binary_bios_measurements Jia Zhang
2019-01-16 22:17   ` Jarkko Sakkinen
  -- strict thread matches above, loose matches on Subject: below --
2019-01-06  7:23 [PATCH 1/2] tpm/eventlog/tpm1: Simplify walking over *pos measurements Jia Zhang
2019-01-10 17:32 ` Jarkko Sakkinen
2019-01-11  8:29   ` Jia Zhang

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).