Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(181)

Side by Side Diff: src/tcs/tcs_evlog_imaem.c

Issue 3581012: Upgrade from trousers 0.3.3 to 0.3.6 and from testsuite 0.2 to 0.3. (Closed) Base URL: ssh://git@gitrw.chromium.org:9222/trousers.git
Patch Set: git cl push Created 10 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « src/tcs/tcs_evlog_biosem.c ('k') | src/tcs/tcs_pbg.c » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 1
2 /* 2 /*
3 * Licensed Materials - Property of IBM 3 * Licensed Materials - Property of IBM
4 * 4 *
5 * trousers - An open source TCG Software Stack 5 * trousers - An open source TCG Software Stack
6 * 6 *
7 * (C) Copyright International Business Machines Corp. 2004-2006 7 * (C) Copyright International Business Machines Corp. 2004-2006
8 * 8 *
9 */ 9 */
10 10
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after
76 ima_get_entries_by_pcr(FILE *handle, UINT32 pcr_index, UINT32 first, 76 ima_get_entries_by_pcr(FILE *handle, UINT32 pcr_index, UINT32 first,
77 UINT32 *count, TSS_PCR_EVENT **events) 77 UINT32 *count, TSS_PCR_EVENT **events)
78 { 78 {
79 int pcr_value; 79 int pcr_value;
80 char page[IMA_READ_SIZE]; 80 char page[IMA_READ_SIZE];
81 int error_path = 1, ptr = 0; 81 int error_path = 1, ptr = 0;
82 UINT32 copied_events = 0, i; 82 UINT32 copied_events = 0, i;
83 struct event_wrapper *list = calloc(1, sizeof(struct event_wrapper)); 83 struct event_wrapper *list = calloc(1, sizeof(struct event_wrapper));
84 struct event_wrapper *cur = list; 84 struct event_wrapper *cur = list;
85 TSS_RESULT result = TCSERR(TSS_E_INTERNAL_ERROR); 85 TSS_RESULT result = TCSERR(TSS_E_INTERNAL_ERROR);
86 86 » FILE *fp = (FILE *) handle;
87 /* Changes for kernel IMA */ 87 » uint len;
88 FILE *fp = (FILE *) handle; 88 » char name[255];
89 int len;
90 char name[255];
91 89
92 if (list == NULL) { 90 if (list == NULL) {
93 LogError("malloc of %zd bytes failed.", sizeof(struct event_wrap per)); 91 LogError("malloc of %zd bytes failed.", sizeof(struct event_wrap per));
94 return TCSERR(TSS_E_OUTOFMEMORY); 92 return TCSERR(TSS_E_OUTOFMEMORY);
95 } 93 }
96 94
97 if (*count == 0) { 95 if (*count == 0) {
98 result = TSS_SUCCESS; 96 result = TSS_SUCCESS;
99 goto free_list; 97 goto free_list;
100 } 98 }
(...skipping 21 matching lines...) Expand all
122 } 120 }
123 121
124 /* copy the template SHA1 XXX endianess ignored */ 122 /* copy the template SHA1 XXX endianess ignored */
125 memcpy(cur->event.rgbPcrValue, &page[ptr], 123 memcpy(cur->event.rgbPcrValue, &page[ptr],
126 cur->event.ulPcrValueLength); 124 cur->event.ulPcrValueLength);
127 125
128 /* Get the template name size, template name */ 126 /* Get the template name size, template name */
129 { 127 {
130 char digest[20]; 128 char digest[20];
131 129
132 » » fread(&len, sizeof len, 1, fp); 130 » » if (fread(&len, 1, sizeof(len), fp) != (sizeof(len))) {
131 » » » LogError("Failed to read event log file");
132 » » » result = TCSERR(TSS_E_INTERNAL_ERROR);
133 » » » goto free_list;
134 » » }
135 » »
133 memset(name, 0, sizeof name); 136 memset(name, 0, sizeof name);
134 » » fread(name, len, 1, fp); 137 » » if (fread(name, 1, len, fp) != len) {
135 138 » » » LogError("Failed to read event log file");
136 » » fread(digest, sizeof digest, 1, fp); 139 » » » result = TCSERR(TSS_E_INTERNAL_ERROR);
140 » » » goto free_list;
141 » » }
142 » » if (fread(digest, 1, sizeof digest, fp) != (sizeof(digest))) {
143 » » » LogError("Failed to read event log file");
144 » » » result = TCSERR(TSS_E_INTERNAL_ERROR);
145 » » » goto free_list;
146 » » }
137 } 147 }
138 /* Get the template data namelen and data */ 148 /* Get the template data namelen and data */
139 » » fread(&cur->event.ulEventLength, sizeof(int), 1, fp); 149 » » if (fread(&cur->event.ulEventLength, 1, sizeof(int), fp) != size of(int)) {
150 » » » LogError("Failed to read event log file");
151 » » » result = TCSERR(TSS_E_INTERNAL_ERROR);
152 » » » goto free_list;
153 » » }
140 cur->event.rgbEvent = malloc(cur->event.ulEventLength + 1); 154 cur->event.rgbEvent = malloc(cur->event.ulEventLength + 1);
141 if (cur->event.rgbEvent == NULL) { 155 if (cur->event.rgbEvent == NULL) {
142 free(cur->event.rgbPcrValue); 156 free(cur->event.rgbPcrValue);
143 LogError("malloc of %u bytes failed.", 157 LogError("malloc of %u bytes failed.",
144 cur->event.ulEventLength); 158 cur->event.ulEventLength);
145 result = TCSERR(TSS_E_OUTOFMEMORY); 159 result = TCSERR(TSS_E_OUTOFMEMORY);
146 goto free_list; 160 goto free_list;
147 } 161 }
148 memset(cur->event.rgbEvent, 0, cur->event.ulEventLength); 162 memset(cur->event.rgbEvent, 0, cur->event.ulEventLength);
149 » » fread(cur->event.rgbEvent, cur->event.ulEventLength, 1, fp); 163 » » if (fread(cur->event.rgbEvent, 1, cur->event.ulEventLength, fp) != cur->event.ulEventLength) {
164 » » » free(cur->event.rgbPcrValue);
165 » » » LogError("Failed to read event log file");
166 » » » result = TCSERR(TSS_E_INTERNAL_ERROR);
167 » » » goto free_list;
168 » » }
150 169
151 copied_events++; 170 copied_events++;
152 printf("%d %s ", copied_events, name); 171 printf("%d %s ", copied_events, name);
153 172
154 printf("%s\n", cur->event.rgbEvent); 173 printf("%s\n", cur->event.rgbEvent);
155 if (copied_events == *count) 174 if (copied_events == *count)
156 goto copy_events; 175 goto copy_events;
157 176
158 cur->next = calloc(1, sizeof(struct event_wrapper)); 177 cur->next = calloc(1, sizeof(struct event_wrapper));
159 if (cur->next == NULL) { 178 if (cur->next == NULL) {
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
199 list = cur; 218 list = cur;
200 cur = list->next; 219 cur = list->next;
201 } 220 }
202 free(list); 221 free(list);
203 return result; 222 return result;
204 } 223 }
205 224
206 TSS_RESULT 225 TSS_RESULT
207 ima_get_entry(FILE *handle, UINT32 pcr_index, UINT32 *num, TSS_PCR_EVENT **ppEve nt) 226 ima_get_entry(FILE *handle, UINT32 pcr_index, UINT32 *num, TSS_PCR_EVENT **ppEve nt)
208 { 227 {
209 » int pcr_value, ptr = 0, len; 228 » int pcr_value, ptr = 0;
229 » uint len;
210 char page[IMA_READ_SIZE]; 230 char page[IMA_READ_SIZE];
211 UINT32 seen_indices = 0; 231 UINT32 seen_indices = 0;
212 TSS_RESULT result = TCSERR(TSS_E_INTERNAL_ERROR); 232 TSS_RESULT result = TCSERR(TSS_E_INTERNAL_ERROR);
213 » TSS_PCR_EVENT *event; 233 » TSS_PCR_EVENT *event = NULL;
214 FILE *fp = (FILE *) handle; 234 FILE *fp = (FILE *) handle;
215 char name[255]; 235 char name[255];
216 printf("ima_get_entry \n");
217 fflush(stdout);
218 236
219 rewind(fp); 237 rewind(fp);
220 while (fread(page, 24, 1, fp)) { 238 while (fread(page, 24, 1, fp)) {
221 /* copy the initial 4 bytes (PCR index) XXX endianess ignored */ 239 /* copy the initial 4 bytes (PCR index) XXX endianess ignored */
222 ptr = 0; 240 ptr = 0;
223 memcpy(&pcr_value, &page[ptr], sizeof(int)); 241 memcpy(&pcr_value, &page[ptr], sizeof(int));
224 242
225 printf("pcr_index %u\n", (UINT32)pcr_value);
226 fflush(stdout);
227 if (pcr_index == (UINT32)pcr_value) { 243 if (pcr_index == (UINT32)pcr_value) {
228 event = calloc(1, sizeof(TSS_PCR_EVENT)); 244 event = calloc(1, sizeof(TSS_PCR_EVENT));
229 event->ulPcrIndex = pcr_value; 245 event->ulPcrIndex = pcr_value;
230 ptr += sizeof(int); 246 ptr += sizeof(int);
231 /* This is the case where we're looking for a specific e vent number in a 247 /* This is the case where we're looking for a specific e vent number in a
232 * specific PCR index. When we've reached the correct ev ent, malloc 248 * specific PCR index. When we've reached the correct ev ent, malloc
233 * space for it, copy it in, then break out of the while loop */ 249 * space for it, copy it in, then break out of the while loop */
234 if (ppEvent && seen_indices == *num) { 250 if (ppEvent && seen_indices == *num) {
235 /* grab this entry */ 251 /* grab this entry */
236 event->ulPcrValueLength = 20; 252 event->ulPcrValueLength = 20;
237 event->rgbPcrValue = malloc(event->ulPcrValueLen gth); 253 event->rgbPcrValue = malloc(event->ulPcrValueLen gth);
238 if (event->rgbPcrValue == NULL) { 254 if (event->rgbPcrValue == NULL) {
239 LogError("malloc of %d bytes failed.", 2 0); 255 LogError("malloc of %d bytes failed.", 2 0);
256 free(event);
240 result = TCSERR(TSS_E_OUTOFMEMORY); 257 result = TCSERR(TSS_E_OUTOFMEMORY);
241 goto done; 258 goto done;
242 } 259 }
243 260
244 /* copy the template SHA1 XXX endianess ignored */ 261 /* copy the template SHA1 XXX endianess ignored */
245 memcpy(event->rgbPcrValue, &page[ptr], 262 memcpy(event->rgbPcrValue, &page[ptr],
246 event->ulPcrValueLength); 263 event->ulPcrValueLength);
247 264
248 /* Get the template name size, template name */ 265 /* Get the template name size, template name */
249 { 266 {
250 char digest[20]; 267 char digest[20];
251 268
252 » » » » » fread(&len, sizeof len, 1, fp); 269 » » » » » if (fread(&len, 1, sizeof(len), fp) != s izeof(len)) {
270 » » » » » » free(event);
271 » » » » » » LogError("Failed to read event l og file");
272 » » » » » » result = TCSERR(TSS_E_INTERNAL_E RROR);
273 » » » » » » goto done;
274 » » » » » }
253 memset(name, 0, sizeof name); 275 memset(name, 0, sizeof name);
254 » » » » » fread(name, len, 1, fp); 276 » » » » » if (fread(name, 1, len, fp) != len) {
255 » » » » » fread(digest, sizeof digest, 1, fp); 277 » » » » » » free(event);
278 » » » » » » LogError("Failed to read event l og file");
279 » » » » » » result = TCSERR(TSS_E_INTERNAL_E RROR);
280 » » » » » » goto done;
281 » » » » » }
282 » » » » » if (fread(digest, 1, sizeof(digest), fp) != sizeof(digest)) {
283 » » » » » » free(event);
284 » » » » » » LogError("Failed to read event l og file");
285 » » » » » » result = TCSERR(TSS_E_INTERNAL_E RROR);
286 » » » » » » goto done;
287 » » » » » }
256 } 288 }
257 /* Get the template data namelen and data */ 289 /* Get the template data namelen and data */
258 » » » » fread(&event->ulEventLength, sizeof(int), 1, fp) ; 290 » » » » if (fread(&event->ulEventLength, 1, sizeof(int), fp) != sizeof(int)) {
291 » » » » » free(event);
292 » » » » » LogError("Failed to read event log file" );
293 » » » » » result = TCSERR(TSS_E_INTERNAL_ERROR);
294 » » » » » goto done;
295 » » » » }
259 event->rgbEvent = malloc(event->ulEventLength + 1); 296 event->rgbEvent = malloc(event->ulEventLength + 1);
260 if (event->rgbEvent == NULL) { 297 if (event->rgbEvent == NULL) {
261 free(event->rgbPcrValue); 298 free(event->rgbPcrValue);
299 free(event);
262 LogError("malloc of %u bytes failed.", 300 LogError("malloc of %u bytes failed.",
263 event->ulEventLength); 301 event->ulEventLength);
264 result = TCSERR(TSS_E_OUTOFMEMORY); 302 result = TCSERR(TSS_E_OUTOFMEMORY);
265 free(event->rgbPcrValue);
266 event->rgbPcrValue = NULL;
267 goto done; 303 goto done;
268 } 304 }
269 memset(event->rgbEvent, 0, event->ulEventLength) ; 305 memset(event->rgbEvent, 0, event->ulEventLength) ;
270 » » » » fread(event->rgbEvent, event->ulEventLength, 1, fp); 306 » » » » if (fread(event->rgbEvent, 1, event->ulEventLeng th, fp) != event->ulEventLength ) {
307 » » » » » free(event->rgbPcrValue);
308 » » » » » free(event);
309 » » » » » LogError("Failed to read event log file" );
310 » » » » » result = TCSERR(TSS_E_INTERNAL_ERROR);
311 » » » » » goto done;
312 » » » » }
313 » » » »
271 *ppEvent = event; 314 *ppEvent = event;
272 result = TSS_SUCCESS; 315 result = TSS_SUCCESS;
273 break; 316 break;
274 } 317 }
275 } 318 }
276 » » fread(&len, sizeof len, 1, fp); 319 » » if (fread(&len, 1, sizeof(len), fp) != sizeof(len)) {
320 » » » free(event->rgbPcrValue);
321 » » » free(event);
322 » » » LogError("Failed to read event log file");
323 » » » result = TCSERR(TSS_E_INTERNAL_ERROR);
324 » » » goto done;
325 » » }
277 fseek(fp, len + 20, SEEK_CUR); 326 fseek(fp, len + 20, SEEK_CUR);
278 » » fread(&len, sizeof len, 1, fp); 327 » » if (fread(&len, 1, sizeof(len), fp) != sizeof(len)) {
328 » » » free(event->rgbPcrValue);
329 » » » free(event);
330 » » » LogError("Failed to read event log file");
331 » » » result = TCSERR(TSS_E_INTERNAL_ERROR);
332 » » » goto done;
333 » » }
279 fseek(fp, len, SEEK_CUR); 334 fseek(fp, len, SEEK_CUR);
280 seen_indices++; 335 seen_indices++;
281 printf("%d - index\n", seen_indices); 336 printf("%d - index\n", seen_indices);
282 } 337 }
283 done: 338 done:
284 fflush(stdout);
285 if (ppEvent == NULL) 339 if (ppEvent == NULL)
286 *num = seen_indices; 340 *num = seen_indices;
287 341
288 return result; 342 return result;
289 } 343 }
290 344
291 int 345 int
292 ima_close(FILE *handle) 346 ima_close(FILE *handle)
293 { 347 {
294 fclose((FILE *)handle); 348 fclose((FILE *)handle);
295 349
296 return 0; 350 return 0;
297 } 351 }
298 #endif 352 #endif
OLDNEW
« no previous file with comments | « src/tcs/tcs_evlog_biosem.c ('k') | src/tcs/tcs_pbg.c » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698