Jan Dabros 23393c6461 char: tpm: Protect tpm_pm_suspend with locks
Currently tpm transactions are executed unconditionally in
tpm_pm_suspend() function, which may lead to races with other tpm
accessors in the system.

Specifically, the hw_random tpm driver makes use of tpm_get_random(),
and this function is called in a loop from a kthread, which means it's
not frozen alongside userspace, and so can race with the work done
during system suspend:

  tpm tpm0: tpm_transmit: tpm_recv: error -52
  tpm tpm0: invalid TPM_STS.x 0xff, dumping stack for forensics
  CPU: 0 PID: 1 Comm: init Not tainted 6.1.0-rc5+ #135
  Hardware name: QEMU Standard PC (Q35 + ICH9, 2009), BIOS 1.16.0-20220807_005459-localhost 04/01/2014
  Call Trace:
   tpm_tis_status.cold+0x19/0x20
   tpm_transmit+0x13b/0x390
   tpm_transmit_cmd+0x20/0x80
   tpm1_pm_suspend+0xa6/0x110
   tpm_pm_suspend+0x53/0x80
   __pnp_bus_suspend+0x35/0xe0
   __device_suspend+0x10f/0x350

Fix this by calling tpm_try_get_ops(), which itself is a wrapper around
tpm_chip_start(), but takes the appropriate mutex.

Signed-off-by: Jan Dabros <jsd@semihalf.com>
Reported-by: Vlastimil Babka <vbabka@suse.cz>
Tested-by: Jason A. Donenfeld <Jason@zx2c4.com>
Tested-by: Vlastimil Babka <vbabka@suse.cz>
Link: https://lore.kernel.org/all/c5ba47ef-393f-1fba-30bd-1230d1b4b592@suse.cz/
Cc: stable@vger.kernel.org
Fixes: e891db1a18bf ("tpm: turn on TPM on suspend for TPM 1.x")
[Jason: reworked commit message, added metadata]
Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
Reviewed-by: Jarkko Sakkinen <jarkko@kernel.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2022-12-04 12:49:13 -08:00
..
2022-10-12 10:23:24 -07:00
2022-11-25 17:50:57 -08:00
2022-11-04 16:03:43 -07:00
2022-12-02 15:35:21 -08:00
2022-11-11 09:03:19 -08:00
2022-09-21 20:33:49 +02:00
2022-12-04 12:18:37 -08:00
2022-10-12 10:23:24 -07:00
2022-10-09 14:05:15 -07:00
2022-11-18 13:59:45 -08:00
2022-10-14 18:41:41 -07:00
2022-12-02 16:27:15 -08:00
2022-10-14 12:38:03 -07:00
2022-11-16 10:36:13 -08:00
2022-10-10 09:10:28 -07:00
2022-10-07 11:32:10 -07:00
2022-11-25 13:54:48 -08:00
2022-11-25 17:50:57 -08:00
2022-11-25 12:32:42 -08:00
2022-11-23 11:19:06 -08:00
2022-11-18 12:02:38 -08:00
2022-11-18 10:59:52 -08:00
2022-10-22 03:29:32 +00:00
2022-10-10 14:02:53 -07:00
2022-10-10 14:02:53 -07:00
2022-11-01 12:21:53 -07:00
2022-11-16 10:49:06 -08:00