From: Peter Huewe <peterhuewe@gmx.de>
To: Kent Yoder <key@linux.vnet.ibm.com>
Cc: Marcel Selhorst <tpmdd@selhorst.net>,
Sirrix AG <tpmdd@sirrix.com>,
tpmdd-devel@lists.sourceforge.net, linux-kernel@vger.kernel.org,
Peter Huewe <peterhuewe@gmx.de>
Subject: [PATCH 2/2] char/tpm: simplify duration calculation and eliminate sparse warning.
Date: Mon, 12 Nov 2012 23:37:18 +0100 [thread overview]
Message-ID: <1352759838-27175-2-git-send-email-peterhuewe@gmx.de> (raw)
In-Reply-To: <1352759838-27175-1-git-send-email-peterhuewe@gmx.de>
This patch changes the semantics of the duration calculation for an
ordinal, by masking out the higher bits of a tpm command, which specify
whether it's an TPM_PROTECTED_COMMAND, TPM_UNPROTECTED_COMMAND,
TPM_CONNECTION_COMMAND, TPM_CONNECTION_COMMAND, TPM_VENDOR_COMMAND.
(See TPM Main Spec Part 2 Section 17 for details).
For all TPM_PROTECTED and TPM_CONNECTION commands the results are
unchanged.
The TPM_UNPROTECTED commands are TSS commands and thus irrelevant as
they are not sent to the tpm.
For vendor commands the semantics change for ordinals 10 and 11 but
they were probably wrong anyway.
For everything else which has the ordinal set to 10 or 11 the semantics
change as it now uses TPM_UNDEFINED instead of TPM_SHORT which was
probably wrong anyway (but irrelevant as not defined by the standard).
This patch also gets rid of the (false positive) sparse warning:
drivers/char/tpm/tpm.c:360 tpm_calc_ordinal_duration() error: buffer
overflow 'tpm_protected_ordinal_duration' 12 <= 243
Signed-off-by: Peter Huewe <peterhuewe@gmx.de>
---
drivers/char/tpm/tpm.c | 13 ++++++-------
1 files changed, 6 insertions(+), 7 deletions(-)
diff --git a/drivers/char/tpm/tpm.c b/drivers/char/tpm/tpm.c
index 9e3c529..a455d11 100644
--- a/drivers/char/tpm/tpm.c
+++ b/drivers/char/tpm/tpm.c
@@ -40,8 +40,9 @@ enum tpm_duration {
};
#define TPM_MAX_ORDINAL 243
-#define TPM_MAX_PROTECTED_ORDINAL 12
-#define TPM_PROTECTED_ORDINAL_MASK 0xFF
+#define TCS_MAX_ORDINAL 12
+#define TPM_PROTECTED_COMMAND 0x00
+#define TPM_CONNECTION_COMMAND 0x40
/*
* Bug workaround - some TPM's don't flush the most
@@ -336,13 +337,11 @@ unsigned long tpm_calc_ordinal_duration(struct tpm_chip *chip,
{
int duration_idx = TPM_UNDEFINED;
int duration = 0;
+ u8 category = (ordinal >> 24) & 0xFF;
- if (ordinal < TPM_MAX_ORDINAL)
+ if ((category == TPM_PROTECTED_COMMAND && ordinal < TPM_MAX_ORDINAL) ||
+ (category == TPM_CONNECTION_COMMAND && ordinal < TCS_MAX_ORDINAL))
duration_idx = tpm_ordinal_duration[ordinal];
- else if ((ordinal & TPM_PROTECTED_ORDINAL_MASK) <
- TPM_MAX_PROTECTED_ORDINAL)
- duration_idx =
- tpm_ordinal_duration[ordinal & TPM_PROTECTED_ORDINAL_MASK];
if (duration_idx != TPM_UNDEFINED)
duration = chip->vendor.duration[duration_idx];
--
1.7.8.6
next prev parent reply other threads:[~2012-11-12 22:29 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2012-11-12 22:37 [PATCH 1/2] char/tpm: Remove duplicated lookup table Peter Huewe
2012-11-12 22:37 ` Peter Huewe [this message]
2012-11-14 22:18 ` [PATCH 2/2] char/tpm: simplify duration calculation and eliminate sparse warning Kent Yoder
2012-11-14 22:37 ` Peter Hüwe
2012-11-15 16:42 ` Kent Yoder
[not found] ` <fa7287de-06dd-40b4-9d9a-56fcc8a5f670@email.android.com>
2012-11-15 21:53 ` Kent Yoder
2012-11-15 23:31 ` [PATCH v2] char/tpm: simplify duration calculation and eliminate smatch warning Peter Huewe
2012-11-16 17:33 ` Kent Yoder
2012-11-14 22:17 ` [PATCH 1/2] char/tpm: Remove duplicated lookup table Kent Yoder
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1352759838-27175-2-git-send-email-peterhuewe@gmx.de \
--to=peterhuewe@gmx.de \
--cc=key@linux.vnet.ibm.com \
--cc=linux-kernel@vger.kernel.org \
--cc=tpmdd-devel@lists.sourceforge.net \
--cc=tpmdd@selhorst.net \
--cc=tpmdd@sirrix.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®