Coverage Report

Created: 2025-07-11 06:15

/src/tpm2/Marshal_PolicyFidoSigned.c
Line
Count
Source (jump to first uncovered line)
1
/*
2
 * Copyright 2019 The Chromium OS Authors. All rights reserved.
3
 * Use of this source code is governed by a BSD-style license that can be
4
 * found in the LICENSE file.
5
 */
6
#include "MemoryLib_fp.h"
7
#include "PolicyFidoSigned_fp.h"
8
9
#if IS_CCE_ENABLED(PolicyFidoSigned)
10
/*
11
 * Marshal output data of PolicyFidoSigned command.
12
 *
13
 * @param source  input buffer of data to marshal
14
 * @param tag     Request tag
15
 * @param buffer  output buffer to write marshalled data
16
 * @param size    size of marshalled data
17
 * @return actual size of response excluding the size of the parameter field.
18
 */
19
static UINT16
20
PolicyFidoSigned_Out_Marshal(PolicyFidoSigned_Out* source,
21
                             TPMI_ST_COMMAND_TAG tag,
22
                             BYTE** buffer,
23
                             INT32* size)
24
0
{
25
0
  if (tag == TPM_ST_SESSIONS) {
26
0
    UINT32 param_size = 0;
27
28
    /* Add param_size=0 to indicate size of the parameter area. */
29
0
    UINT32_Marshal(&param_size, buffer, size);
30
0
  }
31
32
0
  return 0;
33
0
}
34
35
/*
36
 * Unmarshal input data of PolicyFidoSigned command.
37
 *
38
 * @param target       input buffer to unmarshal
39
 * @param req_handles
40
 * @param buffer       output buffer to write unmarshalled data
41
 * @param size         size of unmarshalled data.
42
 * @return TPM_RC_SUCCESS if processed successfully, or
43
 *         TPM_RC_SIZE if input data size is not correct, or
44
 *         TPM_RC_SCHEME if Authenticator algorithm is not specified, or
45
 *         TPM_RC_HASH if hash is missing or wrong.
46
 *
47
 *
48
 */
49
static TPM_RC
50
PolicyFidoSigned_In_Unmarshal(PolicyFidoSigned_In* target,
51
                              TPM_HANDLE req_handles[],
52
                              BYTE** buffer,
53
                              INT32* size)
54
0
{
55
0
  TPM_RC result = TPM_RC_SUCCESS;
56
0
  int i;
57
58
  /* Get request handles from req_handles array. */
59
0
  target->authObject = req_handles[0];
60
0
  target->policySession = req_handles[1];
61
62
0
  result = UINT16_Unmarshal(&target->authData.t.size, buffer, size);
63
0
  if (result != TPM_RC_SUCCESS)
64
0
    return result;
65
66
0
  if (target->authData.t.size > MAX_AUTH_DATA_SIZE ||
67
0
      target->authData.t.size == 0)
68
0
    return TPM_RC_SIZE;
69
70
  /* Unmarshall authData. */
71
0
  for (i = 0; i < target->authData.t.size; ++i) {
72
0
    result = BYTE_Unmarshal(&(target->authData.t.buffer[i]), buffer, size);
73
0
    if (result != TPM_RC_SUCCESS)
74
0
      return result;
75
0
  }
76
77
  /* Unmarshal request parameters. */
78
0
  result = UINT16_Unmarshal(&target->authDataDescrCount, buffer, size);
79
0
  if (result != TPM_RC_SUCCESS)
80
0
    return result;
81
82
0
  if (target->authDataDescrCount > sizeof(target->authDataDescr))
83
0
    return TPM_RC_SIZE;
84
85
  /* Unmarshall authDataDescr. */
86
0
  for (i = 0; i < target->authDataDescrCount; i++) {
87
0
    result = UINT16_Unmarshal(&(target->authDataDescr[i].offset), buffer, size);
88
0
    if (result != TPM_RC_SUCCESS)
89
0
      return result;
90
91
0
    result = UINT16_Unmarshal(&(target->authDataDescr[i].size), buffer, size);
92
0
    if (result != TPM_RC_SUCCESS)
93
0
      return result;
94
95
    /* The range size should be non-zero. */
96
0
    if (target->authDataDescr[i].size == 0)
97
0
      return TPM_RC_VALUE;
98
99
    /* The range is beyond the actual authData string */
100
0
    if (target->authDataDescr[i].offset + target->authDataDescr[i].size >
101
0
        target->authData.t.size)
102
0
      return TPM_RC_VALUE;
103
0
  }
104
105
0
  result = TPMT_SIGNATURE_Unmarshal(&target->auth, buffer, size);
106
0
  if (result != TPM_RC_SUCCESS)
107
0
    return result;
108
109
  /* Size should be zero. */
110
0
  if (*size)
111
0
    return TPM_RC_SIZE;
112
113
0
  return result;
114
0
}
115
116
TPM_RC Exec_PolicyFidoSigned(TPMI_ST_COMMAND_TAG tag,
117
                             BYTE** req_param_buffer,
118
                             INT32* req_param_buffer_size,
119
                             TPM_HANDLE req_handles[],
120
                             UINT32* resp_handle_buf_size,
121
                             UINT32* resp_param_buf_size)
122
0
{
123
0
  TPM_RC result = TPM_RC_SUCCESS;
124
0
  PolicyFidoSigned_In in;
125
0
  PolicyFidoSigned_Out out;
126
0
  BYTE* resp_buf;
127
0
  INT32 resp_buf_size;
128
0
  const INT32 resp_header_size = sizeof(TPM_ST) + sizeof(UINT32) +
129
0
                                 sizeof(TPM_RC);
130
131
0
  *resp_handle_buf_size = 0;
132
0
  *resp_param_buf_size = 0;
133
134
  /* Unmarshal request parameters to input structure. */
135
0
  result = PolicyFidoSigned_In_Unmarshal(&in,
136
0
                                         req_handles,
137
0
                                         req_param_buffer,
138
0
                                         req_param_buffer_size);
139
0
  if (result != TPM_RC_SUCCESS)
140
0
    return result;
141
142
  /* Execute command. */
143
0
  result = TPM2_PolicyFidoSigned(&in, &out);
144
0
  if (result != TPM_RC_SUCCESS)
145
0
    return result;
146
147
  /* Marshal output structure to global response buffer. */
148
0
  resp_buf = MemoryGetResponseBuffer(TPM_CCE_PolicyFidoSigned)
149
0
             + resp_header_size;
150
0
  resp_buf_size = MAX_RESPONSE_SIZE - resp_header_size;
151
152
0
  *resp_param_buf_size = PolicyFidoSigned_Out_Marshal(&out,
153
0
                                                      tag,
154
0
                                                      &resp_buf,
155
0
                                                      &resp_buf_size);
156
0
  return TPM_RC_SUCCESS;
157
0
}
158
#endif    /* IS_CCE_ENABLED(PolicyFidoSigned) */