Commit Graph

18 Commits

Author SHA1 Message Date
Conrad Meyer
6a0086dd4d tpm(4): Fix 'go ready' in TPM 2.0 TIS driver
tpmtis_go_ready() read the value of the TPM_STS register, ORed
TPM_STS_CMD_READY with it, and wrote it back.  However, the TPM Profile
(PTP) specification states that only one bit in the write request value may
be set to 1, or else the entire write request is ignored.

Fix by just writing TPM_STS_CMD_READY.

Similarly, remove the call which clears the TPM_STS_CMD_READY flag in the
same function.  It was being ignored for the same reason.

Submitted by:	Darrick Lew <darrick.freebsd AT gmail.com>
Reviewed by:	vangyzen, myself
MFC after:	if you care about stable, you might want to do so
Sponsored by:	Dell EMC Isilon
Differential Revision:	https://reviews.freebsd.org/D23081
2020-02-01 20:38:22 +00:00
Dimitry Andric
13ae20a8a1 Fix new clang 10.0.0 warnings about converting the result of shift
operations to a boolean in tpm(4):

  sys/dev/tpm/tpm_crb.c:301:32: error: converting the result of '<<' to a boolean; did you mean '(1 << (0)) != 0'? [-Werror,-Wint-in-bool-context]
	  WR4(sc, TPM_CRB_CTRL_CANCEL, !TPM_CRB_CTRL_CANCEL_CMD);
					^
  sys/dev/tpm/tpm_crb.c:73:34: note: expanded from macro 'TPM_CRB_CTRL_CANCEL_CMD'
  #define TPM_CRB_CTRL_CANCEL_CMD         BIT(0)
					  ^
  sys/dev/tpm/tpm20.h:60:19: note: expanded from macro 'BIT'
  #define BIT(x) (1 << (x))
		    ^

In this case, the intent was to clear the zeroth bit, and leave the rest
unaffected.  Therefore, the ~ operator should be used instead.

Noticed by:	cem
MFC after:	3 days
2020-02-01 17:02:26 +00:00
Marcin Wojtas
f39ec261ad Improve tpm20 style
No functional changes to the code are applied.

Submitted by: Kornel Duleba <mindal@semihalf.com>
Obtained from: Semihalf
Sponsored by: Stormshield
2019-04-16 02:46:21 +00:00
Marcin Wojtas
d68a65eabf tpm: Prevent session hijack
Check caller thread id before allowing to read the buffer
to make sure that it can only be accessed by the thread that
did the associated write to the TPM.

Submitted by: Kornel Duleba <mindal@semihalf.com>
Reviewed by: delphij
Obtained from: Semihalf
Sponsored by: Stormshield
Differential Revision: https://reviews.freebsd.org/D19713
2019-04-16 02:28:35 +00:00
Marcin Wojtas
3a3e5039b9 Add a cv_wait to the TPM2.0 harvesting function
Harvesting has to compete for the TPM chip with userspace.
Before this change the callout could hijack an unread buffer
causing a userspace call to the TPM to fail.

Submitted by: Kornel Duleba <mindal@semihalf.com>
Reviewed by: delphij
Obtained from: Semihalf
Sponsored by: Stormshield
Differential Revision: https://reviews.freebsd.org/D19712
2019-04-03 08:22:58 +00:00
Marcin Wojtas
4ee7d3b011 Allow using TPM as entropy source.
TPM has a built-in RNG, with its own entropy source.
The driver was extended to harvest 16 random bytes from TPM every 10 seconds.
A new build option "TPM_HARVEST" was introduced - for now, however, it
is not enabled by default in the GENERIC config.

Submitted by: Kornel Duleba <mindal@semihalf.com>
Reviewed by: markm, delphij
Approved by: secteam
Obtained from: Semihalf
Sponsored by: Stormshield
Differential Revision: https://reviews.freebsd.org/D19620
2019-03-23 05:13:51 +00:00
Takanori Watanabe
877fc2e350 Use ACPI TPM2 table to probe tpmtis and tpmcrb device.
Differential Revision: https://reviews.freebsd.org/D18937
2019-01-25 16:16:10 +00:00
Conrad Meyer
0c3bbec309 tpm(4): Fix GCC build after r342084 (TPM 2.0 driver commit)
Move static variable definition (cdevsw) to a more conventional location
(the C file it is used in), rather than a header.

This fixes the GCC warning, -Wunused-variable ("defined but not used") when
the tpm20.h header is included in files other than tpm20.c (e.g.,
tpm_tis.c).

X-MFC-with:	r342084
Sponsored by:	Dell EMC Isilon
2018-12-20 20:55:33 +00:00
Marcin Wojtas
efa9b503c6 Fix obtaining RSP address in TPM CRB for non-amd64 platforms
On amd64 the RSP address can be read in single 8-byte transaction,
which is obviously not possible on 32-bit platforms. Fix that
by performing 2 4-byte read on them.

Obtained from: Semihalf
Sponsored by: Stormshield
2018-12-20 01:05:09 +00:00
Marcin Wojtas
c9073141b4 Fix error check for ACPI_ID_PROBE in the TPM2.0 driver
Updated API does not return pointer, so adjust the
TPM2.0 driver accordingly.

Reported by: jhb
Obtained from: Semihalf
Sponsored by: Stormshield
2018-12-14 22:22:43 +00:00
Marcin Wojtas
8a263d8fca Fix TPM driver compilation from r342084
Include recent ACPI_ID_PROBE API change.
2018-12-14 17:43:35 +00:00
Marcin Wojtas
a2d5ed9442 Introduce driver for TPM 2.0 in CRB and FIFO (TIS) modes
It was written basing on:
TCG PC Client Platform TPM Profile (PTP) Specification Version 22, Revision 1.03.
It only supports Locality 0. Interrupts are only supported in FIFO mode.

The driver in FIFO mode was tested on x86 with Infineon SLB9665 discrete TPM chip.
Driver in both modes was also tested on qemu with swtpm running on host.

Submitted by: Kornel Duleba <mindal@semihalf.com>
Obtained from: Semihalf
Sponsored by: Stormshield
Differential Revision: https://reviews.freebsd.org/D18048
2018-12-14 16:14:36 +00:00
Takanori Watanabe
5efca36fbd Distinguish _CID match and _HID match and make lower priority probe
when _CID match.

Reviewed by: jhb, imp
Differential Revision:https://reviews.freebsd.org/D16468
2018-10-26 00:05:46 +00:00
David E. O'Brien
9b6f7440b5 Remove dead code.
The #ifdef __FreeBSD__ section within the OpenBSD tpm_attach() implementation
can never be active.
2017-04-06 22:21:49 +00:00
Jean-Sébastien Pédron
bd937497ea Consistently use device_t
Several files use the internal name of `struct device` instead of
`device_t` which is part of the public API. This patch changes all
`struct device *` to `device_t`.

The remaining occurrences of `struct device` are those referring to the
Linux or OpenBSD version of the structure, or the code is not built on
FreeBSD and it's unclear what to do.

Submitted by:	Matthew Macy <mmacy@nextbsd.org> (previous version)
Approved by:	emaste, jhibbits, sbruno
MFC after:	3 days
Differential Revision:	https://reviews.freebsd.org/D7447
2016-08-09 19:32:06 +00:00
Pedro F. Giffuni
453130d9bf sys/dev: minor spelling fixes.
Most affect comments, very few have user-visible effects.
2016-05-03 03:41:25 +00:00
Dimitry Andric
29deb2257c In sys/dev/tpm/tpm.c, #if 0 an unused static function.
MFC after:	3 days
2013-12-29 19:55:06 +00:00
Takanori Watanabe
97f24f666f Add tpm(4) driver for Trusted Platform Module.
You may want to look at http://bsssd.sourceforge.net/ .

Submitted by: Hans-Joerg Hoexer <Hans-Joerg_Hoexer@genua.de>
2010-08-12 00:16:18 +00:00