]> git.saurik.com Git - apple/xnu.git/blob - bsd/dev/dtrace/fbt_blacklist.c
xnu-7195.60.75.tar.gz
[apple/xnu.git] / bsd / dev / dtrace / fbt_blacklist.c
1 /*
2 * CDDL HEADER START
3 *
4 * The contents of this file are subject to the terms of the
5 * Common Development and Distribution License (the "License").
6 * You may not use this file except in compliance with the License.
7 *
8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9 * or http://www.opensolaris.org/os/licensing.
10 * See the License for the specific language governing permissions
11 * and limitations under the License.
12 *
13 * When distributing Covered Code, include this CDDL HEADER in each
14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15 * If applicable, add the following below this CDDL HEADER, with the
16 * fields enclosed by brackets "[]" replaced with your own identifying
17 * information: Portions Copyright [yyyy] [name of copyright owner]
18 *
19 * CDDL HEADER END
20 */
21
22 #include <sys/dtrace_impl.h>
23 #include <sys/fbt.h>
24 #include <sys/sysctl.h>
25
26 #define CLOSURE(s) #s,
27 #define CRITICAL(s) #s,
28
29 #if KASAN
30 #define KASAN_ONLY(s) #s,
31 #else
32 #define KASAN_ONLY(s)
33 #endif /* KASAN */
34
35 #if defined(__arm__) || defined(__arm64__)
36 #define ARM_ONLY(s) #s,
37 #else
38 #define ARM_ONLY(s)
39 #endif /* defined(__arm__) || defined(__arm64__) */
40 #if defined(__x86_64__)
41 #define X86_ONLY(s) #s,
42 #else
43 #define X86_ONLY(s)
44 #endif /* defined(__x86_64__) */
45
46 /*
47 * Routine prefixes that must not be probed, either because they are used in
48 * the exception path, by dtrace code in probe context, or are general
49 * critical routines that must never be probed.
50 *
51 * All routines whose name start with one of these will be ignored.
52 *
53 * This must be kept in asciibetical order for purposes of bsearch().
54 */
55 const char * fbt_blacklist[] =
56 {
57 CRITICAL(Call_DebuggerC)
58 CLOSURE(ClearIdlePop)
59 CLOSURE(Debugger)
60 CRITICAL(IOCPURunPlatformPanicActions)
61 CLOSURE(IS_64BIT_PROCESS)
62 CRITICAL(OSAdd)
63 CRITICAL(OSBit)
64 CLOSURE(OSCompareAndSwap)
65 CRITICAL(OSDecrement)
66 CRITICAL(OSIncrement)
67 CRITICAL(PEARMDebugPanicHook)
68 CRITICAL(PEHaltRestart)
69 CRITICAL(PE_)
70 CRITICAL(SavePanicInfo)
71 CLOSURE(SetIdlePop)
72 CRITICAL(SysChoked)
73 CRITICAL(_ZN15OSMetaClassBase12safeMetaCastEPKS_PK11OSMetaClass) /* OSMetaClassBase::safeMetaCast */
74 CRITICAL(_ZN16IOPlatformExpert11haltRestartEj) /* IOPlatformExpert::haltRestart */
75 CRITICAL(_ZN18IODTPlatformExpert11haltRestartEj) /* IODTPlatformExpert::haltRestart */
76 ARM_ONLY(_ZN8ASPNVRAM4syncEv) /* ASPNVRAM::sync */
77 CRITICAL(_ZN9IODTNVRAM13savePanicInfoEPhy) /* IODTNVRAM::savePanicInfo */
78 CRITICAL(_ZN9IOService14newTemperatureElPS_) /* IOService::newTemperature */
79 CRITICAL(_ZN9IOService26temperatureCriticalForZoneEPS_) /* IOService::temperatureCriticalForZone */
80 CRITICAL(_ZNK11OSMetaClass13checkMetaCastEPK15OSMetaClassBase) /* OSMetaClass::checkMetaCast */
81 CRITICAL(_ZNK15OSMetaClassBase8metaCastEPK11OSMetaClass) /* OSMetaClassBase::metaCast */
82 CRITICAL(_ZNK6OSData14getBytesNoCopyEv) /* Data::getBytesNoCopy, IOHibernateSystemWake path */
83 KASAN_ONLY(__asan)
84 ARM_ONLY(__div)
85 CLOSURE(__dtrace_probe)
86 KASAN_ONLY(__kasan)
87 ARM_ONLY(__mod)
88 CRITICAL(__strlcpy_chk)
89 ARM_ONLY(__udiv)
90 ARM_ONLY(__umod)
91 CRITICAL(_disable_preemption)
92 CRITICAL(_enable_preemption)
93 CLOSURE(absolutetime_to_microtime)
94 X86_ONLY(acpi_)
95 X86_ONLY(act_machine)
96 CLOSURE(act_set_astbsd)
97 ARM_ONLY(alternate_debugger_enter)
98 ARM_ONLY(arm_init_idle_cpu)
99 CLOSURE(ast_dtrace_on)
100 CLOSURE(ast_pending)
101 CRITICAL(bcopy)
102 CLOSURE(clean_dcache)
103 CLOSURE(clean_mmu_dcache)
104 CRITICAL(clock_)
105 X86_ONLY(commpage_)
106 CRITICAL(console_cpu_alloc)
107 CRITICAL(console_cpu_free)
108 CLOSURE(copyin)
109 CLOSURE(copyout)
110 CRITICAL(cpu_)
111 CLOSURE(current_proc)
112 CLOSURE(current_processor)
113 CLOSURE(current_task)
114 CLOSURE(current_thread)
115 CLOSURE(debug_)
116 X86_ONLY(dsmos_)
117 CLOSURE(dtrace_)
118 CRITICAL(enter_lohandler)
119 CRITICAL(fasttrap_)
120 CRITICAL(fbt_invop)
121 CRITICAL(fbt_perfCallback)
122 CLOSURE(find_user_regs)
123 ARM_ONLY(fleh_)
124 CLOSURE(flush_dcache)
125 ARM_ONLY(flush_mmu_tlb_)
126 CLOSURE(flush_tlb64)
127 CRITICAL(fuword)
128 CLOSURE(get_bsdtask_info)
129 CLOSURE(get_bsdthread_info)
130 CRITICAL(get_preemption_level)
131 CRITICAL(get_threadtask)
132 ARM_ONLY(get_vfp_enabled)
133 CRITICAL(getminor)
134 CRITICAL(handle_pending_TLB_flushes)
135 CRITICAL(hibernate_)
136 X86_ONLY(hndl_)
137 CRITICAL(hw_)
138 X86_ONLY(idt64)
139 CRITICAL(interrupt)
140 CRITICAL(invalidate_mmu_icache)
141 CRITICAL(is_saved_state32)
142 KASAN_ONLY(kasan)
143 CLOSURE(kauth_cred_get)
144 CLOSURE(kauth_getgid)
145 CLOSURE(kauth_getuid)
146 CRITICAL(kdb_)
147 CRITICAL(kdp_)
148 CRITICAL(kernel_preempt_check)
149 CRITICAL(kernel_trap)
150 CRITICAL(kprintf)
151 CRITICAL(ks_)
152 CLOSURE(kvtophys)
153 X86_ONLY(lapic_)
154 CRITICAL(lo_alltraps)
155 CRITICAL(lock_debugger)
156 CLOSURE(mach_absolute_time)
157 CRITICAL(machine_)
158 X86_ONLY(mapping_)
159 CRITICAL(mca_cpu_alloc)
160 CRITICAL(mca_cpu_init)
161 CLOSURE(memcpy)
162 CLOSURE(memmove)
163 CRITICAL(ml_)
164 CLOSURE(mt_core_snap)
165 CLOSURE(mt_cur_cpu_cycles)
166 CLOSURE(mt_cur_cpu_instrs)
167 CLOSURE(mt_cur_thread_cycles)
168 CLOSURE(mt_cur_thread_instrs)
169 CLOSURE(mt_fixed_counts)
170 CLOSURE(mt_fixed_counts_internal)
171 CLOSURE(mt_mtc_update_count)
172 CLOSURE(mt_update_thread)
173 CRITICAL(nanoseconds_to_absolutetime)
174 CRITICAL(nanotime_to_absolutetime)
175 CRITICAL(no_asts)
176 CRITICAL(ovbcopy)
177 CRITICAL(packA)
178 X86_ONLY(pal_)
179 CLOSURE(panic)
180 CRITICAL(phystokv)
181 CRITICAL(platform_)
182 X86_ONLY(pltrace)
183 X86_ONLY(pmCPU)
184 X86_ONLY(pmKextRegister)
185 X86_ONLY(pmMarkAllCPUsOff)
186 X86_ONLY(pmSafeMode)
187 X86_ONLY(pmTimerRestore)
188 X86_ONLY(pmTimerSave)
189 X86_ONLY(pmUnRegister)
190 X86_ONLY(pmap64_pdpt)
191 CLOSURE(pmap_find_pa)
192 CLOSURE(pmap_find_phys)
193 ARM_ONLY(pmap_get_cpu_data)
194 CLOSURE(pmap_get_mapwindow)
195 CLOSURE(pmap_pde)
196 CLOSURE(pmap_pde_internal0)
197 CLOSURE(pmap_pde_internal1)
198 CLOSURE(pmap_pte)
199 CLOSURE(pmap_pte_internal)
200 CLOSURE(pmap_put_mapwindow)
201 CLOSURE(pmap_valid_page)
202 CLOSURE(pmap_vtophys)
203 X86_ONLY(pms)
204 CRITICAL(power_management_init)
205 CRITICAL(preemption_underflow_panic)
206 CLOSURE(prf)
207 CLOSURE(proc_best_name)
208 CLOSURE(proc_is64bit)
209 CRITICAL(rbtrace_bt)
210 CRITICAL(register_cpu_setup_func)
211 CRITICAL(ret64_iret)
212 CRITICAL(ret_to_user)
213 CRITICAL(return_to_kernel)
214 CRITICAL(return_to_user)
215 CRITICAL(rtc_)
216 CRITICAL(rtclock_)
217 CRITICAL(saved_state64)
218 CLOSURE(sdt_getargdesc)
219 CRITICAL(sdt_invop)
220 CLOSURE(setPop)
221 ARM_ONLY(sleh_)
222 CRITICAL(sprlock)
223 CRITICAL(sprunlock)
224 CLOSURE(strlcpy)
225 CRITICAL(strlen)
226 CRITICAL(strncmp)
227 CRITICAL(suword)
228 X86_ONLY(sync_iss_to_iks_unconditionally)
229 CLOSURE(systrace_stub)
230 CRITICAL(t_invop)
231 CLOSURE(timer_grab)
232 ARM_ONLY(timer_state_event)
233 CRITICAL(tmrCvt)
234 CRITICAL(trap_from_kernel)
235 CRITICAL(traptrace_)
236 CRITICAL(tsc_)
237 CRITICAL(uart_putc)
238 CRITICAL(unlock_debugger)
239 CRITICAL(unpackA)
240 CRITICAL(unregister_cpu_setup_func)
241 CRITICAL(uread)
242 CRITICAL(uwrite)
243 CRITICAL(vstart)
244 };
245 #define BLACKLIST_COUNT (sizeof(fbt_blacklist)/sizeof(fbt_blacklist[0]))
246
247 /*
248 * Modules that should not be probed.
249 *
250 * This must be kept in asciibetical order for purposes of bsearch().
251 */
252 static const char* fbt_module_blacklist[] = {
253 X86_ONLY(com.apple.driver.AppleACPIEC)
254 X86_ONLY(com.apple.driver.AppleACPIPlatform)
255 ARM_ONLY(com.apple.driver.AppleARMPlatform)
256 X86_ONLY(com.apple.driver.AppleEFI)
257 X86_ONLY(com.apple.driver.AppleIntelCPUPowerManagement)
258 ARM_ONLY(com.apple.driver.AppleInterruptController)
259 X86_ONLY(com.apple.driver.AppleRTC)
260 X86_ONLY(com.apple.iokit.IOACPIFamily)
261 };
262 #define MODULE_BLACKLIST_COUNT (sizeof(fbt_module_blacklist)/sizeof(fbt_module_blacklist[0]))
263
264 int ignore_fbt_blacklist = 0;
265 extern int dtrace_kernel_symbol_mode;
266
267 #pragma clang diagnostic push
268 #pragma clang diagnostic ignored "-Wcast-qual"
269 static int
270 _cmp(const void *a, const void *b)
271 {
272 const char *v = *(const char **)b;
273 return strncmp((const char *)a, v, strlen(v));
274 }
275
276
277 #pragma clang diagnostic pop
278 /*
279 * Module validation
280 */
281 bool
282 fbt_module_excluded(struct modctl* ctl)
283 {
284 const char *excluded;
285
286 ASSERT(!MOD_FBT_DONE(ctl));
287
288 if (ctl->mod_address == 0 || ctl->mod_size == 0 || !ctl->mod_loaded) {
289 return true;
290 }
291
292 if (ignore_fbt_blacklist) {
293 return false;
294 }
295
296 excluded = bsearch(ctl->mod_modname, fbt_module_blacklist,
297 MODULE_BLACKLIST_COUNT, sizeof(fbt_module_blacklist[0]), _cmp);
298 return excluded;
299 }
300
301 /*
302 * FBT probe name validation
303 */
304 bool
305 fbt_excluded(const char* name)
306 {
307 const char *excluded;
308
309 if (ignore_fbt_blacklist) {
310 return false;
311 }
312
313 excluded = bsearch(name, fbt_blacklist, BLACKLIST_COUNT, sizeof(name),
314 _cmp );
315 return excluded;
316 }
317
318 SYSCTL_DECL(_kern_dtrace);
319
320 static int
321 sysctl_dtrace_ignore_fbt_blacklist SYSCTL_HANDLER_ARGS
322 {
323 #pragma unused(oidp, arg2)
324 int err;
325 int value = *(int*)arg1;
326
327 err = sysctl_io_number(req, value, sizeof(value), &value, NULL);
328 if (err) {
329 return err;
330 }
331 if (req->newptr) {
332 if (!(value == 0 || value == 1)) {
333 return ERANGE;
334 }
335
336 /*
337 * We do not allow setting the blacklist back to on, as we have no way
338 * of knowing if those unsafe probes are still used.
339 *
340 * If we are using kernel symbols, we also do not allow any change,
341 * since the symbols are jettison'd after the first pass.
342 *
343 * We do not need to take any locks here because those symbol modes
344 * are permanent and do not change after boot.
345 */
346 if (value != 1 || dtrace_kernel_symbol_mode == DTRACE_KERNEL_SYMBOLS_NEVER ||
347 dtrace_kernel_symbol_mode == DTRACE_KERNEL_SYMBOLS_ALWAYS_FROM_KERNEL) {
348 return EPERM;
349 }
350
351 ignore_fbt_blacklist = 1;
352 }
353
354 return 0;
355 }
356
357 SYSCTL_PROC(_kern_dtrace, OID_AUTO, ignore_fbt_blacklist,
358 CTLTYPE_INT | CTLFLAG_RW | CTLFLAG_LOCKED,
359 &ignore_fbt_blacklist, 0,
360 sysctl_dtrace_ignore_fbt_blacklist, "I", "fbt provider ignore blacklist");
361
362 void
363 fbt_blacklist_init(void)
364 {
365 PE_parse_boot_argn("IgnoreFBTBlacklist", &ignore_fbt_blacklist, sizeof(ignore_fbt_blacklist));
366 #if DEBUG || DEVELOPMENT
367 for (size_t i = 1; i < BLACKLIST_COUNT; i++) {
368 if (strcmp(fbt_blacklist[i - 1], fbt_blacklist[i]) > 0) {
369 panic("unordered fbt blacklist %s > %s", fbt_blacklist[i - 1], fbt_blacklist[i]);
370 }
371 }
372 #endif /* DEBUG || DEVELOPMENT */
373 }