Skip to content

Commit

Permalink
xnu-1504.9.37
Browse files Browse the repository at this point in the history
  • Loading branch information
Darwin authored and das committed Jun 4, 2017
1 parent 6f8055e commit 7aeaee7
Show file tree
Hide file tree
Showing 38 changed files with 558 additions and 170 deletions.
2 changes: 1 addition & 1 deletion bsd/conf/MASTER.i386
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@
# -------- ----- -------- ---------------
# BASE = [ intel mach medium config_dtrace vol pst gdb kernobjc fixpri simple_clock mdebug kernserv driverkit uxpr kernstack ipc_compat ipc_debug sysv_sem sysv_msg sysv_shm audit panic_info config_imageboot config_workqueue psynch ]
# FILESYS = [ devfs revfs hfs journaling fdesc config_fse quota namedstreams fifo union config_volfs hfs_compression config_imgsrc_access ]
# NETWORKING = [ inet inet6 compat_oldsock tcpdrop_synfin bpfilter ipdivert ipfirewall ipv6firewall ipfw2 dummynet traffic_mgt sendfile netmibs bond vlan gif stf zlib randomipid ifnet_input_chk config_mbuf_jumbo ipflow ]
# NETWORKING = [ inet inet6 compat_oldsock tcpdrop_synfin bpfilter ipdivert ipfirewall ipv6firewall ipfw2 dummynet traffic_mgt sendfile netmibs bond vlan gif stf zlib randomipid ifnet_input_chk config_mbuf_jumbo ipflow pkt_priority if_bridge ]
# NFS = [ nfsclient nfsserver ]
# VPN = [ ipsec ]
# RELEASE = [ BASE NETWORKING NFS VPN FILESYS libdriver ]
Expand Down
2 changes: 1 addition & 1 deletion bsd/conf/MASTER.ppc
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@
#
# BASE = [ ppc mach medium config_dtrace vol pst gdb noprofiling simple_clock kernstack sysv_sem sysv_msg sysv_shm audit panic_info config_imageboot config_workqueue ]
# FILESYS = [ devfs revfs hfs journaling fdesc config_fse quota namedstreams fifo union config_volfs hfs_compression ]
# NETWORKING = [ inet inet6 compat_oldsock tcpdrop_synfin bpfilter ipdivert ipfirewall ipv6firewall ipfw2 dummynet traffic_mgt sendfile netmibs bond vlan gif stf zlib randomipid ifnet_input_chk ipflow ]
# NETWORKING = [ inet inet6 compat_oldsock tcpdrop_synfin bpfilter ipdivert ipfirewall ipv6firewall ipfw2 dummynet traffic_mgt sendfile netmibs bond vlan gif stf zlib randomipid ifnet_input_chk ipflow pkt_priority ]
# NFS = [ nfsclient nfsserver ]
# VPN = [ ipsec ]
# RELEASE = [ BASE NETWORKING NFS VPN FILESYS libdriver ]
Expand Down
2 changes: 1 addition & 1 deletion bsd/conf/MASTER.x86_64
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@
# -------- ----- -------- ---------------
# BASE = [ intel mach medium config_dtrace vol pst gdb kernobjc fixpri simple_clock mdebug kernserv driverkit uxpr kernstack ipc_compat ipc_debug sysv_sem sysv_msg sysv_shm audit panic_info config_imageboot config_workqueue psynch ]
# FILESYS = [ devfs revfs hfs journaling fdesc config_fse quota namedstreams fifo union config_volfs hfs_compression config_imgsrc_access ]
# NETWORKING = [ inet inet6 compat_oldsock tcpdrop_synfin bpfilter ipdivert ipfirewall ipv6firewall ipfw2 dummynet traffic_mgt sendfile netmibs bond vlan gif stf zlib randomipid ifnet_input_chk config_mbuf_jumbo ipflow ]
# NETWORKING = [ inet inet6 compat_oldsock tcpdrop_synfin bpfilter ipdivert ipfirewall ipv6firewall ipfw2 dummynet traffic_mgt sendfile netmibs bond vlan gif stf zlib randomipid ifnet_input_chk config_mbuf_jumbo ipflow pkt_priority if_bridge ]
# NFS = [ nfsclient nfsserver ]
# VPN = [ ipsec ]
# RELEASE = [ BASE NETWORKING NFS VPN FILESYS libdriver ]
Expand Down
26 changes: 25 additions & 1 deletion bsd/hfs/hfs_encodings.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2000-2005 Apple Computer, Inc. All rights reserved.
* Copyright (c) 2000-2010 Apple Computer, Inc. All rights reserved.
*
* @APPLE_OSREFERENCE_LICENSE_HEADER_START@
*
Expand Down Expand Up @@ -239,8 +239,20 @@ hfs_to_utf8(ExtendedVCB *vcb, const Str31 hfs_str, ByteCount maxDstLen, ByteCoun
UniChar uniStr[MAX_HFS_UNICODE_CHARS];
ItemCount uniCount;
size_t utf8len;
u_int8_t pascal_length = 0;
hfs_to_unicode_func_t hfs_get_unicode = VCBTOHFS(vcb)->hfs_get_unicode;

/*
* Validate the length of the Pascal-style string before passing it
* down to the decoding engine.
*/
pascal_length = *((const u_int8_t*)(hfs_str));
if (pascal_length > 31) {
/* invalid string; longer than 31 bytes */
error = EINVAL;
return error;
}

error = hfs_get_unicode(hfs_str, uniStr, MAX_HFS_UNICODE_CHARS, &uniCount);

if (uniCount == 0)
Expand Down Expand Up @@ -269,6 +281,18 @@ mac_roman_to_utf8(const Str31 hfs_str, ByteCount maxDstLen, ByteCount *actualDst
UniChar uniStr[MAX_HFS_UNICODE_CHARS];
ItemCount uniCount;
size_t utf8len;
u_int8_t pascal_length = 0;

/*
* Validate the length of the Pascal-style string before passing it
* down to the decoding engine.
*/
pascal_length = *((const u_int8_t*)(hfs_str));
if (pascal_length > 31) {
/* invalid string; longer than 31 bytes */
error = EINVAL;
return error;
}

error = mac_roman_to_unicode(hfs_str, uniStr, MAX_HFS_UNICODE_CHARS, &uniCount);

Expand Down
6 changes: 6 additions & 0 deletions bsd/hfs/hfs_readwrite.c
Original file line number Diff line number Diff line change
Expand Up @@ -1947,6 +1947,12 @@ hfs_vnop_ioctl( struct vnop_ioctl_args /* {
user_bootstrap.fbt_length = bootstrapp->fbt_length;
user_bootstrap.fbt_buffer = CAST_USER_ADDR_T(bootstrapp->fbt_buffer);
}

if ((user_bootstrapp->fbt_offset < 0) || (user_bootstrapp->fbt_offset > 1024) ||
(user_bootstrapp->fbt_length > 1024)) {
return EINVAL;
}

if (user_bootstrapp->fbt_offset + user_bootstrapp->fbt_length > 1024)
return EINVAL;

Expand Down
17 changes: 12 additions & 5 deletions bsd/hfs/hfs_vfsutils.c
Original file line number Diff line number Diff line change
Expand Up @@ -144,9 +144,13 @@ OSErr hfs_MountHFSVolume(struct hfsmount *hfsmp, HFSMasterDirectoryBlock *mdb,
* When an HFS name cannot be encoded with the current
* volume encoding we use MacRoman as a fallback.
*/
if (error || (utf8chars == 0))
if (error || (utf8chars == 0)) {
(void) mac_roman_to_utf8(mdb->drVN, NAME_MAX, &utf8chars, vcb->vcbVN);

/* If we fail to encode to UTF8 from Mac Roman, the name is bad. Deny mount */
if (error) {
goto MtVolErr;
}
}
hfsmp->hfs_logBlockSize = BestBlockSizeFit(vcb->blockSize, MAXBSIZE, hfsmp->hfs_logical_block_size);
vcb->vcbVBMIOSize = kHFSBlockSize;

Expand Down Expand Up @@ -241,7 +245,7 @@ OSErr hfs_MountHFSVolume(struct hfsmount *hfsmp, HFSMasterDirectoryBlock *mdb,
}
hfsmp->hfs_allocation_cp = VTOC(hfsmp->hfs_allocation_vp);

/* mark the volume dirty (clear clean unmount bit) */
/* mark the volume dirty (clear clean unmount bit) */
vcb->vcbAtrb &= ~kHFSVolumeUnmountedMask;

if (error == noErr)
Expand All @@ -264,14 +268,17 @@ OSErr hfs_MountHFSVolume(struct hfsmount *hfsmp, HFSMasterDirectoryBlock *mdb,
hfs_unlock(VTOC(hfsmp->hfs_catalog_vp));
hfs_unlock(VTOC(hfsmp->hfs_extents_vp));

goto CmdDone;
if (error == noErr) {
/* If successful, then we can just return once we've unlocked the cnodes */
return error;
}

//-- Release any resources allocated so far before exiting with an error:
MtVolErr:
ReleaseMetaFileVNode(hfsmp->hfs_catalog_vp);
ReleaseMetaFileVNode(hfsmp->hfs_extents_vp);
ReleaseMetaFileVNode(hfsmp->hfs_allocation_vp);

CmdDone:
return (error);
}

Expand Down
22 changes: 14 additions & 8 deletions bsd/kern/kdebug.c
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
#include <kern/thread.h>
#include <kern/task.h>
#include <kern/debug.h>
#include <kern/assert.h>
#include <vm/vm_kern.h>
#include <sys/lock.h>

Expand Down Expand Up @@ -1659,7 +1660,7 @@ unsigned char *getProcName(struct proc *proc) {
#define TRAP_DEBUGGER __asm__ volatile("tw 4,r3,r3");
#endif

#define SANE_TRACEBUF_SIZE 2*1024*1024
#define SANE_TRACEBUF_SIZE (8 * 1024 * 1024)

/* Initialize the mutex governing access to the stack snapshot subsystem */
__private_extern__ void
Expand Down Expand Up @@ -1713,6 +1714,7 @@ stack_snapshot2(pid_t pid, user_addr_t tracebuf, uint32_t tracebuf_size, uint32_
{
int error = 0;
unsigned bytesTraced = 0;
boolean_t istate;

*retval = -1;
/* Serialize tracing */
Expand All @@ -1723,25 +1725,29 @@ stack_snapshot2(pid_t pid, user_addr_t tracebuf, uint32_t tracebuf_size, uint32_
goto error_exit;
}

MALLOC(stackshot_snapbuf, void *, tracebuf_size, M_TEMP, M_WAITOK);
assert(stackshot_snapbuf == NULL);
if (kmem_alloc_kobject(kernel_map, (vm_offset_t *)&stackshot_snapbuf, tracebuf_size) != KERN_SUCCESS) {
error = ENOMEM;
goto error_exit;
}

if (stackshot_snapbuf == NULL) {
if (panic_active()) {
error = ENOMEM;
goto error_exit;
}

istate = ml_set_interrupts_enabled(FALSE);
/* Preload trace parameters*/
kdp_snapshot_preflight(pid, stackshot_snapbuf, tracebuf_size, flags, dispatch_offset);

/* Trap to the debugger to obtain a coherent stack snapshot; this populates
* the trace buffer
*/
if (panic_active()) {
error = ENOMEM;
goto error_exit;
}

TRAP_DEBUGGER;

ml_set_interrupts_enabled(istate);

bytesTraced = kdp_stack_snapshot_bytes_traced();

if (bytesTraced > 0) {
Expand All @@ -1765,7 +1771,7 @@ stack_snapshot2(pid_t pid, user_addr_t tracebuf, uint32_t tracebuf_size, uint32_

error_exit:
if (stackshot_snapbuf != NULL)
FREE(stackshot_snapbuf, M_TEMP);
kmem_free(kernel_map, (vm_offset_t) stackshot_snapbuf, tracebuf_size);
stackshot_snapbuf = NULL;
STACKSHOT_SUBSYS_UNLOCK();
return error;
Expand Down
49 changes: 48 additions & 1 deletion bsd/kern/kpi_mbuf.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2004-2009 Apple Inc. All rights reserved.
* Copyright (c) 2004-2010 Apple Inc. All rights reserved.
*
* @APPLE_OSREFERENCE_LICENSE_HEADER_START@
*
Expand Down Expand Up @@ -1091,3 +1091,50 @@ mbuf_get_priority(struct mbuf *m)
return (prio);
#endif /* PKT_PRIORITY */
}

mbuf_traffic_class_t
mbuf_get_traffic_class(mbuf_t m)
{
#if !PKT_PRIORITY
#pragma unused(m)
return (MBUF_TC_BE);
#else /* PKT_PRIORITY */
mbuf_priority_t prio = MBUF_TC_BE;

if (m == NULL || !(m->m_flags & M_PKTHDR))
return (prio);

if (m->m_pkthdr.prio <= MBUF_TC_VO)
prio = m->m_pkthdr.prio;

return (prio);
#endif /* PKT_PRIORITY */
}

errno_t
mbuf_set_traffic_class(mbuf_t m, mbuf_traffic_class_t tc)
{
#if !PKT_PRIORITY
#pragma unused(m)
#pragma unused(tc)
return 0;
#else /* PKT_PRIORITY */
errno_t error = 0;

if (m == NULL || !(m->m_flags & M_PKTHDR))
return EINVAL;

switch (tc) {
case MBUF_TC_BE:
case MBUF_TC_BK:
case MBUF_TC_VI:
case MBUF_TC_VO:
m->m_pkthdr.prio = tc;
break;
default:
error = EINVAL;
break;
}
return error;
#endif /* PKT_PRIORITY */
}
41 changes: 40 additions & 1 deletion bsd/kern/kpi_socket.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2003-2008 Apple Inc. All rights reserved.
* Copyright (c) 2003-2010 Apple Inc. All rights reserved.
*
* @APPLE_OSREFERENCE_LICENSE_HEADER_START@
*
Expand Down Expand Up @@ -1006,3 +1006,42 @@ socket_clear_traffic_mgt_flags(socket_t sock, u_int32_t flags)
{
(void) OSBitAndAtomic(~flags, &sock->so_traffic_mgt_flags);
}

__private_extern__ void
set_traffic_class(struct mbuf *m, struct socket *so, int mtc)
{
#if !PKT_PRIORITY
#pragma unused(m)
#pragma unused(so)
#pragma unused(mtc)
return;
#else /* PKT_PRIORITY */
if (!(m->m_flags & M_PKTHDR))
return;

if (soisbackground(so)) {
m->m_pkthdr.prio = MBUF_TC_BK;
} else if (mtc != MBUF_TC_NONE) {
if (mtc >= MBUF_TC_BE && mtc <= MBUF_TC_VO)
m->m_pkthdr.prio = mtc;
} else {
switch (so->so_traffic_class) {
case SO_TC_BE:
m->m_pkthdr.prio = MBUF_TC_BE;
break;
case SO_TC_BK:
m->m_pkthdr.prio = MBUF_TC_BK;
break;
case SO_TC_VI:
m->m_pkthdr.prio = MBUF_TC_VI;
break;
case SO_TC_VO:
m->m_pkthdr.prio = MBUF_TC_VO;
break;
default:
break;
}
}
return;
#endif /* PKT_PRIORITY */
}
20 changes: 20 additions & 0 deletions bsd/kern/uipc_socket.c
Original file line number Diff line number Diff line change
Expand Up @@ -3253,6 +3253,20 @@ sosetopt(struct socket *so, struct sockopt *sopt)
break;
}

#if PKT_PRIORITY
case SO_TRAFFIC_CLASS: {
error = sooptcopyin(sopt, &optval, sizeof (optval),
sizeof (optval));
if (error)
goto bad;
if (optval < SO_TC_BE || optval > SO_TC_VO) {
error = EINVAL;
goto bad;
}
so->so_traffic_class = optval;
}
#endif /* PKT_PRIORITY */

default:
error = ENOPROTOOPT;
break;
Expand Down Expand Up @@ -3542,6 +3556,12 @@ sogetopt(struct socket *so, struct sockopt *sopt)
error = sooptcopyout(sopt, &sonpx, sizeof(struct so_np_extensions));
break;
}
#if PKT_PRIORITY
case SO_TRAFFIC_CLASS:
optval = so->so_traffic_class;
goto integer;
#endif /* PKT_PRIORITY */

default:
error = ENOPROTOOPT;
break;
Expand Down
Loading

0 comments on commit 7aeaee7

Please sign in to comment.