3
* Licensed Materials - Property of IBM
5
* trousers - An open source TCG Software Stack
7
* (C) Copyright International Business Machines Corp. 2004
17
#include "trousers/tss.h"
18
#include "trousers_types.h"
20
#include "tcs_utils.h"
21
#include "tcs_int_literals.h"
22
#include "capabilities.h"
23
#include "tcsd_wrap.h"
29
struct event_log *tcs_event_log = NULL;
34
if (tcs_event_log != NULL)
37
tcs_event_log = calloc(1, sizeof(struct event_log));
38
if (tcs_event_log == NULL) {
39
LogError("malloc of %zd bytes failed.", sizeof(struct event_log));
40
return TCSERR(TSS_E_OUTOFMEMORY);
43
MUTEX_INIT(tcs_event_log->lock);
45
/* allocate as many event lists as there are PCR's */
46
tcs_event_log->lists = calloc(tpm_metrics.num_pcrs, sizeof(struct event_wrapper *));
47
if (tcs_event_log->lists == NULL) {
48
LogError("malloc of %zd bytes failed.",
49
tpm_metrics.num_pcrs * sizeof(struct event_wrapper *));
51
return TCSERR(TSS_E_OUTOFMEMORY);
54
/* assign external event log sources here */
55
//tcs_event_log->firmware_source = EVLOG_IMA_SOURCE;
56
tcs_event_log->firmware_source = EVLOG_BIOS_SOURCE;
57
tcs_event_log->kernel_source = EVLOG_BIOS_SOURCE;
65
struct event_wrapper *cur, *next;
68
MUTEX_LOCK(tcs_event_log->lock);
70
for (i = 0; i < tpm_metrics.num_pcrs; i++) {
71
cur = tcs_event_log->lists[i];
74
free(cur->event.rgbPcrValue);
75
free(cur->event.rgbEvent);
81
MUTEX_UNLOCK(tcs_event_log->lock);
83
free(tcs_event_log->lists);
90
copy_pcr_event(TSS_PCR_EVENT *dest, TSS_PCR_EVENT *source)
92
memcpy(dest, source, sizeof(TSS_PCR_EVENT));
97
event_log_add(TSS_PCR_EVENT *event, UINT32 *pNumber)
99
struct event_wrapper *new, *tmp;
103
MUTEX_LOCK(tcs_event_log->lock);
105
new = calloc(1, sizeof(struct event_wrapper));
107
LogError("malloc of %zd bytes failed.", sizeof(struct event_wrapper));
108
MUTEX_UNLOCK(tcs_event_log->lock);
109
return TCSERR(TSS_E_OUTOFMEMORY);
112
if ((result = copy_pcr_event(&(new->event), event))) {
114
MUTEX_UNLOCK(tcs_event_log->lock);
118
/* go to the end of the list to add the element, so that they're in order */
120
if (tcs_event_log->lists[event->ulPcrIndex] == NULL) {
121
tcs_event_log->lists[event->ulPcrIndex] = new;
124
tmp = tcs_event_log->lists[event->ulPcrIndex];
125
while (tmp->next != NULL) {
134
MUTEX_UNLOCK(tcs_event_log->lock);
140
get_pcr_event(UINT32 pcrIndex, UINT32 eventNumber)
142
struct event_wrapper *tmp;
145
MUTEX_LOCK(tcs_event_log->lock);
147
tmp = tcs_event_log->lists[pcrIndex];
148
for (; tmp; tmp = tmp->next) {
149
if (counter == eventNumber) {
155
MUTEX_UNLOCK(tcs_event_log->lock);
157
return (tmp ? &(tmp->event) : NULL);
160
/* the lock should be held before calling this function */
162
get_num_events(UINT32 pcrIndex)
164
struct event_wrapper *tmp;
167
tmp = tcs_event_log->lists[pcrIndex];
168
for (; tmp; tmp = tmp->next) {
176
concat_pcr_events(TSS_PCR_EVENT **list_so_far, UINT32 list_size, TSS_PCR_EVENT *addition,
177
UINT32 addition_size)
181
ret = realloc(*list_so_far, (list_size + addition_size) * sizeof(TSS_PCR_EVENT));
183
LogError("malloc of %zd bytes failed",
184
(list_size + addition_size) * sizeof(TSS_PCR_EVENT));
188
memcpy(&ret[list_size], addition, addition_size * sizeof(TSS_PCR_EVENT));
192
/* XXX make this a macro */
194
get_pcr_event_size(TSS_PCR_EVENT *e)
196
return (sizeof(TSS_PCR_EVENT) + e->ulEventLength + e->ulPcrValueLength);
200
free_external_events(UINT32 eventCount, TSS_PCR_EVENT *ppEvents)
207
for (j = 0; j < eventCount; j++) {
208
/* This is a fairly heinous hack, but PCR event logs can get really large
209
* and without it, there is a real potential to exhaust memory by leaks.
210
* The PCR event logs that we pull out of securityfs have had their
211
* rgbPcrValue and rgbEvent pointers malloc'd dynamically as the
212
* securityfs log was parsed. The other event log lists that are
213
* maintained by the TCSD don't need to have this data free'd, since that
214
* will happen at shutdown time only. So, for each PCR index that's
215
* read from securityfs, we need to free its pointers after that data has
216
* been set in the packet to send back to the TSP. */
217
if ((tcsd_options.kernel_pcrs & (1 << ppEvents[j].ulPcrIndex)) ||
218
(tcsd_options.firmware_pcrs & (1 << ppEvents[j].ulPcrIndex))) {
219
free(ppEvents[j].rgbPcrValue);
220
free(ppEvents[j].rgbEvent);