1 /* 2 * Copyright (c) 2021 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_COPYRIGHT@ 30 */ 31 32 #ifndef _SYS_KERN_DEBUG_H_ 33 #define _SYS_KERN_DEBUG_H_ 34 35 #include <mach/mach_types.h> 36 37 #include <sys/types.h> 38 39 __BEGIN_DECLS 40 41 /* 42 * A selector is just made of an index into syscall_rejection_masks, 43 * with the exception of the highest bit, which indicates whether the 44 * mask is to be added as an "allow" mask or a "deny" mask. 45 */ 46 typedef uint8_t syscall_rejection_selector_t; 47 48 __END_DECLS 49 50 #define SYSCALL_REJECTION_IS_ALLOW_MASK (1 << 7) 51 #define SYSCALL_REJECTION_INDEX_MASK (~(syscall_rejection_selector_t)SYSCALL_REJECTION_IS_ALLOW_MASK) 52 53 #define SYSCALL_REJECTION_ALLOW(sc) ((sc) | SYSCALL_REJECTION_IS_ALLOW_MASK) 54 #define SYSCALL_REJECTION_DENY(sc) (sc) 55 56 #define SYSCALL_REJECTION_NULL 0 57 #define SYSCALL_REJECTION_ALL 1 58 59 #ifndef KERNEL 60 61 __BEGIN_DECLS 62 63 /* Request that the syscall rejection mask of the current thread be changed to the 64 * one specified by the list of selectors provided, e.g. 65 * syscall_rejection_selector_t selectors[] = 66 * [ SYSCALL_REJECTION_DENY(SYSCALL_REJECTION_ALL), 67 * SYSCALL_REJECTION_ALLOW(MY_SELECTOR) ]; 68 * ret = debug_syscall_reject(selectors, countof(selectors)); 69 */ 70 71 int debug_syscall_reject(const syscall_rejection_selector_t *selectors, size_t len); 72 73 __END_DECLS 74 75 #else /* KERNEL */ 76 77 #include <stdbool.h> 78 79 #include <kern/bits.h> 80 81 #include <sys/sysproto.h> 82 83 __BEGIN_DECLS 84 85 typedef bitmap_t *syscall_rejection_mask_t; 86 87 int debug_syscall_reject(struct proc *p __unused, struct debug_syscall_reject_args *args, int *ret); 88 89 bool debug_syscall_rejection_handle(int syscall_mach_trap_number); 90 91 void rejected_syscall_guard_ast(thread_t thread, mach_exception_data_type_t code, mach_exception_data_type_t subcode); 92 93 extern int debug_syscall_rejection_mode; 94 95 __END_DECLS 96 97 #endif /* KERNEL */ 98 99 #endif /* _SYS_KERN_DEBUG_H_ */ 100