1 /*
2 * Copyright (c) 2000-2004 Apple Computer, Inc. All rights reserved.
3 *
4 * @APPLE_OSREFERENCE_LICENSE_HEADER_START@
5 *
6 * This file contains Original Code and/or Modifications of Original Code
7 * as defined in and that are subject to the Apple Public Source License
8 * Version 2.0 (the 'License'). You may not use this file except in
9 * compliance with the License. The rights granted to you under the License
10 * may not be used to create, or enable the creation or redistribution of,
11 * unlawful or unlicensed copies of an Apple operating system, or to
12 * circumvent, violate, or enable the circumvention or violation of, any
13 * terms of an Apple operating system software license agreement.
14 *
15 * Please obtain a copy of the License at
16 * http://www.opensource.apple.com/apsl/ and read it before using this file.
17 *
18 * The Original Code and all software distributed under the License are
19 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
20 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
21 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
22 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
23 * Please see the License for the specific language governing rights and
24 * limitations under the License.
25 *
26 * @APPLE_OSREFERENCE_LICENSE_HEADER_END@
27 */
28 /*
29 * @OSF_FREE_COPYRIGHT@
30 */
31
32 #include <pexpert/protos.h>
33 #include <pexpert/boot.h>
34 #include <pexpert/device_tree.h>
35
36 #include <mach/mach_types.h>
37 #include <mach/machine/vm_types.h>
38 #include <kern/debug.h>
39 #include <kern/kern_types.h>
40 #include <kern/kalloc.h>
41 #include <libkern/kernel_mach_header.h>
42 #include <os/overflow.h>
43
44 #if defined(KERNEL_INTEGRITY_KTRR) || defined(KERNEL_INTEGRITY_CTRR)
45 extern addr64_t kvtophys(vm_offset_t va);
46 #endif /* defined(KERNEL_INTEGRITY_KTRR) || defined(KERNEL_INTEGRITY_CTRR) */
47
48 #include <sys/types.h>
49
50 SECURITY_READ_ONLY_LATE(static int) DTInitialized;
51 SECURITY_READ_ONLY_LATE(RealDTEntry) DTRootNode;
52 SECURITY_READ_ONLY_LATE(static vm_size_t) DTSize;
53 SECURITY_READ_ONLY_LATE(static vm_offset_t) DTEnd;
54
55 /*
56 *
57 * Support Routines
58 *
59 */
60
61 static inline void
assert_in_dt_region(vm_offset_t const start,vm_offset_t const end,void const * p)62 assert_in_dt_region(vm_offset_t const start, vm_offset_t const end, void const *p)
63 {
64 if ((vm_offset_t)p < start || (vm_offset_t)p > end) {
65 panic("Device tree pointer outside of device tree region: pointer %p, DTEnd %lx", p, (unsigned long)DTEnd);
66 }
67 }
68 #define ASSERT_IN_DT(p) assert_in_dt_region((vm_offset_t)DTRootNode, (vm_offset_t)DTEnd, (p))
69
70 static inline void
assert_prop_in_dt_region(vm_offset_t const start,vm_offset_t const end,DeviceTreeNodeProperty const * prop)71 assert_prop_in_dt_region(vm_offset_t const start, vm_offset_t const end, DeviceTreeNodeProperty const *prop)
72 {
73 vm_offset_t prop_end;
74
75 assert_in_dt_region(start, end, prop);
76 assert_in_dt_region(start, end, (uint8_t const *)prop + sizeof(DeviceTreeNodeProperty));
77 if (os_add3_overflow((vm_offset_t)prop, sizeof(DeviceTreeNodeProperty), prop->length, &prop_end)) {
78 panic("Device tree property overflow: prop %p, length 0x%x", prop, prop->length);
79 }
80 assert_in_dt_region(start, end, (void*)prop_end);
81 }
82 #define ASSERT_PROP_IN_DT(prop) assert_prop_in_dt_region((vm_offset_t)DTRootNode, (vm_offset_t)DTEnd, (prop))
83
84 #define ASSERT_HEADER_IN_DT_REGION(start, end, p, size) assert_in_dt_region((start), (end), (uint8_t const *)(p) + (size))
85 #define ASSERT_HEADER_IN_DT(p, size) ASSERT_IN_DT((uint8_t const *)(p) + (size))
86
87 /*
88 * Since there is no way to know the size of a device tree node
89 * without fully walking it, we employ the following principle to make
90 * sure that the accessed device tree is fully within its memory
91 * region:
92 *
93 * Internally, we check anything we want to access just before we want
94 * to access it (not after creating a pointer).
95 *
96 * Then, before returning a DTEntry to the caller, we check whether
97 * the start address (only!) of the entry is still within the device
98 * tree region.
99 *
100 * Before returning a property value the caller, we check whether the
101 * property is fully within the region.
102 *
103 * "DTEntry"s are opaque to the caller, so only checking their
104 * starting address is enough to satisfy existence within the device
105 * tree region, while for property values we need to make sure that
106 * they are fully within the region.
107 */
108
109 static inline DeviceTreeNodeProperty const *
next_prop_region(vm_offset_t const start,vm_offset_t end,DeviceTreeNodeProperty const * prop)110 next_prop_region(vm_offset_t const start, vm_offset_t end, DeviceTreeNodeProperty const *prop)
111 {
112 uintptr_t next_addr;
113
114 ASSERT_HEADER_IN_DT_REGION(start, end, prop, sizeof(DeviceTreeNodeProperty));
115
116 if (os_add3_overflow((uintptr_t)prop, prop->length, sizeof(DeviceTreeNodeProperty) + 3, &next_addr)) {
117 panic("Device tree property overflow: prop %p, length 0x%x", prop, prop->length);
118 }
119
120 next_addr &= ~(3ULL);
121
122 return (DeviceTreeNodeProperty*)next_addr;
123 }
124 #define next_prop(prop) next_prop_region((vm_offset_t)DTRootNode, (vm_offset_t)DTEnd, (prop))
125
126 static RealDTEntry
skipProperties(RealDTEntry entry)127 skipProperties(RealDTEntry entry)
128 {
129 DeviceTreeNodeProperty const *prop;
130 unsigned int k;
131
132 if (entry == NULL) {
133 return NULL;
134 }
135
136 ASSERT_HEADER_IN_DT(entry, sizeof(DeviceTreeNode));
137
138 if (entry->nProperties == 0) {
139 return NULL;
140 } else {
141 prop = (DeviceTreeNodeProperty const *) (entry + 1);
142 for (k = 0; k < entry->nProperties; k++) {
143 prop = next_prop(prop);
144 }
145 }
146 ASSERT_IN_DT(prop);
147 return (RealDTEntry) prop;
148 }
149
150 static RealDTEntry
skipTree(RealDTEntry root)151 skipTree(RealDTEntry root)
152 {
153 RealDTEntry entry;
154 unsigned int k;
155
156 ASSERT_HEADER_IN_DT(root, sizeof(DeviceTreeNode));
157
158 entry = skipProperties(root);
159 if (entry == NULL) {
160 return NULL;
161 }
162 for (k = 0; k < root->nChildren; k++) {
163 entry = skipTree(entry);
164 }
165 return entry;
166 }
167
168 static RealDTEntry
GetFirstChild(RealDTEntry parent)169 GetFirstChild(RealDTEntry parent)
170 {
171 return skipProperties(parent);
172 }
173
174 static RealDTEntry
GetNextChild(RealDTEntry sibling)175 GetNextChild(RealDTEntry sibling)
176 {
177 return skipTree(sibling);
178 }
179
180 static const char *
GetNextComponent(const char * cp,char * bp)181 GetNextComponent(const char *cp, char *bp)
182 {
183 size_t length = 0;
184 char *origbp = bp;
185
186 while (*cp != 0) {
187 if (*cp == kDTPathNameSeparator) {
188 cp++;
189 break;
190 }
191 if (++length > kDTMaxEntryNameLength) {
192 *origbp = '\0';
193 return cp;
194 }
195 *bp++ = *cp++;
196 }
197 *bp = 0;
198 return cp;
199 }
200
201 static RealDTEntry
FindChild(RealDTEntry cur,char * buf)202 FindChild(RealDTEntry cur, char *buf)
203 {
204 RealDTEntry child;
205 unsigned long index;
206 char const * str;
207 unsigned int dummy;
208
209 ASSERT_HEADER_IN_DT(cur, sizeof(DeviceTreeNode));
210
211 if (cur->nChildren == 0) {
212 return NULL;
213 }
214 index = 1;
215 child = GetFirstChild(cur);
216 while (1) {
217 if (SecureDTGetProperty(child, "name", (void const **)&str, &dummy) != kSuccess) {
218 break;
219 }
220 if (strcmp(str, buf) == 0) {
221 return child;
222 }
223 if (index >= cur->nChildren) {
224 break;
225 }
226 child = GetNextChild(child);
227 index++;
228 }
229 return NULL;
230 }
231
232 /*
233 * External Routines
234 */
235 void
SecureDTInit(void const * base,size_t size)236 SecureDTInit(void const *base, size_t size)
237 {
238 if ((uintptr_t)base + size < (uintptr_t)base) {
239 panic("DeviceTree overflow: %p, size %#zx", base, size);
240 }
241 DTRootNode = base;
242 DTSize = size;
243 DTEnd = (vm_offset_t)DTRootNode + DTSize;
244 DTInitialized = (DTRootNode != 0);
245 }
246
247 bool
SecureDTIsLockedDown(void)248 SecureDTIsLockedDown(void)
249 {
250 #if CONFIG_SPTM
251 return true;
252 #elif defined(KERNEL_INTEGRITY_KTRR) || defined(KERNEL_INTEGRITY_CTRR)
253 /*
254 * We cannot check if the DT is in the CTRR region early on,
255 * because knowledge of the CTRR region is set up later. But the
256 * DT is used in all kinds of early bootstrapping before that.
257 *
258 * Luckily, we know that the device tree must be in front of the
259 * kernel if set up in EXTRADATA (which means it's covered by
260 * CTRR), and after it otherwise.
261 */
262 addr64_t exec_header_phys = kvtophys((vm_offset_t)&_mh_execute_header);
263
264 if (kvtophys((vm_offset_t)DTRootNode) < exec_header_phys) {
265 assert(kvtophys(DTEnd) <= exec_header_phys);
266 return true;
267 }
268 #endif
269 return false;
270 }
271
272 int
SecureDTEntryIsEqual(const DTEntry ref1,const DTEntry ref2)273 SecureDTEntryIsEqual(const DTEntry ref1, const DTEntry ref2)
274 {
275 /* equality of pointers */
276 return ref1 == ref2;
277 }
278
279 static char const *startingP; // needed for find_entry
280 int find_entry(const char *propName, const char *propValue, DTEntry *entryH);
281
282 int
SecureDTFindEntry(const char * propName,const char * propValue,DTEntry * entryH)283 SecureDTFindEntry(const char *propName, const char *propValue, DTEntry *entryH)
284 {
285 if (!DTInitialized) {
286 return kError;
287 }
288
289 startingP = (char const *)DTRootNode;
290 return find_entry(propName, propValue, entryH);
291 }
292
293 int
find_entry(const char * propName,const char * propValue,DTEntry * entryH)294 find_entry(const char *propName, const char *propValue, DTEntry *entryH)
295 {
296 DeviceTreeNode const *nodeP = (DeviceTreeNode const *) (void const *) startingP;
297 unsigned int k;
298
299 ASSERT_HEADER_IN_DT(nodeP, sizeof(DeviceTreeNode));
300
301 if (nodeP->nProperties == 0) {
302 return kError; // End of the list of nodes
303 }
304 startingP = (char const *) (nodeP + 1);
305
306 // Search current entry
307 for (k = 0; k < nodeP->nProperties; ++k) {
308 DeviceTreeNodeProperty const *propP = (DeviceTreeNodeProperty const *) (void const *) startingP;
309 ASSERT_PROP_IN_DT(propP);
310
311 startingP += sizeof(*propP) + ((propP->length + 3) & -4);
312
313 if (strcmp(propP->name, propName) == 0) {
314 if (propValue == NULL || strcmp((char const *)(propP + 1), propValue) == 0) {
315 *entryH = (DTEntry)nodeP;
316 ASSERT_HEADER_IN_DT(*entryH, sizeof(DeviceTreeNode));
317 return kSuccess;
318 }
319 }
320 }
321
322 // Search child nodes
323 for (k = 0; k < nodeP->nChildren; ++k) {
324 if (find_entry(propName, propValue, entryH) == kSuccess) {
325 return kSuccess;
326 }
327 }
328 return kError;
329 }
330
331 /**
332 * @brief Recursive helper function for SecureDTFindNodeWithPropertyEqualToValue().
333 *
334 * @param[in] currentNode The root node of the subtree currently being searched.
335 * @param[out] currentNodeSize The size (in bytes) of the current node. This is
336 * only set if the current subtree doesn't contain the target node so that our
337 * parent can know where to continue the search.
338 */
339 static int
SecureDTFindNodeWithPropertyEqualToValueHelper(const char * const propertyName,const void * const propertyValue,const size_t propertyValueSize,const DeviceTreeNode ** const devicetreeNode,const DeviceTreeNode * const currentNode,size_t * const currentNodeSize)340 SecureDTFindNodeWithPropertyEqualToValueHelper(
341 const char *const propertyName,
342 const void *const propertyValue,
343 const size_t propertyValueSize,
344 const DeviceTreeNode **const devicetreeNode,
345 const DeviceTreeNode *const currentNode,
346 size_t *const currentNodeSize)
347 {
348 // This variable tracks our current position in the devicetree blob. This is
349 // necessary because the sizes of both properties and nodes are variable.
350 uintptr_t current_position = (uintptr_t)(currentNode + 1);
351
352 // Check to see if the target node is this one. That is, check if the
353 // current node has the specified property equal to the specified value.
354 for (int i = 0; i < currentNode->nProperties; i++) {
355 const DeviceTreeNodeProperty *const property = (const DeviceTreeNodeProperty *const)current_position;
356
357 // Move on if the property name doesn't match.
358 if (strncmp(propertyName, property->name, kPropNameLength) != 0) {
359 goto next_property;
360 }
361
362 // Move on if the property value doesn't match.
363 if (propertyValueSize != property->length) {
364 goto next_property;
365 }
366 const void *const value = property + 1;
367 if (memcmp(propertyValue, value, propertyValueSize) != 0) {
368 goto next_property;
369 }
370
371 // Both name and value match!
372 *devicetreeNode = currentNode;
373 return kSuccess;
374
375 next_property:
376 // The next property can be found at the closest 4-byte boundary after
377 // the current property's value.
378 current_position += sizeof(DeviceTreeNodeProperty) + ((property->length + 3) & ~3);
379 }
380
381 // If we're here, then the current node isn't the target node. Check to see
382 // if the target node can be found in any of the child subtrees.
383 for (int i = 0; i < currentNode->nChildren; i++) {
384 const DeviceTreeNode *const child = (const DeviceTreeNode *const)current_position;
385 size_t child_size;
386 const int retval = SecureDTFindNodeWithPropertyEqualToValueHelper(
387 propertyName,
388 propertyValue,
389 propertyValueSize,
390 devicetreeNode,
391 child,
392 &child_size);
393 if (retval == kSuccess) {
394 return kSuccess;
395 }
396 current_position += child_size;
397 }
398
399 // The target node cannot be found in the current subtree.
400 *currentNodeSize = current_position - (uintptr_t)currentNode;
401 return kError;
402 }
403
404 int
SecureDTFindNodeWithPropertyEqualToValue(const char * const propertyName,const void * const propertyValue,const size_t propertyValueSize,const DeviceTreeNode ** const devicetreeNode)405 SecureDTFindNodeWithPropertyEqualToValue(
406 const char *const propertyName,
407 const void *const propertyValue,
408 const size_t propertyValueSize,
409 const DeviceTreeNode **const devicetreeNode)
410 {
411 if (!DTInitialized) {
412 return kError;
413 }
414 size_t unused;
415 return SecureDTFindNodeWithPropertyEqualToValueHelper(
416 propertyName,
417 propertyValue,
418 propertyValueSize,
419 devicetreeNode,
420 DTRootNode,
421 &unused);
422 };
423
424 int
SecureDTFindNodeWithPhandle(const uint32_t phandle,const DeviceTreeNode ** const devicetreeNode)425 SecureDTFindNodeWithPhandle(
426 const uint32_t phandle,
427 const DeviceTreeNode **const devicetreeNode)
428 {
429 return SecureDTFindNodeWithPropertyEqualToValue(
430 "AAPL,phandle",
431 &phandle,
432 sizeof(phandle),
433 devicetreeNode);
434 }
435
436 int
SecureDTFindNodeWithStringProperty(const char * const propertyName,const char * const propertyValue,const DeviceTreeNode ** const devicetreeNode)437 SecureDTFindNodeWithStringProperty(
438 const char *const propertyName,
439 const char *const propertyValue,
440 const DeviceTreeNode **const devicetreeNode)
441 {
442 // The property length for strings that gets encoded in the devicetree blob
443 // includes the null-terminator.
444 return SecureDTFindNodeWithPropertyEqualToValue(
445 propertyName,
446 propertyValue,
447 strlen(propertyValue) + 1,
448 devicetreeNode);
449 }
450
451 int
SecureDTLookupEntry(const DTEntry searchPoint,const char * pathName,DTEntry * foundEntry)452 SecureDTLookupEntry(const DTEntry searchPoint, const char *pathName, DTEntry *foundEntry)
453 {
454 DTEntryNameBuf buf;
455 RealDTEntry cur;
456 const char * cp;
457
458 if (!DTInitialized) {
459 return kError;
460 }
461 if (searchPoint == NULL) {
462 cur = DTRootNode;
463 } else {
464 cur = searchPoint;
465 }
466 ASSERT_IN_DT(cur);
467 cp = pathName;
468 if (*cp == kDTPathNameSeparator) {
469 cp++;
470 if (*cp == 0) {
471 *foundEntry = cur;
472 return kSuccess;
473 }
474 }
475 do {
476 cp = GetNextComponent(cp, buf);
477
478 /* Check for done */
479 if (*buf == 0) {
480 if (*cp == 0) {
481 *foundEntry = cur;
482 return kSuccess;
483 }
484 break;
485 }
486
487 cur = FindChild(cur, buf);
488 } while (cur != NULL);
489
490 return kError;
491 }
492
493 int
SecureDTInitEntryIterator(const DTEntry startEntry,DTEntryIterator iter)494 SecureDTInitEntryIterator(const DTEntry startEntry, DTEntryIterator iter)
495 {
496 if (!DTInitialized) {
497 return kError;
498 }
499
500 if (startEntry != NULL) {
501 iter->outerScope = (RealDTEntry) startEntry;
502 iter->currentScope = (RealDTEntry) startEntry;
503 } else {
504 iter->outerScope = DTRootNode;
505 iter->currentScope = DTRootNode;
506 }
507 iter->currentEntry = NULL;
508 iter->savedScope = NULL;
509 iter->currentIndex = 0;
510
511 return kSuccess;
512 }
513
514 int
SecureDTEnterEntry(DTEntryIterator iter,DTEntry childEntry)515 SecureDTEnterEntry(DTEntryIterator iter, DTEntry childEntry)
516 {
517 DTSavedScopePtr newScope;
518
519 if (childEntry == NULL) {
520 return kError;
521 }
522 newScope = (DTSavedScopePtr) kalloc_type(struct DTSavedScope, Z_WAITOK);
523 newScope->nextScope = iter->savedScope;
524 newScope->scope = iter->currentScope;
525 newScope->entry = iter->currentEntry;
526 newScope->index = iter->currentIndex;
527
528 iter->currentScope = childEntry;
529 iter->currentEntry = NULL;
530 iter->savedScope = newScope;
531 iter->currentIndex = 0;
532
533 return kSuccess;
534 }
535
536 int
SecureDTExitEntry(DTEntryIterator iter,DTEntry * currentPosition)537 SecureDTExitEntry(DTEntryIterator iter, DTEntry *currentPosition)
538 {
539 DTSavedScopePtr newScope;
540
541 newScope = iter->savedScope;
542 if (newScope == NULL) {
543 return kError;
544 }
545 iter->savedScope = newScope->nextScope;
546 iter->currentScope = newScope->scope;
547 iter->currentEntry = newScope->entry;
548 iter->currentIndex = newScope->index;
549 *currentPosition = iter->currentEntry;
550
551 kfree_type(struct DTSavedScope, newScope);
552
553 return kSuccess;
554 }
555
556 int
SecureDTIterateEntries(DTEntryIterator iter,DTEntry * nextEntry)557 SecureDTIterateEntries(DTEntryIterator iter, DTEntry *nextEntry)
558 {
559 if (iter->currentIndex >= iter->currentScope->nChildren) {
560 *nextEntry = NULL;
561 return kIterationDone;
562 } else {
563 iter->currentIndex++;
564 if (iter->currentIndex == 1) {
565 iter->currentEntry = GetFirstChild(iter->currentScope);
566 } else {
567 iter->currentEntry = GetNextChild(iter->currentEntry);
568 }
569 ASSERT_IN_DT(iter->currentEntry);
570 *nextEntry = iter->currentEntry;
571 return kSuccess;
572 }
573 }
574
575 int
SecureDTRestartEntryIteration(DTEntryIterator iter)576 SecureDTRestartEntryIteration(DTEntryIterator iter)
577 {
578 #if 0
579 // This commented out code allows a second argument (outer)
580 // which (if true) causes restarting at the outer scope
581 // rather than the current scope.
582 DTSavedScopePtr scope;
583
584 if (outer) {
585 while ((scope = iter->savedScope) != NULL) {
586 iter->savedScope = scope->nextScope;
587 kfree_type(struct DTSavedScope, scope);
588 }
589 iter->currentScope = iter->outerScope;
590 }
591 #endif
592 iter->currentEntry = NULL;
593 iter->currentIndex = 0;
594 return kSuccess;
595 }
596
597 static int
SecureDTGetPropertyInternal(const DTEntry entry,const char * propertyName,void const ** propertyValue,unsigned int * propertySize,vm_offset_t const region_start,vm_size_t region_size)598 SecureDTGetPropertyInternal(const DTEntry entry, const char *propertyName, void const **propertyValue, unsigned int *propertySize, vm_offset_t const region_start, vm_size_t region_size)
599 {
600 DeviceTreeNodeProperty const *prop;
601 unsigned int k;
602
603 if (entry == NULL) {
604 return kError;
605 }
606
607 ASSERT_HEADER_IN_DT_REGION(region_start, region_start + region_size, entry, sizeof(DeviceTreeNode));
608
609 if (entry->nProperties == 0) {
610 return kError;
611 } else {
612 prop = (DeviceTreeNodeProperty const *) (entry + 1);
613 for (k = 0; k < entry->nProperties; k++) {
614 assert_prop_in_dt_region(region_start, region_start + region_size, prop);
615 if (strcmp(prop->name, propertyName) == 0) {
616 *propertyValue = (void const *) (((uintptr_t)prop)
617 + sizeof(DeviceTreeNodeProperty));
618 *propertySize = prop->length;
619 return kSuccess;
620 }
621 prop = next_prop_region(region_start, region_start + region_size, prop);
622 }
623 }
624 return kError;
625 }
626
627 int
SecureDTGetProperty(const DTEntry entry,const char * propertyName,void const ** propertyValue,unsigned int * propertySize)628 SecureDTGetProperty(const DTEntry entry, const char *propertyName, void const **propertyValue, unsigned int *propertySize)
629 {
630 return SecureDTGetPropertyInternal(entry, propertyName, propertyValue, propertySize,
631 (vm_offset_t)DTRootNode, (vm_size_t)((uintptr_t)DTEnd - (uintptr_t)DTRootNode));
632 }
633
634 int
SecureDTGetPropertyRegion(const DTEntry entry,const char * propertyName,void const ** propertyValue,unsigned int * propertySize,vm_offset_t const region_start,vm_size_t region_size)635 SecureDTGetPropertyRegion(const DTEntry entry, const char *propertyName, void const **propertyValue, unsigned int *propertySize, vm_offset_t const region_start, vm_size_t region_size)
636 {
637 return SecureDTGetPropertyInternal(entry, propertyName, propertyValue, propertySize,
638 region_start, region_size);
639 }
640
641
642 int
SecureDTInitPropertyIterator(const DTEntry entry,DTPropertyIterator iter)643 SecureDTInitPropertyIterator(const DTEntry entry, DTPropertyIterator iter)
644 {
645 iter->entry = entry;
646 iter->currentProperty = NULL;
647 iter->currentIndex = 0;
648 return kSuccess;
649 }
650
651 int
SecureDTIterateProperties(DTPropertyIterator iter,char const ** foundProperty)652 SecureDTIterateProperties(DTPropertyIterator iter, char const **foundProperty)
653 {
654 if (iter->currentIndex >= iter->entry->nProperties) {
655 *foundProperty = NULL;
656 return kIterationDone;
657 } else {
658 iter->currentIndex++;
659 if (iter->currentIndex == 1) {
660 iter->currentProperty = (DeviceTreeNodeProperty const *) (iter->entry + 1);
661 } else {
662 iter->currentProperty = next_prop(iter->currentProperty);
663 }
664 ASSERT_PROP_IN_DT(iter->currentProperty);
665 *foundProperty = iter->currentProperty->name;
666 return kSuccess;
667 }
668 }
669
670 int
SecureDTRestartPropertyIteration(DTPropertyIterator iter)671 SecureDTRestartPropertyIteration(DTPropertyIterator iter)
672 {
673 iter->currentProperty = NULL;
674 iter->currentIndex = 0;
675 return kSuccess;
676 }
677