#include <mach/host_priv_server.h>
#include <kern/host.h>
#include <kern/processor.h>
-#include <kern/lock.h>
#include <kern/task.h>
#include <kern/thread.h>
#include <kern/ipc_host.h>
#include <ipc/ipc_port.h>
#include <ipc/ipc_space.h>
+#if CONFIG_MACF
+#include <security/mac_mach_internal.h>
+#endif
+
/*
* Forward declarations
*/
*/
kern_return_t
host_set_exception_ports(
- host_priv_t host_priv,
+ host_priv_t host_priv,
exception_mask_t exception_mask,
ipc_port_t new_port,
exception_behavior_t new_behavior,
return KERN_INVALID_ARGUMENT;
}
- assert(host_priv == &realhost);
-
if (exception_mask & ~EXC_MASK_VALID) {
return KERN_INVALID_ARGUMENT;
}
return KERN_INVALID_ARGUMENT;
}
}
- /* Cannot easily check "new_flavor", but that just means that
- * the flavor in the generated exception message might be garbage:
- * GIGO
+
+ /*
+ * Check the validity of the thread_state_flavor by calling the
+ * VALID_THREAD_STATE_FLAVOR architecture dependent macro defined in
+ * osfmk/mach/ARCHITECTURE/thread_status.h
*/
+ if (new_flavor != 0 && !VALID_THREAD_STATE_FLAVOR(new_flavor))
+ return (KERN_INVALID_ARGUMENT);
+
+#if CONFIG_MACF
+ if (mac_task_check_set_host_exception_ports(current_task(), exception_mask) != 0)
+ return KERN_NO_ACCESS;
+#endif
+
+ assert(host_priv == &realhost);
+
host_lock(host_priv);
for (i = FIRST_EXCEPTION; i < EXC_TYPES_COUNT; i++) {
kern_return_t
host_swap_exception_ports(
- host_priv_t host_priv,
+ host_priv_t host_priv,
exception_mask_t exception_mask,
ipc_port_t new_port,
exception_behavior_t new_behavior,
return KERN_INVALID_ARGUMENT;
}
}
- /* Cannot easily check "new_flavor", but that just means that
- * the flavor in the generated exception message might be garbage:
- * GIGO */
- host_lock(host_priv);
+ if (new_flavor != 0 && !VALID_THREAD_STATE_FLAVOR(new_flavor))
+ return (KERN_INVALID_ARGUMENT);
- count = 0;
+#if CONFIG_MACF
+ if (mac_task_check_set_host_exception_ports(current_task(), exception_mask) != 0)
+ return KERN_NO_ACCESS;
+#endif /* CONFIG_MACF */
- for (i = FIRST_EXCEPTION; i < EXC_TYPES_COUNT; i++) {
+ host_lock(host_priv);
+
+ assert(EXC_TYPES_COUNT > FIRST_EXCEPTION);
+ for (count=0, i = FIRST_EXCEPTION; i < EXC_TYPES_COUNT && count < *CountCnt; i++) {
if (exception_mask & (1 << i)) {
for (j = 0; j < count; j++) {
/*
ipc_port_copy_send(new_port);
host_priv->exc_actions[i].behavior = new_behavior;
host_priv->exc_actions[i].flavor = new_flavor;
- if (count > *CountCnt) {
- break;
- }
} else
old_port[i] = IP_NULL;
}/* for */
/*
* Consume send rights without any lock held.
*/
- for (i = FIRST_EXCEPTION; i < EXC_TYPES_COUNT; i++)
+ while (--i >= FIRST_EXCEPTION) {
if (IP_VALID(old_port[i]))
ipc_port_release_send(old_port[i]);
+ }
+
if (IP_VALID(new_port)) /* consume send right */
ipc_port_release_send(new_port);
*CountCnt = count;