]> git.ipfire.org Git - thirdparty/kernel/stable-queue.git/blame - releases/2.6.36.4/tpm_tis-use-timeouts-returned-from-tpm.patch
5.1-stable patches
[thirdparty/kernel/stable-queue.git] / releases / 2.6.36.4 / tpm_tis-use-timeouts-returned-from-tpm.patch
CommitLineData
21bbe2c0
GKH
1From 9b29050f8f75916f974a2d231ae5d3cd59792296 Mon Sep 17 00:00:00 2001
2From: Stefan Berger <stefanb@linux.vnet.ibm.com>
3Date: Tue, 11 Jan 2011 14:37:29 -0500
4Subject: tpm_tis: Use timeouts returned from TPM
5
6From: Stefan Berger <stefanb@linux.vnet.ibm.com>
7
8commit 9b29050f8f75916f974a2d231ae5d3cd59792296 upstream.
9
10The current TPM TIS driver in git discards the timeout values returned
11from the TPM. The check of the response packet needs to consider that
12the return_code field is 0 on success and the size of the expected
13packet is equivalent to the header size + u32 length indicator for the
14TPM_GetCapability() result + 3 timeout indicators of type u32.
15
16I am also adding a sysfs entry 'timeouts' showing the timeouts that are
17being used.
18
19Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
20Tested-by: Guillaume Chazarain <guichaz@gmail.com>
21Signed-off-by: Rajiv Andrade <srajiv@linux.vnet.ibm.com>
22Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
23
24---
25 drivers/char/tpm/tpm.c | 18 ++++++++++++++++--
26 drivers/char/tpm/tpm.h | 2 ++
27 drivers/char/tpm/tpm_tis.c | 4 +++-
28 3 files changed, 21 insertions(+), 3 deletions(-)
29
30--- a/drivers/char/tpm/tpm.c
31+++ b/drivers/char/tpm/tpm.c
32@@ -567,9 +567,11 @@ duration:
33 if (rc)
34 return;
35
36- if (be32_to_cpu(tpm_cmd.header.out.return_code)
37- != 3 * sizeof(u32))
38+ if (be32_to_cpu(tpm_cmd.header.out.return_code) != 0 ||
39+ be32_to_cpu(tpm_cmd.header.out.length)
40+ != sizeof(tpm_cmd.header.out) + sizeof(u32) + 3 * sizeof(u32))
41 return;
42+
43 duration_cap = &tpm_cmd.params.getcap_out.cap.duration;
44 chip->vendor.duration[TPM_SHORT] =
45 usecs_to_jiffies(be32_to_cpu(duration_cap->tpm_short));
46@@ -913,6 +915,18 @@ ssize_t tpm_show_caps_1_2(struct device
47 }
48 EXPORT_SYMBOL_GPL(tpm_show_caps_1_2);
49
50+ssize_t tpm_show_timeouts(struct device *dev, struct device_attribute *attr,
51+ char *buf)
52+{
53+ struct tpm_chip *chip = dev_get_drvdata(dev);
54+
55+ return sprintf(buf, "%d %d %d\n",
56+ jiffies_to_usecs(chip->vendor.duration[TPM_SHORT]),
57+ jiffies_to_usecs(chip->vendor.duration[TPM_MEDIUM]),
58+ jiffies_to_usecs(chip->vendor.duration[TPM_LONG]));
59+}
60+EXPORT_SYMBOL_GPL(tpm_show_timeouts);
61+
62 ssize_t tpm_store_cancel(struct device *dev, struct device_attribute *attr,
63 const char *buf, size_t count)
64 {
65--- a/drivers/char/tpm/tpm.h
66+++ b/drivers/char/tpm/tpm.h
67@@ -56,6 +56,8 @@ extern ssize_t tpm_show_owned(struct dev
68 char *);
69 extern ssize_t tpm_show_temp_deactivated(struct device *,
70 struct device_attribute *attr, char *);
71+extern ssize_t tpm_show_timeouts(struct device *,
72+ struct device_attribute *attr, char *);
73
74 struct tpm_chip;
75
76--- a/drivers/char/tpm/tpm_tis.c
77+++ b/drivers/char/tpm/tpm_tis.c
78@@ -355,6 +355,7 @@ static DEVICE_ATTR(temp_deactivated, S_I
79 NULL);
80 static DEVICE_ATTR(caps, S_IRUGO, tpm_show_caps_1_2, NULL);
81 static DEVICE_ATTR(cancel, S_IWUSR | S_IWGRP, NULL, tpm_store_cancel);
82+static DEVICE_ATTR(timeouts, S_IRUGO, tpm_show_timeouts, NULL);
83
84 static struct attribute *tis_attrs[] = {
85 &dev_attr_pubek.attr,
86@@ -364,7 +365,8 @@ static struct attribute *tis_attrs[] = {
87 &dev_attr_owned.attr,
88 &dev_attr_temp_deactivated.attr,
89 &dev_attr_caps.attr,
90- &dev_attr_cancel.attr, NULL,
91+ &dev_attr_cancel.attr,
92+ &dev_attr_timeouts.attr, NULL,
93 };
94
95 static struct attribute_group tis_attr_grp = {