xref: /aosp_15_r20/external/coreboot/src/security/vboot/secdata_mock.c (revision b9411a12aaaa7e1e6a6fb7c5e057f44ee179a49c)
1 /* SPDX-License-Identifier: BSD-3-Clause */
2 
3 /*
4  * Functions for querying, manipulating and locking rollback indices
5  * stored in the TPM NVRAM.
6  */
7 
8 #include <security/tpm/tspi.h>
9 #include <security/tpm/tss_errors.h>
10 #include <vb2_api.h>
11 
12 #include "antirollback.h"
13 
vb2ex_tpm_clear_owner(struct vb2_context * ctx)14 vb2_error_t vb2ex_tpm_clear_owner(struct vb2_context *ctx)
15 {
16 	return VB2_SUCCESS;
17 }
18 
antirollback_read_space_firmware(struct vb2_context * ctx)19 tpm_result_t antirollback_read_space_firmware(struct vb2_context *ctx)
20 {
21 	vb2api_secdata_firmware_create(ctx);
22 	return TPM_SUCCESS;
23 }
24 
antirollback_write_space_firmware(struct vb2_context * ctx)25 tpm_result_t antirollback_write_space_firmware(struct vb2_context *ctx)
26 {
27 	return TPM_SUCCESS;
28 }
29 
antirollback_read_space_kernel(struct vb2_context * ctx)30 tpm_result_t antirollback_read_space_kernel(struct vb2_context *ctx)
31 {
32 	/*
33 	 * The new kernel secdata v1 stores the last read EC hash, and reboots the
34 	 * device during EC software sync when that hash didn't match the currently
35 	 * active hash on the EC (this is used with TPM_GOOGLE to support EC-EFS2 and
36 	 * pretty much a no-op for other devices). Generally, of course the whole
37 	 * point of secdata is always that it persists across reboots, but with
38 	 * MOCK_SECDATA we can't do that. Previously we always happened to somewhat
39 	 * get away with presenting freshly-reinitialized data for MOCK_SECDATA on
40 	 * every boot, but with the EC hash feature in secdata v1, that would cause
41 	 * a reboot loop. The simplest solution is to just pretend we're a secdata
42 	 * v0 device when using MOCK_SECDATA.
43 	 */
44 	vb2api_secdata_kernel_create_v0(ctx);
45 	return TPM_SUCCESS;
46 }
47 
antirollback_write_space_kernel(struct vb2_context * ctx)48 tpm_result_t antirollback_write_space_kernel(struct vb2_context *ctx)
49 {
50 	return TPM_SUCCESS;
51 }
52 
antirollback_lock_space_firmware(void)53 tpm_result_t antirollback_lock_space_firmware(void)
54 {
55 	return TPM_SUCCESS;
56 }
57 
antirollback_lock_space_mrc_hash(uint32_t index)58 tpm_result_t antirollback_lock_space_mrc_hash(uint32_t index)
59 {
60 	return TPM_SUCCESS;
61 }
62 
antirollback_read_space_mrc_hash(uint32_t index,uint8_t * data,uint32_t size)63 tpm_result_t antirollback_read_space_mrc_hash(uint32_t index, uint8_t *data, uint32_t size)
64 {
65 	return TPM_SUCCESS;
66 }
67 
antirollback_write_space_mrc_hash(uint32_t index,const uint8_t * data,uint32_t size)68 tpm_result_t antirollback_write_space_mrc_hash(uint32_t index, const uint8_t *data,
69 					      uint32_t size)
70 {
71 	return TPM_SUCCESS;
72 }
73 
antirollback_read_space_vbios_hash(uint8_t * data,uint32_t size)74 tpm_result_t antirollback_read_space_vbios_hash(uint8_t *data, uint32_t size)
75 {
76 	return TPM_SUCCESS;
77 }
78 
antirollback_write_space_vbios_hash(const uint8_t * data,uint32_t size)79 tpm_result_t antirollback_write_space_vbios_hash(const uint8_t *data, uint32_t size)
80 {
81 	return TPM_SUCCESS;
82 }
83