#include <sys/param.h>
-#include <sys/systm.h> /* XXX printf() */
+#include <sys/systm.h> /* XXX printf() */
#include <sys/types.h>
#include <sys/fcntl.h>
#include <security/mac_policy.h>
#include <libkern/section_keywords.h>
-#include <libkern/OSDebug.h> /* OSBPrintBacktrace */
+#include <libkern/OSDebug.h> /* OSBPrintBacktrace */
/* forward declaration; see bsd_init.c */
* Note: CHECK_POLICY_CHECK is probably not very useful unless you
* are kernel debugging and set a breakpoint.
*/
-#define CHECK_POLICY_CHECK 0x00000001 /* Check on calls */
-#define CHECK_POLICY_FAIL 0x00000002 /* EPERM on fails */
-#define CHECK_POLICY_BACKTRACE 0x00000004 /* Show call stack on fails */
-#define CHECK_POLICY_PANIC 0x00000008 /* Panic on fails */
-#define CHECK_POLICY_PERIODIC 0x00000010 /* Show fails periodically */
+#define CHECK_POLICY_CHECK 0x00000001 /* Check on calls */
+#define CHECK_POLICY_FAIL 0x00000002 /* EPERM on fails */
+#define CHECK_POLICY_BACKTRACE 0x00000004 /* Show call stack on fails */
+#define CHECK_POLICY_PANIC 0x00000008 /* Panic on fails */
+#define CHECK_POLICY_PERIODIC 0x00000010 /* Show fails periodically */
static int policy_flags = 0;
-#define CHECK_SET_HOOK(x) .mpo_##x = (mpo_##x##_t *)common_hook,
+#define CHECK_SET_HOOK(x) .mpo_##x = (mpo_##x##_t *)common_hook,
/*
* Init; currently, we only print our arrival notice.
/* Implementation */
-#define CLASS_PERIOD_LIMIT 10000
-#define CLASS_PERIOD_MULT 20
+#define CLASS_PERIOD_LIMIT 10000
+#define CLASS_PERIOD_MULT 20
static int policy_check_event = 1;
static int policy_check_period = 1;
static int
common_hook(void)
{
- int i;
- int rv = 0;
+ int i;
+ int rv = 0;
if ((i = get_thread_lock_count(current_thread())) != 0) {
/*
* fail the MACF check if we hold a lock; this assumes a
* a non-void (authorization) MACF hook.
*/
- if (policy_flags & CHECK_POLICY_FAIL)
+ if (policy_flags & CHECK_POLICY_FAIL) {
rv = EPERM;
+ }
/*
* display a backtrace if we hold a lock and we are not
*/
if ((policy_flags & (CHECK_POLICY_BACKTRACE | CHECK_POLICY_PANIC)) == CHECK_POLICY_BACKTRACE) {
if (policy_flags & CHECK_POLICY_PERIODIC) {
- /* at exponentially increasing intervals */
- if (!(policy_check_event % policy_check_period)) {
- if (policy_check_event <= policy_check_next || policy_check_period == CLASS_PERIOD_LIMIT) {
- /*
- * According to Derek, we could
- * technically get a symbolicated name
- * here, if we refactered some code
- * and set the "keepsyms=1" boot
- * argument...
- */
- OSReportWithBacktrace("calling MACF hook with mutex count %d (event %d) ", i, policy_check_event);
- }
- } else {
- if (policy_check_period < CLASS_PERIOD_LIMIT) {
- policy_check_next *= CLASS_PERIOD_MULT;
- policy_check_period *= CLASS_PERIOD_MULT;
+ /* at exponentially increasing intervals */
+ if (!(policy_check_event % policy_check_period)) {
+ if (policy_check_event <= policy_check_next || policy_check_period == CLASS_PERIOD_LIMIT) {
+ /*
+ * According to Derek, we could
+ * technically get a symbolicated name
+ * here, if we refactered some code
+ * and set the "keepsyms=1" boot
+ * argument...
+ */
+ OSReportWithBacktrace("calling MACF hook with mutex count %d (event %d) ", i, policy_check_event);
+ }
+ } else {
+ if (policy_check_period < CLASS_PERIOD_LIMIT) {
+ policy_check_next *= CLASS_PERIOD_MULT;
+ policy_check_period *= CLASS_PERIOD_MULT;
+ }
}
- }
} else {
/* always */
OSReportWithBacktrace("calling MACF hook with mutex count %d (event %d) ", i, policy_check_event);
}
/* Panic */
- if (policy_flags & CHECK_POLICY_PANIC)
+ if (policy_flags & CHECK_POLICY_PANIC) {
panic("calling MACF hook with mutex count %d\n", i);
+ }
/* count for non-fatal tracing */
policy_check_event++;
return rv;
}
-#if (MAC_POLICY_OPS_VERSION != 55)
+#if (MAC_POLICY_OPS_VERSION != 62)
# error "struct mac_policy_ops doesn't match definition in mac_policy.h"
#endif
/*
CHECK_SET_HOOK(vnode_check_rename)
CHECK_SET_HOOK(kext_check_query)
CHECK_SET_HOOK(proc_notify_exec_complete)
- .mpo_reserved5 = (mpo_reserved_hook_t *)common_hook,
- .mpo_reserved6 = (mpo_reserved_hook_t *)common_hook,
+ .mpo_reserved4 = (mpo_reserved_hook_t *)common_hook,
+ CHECK_SET_HOOK(proc_check_syscall_unix)
CHECK_SET_HOOK(proc_check_expose_task)
CHECK_SET_HOOK(proc_check_set_host_special_port)
CHECK_SET_HOOK(proc_check_set_host_exception_port)
CHECK_SET_HOOK(exc_action_label_update)
CHECK_SET_HOOK(vnode_check_trigger_resolve)
- .mpo_reserved1 = (mpo_reserved_hook_t *)common_hook,
+ CHECK_SET_HOOK(mount_check_mount_late)
+ CHECK_SET_HOOK(mount_check_snapshot_mount)
.mpo_reserved2 = (mpo_reserved_hook_t *)common_hook,
- .mpo_reserved3 = (mpo_reserved_hook_t *)common_hook,
CHECK_SET_HOOK(skywalk_flow_check_connect)
CHECK_SET_HOOK(skywalk_flow_check_listen)
CHECK_SET_HOOK(proc_check_setlcid)
CHECK_SET_HOOK(proc_check_signal)
CHECK_SET_HOOK(proc_check_wait)
- CHECK_SET_HOOK(proc_label_destroy)
- CHECK_SET_HOOK(proc_label_init)
+ CHECK_SET_HOOK(proc_check_dump_core)
+
+ .mpo_reserved5 = (mpo_reserved_hook_t *)common_hook,
CHECK_SET_HOOK(socket_check_accept)
CHECK_SET_HOOK(socket_check_accepted)
CHECK_SET_HOOK(iokit_check_set_properties)
+ .mpo_reserved3 = (mpo_reserved_hook_t *)common_hook,
+
CHECK_SET_HOOK(vnode_check_searchfs)
CHECK_SET_HOOK(priv_check)
static SECURITY_READ_ONLY_LATE(struct mac_policy_conf) policy_conf = {
.mpc_name = "CHECK",
.mpc_fullname = "Check Assumptions Policy",
- .mpc_field_off = NULL, /* no label slot */
- .mpc_labelnames = NULL, /* no policy label names */
- .mpc_labelname_count = 0, /* count of label names is 0 */
- .mpc_ops = &policy_ops, /* policy operations */
+ .mpc_field_off = NULL, /* no label slot */
+ .mpc_labelnames = NULL, /* no policy label names */
+ .mpc_labelname_count = 0, /* count of label names is 0 */
+ .mpc_ops = &policy_ops, /* policy operations */
.mpc_loadtime_flags = 0,
.mpc_runtime_flags = 0,
};
check_policy_init(int flags)
{
/* Only instantiate the module if we have been asked to do checking */
- if (!flags)
+ if (!flags) {
return 0;
+ }
policy_flags = flags;