Skip to content

Commit b192391

Browse files
committed
Merge tag 'tpmdd-next-6.10-rc1' of git://git.kernel.org/pub/scm/linux/kernel/git/jarkko/linux-tpmdd
Pull TPM updates from Jarkko Sakkinen: "These are the changes for the TPM driver with a single major new feature: TPM bus encryption and integrity protection. The key pair on TPM side is generated from so called null random seed per power on of the machine [1]. This supports the TPM encryption of the hard drive by adding layer of protection against bus interposer attacks. Other than that, a few minor fixes and documentation for tpm_tis to clarify basics of TPM localities for future patch review discussions (will be extended and refined over times, just a seed)" Link: https://lore.kernel.org/linux-integrity/[email protected]/ [1] * tag 'tpmdd-next-6.10-rc1' of git://git.kernel.org/pub/scm/linux/kernel/git/jarkko/linux-tpmdd: (28 commits) Documentation: tpm: Add TPM security docs toctree entry tpm: disable the TPM if NULL name changes Documentation: add tpm-security.rst tpm: add the null key name as a sysfs export KEYS: trusted: Add session encryption protection to the seal/unseal path tpm: add session encryption protection to tpm2_get_random() tpm: add hmac checks to tpm2_pcr_extend() tpm: Add the rest of the session HMAC API tpm: Add HMAC session name/handle append tpm: Add HMAC session start and end functions tpm: Add TCG mandated Key Derivation Functions (KDFs) tpm: Add NULL primary creation tpm: export the context save and load commands tpm: add buffer function to point to returned parameters crypto: lib - implement library version of AES in CFB mode KEYS: trusted: tpm2: Use struct tpm_buf for sized buffers tpm: Add tpm_buf_read_{u8,u16,u32} tpm: TPM2B formatted buffers tpm: Store the length of the tpm_buf data separately. tpm: Update struct tpm_buf documentation comments ...
2 parents c024814 + 1d479e3 commit b192391

File tree

25 files changed

+2519
-212
lines changed

25 files changed

+2519
-212
lines changed

Diff for: Documentation/devicetree/bindings/tpm/tcg,tpm-tis-i2c.yaml

+1
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ properties:
3232
- enum:
3333
- infineon,slb9673
3434
- nuvoton,npct75x
35+
- st,st33ktpm2xi2c
3536
- const: tcg,tpm-tis-i2c
3637

3738
- description: TPM 1.2 and 2.0 chips with vendor-specific I²C interface

Diff for: Documentation/security/tpm/index.rst

+2
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ Trusted Platform Module documentation
55
.. toctree::
66

77
tpm_event_log
8+
tpm-security
9+
tpm_tis
810
tpm_vtpm_proxy
911
xen-tpmfront
1012
tpm_ftpm_tee

Diff for: Documentation/security/tpm/tpm-security.rst

+216
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,216 @@
1+
.. SPDX-License-Identifier: GPL-2.0-only
2+
3+
TPM Security
4+
============
5+
6+
The object of this document is to describe how we make the kernel's
7+
use of the TPM reasonably robust in the face of external snooping and
8+
packet alteration attacks (called passive and active interposer attack
9+
in the literature). The current security document is for TPM 2.0.
10+
11+
Introduction
12+
------------
13+
14+
The TPM is usually a discrete chip attached to a PC via some type of
15+
low bandwidth bus. There are exceptions to this such as the Intel
16+
PTT, which is a software TPM running inside a software environment
17+
close to the CPU, which are subject to different attacks, but right at
18+
the moment, most hardened security environments require a discrete
19+
hardware TPM, which is the use case discussed here.
20+
21+
Snooping and Alteration Attacks against the bus
22+
-----------------------------------------------
23+
24+
The current state of the art for snooping the `TPM Genie`_ hardware
25+
interposer which is a simple external device that can be installed in
26+
a couple of seconds on any system or laptop. Recently attacks were
27+
successfully demonstrated against the `Windows Bitlocker TPM`_ system.
28+
Most recently the same `attack against TPM based Linux disk
29+
encryption`_ schemes. The next phase of research seems to be hacking
30+
existing devices on the bus to act as interposers, so the fact that
31+
the attacker requires physical access for a few seconds might
32+
evaporate. However, the goal of this document is to protect TPM
33+
secrets and integrity as far as we are able in this environment and to
34+
try to insure that if we can't prevent the attack then at least we can
35+
detect it.
36+
37+
Unfortunately, most of the TPM functionality, including the hardware
38+
reset capability can be controlled by an attacker who has access to
39+
the bus, so we'll discuss some of the disruption possibilities below.
40+
41+
Measurement (PCR) Integrity
42+
---------------------------
43+
44+
Since the attacker can send their own commands to the TPM, they can
45+
send arbitrary PCR extends and thus disrupt the measurement system,
46+
which would be an annoying denial of service attack. However, there
47+
are two, more serious, classes of attack aimed at entities sealed to
48+
trust measurements.
49+
50+
1. The attacker could intercept all PCR extends coming from the system
51+
and completely substitute their own values, producing a replay of
52+
an untampered state that would cause PCR measurements to attest to
53+
a trusted state and release secrets
54+
55+
2. At some point in time the attacker could reset the TPM, clearing
56+
the PCRs and then send down their own measurements which would
57+
effectively overwrite the boot time measurements the TPM has
58+
already done.
59+
60+
The first can be thwarted by always doing HMAC protection of the PCR
61+
extend and read command meaning measurement values cannot be
62+
substituted without producing a detectable HMAC failure in the
63+
response. However, the second can only really be detected by relying
64+
on some sort of mechanism for protection which would change over TPM
65+
reset.
66+
67+
Secrets Guarding
68+
----------------
69+
70+
Certain information passing in and out of the TPM, such as key sealing
71+
and private key import and random number generation, is vulnerable to
72+
interception which HMAC protection alone cannot protect against, so
73+
for these types of command we must also employ request and response
74+
encryption to prevent the loss of secret information.
75+
76+
Establishing Initial Trust with the TPM
77+
---------------------------------------
78+
79+
In order to provide security from the beginning, an initial shared or
80+
asymmetric secret must be established which must also be unknown to
81+
the attacker. The most obvious avenues for this are the endorsement
82+
and storage seeds, which can be used to derive asymmetric keys.
83+
However, using these keys is difficult because the only way to pass
84+
them into the kernel would be on the command line, which requires
85+
extensive support in the boot system, and there's no guarantee that
86+
either hierarchy would not have some type of authorization.
87+
88+
The mechanism chosen for the Linux Kernel is to derive the primary
89+
elliptic curve key from the null seed using the standard storage seed
90+
parameters. The null seed has two advantages: firstly the hierarchy
91+
physically cannot have an authorization, so we are always able to use
92+
it and secondly, the null seed changes across TPM resets, meaning if
93+
we establish trust on the null seed at start of day, all sessions
94+
salted with the derived key will fail if the TPM is reset and the seed
95+
changes.
96+
97+
Obviously using the null seed without any other prior shared secrets,
98+
we have to create and read the initial public key which could, of
99+
course, be intercepted and substituted by the bus interposer.
100+
However, the TPM has a key certification mechanism (using the EK
101+
endorsement certificate, creating an attestation identity key and
102+
certifying the null seed primary with that key) which is too complex
103+
to run within the kernel, so we keep a copy of the null primary key
104+
name, which is what is exported via sysfs so user-space can run the
105+
full certification when it boots. The definitive guarantee here is
106+
that if the null primary key certifies correctly, you know all your
107+
TPM transactions since start of day were secure and if it doesn't, you
108+
know there's an interposer on your system (and that any secret used
109+
during boot may have been leaked).
110+
111+
Stacking Trust
112+
--------------
113+
114+
In the current null primary scenario, the TPM must be completely
115+
cleared before handing it on to the next consumer. However the kernel
116+
hands to user-space the name of the derived null seed key which can
117+
then be verified by certification in user-space. Therefore, this chain
118+
of name handoff can be used between the various boot components as
119+
well (via an unspecified mechanism). For instance, grub could use the
120+
null seed scheme for security and hand the name off to the kernel in
121+
the boot area. The kernel could make its own derivation of the key
122+
and the name and know definitively that if they differ from the handed
123+
off version that tampering has occurred. Thus it becomes possible to
124+
chain arbitrary boot components together (UEFI to grub to kernel) via
125+
the name handoff provided each successive component knows how to
126+
collect the name and verifies it against its derived key.
127+
128+
Session Properties
129+
------------------
130+
131+
All TPM commands the kernel uses allow sessions. HMAC sessions may be
132+
used to check the integrity of requests and responses and decrypt and
133+
encrypt flags may be used to shield parameters and responses. The
134+
HMAC and encryption keys are usually derived from the shared
135+
authorization secret, but for a lot of kernel operations that is well
136+
known (and usually empty). Thus, every HMAC session used by the
137+
kernel must be created using the null primary key as the salt key
138+
which thus provides a cryptographic input into the session key
139+
derivation. Thus, the kernel creates the null primary key once (as a
140+
volatile TPM handle) and keeps it around in a saved context stored in
141+
tpm_chip for every in-kernel use of the TPM. Currently, because of a
142+
lack of de-gapping in the in-kernel resource manager, the session must
143+
be created and destroyed for each operation, but, in future, a single
144+
session may also be reused for the in-kernel HMAC, encryption and
145+
decryption sessions.
146+
147+
Protection Types
148+
----------------
149+
150+
For every in-kernel operation we use null primary salted HMAC to
151+
protect the integrity. Additionally, we use parameter encryption to
152+
protect key sealing and parameter decryption to protect key unsealing
153+
and random number generation.
154+
155+
Null Primary Key Certification in Userspace
156+
===========================================
157+
158+
Every TPM comes shipped with a couple of X.509 certificates for the
159+
primary endorsement key. This document assumes that the Elliptic
160+
Curve version of the certificate exists at 01C00002, but will work
161+
equally well with the RSA certificate (at 01C00001).
162+
163+
The first step in the certification is primary creation using the
164+
template from the `TCG EK Credential Profile`_ which allows comparison
165+
of the generated primary key against the one in the certificate (the
166+
public key must match). Note that generation of the EK primary
167+
requires the EK hierarchy password, but a pre-generated version of the
168+
EC primary should exist at 81010002 and a TPM2_ReadPublic() may be
169+
performed on this without needing the key authority. Next, the
170+
certificate itself must be verified to chain back to the manufacturer
171+
root (which should be published on the manufacturer website). Once
172+
this is done, an attestation key (AK) is generated within the TPM and
173+
it's name and the EK public key can be used to encrypt a secret using
174+
TPM2_MakeCredential. The TPM then runs TPM2_ActivateCredential which
175+
will only recover the secret if the binding between the TPM, the EK
176+
and the AK is true. the generated AK may now be used to run a
177+
certification of the null primary key whose name the kernel has
178+
exported. Since TPM2_MakeCredential/ActivateCredential are somewhat
179+
complicated, a more simplified process involving an externally
180+
generated private key is described below.
181+
182+
This process is a simplified abbreviation of the usual privacy CA
183+
based attestation process. The assumption here is that the
184+
attestation is done by the TPM owner who thus has access to only the
185+
owner hierarchy. The owner creates an external public/private key
186+
pair (assume elliptic curve in this case) and wraps the private key
187+
for import using an inner wrapping process and parented to the EC
188+
derived storage primary. The TPM2_Import() is done using a parameter
189+
decryption HMAC session salted to the EK primary (which also does not
190+
require the EK key authority) meaning that the inner wrapping key is
191+
the encrypted parameter and thus the TPM will not be able to perform
192+
the import unless is possesses the certified EK so if the command
193+
succeeds and the HMAC verifies on return we know we have a loadable
194+
copy of the private key only for the certified TPM. This key is now
195+
loaded into the TPM and the Storage primary flushed (to free up space
196+
for the null key generation).
197+
198+
The null EC primary is now generated using the Storage profile
199+
outlined in the `TCG TPM v2.0 Provisioning Guidance`_; the name of
200+
this key (the hash of the public area) is computed and compared to the
201+
null seed name presented by the kernel in
202+
/sys/class/tpm/tpm0/null_name. If the names do not match, the TPM is
203+
compromised. If the names match, the user performs a TPM2_Certify()
204+
using the null primary as the object handle and the loaded private key
205+
as the sign handle and providing randomized qualifying data. The
206+
signature of the returned certifyInfo is verified against the public
207+
part of the loaded private key and the qualifying data checked to
208+
prevent replay. If all of these tests pass, the user is now assured
209+
that TPM integrity and privacy was preserved across the entire boot
210+
sequence of this kernel.
211+
212+
.. _TPM Genie: https://www.nccgroup.trust/globalassets/about-us/us/documents/tpm-genie.pdf
213+
.. _Windows Bitlocker TPM: https://dolosgroup.io/blog/2021/7/9/from-stolen-laptop-to-inside-the-company-network
214+
.. _attack against TPM based Linux disk encryption: https://www.secura.com/blog/tpm-sniffing-attacks-against-non-bitlocker-targets
215+
.. _TCG EK Credential Profile: https://trustedcomputinggroup.org/resource/tcg-ek-credential-profile-for-tpm-family-2-0/
216+
.. _TCG TPM v2.0 Provisioning Guidance: https://trustedcomputinggroup.org/resource/tcg-tpm-v2-0-provisioning-guidance/

Diff for: Documentation/security/tpm/tpm_tis.rst

+46
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
.. SPDX-License-Identifier: GPL-2.0
2+
3+
=========================
4+
TPM FIFO interface driver
5+
=========================
6+
7+
TCG PTP Specification defines two interface types: FIFO and CRB. The former is
8+
based on sequenced read and write operations, and the latter is based on a
9+
buffer containing the full command or response.
10+
11+
FIFO (First-In-First-Out) interface is used by the tpm_tis_core dependent
12+
drivers. Originally Linux had only a driver called tpm_tis, which covered
13+
memory mapped (aka MMIO) interface but it was later on extended to cover other
14+
physical interfaces supported by the TCG standard.
15+
16+
For historical reasons above the original MMIO driver is called tpm_tis and the
17+
framework for FIFO drivers is named as tpm_tis_core. The postfix "tis" in
18+
tpm_tis comes from the TPM Interface Specification, which is the hardware
19+
interface specification for TPM 1.x chips.
20+
21+
Communication is based on a 20 KiB buffer shared by the TPM chip through a
22+
hardware bus or memory map, depending on the physical wiring. The buffer is
23+
further split into five equal-size 4 KiB buffers, which provide equivalent
24+
sets of registers for communication between the CPU and TPM. These
25+
communication endpoints are called localities in the TCG terminology.
26+
27+
When the kernel wants to send commands to the TPM chip, it first reserves
28+
locality 0 by setting the requestUse bit in the TPM_ACCESS register. The bit is
29+
cleared by the chip when the access is granted. Once it completes its
30+
communication, the kernel writes the TPM_ACCESS.activeLocality bit. This
31+
informs the chip that the locality has been relinquished.
32+
33+
Pending localities are served in order by the chip in descending order, one at
34+
a time:
35+
36+
- Locality 0 has the lowest priority.
37+
- Locality 5 has the highest priority.
38+
39+
Further information on the purpose and meaning of the localities can be found
40+
in section 3.2 of the TCG PC Client Platform TPM Profile Specification.
41+
42+
References
43+
==========
44+
45+
TCG PC Client Platform TPM Profile (PTP) Specification
46+
https://trustedcomputinggroup.org/resource/pc-client-platform-tpm-profile-ptp-specification/

Diff for: drivers/char/tpm/Kconfig

+16-1
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,20 @@ menuconfig TCG_TPM
2727

2828
if TCG_TPM
2929

30+
config TCG_TPM2_HMAC
31+
bool "Use HMAC and encrypted transactions on the TPM bus"
32+
default y
33+
select CRYPTO_ECDH
34+
select CRYPTO_LIB_AESCFB
35+
select CRYPTO_LIB_SHA256
36+
help
37+
Setting this causes us to deploy a scheme which uses request
38+
and response HMACs in addition to encryption for
39+
communicating with the TPM to prevent or detect bus snooping
40+
and interposer attacks (see tpm-security.rst). Saying Y
41+
here adds some encryption overhead to all kernel to TPM
42+
transactions.
43+
3044
config HW_RANDOM_TPM
3145
bool "TPM HW Random Number Generator support"
3246
depends on TCG_TPM && HW_RANDOM && !(TCG_TPM=y && HW_RANDOM=m)
@@ -149,14 +163,15 @@ config TCG_NSC
149163
config TCG_ATMEL
150164
tristate "Atmel TPM Interface"
151165
depends on PPC64 || HAS_IOPORT_MAP
166+
depends on HAS_IOPORT
152167
help
153168
If you have a TPM security chip from Atmel say Yes and it
154169
will be accessible from within Linux. To compile this driver
155170
as a module, choose M here; the module will be called tpm_atmel.
156171

157172
config TCG_INFINEON
158173
tristate "Infineon Technologies TPM Interface"
159-
depends on PNP
174+
depends on PNP || COMPILE_TEST
160175
help
161176
If you have a TPM security chip from Infineon Technologies
162177
(either SLD 9630 TT 1.1 or SLB 9635 TT 1.2) say Yes and it

Diff for: drivers/char/tpm/Makefile

+2
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,9 @@ tpm-y += tpm-sysfs.o
1515
tpm-y += eventlog/common.o
1616
tpm-y += eventlog/tpm1.o
1717
tpm-y += eventlog/tpm2.o
18+
tpm-y += tpm-buf.o
1819

20+
tpm-$(CONFIG_TCG_TPM2_HMAC) += tpm2-sessions.o
1921
tpm-$(CONFIG_ACPI) += tpm_ppi.o eventlog/acpi.o
2022
tpm-$(CONFIG_EFI) += eventlog/efi.o
2123
tpm-$(CONFIG_OF) += eventlog/of.o

Diff for: drivers/char/tpm/eventlog/acpi.c

-1
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,6 @@ int tpm_read_log_acpi(struct tpm_chip *chip)
142142

143143
log->bios_event_log_end = log->bios_event_log + len;
144144

145-
ret = -EIO;
146145
virt = acpi_os_map_iomem(start, len);
147146
if (!virt) {
148147
dev_warn(&chip->dev, "%s: Failed to map ACPI memory\n", __func__);

0 commit comments

Comments
 (0)