-------------------------------------------------------------------------------- XNU is now ready to build!
To build the kernel for supported x86_64 machines: cd xnu-7195.81.3 make SDKROOT=macosx TARGET_CONFIGS="RELEASE X86_64 NONE"
To build for supported arm64e machines you can, e.g.: cd xnu-7195.81.3 make SDKROOT=macosx KDKROOT=/path/to/KDK TARGET_CONFIGS="RELEASE ARM64 T8101"
For a table of supported arm64 products, visit: https://kernelshaman.blogspot.com/2021/02/building-xnu-for-macos-112-intel-apple.html#xnu-arm64e
See xnu's top-level README file for additional build and configuration variables which can be passed on the command line, e.g., Speed up the build with: BUILD_LTO=0 Build the development kernel with: KERNEL_CONFIGS=DEVELOPMENT Use LOGCOLORS=y to colorize the output Use CONCISE=y to keep all the build output on a single line --------------------------------------------------------------------------------
1 2 3 4 5
cd xnu-7195.81.3 // 正常编译xnu的命令 make SDKROOT=macosx TARGET_CONFIGS="RELEASE X86_64 NONE" // 使用codeql编译命令 codeql database create xnu-database --language=cpp --command="make SDKROOT=macosx ARCH_CONFIGS=X86_64 KERNEL_CONFIGS=RELEASE"
/* * Generate an error packet of type error * in response to bad packet ip. */ void icmp_error( struct mbuf *n, int type, int code, u_int32_t dest, u_int32_t nextmtu) { ... }
if (eh->ether_dhost[0] & 1) { /* Check for broadcast */ if (_ether_cmp(etherbroadcastaddr, eh->ether_dhost) == 0) { m->m_flags |= M_BCAST; } else { m->m_flags |= M_MCAST; } }
if (m->m_flags & M_HASFCS) { /* * If the M_HASFCS is set by the driver we want to make sure * that we strip off the trailing FCS data before handing it * up the stack. */ m_adj(m, -ETHER_CRC_LEN); m->m_flags &= ~M_HASFCS; }
if ((eh->ether_dhost[0] & 1) == 0) { /* * When the driver is put into promiscuous mode we may receive * unicast frames that are not intended for our interfaces. * They are marked here as being promiscuous so the caller may * dispose of them after passing the packets to any interface * filters. */ if (_ether_cmp(eh->ether_dhost, IF_LLADDR(ifp))) { m->m_flags |= M_PROMISC; } }
/* check for IEEE 802.15.4 */ if (ether_type == htons(ETHERTYPE_IEEE802154)) { *protocol_family = PF_802154; return0; }
/* * Function: sixlowpan_attach_protocol * Purpose: * Attach a DLIL protocol to the interface * The ethernet demux actually special cases 802.15.4. * The demux here isn't used. The demux will return PF_802154 for the * appropriate packets and our sixlowpan_input function will be called. */ staticint sixlowpan_attach_protocol(struct ifnet *ifp) { int error; structifnet_attach_proto_paramreg;
/* * 6lowpan input routine. * Decapsulate the 802.15.4 Data Frame * Header decompression on the payload * Pass the mbuf to the IPV6 protocol stack using proto_input() */ staticint sixlowpan_input(ifnet_t p, __unused protocol_family_t protocol, mbuf_t m, __unused char *frame_header) { frame802154_t ieee02154hdr; u_int8_t *payload = NULL; if6lpan_ref ifl = NULL; bpf_packet_func bpf_func; mbuf_t mc, m_temp; int off, err = 0; u_int16_t len;
/* Allocate an mbuf cluster for the 802.15.4 frame and uncompressed payload */ mc = m_getcl(M_WAITOK, MT_DATA, M_PKTHDR); if (mc == NULL) { err = -1; goto err_out; }
memcpy(&len, mtod(m, u_int8_t *), sizeof(u_int16_t)); len = ntohs(len);** // This is the size read from the frame on the wire. m_adj(m, sizeof(u_int16_t)); /* Copy the compressed 802.15.4 payload from source mbuf to allocated cluster mbuf */ for (m_temp = m, off = 0; m_temp != NULL; m_temp = m_temp->m_next) { if (m_temp->m_len > 0) { m_copyback(mc, off, m_temp->m_len, mtod(m_temp, void *)); off += m_temp->m_len; } }
if (hdroffset < 0) { // 1 /* * hdroffset negative means that we have to remove * hdrlen of extra stuff */ memmove(&payload[0], &payload[hdrlen], ieee02154hdr->payload_len - hdrlen); ieee02154hdr->payload_len -= hdrlen; } else { /* * hdroffset is the size of the compressed header * -- i.e. when the untouched data starts * * hdrlen is the size of the decompressed header * that takes the place of compressed header of size hdroffset */ memmove(payload + hdrlen, payload + hdroffset, ieee02154hdr->payload_len - hdroffset); // 2, oob write here, `ieee02154hdr-> payload_len-3 = -2` memcpy(payload, hdrbuf, hdrlen); ieee02154hdr->payload_len += hdrlen - hdroffset; }