-
Notifications
You must be signed in to change notification settings - Fork 3
/
kextd_usernotification.c
2429 lines (2159 loc) · 96.4 KB
/
kextd_usernotification.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/*
* Copyright (c) 2008 Apple Inc. All rights reserved.
*
* @APPLE_OSREFERENCE_LICENSE_HEADER_START@
*
* This file contains Original Code and/or Modifications of Original Code
* as defined in and that are subject to the Apple Public Source License
* Version 2.0 (the 'License'). You may not use this file except in
* compliance with the License. The rights granted to you under the License
* may not be used to create, or enable the creation or redistribution of,
* unlawful or unlicensed copies of an Apple operating system, or to
* circumvent, violate, or enable the circumvention or violation of, any
* terms of an Apple operating system software license agreement.
*
* Please obtain a copy of the License at
* http://www.opensource.apple.com/apsl/ and read it before using this file.
*
* The Original Code and all software distributed under the License are
* distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
* EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
* INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
* Please see the License for the specific language governing rights and
* limitations under the License.
*
* @APPLE_OSREFERENCE_LICENSE_HEADER_END@
*/
#include <IOKit/kext/kextmanager_types.h>
#include <IOKit/kext/OSKextPrivate.h>
#include "kextd_usernotification.h"
#include "security.h"
//#include <ApplicationServices/ApplicationServices.h>
// xxx - do we want a new log activity flag?
#ifdef NO_CFUserNotification
void kextd_raise_notification(
CFStringRef alertHeader,
CFArrayRef alertMessageArray)
{
return;
}
#else
SCDynamicStoreRef sSysConfigDynamicStore = NULL;
uid_t sConsoleUser = (uid_t)-1;
CFRunLoopSourceRef sNotificationQueueRunLoopSource = NULL; // must release
CFMutableArrayRef sPendedNonsecureKextPaths = NULL; // must release
CFUserNotificationRef sNonSecureNotification = NULL; // must release
CFRunLoopSourceRef sNonSecureNotificationRunLoopSource = NULL; // must release
CFMutableDictionaryRef sNotifiedNonsecureKextPaths = NULL; // must release
CFMutableArrayRef sPendedRevokedCertKextPaths = NULL; // must release
CFUserNotificationRef sRevokedCertNotification = NULL; // must release
CFRunLoopSourceRef sRevokedCertNotificationRunLoopSource = NULL; // must release
#if 0 // not yet
CFMutableArrayRef sPendedUnsignedKextPaths = NULL; // must release
CFUserNotificationRef sUnsignedKextNotification = NULL; // must release
CFRunLoopSourceRef sUnsignedKextNotificationRunLoopSource = NULL; // must release
#endif
CFMutableArrayRef sPendedNoLoadKextPaths = NULL; // must release
CFUserNotificationRef sNoLoadKextNotification = NULL; // must release
CFRunLoopSourceRef sNoLoadKextNotificationRunLoopSource = NULL; // must release
CFMutableArrayRef sPendedInvalidSignedKextPaths = NULL; // must release
CFUserNotificationRef sInvalidSigNotification = NULL; // must release
CFRunLoopSourceRef sInvalidSigNotificationRunLoopSource = NULL; // must release
CFMutableArrayRef sPendedExcludedKextPaths = NULL; // must release
CFUserNotificationRef sExcludedKextNotification = NULL; // must release
CFRunLoopSourceRef sExcludedKextNotificationRunLoopSource = NULL; // must release
CFDictionaryRef sKextTranslationsPlist = NULL;
static void _sessionDidChange(
SCDynamicStoreRef store,
CFArrayRef changedKeys,
void * info);
void _checkNotificationQueue(void * info);
void _notificationDismissed(
CFUserNotificationRef userNotification,
CFOptionFlags responseFlags);
static CFStringRef createBundleMappingKey( CFStringRef theBundleID );
static Boolean isInAlertsSentArray(
CFArrayRef theSentArray,
CFDictionaryRef theDict,
CFStringRef theMappingKey );
static CFStringRef getKextAlertMessage(
CFDictionaryRef theDict,
CFStringRef theMappingKey );
static Boolean sendKextAlertNotifications(
CFMutableArrayRef * theSentAlertsArrayPtr,
CFArrayRef theKextsArray,
int theAlertType );
static CFStringRef createPathFromAlertType(
CFStringRef theVolRoot,
int theAlertType );
static Boolean doingSystemInstall(void);
static void kextd_raise_nonsecure_notification(
CFStringRef alertHeader,
CFArrayRef alertMessageArray );
static void kextd_raise_noload_notification(
CFStringRef alertHeader,
CFArrayRef alertMessageArray );
static void kextd_raise_invalidsig_notification(
CFStringRef alertHeader,
CFArrayRef alertMessageArray );
static void kextd_raise_revokedcert_notification(
CFStringRef alertHeader,
CFArrayRef alertMessageArray );
static void revealInFinder( CFArrayRef theArray );
#if 0 // not yet
static void kextd_raise_unsignedkext_notification(
CFStringRef alertHeader,
CFArrayRef alertMessageArray );
#endif
static void kextd_raise_excludedkext_notification(
CFStringRef alertHeader,
CFArrayRef alertMessageArray );
static int validateKextsAlertDict( CFDictionaryRef theDict );
/*******************************************************************************
*******************************************************************************/
ExitStatus startMonitoringConsoleUser(
KextdArgs * toolArgs,
unsigned int * sourcePriority)
{
ExitStatus result = EX_OSERR;
CFStringRef consoleUserName = NULL; // must release
CFStringRef consoleUserKey = NULL; // must release
CFMutableArrayRef keys = NULL; // must release
CFRunLoopSourceRef sysConfigRunLoopSource = NULL; // must release
CFRunLoopSourceContext sourceContext;
sSysConfigDynamicStore = SCDynamicStoreCreate(
kCFAllocatorDefault, CFSTR(KEXTD_SERVER_NAME),
_sessionDidChange, /* context */ NULL);
if (!sSysConfigDynamicStore) {
OSKextLogMemError();
goto finish;
}
consoleUserName = SCDynamicStoreCopyConsoleUser(sSysConfigDynamicStore,
&sConsoleUser, NULL);
if (!consoleUserName) {
sConsoleUser = (uid_t)-1;
OSKextLog(/* kext */ NULL,
kOSKextLogDebugLevel | kOSKextLogGeneralFlag,
"No user logged in at kextd startup.");
} else {
OSKextLog(/* kext */ NULL,
kOSKextLogDebugLevel | kOSKextLogGeneralFlag,
"User %d logged in at kextd startup.", sConsoleUser);
}
consoleUserKey = SCDynamicStoreKeyCreateConsoleUser(kCFAllocatorDefault);
if (!consoleUserKey) {
OSKextLogMemError();
goto finish;
}
keys = CFArrayCreateMutable(kCFAllocatorDefault, 0, &kCFTypeArrayCallBacks);
if (!keys) {
OSKextLogMemError();
goto finish;
}
CFArrayAppendValue(keys, consoleUserKey);
SCDynamicStoreSetNotificationKeys(sSysConfigDynamicStore, keys,
/* patterns */ NULL);
sysConfigRunLoopSource = SCDynamicStoreCreateRunLoopSource(
kCFAllocatorDefault, sSysConfigDynamicStore, 0);
if (!sysConfigRunLoopSource) {
OSKextLogMemError();
goto finish;
}
CFRunLoopAddSource(CFRunLoopGetCurrent(), sysConfigRunLoopSource,
kCFRunLoopCommonModes);
bzero(&sourceContext, sizeof(CFRunLoopSourceContext));
sourceContext.version = 0;
sourceContext.perform = _checkNotificationQueue;
sNotificationQueueRunLoopSource = CFRunLoopSourceCreate(kCFAllocatorDefault,
(*sourcePriority)++, &sourceContext);
if (!sNotificationQueueRunLoopSource) {
OSKextLog(/* kext */ NULL, kOSKextLogErrorLevel | kOSKextLogGeneralFlag,
"Failed to create alert run loop source.");
goto finish;
}
CFRunLoopAddSource(CFRunLoopGetCurrent(), sNotificationQueueRunLoopSource,
kCFRunLoopDefaultMode);
if (!createCFMutableArray(&sPendedNonsecureKextPaths,
&kCFTypeArrayCallBacks)) {
OSKextLogMemError();
goto finish;
}
if (!createCFMutableArray(&sPendedNoLoadKextPaths,
&kCFTypeArrayCallBacks)) {
OSKextLogMemError();
goto finish;
}
if (!createCFMutableArray(&sPendedRevokedCertKextPaths,
&kCFTypeArrayCallBacks)) {
OSKextLogMemError();
goto finish;
}
#if 0 // not yet
if (!createCFMutableArray(&sPendedUnsignedKextPaths,
&kCFTypeArrayCallBacks)) {
OSKextLogMemError();
goto finish;
}
#endif
if (!createCFMutableArray(&sPendedInvalidSignedKextPaths,
&kCFTypeArrayCallBacks)) {
OSKextLogMemError();
goto finish;
}
if (!createCFMutableArray(&sPendedExcludedKextPaths,
&kCFTypeArrayCallBacks)) {
OSKextLogMemError();
goto finish;
}
if (!createCFMutableDictionary(&sNotifiedNonsecureKextPaths)) {
OSKextLogMemError();
goto finish;
}
result = EX_OK;
finish:
SAFE_RELEASE(consoleUserName);
SAFE_RELEASE(consoleUserKey);
SAFE_RELEASE(keys);
SAFE_RELEASE(sysConfigRunLoopSource);
return result;
}
/*******************************************************************************
*******************************************************************************/
void stopMonitoringConsoleUser(void)
{
SAFE_RELEASE(sSysConfigDynamicStore);
SAFE_RELEASE(sNotificationQueueRunLoopSource);
SAFE_RELEASE(sPendedNonsecureKextPaths);
SAFE_RELEASE(sPendedNoLoadKextPaths);
SAFE_RELEASE(sPendedRevokedCertKextPaths);
SAFE_RELEASE(sPendedInvalidSignedKextPaths);
// SAFE_RELEASE(sPendedUnsignedKextPaths);
SAFE_RELEASE(sPendedExcludedKextPaths);
SAFE_RELEASE(sNotifiedNonsecureKextPaths);
return;
}
/*******************************************************************************
*******************************************************************************/
static void _sessionDidChange(
SCDynamicStoreRef store,
CFArrayRef changedKeys,
void * info)
{
CFStringRef consoleUserName = NULL; // must release
uid_t oldUser = sConsoleUser;
/* If any users are logged on via fast user switching, logging out to
* loginwindow sets the console user to 0 (root). We can't do a reset
* until all users have fully logged out, in which case
* SCDynamicStoreCopyConsoleUser() returns NULL.
*/
consoleUserName = SCDynamicStoreCopyConsoleUser(sSysConfigDynamicStore,
&sConsoleUser, NULL);
if (!consoleUserName) {
if (oldUser != (uid_t)-1) {
OSKextLog(/* kext */ NULL,
kOSKextLogDebugLevel | kOSKextLogGeneralFlag,
"User %d logged out.", oldUser);
}
sConsoleUser = (uid_t)-1;
resetUserNotifications(/* dismissAlert */ true);
goto finish;
}
/* Sometimes we'll get >1 notification on a user login, so make sure
* the old & new uid are different.
*/
if (sConsoleUser != (uid_t)-1 && oldUser != sConsoleUser) {
OSKextLog(/* kext */ NULL,
kOSKextLogDebugLevel | kOSKextLogGeneralFlag,
"User %d logged in.", sConsoleUser);
CFRunLoopSourceSignal(sNotificationQueueRunLoopSource);
CFRunLoopWakeUp(CFRunLoopGetCurrent());
}
finish:
SAFE_RELEASE(consoleUserName);
return;
}
/*******************************************************************************
*******************************************************************************/
void resetUserNotifications(Boolean dismissAlert)
{
OSKextLog(/* kext */ NULL,
kOSKextLogDebugLevel | kOSKextLogGeneralFlag,
"Resetting user notifications.");
if (dismissAlert) {
/* Release any reference to any pending user notifications.
*/
if (sNonSecureNotification) {
CFUserNotificationCancel(sNonSecureNotification);
CFRelease(sNonSecureNotification);
sNonSecureNotification = NULL;
}
if (sNonSecureNotificationRunLoopSource) {
CFRunLoopRemoveSource(CFRunLoopGetCurrent(),
sNonSecureNotificationRunLoopSource,
kCFRunLoopDefaultMode);
CFRelease(sNonSecureNotificationRunLoopSource);
sNonSecureNotificationRunLoopSource = NULL;
}
if (sNoLoadKextNotification) {
CFUserNotificationCancel(sNoLoadKextNotification);
CFRelease(sNoLoadKextNotification);
sNoLoadKextNotification = NULL;
}
if (sNoLoadKextNotificationRunLoopSource) {
CFRunLoopRemoveSource(CFRunLoopGetCurrent(),
sNoLoadKextNotificationRunLoopSource,
kCFRunLoopDefaultMode);
CFRelease(sNoLoadKextNotificationRunLoopSource);
sNoLoadKextNotificationRunLoopSource = NULL;
}
if (sRevokedCertNotification) {
CFUserNotificationCancel(sRevokedCertNotification);
CFRelease(sRevokedCertNotification);
sRevokedCertNotification = NULL;
}
if (sRevokedCertNotificationRunLoopSource) {
CFRunLoopRemoveSource(CFRunLoopGetCurrent(),
sRevokedCertNotificationRunLoopSource,
kCFRunLoopDefaultMode);
CFRelease(sRevokedCertNotificationRunLoopSource);
sRevokedCertNotificationRunLoopSource = NULL;
}
#if 0 // not yet
if (sUnsignedKextNotification) {
CFUserNotificationCancel(sUnsignedKextNotification);
CFRelease(sUnsignedKextNotification);
sUnsignedKextNotification = NULL;
}
if (sUnsignedKextNotificationRunLoopSource) {
CFRunLoopRemoveSource(CFRunLoopGetCurrent(),
sUnsignedKextNotificationRunLoopSource,
kCFRunLoopDefaultMode);
CFRelease(sUnsignedKextNotificationRunLoopSource);
sUnsignedKextNotificationRunLoopSource = NULL;
}
#endif
if (sInvalidSigNotification) {
CFUserNotificationCancel(sInvalidSigNotification);
CFRelease(sInvalidSigNotification);
sInvalidSigNotification = NULL;
}
if (sInvalidSigNotificationRunLoopSource) {
CFRunLoopRemoveSource(CFRunLoopGetCurrent(),
sInvalidSigNotificationRunLoopSource,
kCFRunLoopDefaultMode);
CFRelease(sInvalidSigNotificationRunLoopSource);
sInvalidSigNotificationRunLoopSource = NULL;
}
if (sExcludedKextNotification) {
CFUserNotificationCancel(sExcludedKextNotification);
CFRelease(sExcludedKextNotification);
sExcludedKextNotification = NULL;
}
if (sExcludedKextNotificationRunLoopSource) {
CFRunLoopRemoveSource(CFRunLoopGetCurrent(),
sExcludedKextNotificationRunLoopSource,
kCFRunLoopDefaultMode);
CFRelease(sExcludedKextNotificationRunLoopSource);
sExcludedKextNotificationRunLoopSource = NULL;
}
}
/* Clear the record of which kexts the user has been told are insecure.
* If extensions folders have been modified, who knows which kexts are changed?
* If user is logging out, logging back in will get the same alerts.
*/
CFArrayRemoveAllValues(sPendedNonsecureKextPaths);
CFDictionaryRemoveAllValues(sNotifiedNonsecureKextPaths);
/* clean up pending kext alerts too */
CFArrayRemoveAllValues(sPendedRevokedCertKextPaths);
CFArrayRemoveAllValues(sPendedNoLoadKextPaths);
CFArrayRemoveAllValues(sPendedInvalidSignedKextPaths);
// CFArrayRemoveAllValues(sPendedUnsignedKextPaths);
CFArrayRemoveAllValues(sPendedExcludedKextPaths);
return;
}
/*******************************************************************************
*******************************************************************************/
void _checkNotificationQueue(void * info __unused)
{
CFStringRef kextPath = NULL; // do not release
CFMutableArrayRef nonsecureAlertMessageArray = NULL; // must release
CFMutableArrayRef noLoadAlertMessageArray = NULL; // must release
CFMutableArrayRef revokedCertAlertMessageArray = NULL; // must release
CFMutableArrayRef invalidSigAlertMessageArray = NULL; // must release
CFMutableArrayRef unsignedKextAlertMessageArray = NULL; // must release
CFMutableArrayRef excludedAlertMessageArray = NULL; // must release
CFMutableStringRef excludedAlertHeader = NULL; // must release
CFIndex count, i;
if (sConsoleUser == (uid_t)-1) {
goto finish;
}
/* handle alerts for kexts that do not have the proper privs set
*/
if (CFArrayGetCount(sPendedNonsecureKextPaths) &&
sNonSecureNotificationRunLoopSource == NULL) {
nonsecureAlertMessageArray = CFArrayCreateMutable(kCFAllocatorDefault,
0,
&kCFTypeArrayCallBacks);
if (nonsecureAlertMessageArray == NULL) {
goto finish;
}
kextPath = (CFStringRef) CFArrayGetValueAtIndex(
sPendedNonsecureKextPaths, 0);
if (!kextPath) {
goto finish;
}
/* This is the localized format string for the alert message.
*/
CFArrayAppendValue(nonsecureAlertMessageArray,
CFSTR("The system extension \""));
CFArrayAppendValue(nonsecureAlertMessageArray, kextPath);
CFArrayAppendValue(nonsecureAlertMessageArray,
CFSTR("\" was installed improperly and cannot be used. "
"Please try reinstalling it, or contact the product's vendor "
"for an update."));
CFArrayRemoveValueAtIndex(sPendedNonsecureKextPaths, 0);
kextd_raise_nonsecure_notification(CFSTR("System extension cannot be used"),
nonsecureAlertMessageArray);
}
/* handle alerts for kext signature verification errors that result
* in a kext not loading (currently only kexts in /Library/Extensions/
*/
count = CFArrayGetCount(sPendedNoLoadKextPaths);
if (count > 0 && sNoLoadKextNotificationRunLoopSource == NULL) {
noLoadAlertMessageArray = CFArrayCreateMutable(
kCFAllocatorDefault,
0,
&kCFTypeArrayCallBacks );
if (noLoadAlertMessageArray == NULL) {
goto finish;
}
CFArrayAppendValue(
noLoadAlertMessageArray,
(count > 1 ? CFSTR("The following kernel extensions can't "
"be loaded because they are from "
"unidentified developers. Extensions "
"loaded from /Library/Extensions must be "
"signed by identified developers. \r")
: CFSTR("The kernel extension at \"")) );
for (i = 0; i < count; i ++) {
kextPath = (CFStringRef)
CFArrayGetValueAtIndex( sPendedNoLoadKextPaths, i );
if (kextPath) {
if (count > 1) {
CFArrayAppendValue(noLoadAlertMessageArray, CFSTR("\r"));
}
CFArrayAppendValue(noLoadAlertMessageArray, kextPath);
}
}
if (count == 1) {
CFArrayAppendValue(noLoadAlertMessageArray,
CFSTR("\" can't be loaded because it is from an "
"unidentified developer. Extensions "
"loaded from /Library/Extensions must be "
"signed by identified developers."));
}
CFArrayAppendValue(noLoadAlertMessageArray,
CFSTR("\r\rPlease contact the kernel extension "
"vendor for updated software."));
CFArrayRemoveAllValues(sPendedNoLoadKextPaths);
kextd_raise_noload_notification(
(count > 1 ? CFSTR("Kernel extensions could not be loaded")
: CFSTR("Kernel extension could not be loaded")),
noLoadAlertMessageArray);
}
/* handle alerts for kexts with a revoked cert
*/
count = CFArrayGetCount(sPendedRevokedCertKextPaths);
if (count > 0 && sRevokedCertNotificationRunLoopSource == NULL) {
revokedCertAlertMessageArray = CFArrayCreateMutable(
kCFAllocatorDefault,
0,
&kCFTypeArrayCallBacks );
if (revokedCertAlertMessageArray == NULL) {
goto finish;
}
CFArrayAppendValue(
revokedCertAlertMessageArray,
(count > 1 ? CFSTR("The following kernel extensions "
"are damaged and can't be "
"loaded. \r")
: CFSTR("The kernel extension at \"")) );
for (i = 0; i < count; i ++) {
kextPath = (CFStringRef) CFArrayGetValueAtIndex(
sPendedRevokedCertKextPaths, i );
if (kextPath) {
if (count > 1) {
CFArrayAppendValue(revokedCertAlertMessageArray, CFSTR("\r"));
}
CFArrayAppendValue(revokedCertAlertMessageArray,
kextPath);
}
}
if (count == 1) {
CFArrayAppendValue(revokedCertAlertMessageArray,
CFSTR("\" is damaged and can't be loaded."));
}
CFArrayAppendValue(revokedCertAlertMessageArray,
(count > 1
? CFSTR("\r\rYou should move them to the Trash.")
: CFSTR("\r\rYou should move it to the Trash."))
);
// CFArrayRemoveAllValues(sPendedRevokedCertKextPaths); do not remove here, need to use these to reveal in Finder
kextd_raise_revokedcert_notification(
(count > 1 ? CFSTR("Kernel extensions could not be loaded")
: CFSTR("Kernel extension could not be loaded")),
revokedCertAlertMessageArray);
}
#if 0 // not yet
/* handle alerts for unsigned kexts
*/
count = CFArrayGetCount(sPendedUnsignedKextPaths);
if (count > 0 && sUnsignedKextNotificationRunLoopSource == NULL) {
unsignedKextAlertMessageArray = CFArrayCreateMutable(kCFAllocatorDefault,
0,
&kCFTypeArrayCallBacks);
if (unsignedKextAlertMessageArray == NULL) {
goto finish;
}
CFArrayAppendValue(unsignedKextAlertMessageArray,
CFSTR("The following kernel extensions are not "
"signed.\r"));
for (i = 0; i < count; i ++) {
kextPath = (CFStringRef) CFArrayGetValueAtIndex(
sPendedUnsignedKextPaths, i);
if (kextPath) {
CFArrayAppendValue(unsignedKextAlertMessageArray,
CFSTR("\r"));
CFArrayAppendValue(unsignedKextAlertMessageArray,
kextPath);
}
}
CFArrayAppendValue(unsignedKextAlertMessageArray,
CFSTR("\r\rPlease contact the vendor for each "
"kernel extension for updated software."));
CFArrayRemoveAllValues(sPendedUnsignedKextPaths);
kextd_raise_unsignedkext_notification(CFSTR("Kernel extensions are not signed"),
unsignedKextAlertMessageArray);
}
#endif
/* handle alerts for kext signature verification errors
*/
count = CFArrayGetCount(sPendedInvalidSignedKextPaths);
if (count > 0 && sInvalidSigNotificationRunLoopSource == NULL) {
invalidSigAlertMessageArray = CFArrayCreateMutable(kCFAllocatorDefault,
0,
&kCFTypeArrayCallBacks);
if (invalidSigAlertMessageArray == NULL) {
goto finish;
}
CFArrayAppendValue(invalidSigAlertMessageArray,
(count > 1 ? CFSTR("The following kernel extensions are not "
"from identified developers but will "
"still be loaded. \r")
: CFSTR("The kernel extension at \"")) );
for (i = 0; i < count; i ++) {
kextPath = (CFStringRef) CFArrayGetValueAtIndex(
sPendedInvalidSignedKextPaths, i);
if (kextPath) {
if (count > 1) {
CFArrayAppendValue(invalidSigAlertMessageArray, CFSTR("\r"));
}
CFArrayAppendValue(invalidSigAlertMessageArray, kextPath);
}
}
if (count == 1) {
CFArrayAppendValue(invalidSigAlertMessageArray,
CFSTR("\" is not from an identified developer "
"but will still be loaded."));
}
CFArrayAppendValue(invalidSigAlertMessageArray,
CFSTR("\r\rPlease contact the kernel extension "
"vendor for updated software."));
CFArrayRemoveAllValues(sPendedInvalidSignedKextPaths);
kextd_raise_invalidsig_notification(
(count > 1 ? CFSTR("Kernel extensions are not from identified "
"developers")
: CFSTR("Kernel extension is not from an identified "
"developer")),
invalidSigAlertMessageArray);
}
#if 1 // <rdar://problem/12811081> warn user about excluded kexts
count = CFArrayGetCount(sPendedExcludedKextPaths);
if (count > 0 && sExcludedKextNotificationRunLoopSource == NULL) {
excludedAlertMessageArray =
CFArrayCreateMutable(kCFAllocatorDefault,
0,
&kCFTypeArrayCallBacks);
if (excludedAlertMessageArray == NULL) {
goto finish;
}
excludedAlertHeader = CFStringCreateMutable(kCFAllocatorDefault, 0);
if (excludedAlertHeader == NULL) {
goto finish;
}
if (count > 1) {
CFStringAppend(excludedAlertHeader,
CFSTR("Some system extensions are not compatible with this version of OS X and can’t be used:"));
for (i = 0; i < count; i ++) {
kextPath = (CFStringRef) CFArrayGetValueAtIndex(
sPendedExcludedKextPaths, i);
if (kextPath) {
CFRange myRange;
myRange = CFStringFind(kextPath, CFSTR("/"), kCFCompareBackwards);
// just get kext name if possible, not the full path
if (myRange.length != 0 && myRange.location++ < CFStringGetLength(kextPath)) {
CFStringRef myString;
myRange.length = CFStringGetLength(kextPath) - myRange.location;
myString = CFStringCreateWithSubstring(kCFAllocatorDefault,
kextPath,
myRange);
if (myString) {
CFArrayAppendValue(excludedAlertMessageArray,
myString);
SAFE_RELEASE(myString);
}
else {
// fall back to full path
CFArrayAppendValue(excludedAlertMessageArray,
kextPath);
}
}
else {
// fall back to full path
CFArrayAppendValue(excludedAlertMessageArray,
kextPath);
}
CFArrayAppendValue(excludedAlertMessageArray,
CFSTR("\r"));
}
}
// one extra for "Please contact the developer..." to look good
CFArrayAppendValue(excludedAlertMessageArray,
CFSTR("\r"));
}
else {
kextPath = (CFStringRef) CFArrayGetValueAtIndex(
sPendedExcludedKextPaths, 0 );
if (kextPath == NULL) {
goto finish;
}
CFStringAppend(excludedAlertHeader,
CFSTR("The system extension \""));
CFRange myRange;
myRange = CFStringFind(kextPath, CFSTR("/"), kCFCompareBackwards);
// just get kext name if possible, not the full path
if (myRange.length != 0 && myRange.location++ < CFStringGetLength(kextPath)) {
CFStringRef myString;
myRange.length = CFStringGetLength(kextPath) - myRange.location;
myString = CFStringCreateWithSubstring(kCFAllocatorDefault,
kextPath,
myRange);
if (myString) {
CFStringAppend(excludedAlertHeader,
myString);
SAFE_RELEASE(myString);
}
else {
// fall back to full path
CFStringAppend(excludedAlertHeader,
kextPath);
}
}
else {
// fall back to full path
CFStringAppend(excludedAlertHeader,
kextPath);
}
CFStringAppend(excludedAlertHeader,
CFSTR("\" is not compatible with this version of OS X and can’t be used."));
}
CFArrayAppendValue(excludedAlertMessageArray,
CFSTR("Please contact the developer for updated software."));
CFArrayRemoveAllValues(sPendedExcludedKextPaths);
kextd_raise_excludedkext_notification(excludedAlertHeader,
excludedAlertMessageArray);
}
#endif // <rdar://problem/12811081>
finish:
SAFE_RELEASE(nonsecureAlertMessageArray);
SAFE_RELEASE(noLoadAlertMessageArray);
SAFE_RELEASE(excludedAlertMessageArray);
SAFE_RELEASE(revokedCertAlertMessageArray);
SAFE_RELEASE(invalidSigAlertMessageArray);
SAFE_RELEASE(unsignedKextAlertMessageArray);
SAFE_RELEASE(excludedAlertHeader);
return;
}
/******************************************************************************
******************************************************************************/
Boolean recordNonsecureKexts(CFArrayRef kextList)
{
Boolean result = false;
CFStringRef nonsecureKextPath = NULL; // must release
CFIndex count, i;
if (kextList && (count = CFArrayGetCount(kextList))) {
for (i = 0; i < count; i ++) {
OSKextRef checkKext = (OSKextRef)CFArrayGetValueAtIndex(kextList, i);
SAFE_RELEASE_NULL(nonsecureKextPath);
if (OSKextIsAuthentic(checkKext)) {
continue;
}
nonsecureKextPath = copyKextPath(checkKext);
if (!nonsecureKextPath) {
OSKextLogMemError();
goto finish;
}
if (!CFDictionaryGetValue(sNotifiedNonsecureKextPaths,
nonsecureKextPath)) {
CFArrayAppendValue(sPendedNonsecureKextPaths,
nonsecureKextPath);
CFDictionarySetValue(sNotifiedNonsecureKextPaths,
nonsecureKextPath, kCFBooleanTrue);
result = true;
}
}
}
finish:
SAFE_RELEASE(nonsecureKextPath);
if (result) {
CFRunLoopSourceSignal(sNotificationQueueRunLoopSource);
CFRunLoopWakeUp(CFRunLoopGetCurrent());
}
return result;
}
/*******************************************************************************
*******************************************************************************/
Boolean recordNoLoadKextPath(CFStringRef theKextPath)
{
Boolean result = false;
if (theKextPath == NULL) {
goto finish;
}
CFArrayAppendValue(sPendedNoLoadKextPaths, theKextPath);
result = true;
finish:
return result;
}
/*******************************************************************************
*******************************************************************************/
void sendNoLoadKextNotification(void)
{
if (CFArrayGetCount(sPendedNoLoadKextPaths)) {
CFRunLoopSourceSignal(sNotificationQueueRunLoopSource);
CFRunLoopWakeUp(CFRunLoopGetCurrent());
}
return;
}
/*******************************************************************************
*******************************************************************************/
void recordRevokedCertKextPath(CFStringRef theKextPath)
{
if (theKextPath == NULL) {
goto finish;
}
CFArrayAppendValue(sPendedRevokedCertKextPaths, theKextPath);
finish:
return;
}
/*******************************************************************************
*******************************************************************************/
void sendRevokedCertKextPath(void)
{
if (CFArrayGetCount(sPendedRevokedCertKextPaths)) {
CFRunLoopSourceSignal(sNotificationQueueRunLoopSource);
CFRunLoopWakeUp(CFRunLoopGetCurrent());
}
return;
}
/*******************************************************************************
*******************************************************************************/
Boolean recordInvalidSignedKextPath(CFStringRef theKextPath)
{
Boolean result = false;
if (theKextPath == NULL) {
goto finish;
}
CFArrayAppendValue(sPendedInvalidSignedKextPaths, theKextPath);
result = true;
finish:
return result;
}
/*******************************************************************************
*******************************************************************************/
void sendInvalidSignedKextNotification(void)
{
if (CFArrayGetCount(sPendedInvalidSignedKextPaths)) {
CFRunLoopSourceSignal(sNotificationQueueRunLoopSource);
CFRunLoopWakeUp(CFRunLoopGetCurrent());
}
return;
}
#if 0 // not yet
/*******************************************************************************
*******************************************************************************/
Boolean recordUnsignedKextPath(CFStringRef theKextPath)
{
Boolean result = false;
if (theKextPath == NULL) {
goto finish;
}
CFArrayAppendValue(sPendedUnsignedKextPaths, theKextPath);
result = true;
finish:
return result;
}
/*******************************************************************************
*******************************************************************************/
void sendUnsignedKextNotification(void)
{
if (CFArrayGetCount(sPendedUnsignedKextPaths)) {
CFRunLoopSourceSignal(sNotificationQueueRunLoopSource);
CFRunLoopWakeUp(CFRunLoopGetCurrent());
}
return;
}
#endif
/*******************************************************************************
*******************************************************************************/
Boolean recordExcludedKextPath(CFStringRef theKextPath)
{
Boolean result = false;
if (theKextPath == NULL) {
goto finish;
}
CFArrayAppendValue(sPendedExcludedKextPaths, theKextPath);
result = true;
finish:
return result;
}
/*******************************************************************************
*******************************************************************************/
void sendExcludedKextNotification(void)
{
if (CFArrayGetCount(sPendedExcludedKextPaths)) {
CFRunLoopSourceSignal(sNotificationQueueRunLoopSource);
CFRunLoopWakeUp(CFRunLoopGetCurrent());
}
return;
}
/*******************************************************************************
*******************************************************************************/
static CFMutableDictionaryRef createAlertDict(
CFStringRef alertHeader,
CFArrayRef alertMessageArray )
{
CFMutableDictionaryRef alertDict = NULL; // do not release
CFURLRef iokitFrameworkBundleURL = NULL; // must release
/* Do not alert if we're doing a system install */
if ( doingSystemInstall() ) {
goto finish;
}
OSKextLog(/* kext */ NULL,
kOSKextLogDebugLevel | kOSKextLogGeneralFlag,
"Raising user notification.");
if (sConsoleUser == (uid_t)-1) {
OSKextLog(/* kext */ NULL,
kOSKextLogDebugLevel | kOSKextLogGeneralFlag,
"No logged in user.");
goto finish;
}
iokitFrameworkBundleURL = CFURLCreateWithFileSystemPath(
kCFAllocatorDefault,
CFSTR("/System/Library/Frameworks/IOKit.framework"),
kCFURLPOSIXPathStyle, true);
if (!iokitFrameworkBundleURL) {
goto finish;
}
alertDict = CFDictionaryCreateMutable(
kCFAllocatorDefault, 0,
&kCFTypeDictionaryKeyCallBacks,
&kCFTypeDictionaryValueCallBacks);
if (!alertDict) {
goto finish;
}
CFDictionarySetValue(alertDict, kCFUserNotificationLocalizationURLKey,
iokitFrameworkBundleURL);
CFDictionarySetValue(alertDict, kCFUserNotificationAlertHeaderKey,
alertHeader);
CFDictionarySetValue(alertDict, kCFUserNotificationDefaultButtonTitleKey,
CFSTR("OK"));
CFDictionarySetValue(alertDict, kCFUserNotificationAlertMessageKey,
alertMessageArray);
finish:
SAFE_RELEASE(iokitFrameworkBundleURL);
return(alertDict);
}