Skip to content

Commit

Permalink
xnu-6153.41.3
Browse files Browse the repository at this point in the history
  • Loading branch information
Darwin authored and das committed Jan 11, 2021
1 parent 18c0ee9 commit 84185d2
Show file tree
Hide file tree
Showing 170 changed files with 3,420 additions and 2,205 deletions.
2 changes: 2 additions & 0 deletions bsd/dev/dtrace/fbt_blacklist.c
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,7 @@ const char * fbt_blacklist[] =
CLOSURE(prf)
CLOSURE(proc_is64bit)
CLOSURE(proc_selfname)
CRITICAL(rbtrace_bt)
CRITICAL(register_cpu_setup_func)
CRITICAL(ret64_iret)
CRITICAL(ret_to_user)
Expand All @@ -227,6 +228,7 @@ const char * fbt_blacklist[] =
ARM_ONLY(timer_state_event)
CRITICAL(tmrCvt)
CRITICAL(trap_from_kernel)
CRITICAL(traptrace_)
CRITICAL(tsc_)
CRITICAL(uart_putc)
CRITICAL(unlock_debugger)
Expand Down
6 changes: 6 additions & 0 deletions bsd/dev/i386/sysctl.c
Original file line number Diff line number Diff line change
Expand Up @@ -1051,4 +1051,10 @@ SYSCTL_PROC(_machdep_misc, OID_AUTO, spin_forever,
0, 0,
spin_in_the_kernel, "I", "Spin forever");


extern int traptrace_enabled;
SYSCTL_INT(_machdep_misc, OID_AUTO, traptrace_enabled,
CTLFLAG_KERN | CTLFLAG_RW | CTLFLAG_LOCKED,
&traptrace_enabled, 0, "Enabled/disable trap trace");

#endif /* DEVELOPMENT || DEBUG */
10 changes: 10 additions & 0 deletions bsd/kern/bsd_init.c
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,7 @@
#include <net/restricted_in_port.h> /* for restricted_in_port_init() */
#include <kern/assert.h> /* for assert() */
#include <sys/kern_overrides.h> /* for init_system_override() */
#include <sys/lockf.h> /* for lf_init() */

#include <net/init.h>

Expand Down Expand Up @@ -315,6 +316,8 @@ __private_extern__ int bootarg_vnode_cache_defeat = 0;
__private_extern__ int bootarg_no_vnode_jetsam = 0;
#endif /* CONFIG_JETSAM && (DEVELOPMENT || DEBUG) */

__private_extern__ int bootarg_no_vnode_drain = 0;

/*
* Prevent kernel-based ASLR from being used, for testing.
*/
Expand Down Expand Up @@ -760,6 +763,10 @@ bsd_init(void)
bsd_init_kprintf("calling vfsinit\n");
vfsinit();

/* Initialize file locks. */
bsd_init_kprintf("calling lf_init\n");
lf_init();

#if CONFIG_PROC_UUID_POLICY
/* Initial proc_uuid_policy subsystem */
bsd_init_kprintf("calling proc_uuid_policy_init()\n");
Expand Down Expand Up @@ -1331,6 +1338,9 @@ parse_bsd_args(void)
}
#endif /* CONFIG_JETSAM && (DEVELOPMENT || DEBUG) */

if (PE_parse_boot_argn("-no_vnode_drain", namep, sizeof(namep))) {
bootarg_no_vnode_drain = 1;
}

#if CONFIG_EMBEDDED
/*
Expand Down
2 changes: 0 additions & 2 deletions bsd/kern/kdebug.c
Original file line number Diff line number Diff line change
Expand Up @@ -84,8 +84,6 @@
/*
* IOP(s)
*
* https://coreoswiki.apple.com/wiki/pages/U6z3i0q9/Consistent_Logging_Implementers_Guide.html
*
* IOP(s) are auxiliary cores that want to participate in kdebug event logging.
* They are registered dynamically. Each is assigned a cpu_id at registration.
*
Expand Down
89 changes: 80 additions & 9 deletions bsd/kern/kern_control.c
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@ struct ctl_cb {
void *userdata;
struct sockaddr_ctl sac;
u_int32_t usecount;
u_int32_t kcb_usecount;
};

#ifndef ROUNDUP64
Expand Down Expand Up @@ -351,6 +352,27 @@ ctl_sofreelastref(struct socket *so)
return 0;
}

/*
* Use this function to serialize calls into the kctl subsystem
*/
static void
ctl_kcb_increment_use_count(struct ctl_cb *kcb, lck_mtx_t *mutex_held)
{
LCK_MTX_ASSERT(mutex_held, LCK_MTX_ASSERT_OWNED);
while (kcb->kcb_usecount > 0) {
msleep(&kcb->kcb_usecount, mutex_held, PSOCK | PCATCH, "kcb_usecount", NULL);
}
kcb->kcb_usecount++;
}

static void
clt_kcb_decrement_use_count(struct ctl_cb *kcb)
{
assert(kcb->kcb_usecount != 0);
kcb->kcb_usecount--;
wakeup_one((caddr_t)&kcb->kcb_usecount);
}

static int
ctl_detach(struct socket *so)
{
Expand All @@ -360,6 +382,9 @@ ctl_detach(struct socket *so)
return 0;
}

lck_mtx_t *mtx_held = socket_getlock(so, PR_F_WILLUNLOCK);
ctl_kcb_increment_use_count(kcb, mtx_held);

if (kcb->kctl != NULL && kcb->kctl->bind != NULL &&
kcb->userdata != NULL && !(so->so_state & SS_ISCONNECTED)) {
// The unit was bound, but not connected
Expand All @@ -374,6 +399,7 @@ ctl_detach(struct socket *so)

soisdisconnected(so);
so->so_flags |= SOF_PCBCLEARING;
clt_kcb_decrement_use_count(kcb);
return 0;
}

Expand Down Expand Up @@ -522,23 +548,29 @@ ctl_bind(struct socket *so, struct sockaddr *nam, struct proc *p)
panic("ctl_bind so_pcb null\n");
}

lck_mtx_t *mtx_held = socket_getlock(so, PR_F_WILLUNLOCK);
ctl_kcb_increment_use_count(kcb, mtx_held);

error = ctl_setup_kctl(so, nam, p);
if (error) {
return error;
goto out;
}

if (kcb->kctl == NULL) {
panic("ctl_bind kctl null\n");
}

if (kcb->kctl->bind == NULL) {
return EINVAL;
error = EINVAL;
goto out;
}

socket_unlock(so, 0);
error = (*kcb->kctl->bind)(kcb->kctl->kctlref, &kcb->sac, &kcb->userdata);
socket_lock(so, 0);

out:
clt_kcb_decrement_use_count(kcb);
return error;
}

Expand All @@ -552,9 +584,12 @@ ctl_connect(struct socket *so, struct sockaddr *nam, struct proc *p)
panic("ctl_connect so_pcb null\n");
}

lck_mtx_t *mtx_held = socket_getlock(so, PR_F_WILLUNLOCK);
ctl_kcb_increment_use_count(kcb, mtx_held);

error = ctl_setup_kctl(so, nam, p);
if (error) {
return error;
goto out;
}

if (kcb->kctl == NULL) {
Expand Down Expand Up @@ -596,6 +631,8 @@ ctl_connect(struct socket *so, struct sockaddr *nam, struct proc *p)
kctlstat.kcs_conn_fail++;
lck_mtx_unlock(ctl_mtx);
}
out:
clt_kcb_decrement_use_count(kcb);
return error;
}

Expand All @@ -605,6 +642,8 @@ ctl_disconnect(struct socket *so)
struct ctl_cb *kcb = (struct ctl_cb *)so->so_pcb;

if ((kcb = (struct ctl_cb *)so->so_pcb)) {
lck_mtx_t *mtx_held = socket_getlock(so, PR_F_WILLUNLOCK);
ctl_kcb_increment_use_count(kcb, mtx_held);
struct kctl *kctl = kcb->kctl;

if (kctl && kctl->disconnect) {
Expand All @@ -628,6 +667,7 @@ ctl_disconnect(struct socket *so)
kctlstat.kcs_gencnt++;
lck_mtx_unlock(ctl_mtx);
socket_lock(so, 0);
clt_kcb_decrement_use_count(kcb);
}
return 0;
}
Expand Down Expand Up @@ -694,11 +734,20 @@ ctl_sbrcv_trim(struct socket *so)
static int
ctl_usr_rcvd(struct socket *so, int flags)
{
int error = 0;
struct ctl_cb *kcb = (struct ctl_cb *)so->so_pcb;
struct kctl *kctl;

if (kcb == NULL) {
return ENOTCONN;
}

lck_mtx_t *mtx_held = socket_getlock(so, PR_F_WILLUNLOCK);
ctl_kcb_increment_use_count(kcb, mtx_held);

if ((kctl = kcb->kctl) == NULL) {
return EINVAL;
error = EINVAL;
goto out;
}

if (kctl->rcvd) {
Expand All @@ -709,7 +758,9 @@ ctl_usr_rcvd(struct socket *so, int flags)

ctl_sbrcv_trim(so);

return 0;
out:
clt_kcb_decrement_use_count(kcb);
return error;
}

static int
Expand All @@ -730,6 +781,9 @@ ctl_send(struct socket *so, int flags, struct mbuf *m,
error = ENOTCONN;
}

lck_mtx_t *mtx_held = socket_getlock(so, PR_F_WILLUNLOCK);
ctl_kcb_increment_use_count(kcb, mtx_held);

if (error == 0 && (kctl = kcb->kctl) == NULL) {
error = EINVAL;
}
Expand All @@ -749,6 +803,8 @@ ctl_send(struct socket *so, int flags, struct mbuf *m,
if (error != 0) {
OSIncrementAtomic64((SInt64 *)&kctlstat.kcs_send_fail);
}
clt_kcb_decrement_use_count(kcb);

return error;
}

Expand All @@ -769,6 +825,9 @@ ctl_send_list(struct socket *so, int flags, struct mbuf *m,
error = ENOTCONN;
}

lck_mtx_t *mtx_held = socket_getlock(so, PR_F_WILLUNLOCK);
ctl_kcb_increment_use_count(kcb, mtx_held);

if (error == 0 && (kctl = kcb->kctl) == NULL) {
error = EINVAL;
}
Expand Down Expand Up @@ -808,6 +867,8 @@ ctl_send_list(struct socket *so, int flags, struct mbuf *m,
if (error != 0) {
OSIncrementAtomic64((SInt64 *)&kctlstat.kcs_send_list_fail);
}
clt_kcb_decrement_use_count(kcb);

return error;
}

Expand Down Expand Up @@ -1234,16 +1295,21 @@ ctl_ctloutput(struct socket *so, struct sockopt *sopt)
return EINVAL;
}

lck_mtx_t *mtx_held = socket_getlock(so, PR_F_WILLUNLOCK);
ctl_kcb_increment_use_count(kcb, mtx_held);

switch (sopt->sopt_dir) {
case SOPT_SET:
if (kctl->setopt == NULL) {
return ENOTSUP;
error = ENOTSUP;
goto out;
}
if (sopt->sopt_valsize != 0) {
MALLOC(data, void *, sopt->sopt_valsize, M_TEMP,
M_WAITOK | M_ZERO);
if (data == NULL) {
return ENOMEM;
error = ENOMEM;
goto out;
}
error = sooptcopyin(sopt, data,
sopt->sopt_valsize, sopt->sopt_valsize);
Expand All @@ -1263,14 +1329,16 @@ ctl_ctloutput(struct socket *so, struct sockopt *sopt)

case SOPT_GET:
if (kctl->getopt == NULL) {
return ENOTSUP;
error = ENOTSUP;
goto out;
}

if (sopt->sopt_valsize && sopt->sopt_val) {
MALLOC(data, void *, sopt->sopt_valsize, M_TEMP,
M_WAITOK | M_ZERO);
if (data == NULL) {
return ENOMEM;
error = ENOMEM;
goto out;
}
/*
* 4108337 - copy user data in case the
Expand Down Expand Up @@ -1306,6 +1374,9 @@ ctl_ctloutput(struct socket *so, struct sockopt *sopt)
}
break;
}

out:
clt_kcb_decrement_use_count(kcb);
return error;
}

Expand Down
Loading

0 comments on commit 84185d2

Please sign in to comment.