Posted by Gal Beniamini, Project Zero
It’s a well understood fact that platform security is an integral part of the security of complex systems. For mobile devices, this statement rings even truer; modern mobile platforms include multiple processing units, all elaborately communicating with one another. While the code running on the application processor (AP) has been the subject of much research, other components have seldom received the same scrutiny.
![](https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiH5xqTXV21Uv5mD_VpbggiyYO_NHW6AdpVDZRyRVEC533CEh1rLRXe-u6XgZo_HXPnDKnj5GJNJnNYSsD2BxVl2EwGdEupFV3070i1CCEhPhabV-XIbMxV88Ym5bJbyxbXQLrfEL-VWqkZgiqAc5hXAWawzDZVdqTsw5-UoG1_Fd1c7WKPN2dA-QxB/s346/W1TY1wagZMdeMIE6svCyqHmC56aJorS6WzjKrkUYPRKiYc2LkRBz-X0mhpT270HIo1G1NsSdMNf2gm9DdzvEXnoJxFTFkrTVET-SKRWXTnet-kyZSOLk5p-GP3j4pWtXDCDPbRqh.png)
Over the years, as a result of the focused attention by security folk, the defenses of code running on the application processor have been reinforced. Taking Android as a case study, this includes hardening the operating system, improving the security of applications, and introducing incremental security enhancements affecting the entire system. All positive improvements, no doubt. However, attackers tend to follow the path of least resistance. Improving the security of one component will inevitably cause some attackers to start looking elsewhere for an easier point of entry.
In this two-part blog series, we’ll explore the exposed attack surface introduced by Broadcom’s Wi-Fi SoC on mobile devices. Specifically, we’ll focus our attention on devices running Android, although a vast amount of this research applies to other systems including the same Wi-Fi SoCs. The first blog post will focus on exploring the Wi-Fi SoC itself; we’ll discover and exploit vulnerabilities which will allow us to remotely gain code execution on the chip. In the second blog post, we’ll further elevate our privileges from the SoC into the the operating system’s kernel. Chaining the two together, we’ll demonstrate full device takeover by Wi-Fi proximity alone, requiring no user interaction.
We’ll focus on Broadcom’s Wi-Fi SoCs since they are the most common Wi-Fi chipset used on mobile devices. A partial list of devices which make use of this platform includes the Nexus 5, 6 and 6P, most Samsung flagship devices, and all iPhones since the iPhone 4. For the purpose of this blog post, we’ll demonstrate a Wi-Fi remote code execution exploit on a fully updated (at the time, now fixed) Nexus 6P, running Android 7.1.1 version NUF26K.
All the vulnerabilities in the post have been disclosed to Broadcom. Broadcom has been incredibly responsive and helpful, both in fixing the vulnerabilities and making the fixes available to affected vendors. For a complete timeline, see the bug tracker entries. They’ve also been very open to discussions relating to the security of the Wi-Fi SoC.
I would like to thank Thomas Dullien (@halvarflake) for helping boot up the research, for the productive brainstorming, and for helping search the literature for any relevant clues. I’d also like to thank my colleagues in the London office for helping make sense of the exploitation constraints, and for listening to my ramblings.
Why-Fi?
In the past decade, the use of Wi-Fi has become commonplace on mobile devices. Gradually, Wi-Fi has evolved into a formidable set of specifications—some detailing the physical layer, others focusing on the MAC layer. In order to deal with this increased complexity, vendors have started producing “FullMAC” Wi-Fi SoCs.
In essence, these are small SoCs that perform all the PHY, MAC and MAC SubLayer Management Entity (MLME) processing on their own, allowing the operating system to abstract itself away from the complex (and sometimes chip-specific) features related to Wi-Fi. The introduction of Wi-Fi FullMAC chips has also improved the power consumption of mobile devices, since much of the processing is done on a low-power SoC instead of the power-hungry application processor. Perhaps most importantly, FullMAC chips are much easier to integrate, as they implement the MLME within their firmware, reducing the complexity on the host’s side.
All that said and done, the introduction of Wi-Fi FullMAC chips does not come without a cost. Introducing these new pieces of hardware, running proprietary and complex code bases, may weaken the overall security of the devices and introduce vulnerabilities which could compromise the entire system.
![](https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgFqnUgNFnxODAtsMrTIp-5f71iyZCKC02qAlQss1t4msfTlF6deNSDPMQ0AEApwaPwRSTP1NBBxI5_gkIaVZx_yYr4v9NhuVp5YTdXLH2E8mf7G-nVr3HNogReQKV3GaPhUPwdkSeHF-8QxeiDeIfVnu0w6hSG1cURcC74EhBIXyghfdU7y61gDXgn/s391/FYiKnU7H-OPvXkJXielxUV2mtu22BPCJpuauT5Ri2Dm9EJpubbT3G8OFvXmnUFdvOkGcmNZOZn5__Tq589JQ-87CaOCEIB9Rx08nbrpcE7BVxwpJbRjPjDSvaO4oMYDgwI5qin4v.png)
Exploring the Platform
To start off our research, we’ll need to find some way to explore the Wi-Fi chip. Luckily, Cypress has recently acquired Broadcom’s Wireless IOT business, and have published many of the datasheets related to Broadcom’s Wi-Fi chipsets (albeit for a slightly older SoC, the BCM4339). Reading through the datasheet, we gain some insight into the hardware architecture behind the Wi-Fi chipset.
![](https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhSO4-E82dgAv3bNJzATJsKOQoaaJ3g2eH7xn_53Fk2Ggo64-rmz3jVPYEdMhQyKsNXVgb11YQOJHgoHZbwYaukX7IUOYmvK8suD2LCegynE25Rdmzacb2RyFniJCM5CbTG3whwVJ37Pppv9p0DKs_tEyUk3OJ1_yxml7vaekhHb1TnLMUQ7AOE_W3a/s600/apx1Ic63367MdN65dAm9KdZgMahq-JkN4GTX_cavRgk4EQvZZb0mat-yXbAU3sVkPZOYgJvfRCQxEw_bRW2dtyylPWEs8emJFlbbTaNRNngyoK4dNLcD2p4k3olKMQ32-gf03Qjd.png)
Specifically, we can see that there’s an ARM Cortex R4 core, which runs all the logic for handling and processing frames. Moreover, the datasheet reveals that the ARM core has 640KB of ROM used to hold the firmware’s code, and 768KB of RAM which is used for data processing (e.g., heap) and to store patches to firmware code.
To start analysing the code running on the ARM core, we’ll need to extract the contents of the ROM, and to locate the data that is loaded into RAM.
Let’s start by tackling the second problem first - where is the data that’s loaded into the ARM core’s RAM? Since this data is not present in ROM, it must be loaded externally when the chip first powers on. Therefore, by reading through the initialisation code in the host’s driver, we should be able to locate the file containing the RAM’s contents. Indeed, going over the driver’s code, we find the BCMDHD_FW_PATH config, which is used to denote the location of the file whose contents are uploaded to RAM by the driver.
So what about the ROM’s contents? One way to extract the ROM would be to use the host driver’s chip memory access capabilities (via PIO over SDIO or PCIe) to read the ROM’s contents directly. However, doing so would require modifying the driver to enable us to issue the commands needed to dump the ROM. Another way to retrieve the ROM would be to load our own modified firmware file into RAM, into which we’ll insert a small stub that can be used to dump the ROM’s memory range. Luckily, none of these approaches is actually needed in this case; Broadcom provides an extremely powerful command-line utility called dhdutil, which can be used to interact with the chip via the bcmdhd driver.
Among the various capabilities this utility supports, it also allows us to directly read and write memory on the dongle by issuing a special command - “membytes”. Since we already know the size of the ROM (from the datasheet), we can just use the membytes command to read the ROM’s contents directly. However, there’s one last question we need to answer first - where is the ROM located? According to the great research done by the folks behind NexMon, the ROM is loaded at address 0x0, and the RAM is loaded at address 0x180000 (while NexMon focused on BCM4339, this fact remains true for newer chips as well, such as the BCM4358).
Finally, putting all this together, we can acquire the RAM’s contents from the firmware file, dump the ROM using dhdutil, and combine the two into a single file which we can then start analysing in IDA.
![](https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiSQ-n8JEzzY9nSnl8lT6gwLfdyMbbXuRpREVKkzRuD4WotLnx6HN2r4UJ4hDmfnTY8gDB2g9DMkFH8NDMJJ407bGMx7xi91tHfGal01V0UFybVy-ZftPDX3w_6TG2boWgi-AShXtDWYczqkTtrt6jmTlGMu5ToYxY7LNt6HEOTi3k-h-G1PwYMcrda/s222/iZEHMRbvDpU8oOK6BymavepG6TKpDwz77zlqfADmpet2vg4yBsD_edVfdZLsNOjFf3Ms2H-LcI_hAXJt_t3_5gGwtU4MHIaGRqq9Z0_1pH1Fc0OjDiSipJBHSSlLheN_Tnq33CZv.png)
Analysing the Firmware
Due to the relatively small size of the available memory (both ROM and RAM), Broadcom went to extreme efforts in order to conserve memory. For starters, they’ve stripped the symbols and most of the strings from the binary. This has the added bonus of making it slightly more cumbersome to reverse-engineer the firmware’s code. They’ve also opted for using the Thumb-2 instruction set exclusively, which allows for better code density. As a result, the ROM image on the BCM4358 is so tightly packed that it contains less than 300 unused bytes.
However, this is still not quite enough... Remember that the RAM has to accommodate the heap, stack and global data structures, as well as all the patches or modifications to ROM functions. Quite a tall order for a measly 768KB. To get around this, Broadcom has decided to place all the functions that are only used during the firmware’s initialisation in two special regions. Once the initialisation is completed, these regions are “reclaimed”, and are thereafter converted into heap chunks.
What’s more, heap chunks are interspersed between code and data structures in RAM - since the latter sometimes have alignment requirements (or are referenced directly from ROM, so they cannot be moved). The end result is that RAM is a jumbled mess of heap chunks, code and data structures.
![](https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjmtlUfz96faLvg6AEWsRHC4LYa3GN09zVLM8S14HM-0Ky7M7OVE240AfvEziOdZENZsll-KuP4OLnOZhPtxpoi765xzLF_kwjfZKpP216a0ZCT_11ZSiqCjUta8D5Et7MISV_bHT5SprDVXPRkKDF_0cPA3Q5_o3RVfte_XJUlHJVBZkzlq0Up7c7y/s600/oGs08Ufp79LKXUYr7f6gpLURAfh8HUMcgoabsW2Pi1NSdfFv9VOkKYdGk31IcjWioT_9qdh-8p6YySNiYsKkfYVoUhQwXfKa6PhJppHCsdUc_jCY5xebfPmc0arNAwZCOJS2aOog.png)
After spending some time analysing the firmware, we can begin identifying at least a few strings containing function names and other hints, helping us get a grasp of the code base. Additionally, the NexMon researchers have released their gathered symbols corresponding to firmware on the BCM4339. We can apply the same symbols to the BCM4339’s firmware, and then use bindiff to correlate the symbol names in newer firmware versions for more recent chips.
Lastly, there’s one more trick in our hat - Broadcom produces SoftMAC chips in addition to the FullMAC SoCs we’re analysing. Since these SoftMAC chips don’t handle the MLME layer, their corresponding driver must perform that processing. As a result, much of Broadcom’s MLME processing code is included in the open-source SoftMAC driver - brcmsmac. While this won’t help us out with any of the chip-specific features or the more internal processing code, it does seem to share many utility functions with the firmware’s code.
Hunting for Bugs
Now that we have a grasp of the firmware’s structure and have the means to analyse it, we can finally start hunting for bugs. But… Where should we start?
Even with all the tricks mentioned before, this is a relatively large and opaque binary, and strings or symbols are few and far between. One possibility would be to instrument the firmware in order to trace the code paths taken while a packet is received and processed. The Cortex R4 does, indeed, have debug registers which can be used to place breakpoints and inspect the code flow at various locations. Alternately, we could manually locate a set of functions which are used to parse and retrieve information from a received frame, and work our way backwards from there.
This is where familiarity with Wi-Fi comes in handy; Wi-Fi management frames encode most of their information in small “tagged” chunks of data, called Information Elements (IEs). These tagged chunks of data are structured as TLVs, where the tag and length fields are a single byte long.
![](https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgsIHaU2it4dXe3ftgsLaiAmlw0VsE4hj9LJTSizC91Eq7urjWtXNnqEmCW13WIokZ94t53ghv6JEl2FLSgnzGzdJhIBtsvZBCIJvJhivWUBkBcJoqKplxPtuKsRhqNTVSROsSfMspdOVV2m97-zMntRUjbnT7vDeKlSw64I4jyE1o4ecRE3O-8paW8/s226/6ZWZUFCERUbsS3vHuPAAu02eDDE-ZwcQ7pzvhPRZT8PFkUsfqGkFyNo5DHUQpAYbXXf-cvzBVekWBqQdV1hQb9OVIQCI9Bu-fKy0tq9wNoLvv9Xj0Wikv0qz7WuHs9vJTyN5QGzu.png)
Since a large portion of the information transferred in Wi-Fi frames (other than the data itself) is encoded using IEs, they make for good candidates from which we can work our way backwards. Moreover, as “tag” values are unique and standardised, we can use their values to help familiarise ourselves with the currently handled code flow.
Looking at the brcmsmac driver, we can see that there’s a single function which Broadcom uses in order to extract IEs from a frame - bcm_parse_tlvs. After a brief search (by correlating hints from nearby strings), we find the same function in the firmware’s ROM. Great.
Now we can start cross-referencing locations which call this function, and reverse each of these call-sites. While substantially easier than reversing every part of the firmware, this still takes a considerable amount of time (as the function has more than 110 cross-references, some to other wrapper functions which themselves are called from multiple locations).
After reverse engineering all of the call sites, I’ve found a few vulnerabilities related to the handling of information elements embedded in management frames.
Two of the vulnerabilities can be triggered when connecting to networks supporting wireless roaming features; 802.11r Fast BSS Transition (FT), or Cisco’s CCKM roaming. On the one side, these vulnerabilities should be relatively straightforward to exploit - they are simple stack overflows. Moreover, the operating system running on the firmware (HNDRTE) does not use stack cookies, so there’s no additional information leak or bypass required.
However, while these vulnerabilities may be comfortable to exploit, they require some set-up to get working. First, we’d need to broadcast Wi-Fi networks that support these features. 802.11r FT is an open(-ish) standard, and is implemented by hostapd. In contrast, CCKM is a proprietary standard (although some information can be found online). Figuring out how to emulate a CCKM network (or buying a CCKM-capable WLC from Cisco) would be cumbersome (or costly).
Additionally, we’d need to figure out which devices actually support the aforementioned features. Broadcom provides many features which can be licensed by customers -- not all features are present on all devices (in fact, their corresponding patches probably wouldn’t even fit in RAM).
Luckily, Broadcom makes it easy to distinguish which features are actually present in each firmware image. The last few bytes in the RAM contents downloaded to the chip contain the firmware’s “version string”. This string contains the date at which the firmware was compiled, the chip’s revision, the firmware’s version and a list of dash-delimited “tags”. Each tag represents a feature that is supported by the firmware image. For example, here’s the version string from the Nexus 6P:
4358a3-roml/pcie-ag-p2p-pno-aoe-pktfilter-keepalive-sr-mchan-pktctx-hostpp-lpc-pwropt-txbf-wl11u-mfp-betdls-amsdutx5g-txpwr-rcc-wepso-sarctrl-btcdyn-xorcsum-proxd-gscan-linkstat-ndoe-hs20sta-oobrev-hchk-logtrace-rmon-apf-d11status Version: 7.112.201.1 (r659325) CRC: 8c7aa795 Date: Tue 2016-09-13 15:05:58 PDT Ucode Ver: 963.317 FWID: 01-ba83502b
The presence of the 802.11r FT feature is indicated by the “fbt” tag. Similarly, support for CCKM is indicated by the “ccx” tag. Unfortunately, it seems that the Nexus 6P supports neither of these features. In fact, running a quick search for the “ccx” feature (CCKM support) on my own repository of Android firmware images revealed that this feature is not supported on any Nexus device, but is supported on a wide variety of Samsung flagship devices, a very partial list of which includes the Galaxy S7 (G930F, G930V), the Galaxy S7 Edge (G935F, G9350), the Galaxy S6 Edge (G925V) and many more.
So what about the other two vulnerabilities? Both of them relate to the implementation of Tunneled Direct Link Setup (TDLS). TDLS connections allow peers on a Wi-Fi network to exchange data between one another without passing it through the Access Point (AP), thus preventing congestion at the AP.
Support for TDLS in the firmware is indicated by the “betdls” and “tdls” tags. Searching through my firmware repository I can see that the vast majority of devices do, indeed, support TDLS. This includes all recent Nexus devices (Nexus 5, 6, 6P) and most Samsung flagships.
What’s more, TDLS is specified as part of the 802.11z standard (requires IEEE subscription). Since all the information regarding TDLS is available, we could read the standard in order to gain familiarity with the relevant code paths in Broadcom’s implementation. As an open standard, it is also supported by open-source supplicants, such as wpa_supplicant. As a result, we can inspect the implementation of the TDLS features in wpa_supplicant in order to further improve our understanding of the relevant code in the firmware.
Lastly, as we’ll see later on, triggering these two vulnerabilities can be done by any peer on the Wi-Fi network, without requiring any action on the part of the device being attacked (and with no indication that such an attack is taking place). This makes these vulnerabilities all the more interesting to explore.
In any case, it seems like we’ve made our mind up! We’re going to exploit the TDLS vulnerabilities. Before we do so, however, let’s take a second to learn a little bit about TDLS, and the vulnerabilities discovered (skip this part it you’re already familiar with TDLS).
802.11z TDLS 101
There are many use cases where two peers on the same Wi-Fi network wish to transfer large swaths of data between one another. For example, casting a video from your mobile device to your Chromecast would require large amounts of data to be transmitted. In most cases, the Chromecast would be relatively nearby to the caster (after all, you’d probably be watching the screen to which you’re casting). Therefore, it would seem wasteful to pass the entire data stream from the device to the AP, only to then pass it on to the Chromecast.
It’s not just the increased latency of adding an additional hop (the AP) that will degrade the connection’s quality. Passing such large amounts of data to the AP would also put a strain on the AP itself, cause congestion, and would degrade the Wi-Fi connectivity for all peers on the network.
This is where TDLS comes into play. TDLS is meant to provide a means of peer-to-peer communication on a Wi-Fi network that is AP-independant.
Over The Air
Let’s start by familiarising ourselves with the structure of TDLS frames. As you may know, 802.11 frames use the “flags” field in order to indicate the “direction” in which a frame is travelling (from the client to the AP, AP to client, etc.). TDLS traffic co-opts the use of the flag values indicating traffic in an Ad-Hoc (IBSS) network (To-DS=0, From-DS=0).
![](https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjoaaU2nk0AO13SnCVV8JfqD1JngX6PxL_xxJ1InAVPuRnfwW4a5pVO3UILNO5LrQdMrZkwuZlginO2A-g5YMJ8mvZdWBBQCMLQaicVscJ2PQ0ZA6xmciTysaGwYMZkzOvbZCJUJBO1RIPPXp3HGTBdMm_PNmHDkP8gfZzzku9TZTXl8yrO9gKQcs2V/s600/cnrrBl46eQdWi4-McFMNNlEoo3o_an9eKfEpmPxyGiLLFSfPfb-_7r7ZDmrc1xHnwcLXFDLGHsa0yFPnqkQzIbhEyzPaQc8dJN8pFDmLXinzqr0HY_LmiPqxeW1uccYjnV8cQh7J.png)
Next, TDLS frames are identified by a special ethertype value - 0x890D. TDLS frames transmitted over Wi-Fi use a constant value in the “payload type” field, indicating that the payload has the following structure:
![](https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhvRnzmVD4X49o1EsLjKwH8CkGDG1XmCxkYENKGsechFMPsSXJoaF_KupUKUCTR3jYzfd0keDW2FHHlPSCtESku7A05a3wnNng1as6zijDAwbrCPD4pv1csX0dxLrRL91kL00N_FkUwk3EAdOud2_pkdAnzfUZCSC1Ujxg1h-wuio6m2mLntYjpD2KO/s351/DVk0JecAKj9b8TVwP3AexklPaHNs4-2ri4vKvxZZJWQq5Dsg3fkmEIaC6JBLKB4bHXHKOmu_y2DUN-8gQvaASX4ohbVWYtoY3E1qmjj2uvGaEEKLJ8XqCWmFXp-6ydX8k5M410fG.png)
The category for TDLS frames is also set to a constant value. This leaves us with only one field which distinguishes between different TDLS frame types - the “action code”. This 1-byte field indicates the kind of TDLS frame we’re transmitting. This, in turn, controls the way in which the “payload” in interpreted by the receiving end.
High-Level Flow
Before two peers can establish a connection, they must first know about the existence of one another. This is called the “discovery” phase. A Wi-Fi client that wishes to discover TDLS-capable peers on the network, can do so by sending a “TDLS Discovery Request” frame to a peer. A TDLS-capable peer that receives this frame, responds by sending a “TDLS Discovery Response” frame. The request and response are correlated to one another using a 1-byte “dialog token”.
![](https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiO1KkAPq5I-0bym2cycO90XPliT1KVY9TOdKs0oGsmNdqQxjNcsAJH428tvp0NFmyRXkSfZU72GbJBubC2n7bIDmfk5G0lpxtYxQmy221-FU5hF5hHZqvPvvyYL050Zirb63Ym5QLnD9U1QWmPNF4Aw3G8DkuAq38lxb8Ic5rYC-NeK4kqJbGqeqDu/s333/kV-mDvwiCz_zKjCZy_4nKwgtbyX_2XSHWm4ikhZKa6lmWC8kRfUm_PLra0Svp_qZcL3Ma_MLv5VWQaXjZxHd0Otlp9V5W35ZB81G6TU57RBuDx2-toCZlOOCsYPwtv1EjGGYbo47.png)
Next, the peers may wish to set up a connection. To do so, they must perform a 3-way handshake. This handshake serves a dual purpose; first, it indicates that a connection is successfully established between the two peers. Second, it’s used to derive the TDLS Peer Key (TPK), which secures the TDLS traffic between the peers.
![](https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhKHXmnuBUM9r10M0e_IP0qfndOdaNs-JpxlmfpybqdXQVigN92NvXSEv35UXJTcGi0lRUf53Pcwja5l9zhI9whw00S-9Ot5xHZINetrtsIuskYVUHzG22TcBUxeqfqe-VFOM_xnbEbbovrwnn9vOTnVt3OXYCCMa_mA78WkfrjtqUB92wIxgTWijg3/s508/Oh-TcD-3_j_JDlBzs5tX1kDwEYYxdGbcV6MhN7ko0hVRGceyZeoS3TNzXW_4XFiiBMGmRWa6QLRVqwTCgsUOIBhrOOV132VU2lUnPWHV0lUonR-I4oPvQI40iB7xfwWUGFiGZc-3.png)
Finally, once the connection is created, the two peers can exchange peer traffic between one another. When one of the peers wishes to tear-down the connection, they may do so by sending a “TDLS Teardown” frame. Upon reception of such a frame, the TDLS-peer will remove the connection and free up all the related resources.
Now that we know enough about TDLS, let’s take a closer look at the vulnerabilities at hand!
The Primitives
In order to ensure the integrity of messages transferred during the setup and teardown phases, the corresponding TDLS frames include Message Integrity Codes (MIC). For the setup phase, once the second handshake message (M2) is received, the TPK can be derived by both parties. Using the TPK, the TDLS-initiator can calculate a MIC over the contents of the third handshake frame, which can then be verified by the TDLS-responder.
![](https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjJJqvQ4LceVp2kxNyFwZKa6hl1U02FD_mOL63FJuf6V-Ft-lpAVWmnTJyESS8n-j5XJ3ARXHTmaC3HXRzXmaoeds3hJ2rNxypmNxr_qM_ZpDOcUxV5i8jTznuhO4MrGLLr8Jlwpn7AlfNOXSMIYtU33To7UiMhHqKLy5d2no_pkCKtdl0SVDjSje4A/s600/dzFVyIu0UArFseM_j0zi6HIv5Oir-w6nJAGkVBaMYP4nplNaRp0unCEEKYiCueCgoWP3FKjSVrS0sAhZZiqMJsvflDRBSmCPSQK4-njtl1o7bvqNFhEzq3XdJWhEnm2kv3x5C6gt.png)
![](https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEj8K0YfaMqDu_q2xMMF5ubZBPqLjQkhfHg9YdFSMR6LMHe5HIIbpkLu2XB4-6Ny9xapVyY3PcLQGJeBuhz7y8CHWxYSKzzyUgId5o58rDah-lGF1FzeXcKWxRzqweTEqsYZNAVx05Qx-GtrK2K_G6pRfP90JyOViadJ7vszojFnlGOA53KpL6hjde0i/s600/cqTEaQ8v5sek0Hua-eP2__YqIScneYwaly70f4N5H18UbsG2p0PuEb0aUeei1073Jii7WqAnQ46VyoxpzV0K1PX57xKSL6jg2_kQlRCvmz0EMml5dNEwbPJhsDjJdtNxiVpM3gQO.png)
So how can we find these calculations in the firmware’s code? Well, as luck would have it, some strings referring to TDLS were left-over in the firmware’s ROM, allowing us to quickly home in on the relevant functions.
After reverse-engineering much of the flow leading up to the processing of handling TDLS action frames, we finally reach the function responsible for handling TDLS Setup Confirm (PMK M3) frames. The function first performs some validations to ensure that the request is legitimate. It queries the internal data structures to ensure that a TDLS connection is indeed being set up with the requesting peer. Then, it verifies the Link-ID IE (by checking that its encoded BSSID matches that of the current network), and also verifies the 32-byte initiator nonce (“Snonce”) value (by comparing it to the stored initial nonce).
Once a certain degree of confidence is established that the request may indeed be legitimate, the function moves on to call an internal helper function, tasked with calculating the MIC and ensuring that it matches the one encoded in the frame. Quite helpfully, the firmware also includes the name for this function (“wlc_tdls_cal_mic_chk”).
After reverse-engineering the function, we arrive at the following approximate high-level logic:
1. uint8_t* buffer = malloc(256);
2. uint8_t* pos = buffer;
3.
4. //Copying the initial (static) information
5. uint8_t* linkid_ie = bcm_parse_tlvs(..., 101);
6. memcpy(pos, linkid_ie + 0x8, 0x6); pos += 0x6; //Initiator MAC
7. memcpy(pos, linkid_ie + 0xE, 0x6); pos += 0x6; //Responder MAC
8. *pos = transaction_seq; pos++; //TransactionSeq
9. memcpy(pos, linkid_ie, 0x14); pos += 0x14; //LinkID-IE
10.
11. //Copying the RSN IE
12. uint8_t* rsn_ie = bcm_parse_tlvs(..., 48);
13. if (rsn_ie[1] + 2 + (pos - buffer) > 0xFF) {
14. ... //Handle overflow
15. }
16. memcpy(pos, rsn_ie, rsn_ie[1] + 2); pos += rsn_ie[1] + 2; //RSN-IE
17.
18. //Copying the remaining IEs
19. uint8_t* timeout_ie = bcm_parse_tlvs(..., 56);
20. uint8_t* ft_ie = bcm_parse_tlvs(..., 55);
21. memcpy(pos, timeout_ie, 0x7); pos += 0x7; //Timeout Interval IE
22. memcpy(pos, ft_ie, 0x54); pos += 0x54; //Fast-Transition IE
As can be seen above, although the function verifies that the RSN IE’s length does not exceed the allocated buffer’s length (line 13), it fails to verify that the subsequent IEs also do not overflow the buffer. As such, setting the RSN IE’s length to a large value (e.g., such that rsn_ie[1] + 2 + (pos - buffer) == 0xFF) will cause the Timeout Interval and Fast Transition IEs to be copied out-of-bounds, overflowing the buffer.
![](https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjJGKWFnB3Clwhiu49alKrQba7FKCKvUrdih9dX3a5JZk93DY8f7UX3INTvOVhAGx34jiLKgOJdGpJvm3sUfDW6ORFUHRqLfeyXKTmSNArDssetsVIMQkU2KVaF4QayPzkZNCLNrYn3l-8fSnafQIRBRoBQAYY6yLwlgiMgwNThmIz1JrKgJ4nsOox9/s461/JZmas5VWGmWAi9hcs__eDY6QYbyZv3kZv0eFFROiDpVciAhoycAIyPmstKdF6s0LTOoL2nJqJ1UJduhwSwculdvGHjFw49pr6Td0YF5vcX5_PtI-E6jt6uQBBxYSrHZpOkjIMzNc.png)
![](https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgF0-bhAV6qEm9-VxVXYjxr400P4puS0GGU0PjbUvjMn9xkrHWqpy9CkyfkU1TQx137FbTb4b8EYj1EiL8bibQDKfq2JqXAit6DsmSmeDIR4M1jEddOXodVxDDW-mprH7hiBIg3DAbIVTLDE_5PIBMFs2twgygCqCB7hgOitZZNon8bnWcLl0ku_KAT/s571/0CDFaaI71GyJJj_pMkJfhSNBLcJPFb0ijL-lL-XiQj7Sq1lwQDaivaowWxfi1t9c9SNCH108FHyPFnr3Y4kb7iHsDVSINxyG9sD4IDAuNi-BVcBaHko_Bd30JjeBBtfpU-mVgPOK.png)
In this diagram, orange fields are those which are “irrelevant” for the overflow, since they are positioned within the buffer’s bounds. Red fields indicate values that cannot be fully controlled by us, and green fields indicate values which are fully controllable.
For example, the Timeout Interval IE is verified prior to the MIC’s calculation and only has a constrained set of allowed values, making it uncontrollable. Similarly, the FTIE’s tag and length fields are constant, and therefore not controllable. Lastly, the 32-byte “Anonce” value is randomly chosen by the TDLS responder, placing it firmly out of our field of influence.
But the situation isn’t that grim. In fact, several of the fields in the FTIE itself can be arbitrarily chosen - for example, the “Snonce” value is chosen by the TLDS-initiator during the first message in the handshake. Moreover, the “MIC Control” field in the FTIE can be freely chosen, since it is not verified prior to the execution of this function.
In any case, now that we’ve audited the MIC verification for the setup stage, let’s turn our sights towards the MIC verification during the teardown stage. Perhaps the code is similarly broken there? Taking a look at the MIC calculation in the teardown stage (“wlc_tdls_cal_mic_chk”), we arrive at the following high-level logic:
1. uint8_t* buffer = malloc(256);
2. ...
3. uint8_t* linkid_ie = bcm_parse_tlvs(..., 101); //Link ID
4. memcpy(buffer, linkid_ie, 0x14);
5. ...
6. uint8_t* ft_ie = bcm_parse_tlvs(..., 55);
7. memcpy(buffer + 0x18, ft_ie, ft_ie[1] + 2); //Fast-Transition IE
Ah-ha, so once again a straightforward overflow; the FT-IE’s length field is not verified to ensure that it doesn’t exceed the length of the allocated buffer. This means that simply by providing a crafted FT-IE, we can trigger the overflow. Nevertheless, once again there are several verifications prior to triggering the vulnerable code path which limit our control on the overflowing elements. Let’s try and plot the placement of elements during the overflow:
![](https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEj4C3TMrfd7Swzsy4cGIr_j2v18c5LqQnvmCxjxx5Qeu8cvWURWHg8bimoDiD9nxx5Hjpbw6b3E5J6cjgpkQJJ4H9FgtBTv8EvyWeiQoA21iuYbYJNk-71NX91SZbxxlkjE6AW5IIdHWjrHbO8lams-lz1Bc6V0IyEvrI5TlvEhD0sFqGOmdLNo_uU3/s600/F27uAPWeNAU7MulIxiZcVVTjK61mYx4DN8eq2yplHCNXhM7NuZodxFoR_5FsRm4zMip6ILZ-Me2vk_w-b0kao2-hMGldahOFWQYrRaDZcs-pzpe4gfhjqh1yHh1CU_QNHFlTbTYD.png)
This seems much simpler - we don’t need to worry ourselves about the values stored in the FTIE that are verified prior to the overflow, since they’re all placed neatly within the buffer’s range. Instead, the attacker controlled portion is simply spare data that is not subject to any verification, and can therefore be freely chosen by us. That said, the overflow’s extent is quite limited - we can only overwrite at most 25 bytes beyond the range of the buffer.
Writing an Exploit
Investigating the Heap State
At long last we have a grasp of the primitives at hand. Now, it’s time to test out whether our hypotheses match reality. To do so, we’ll need a testbed that’ll enable us to send crafted frames, triggering the overflows. Recall that wpa_supplicant is an open-source portable supplicant that fully supports TDLS. This makes it a prime candidate for our research platform. We could use wpa_supplicant as a base on top of which we’ll craft our frames. That would save us the need to re-implement all the logic entailed in setting up and maintaining a TDLS connection.
To test out the vulnerabilities, we’ll modify wpa_supplicant to allow us to send TDLS Teardown frames containing an overly-large FTIE. Going over wpa_supplicant’s code, we can quickly identify the function in charge of generating and sending the teardown frame - wpa_tdls_send_teardown. By adding a few small changes to this function (in green) we should be able to trigger the overflow upon reception the teardown frame, causing 25 bytes of 0xAB to be written OOB:
static int wpa_tdls_send_teardown(struct wpa_sm *sm, const u8 *addr, u16 reason_code)
{
...
ftie = (struct wpa_tdls_ftie *) pos;
ftie->ie_type = WLAN_EID_FAST_BSS_TRANSITION;
ftie->ie_len = 255;
os_memset(pos + 2, 0x00, ftie->ie_len);
os_memset(pos + ftie->ie_len + 2 - 0x19, 0xAB, 0x19); //Overflowing with 0xAB
os_memcpy(ftie->Anonce, peer->rnonce, WPA_NONCE_LEN);
os_memcpy(ftie->Snonce, peer->inonce, WPA_NONCE_LEN);
pos += ftie->ie_len + 2;
...
}
Now we just need to interact with wpa_supplicant in order to setup and teardown a TDLS connection to our target device. Conveniently, wpa_supplicant supports many command interfaces, including a command-line utility called wpa_cli. This command line interface also supports several commands exposing TDLS functionality:
- TDLS_DISCOVER - Sends a “TDLS Discovery Request” frame and lists the response
- TDLS_SETUP - Creates a TDLS connection to the peer with the given MAC address
- TDLS_TEARDOWN - Tears down the TDLS connection to the peer with the given MAC
Indeed, after compiling wpa_supplicant with TDLS support (CONFIG_TDLS), setting up a network, and connecting our target device and our research platform to the network, we can see that issuing the TDLS_DISCOVER command works - we can indeed identify our peer.
![](https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgDJS-Gd9IjOJFqlvyWLPdMgcmBUKGsPc_RBL6FNn9BZnCW-TLobRiVAoiXib3tS9Gk_AN07VhAslXxcS-lVjrD2nK5F8N0SUbVBjd2snWveEoCUKi-d2FxRlxmZ9gBRx8cD3YHyXZVnCNFKv-h-9aaqmdsoaC4upID2jQ3ObcA6ca2qOkKBefgxcGA/s600/WH5rcRXG5QbKB9htMUAJ1LL3JI4voS7v_OU-orrfx412Cjx72R-oA87hvx7ehmD4ee99wMBA-ItYAJnCXsIOvzvRdVNyMy9CmQFkcJ2CbpST5Bdq4m3LO3d8x-vf5V2y3vT0qNXF.png)
Moving on, we can now send a TDLS_SETUP command, followed by our crafted TDLS_TEARDOWN. If everything adds up correctly, this should trigger the overflow. However, this raises a slightly more subtle question - how will we know when the overflow occurs? It may just so happen that the data we’re overflowing is unused. Alternately, it may be the case that when the firmware crashes, it just silently starts up again, leaving us none the wiser.
To answer this fully, we’ll need to understand the logic behind Broadcom’s heap implementation. Digging into the allocator’s logic, we find that it is extremely straightforward; it is a simple “best-fit” allocator, which performs forward and backward coalescing, and keeps a singly linked list of free chunks. When chunks are allocated, they are carved from the end (highest address) of the best-fitting free chunk (smallest chunk that is large enough). Heap chunks have the following structure:
![](https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgp9U9A6gi2hdNFf0G7WlhC3hZb4uSGiVNQGlHWP-3jKt44YaTR535NEiuCU-N-eg1CaN2YjwCLs24RyclTwQevZckyn3IjSAm-WbPTMVC6gpRZ177-zP6UpDkgHy1z90SUTTUANzIlmVwpzDDzBYsFsGkQ_ibPhHe9gjPkjE6tZCEJ9l39zr_1vad-/s281/eYtCRiw_J6qu5Uwj4BIJS5lsCZcdjEor3SNdp3m_Ow7sj-F3-nW0xTZgGfqJuNxzH2FdTSNote4AvrB2OJBGkhHZPT58BeZN60NSM42pLaJ2ljUD9qKaEkZexD_vBff48JEZcYgt.png)
(recall that the Cortex R4 is a 32-bit ARM processor, so all fields are stored in little-endian)
By reverse-engineering the allocator’s implementation, we can also find the location of the pointer to the head of the first free-chunk in RAM. Combining these two facts together, we can create a utility which, given a dump of the firmware’s RAM, can plot the current state of the heap’s freelist. Acquiring a snapshot of the firmware’s RAM can be easily achieved by using dhdutil’s “upload” command.
After writing a small visualiser script which walks over the heap’s freelist and exports the its contents into dot, we can plot the state of the freelist using graphviz, like so:
![](https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhpl1Q7gb_LU-k32oLT3dNtZ__I-jNsJcnBlzkkmcSC-BxTY8VJnxAN09OdqWsioLTBUzganqy9ugfPLts8HGb0SPaDzjQRePaTyFVX6tfQ4w8NgRCKJpkiQNVDTyPGlfrMo9KLcv5ANwYeIKBES6-3M0bMx19TUMl_J5AIgSvyidu_aZ76KuoS2b4C/s600/uWCOeaKucccgPJ5z3CuclZ-KTjcvbSLasBWvL1Cl61qZhnQgscb5egcZjGyrDnzLKMe2Ch-GJWhsoMNwbGUEKcX_TCNEGQlJgl-1J_kjmxP6uMaz-wmVLE_-hWHVbeePgtz_JSZX.png)
Now, we can send out crafted TDLS_TEARDOWN frame, immediately take a snapshot of the firmware’s RAM, and check the freelist for any signs of corruption:
![](https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgZBk9VNhxaPeTBNAZbE7PxoWA5S4QxPsnzIZai199IJhB2l2gRe3aJmTajHm9ettunTfwlLspwCfBWPcrAOwqtssRLxq61g_JPur8WCeaUaYRsp5S-K7CqJRNcjUoOQ4JI6OY929dxQTrLA9gQ7n853cYGYXhVQpEqys3_bccPERSvpZ1p2JGeX-ws/s600/138O5kCGyAtfYuzEJ7-EUA6xsMAJGG5Jk21cRb82j9qX40fwsN9mA6KEGmw0yAMz5vzrkGw67GLE7NK0KjBPGdt8UcQcpyMEQh2gU2mKv9949UrSZ_iFUM0Qelz458yAkNUTl8oZ.png)
Ah-ha! Indeed one of the chunks in the freelist suddenly has an exceptionally large size after tearing down the connection. Recall that since the allocator uses “best-fit”, this means that subsequent allocations won’t be placed in this block as long as other large enough free chunks exist. This also means that the firmware did not crash, and in fact continued to function correctly. Had we not visualised the state of the heap, we wouldn’t have been able to determine anything had happened at all.
In any case, now that we’ve confirmed that the overflow does in fact occur, it’s time to move to the next stage of exploitation. We need less crude tools in order to allow us to monitor the state of the heap during the setup and teardown processes. To this end, it would be advantageous to hook the malloc and free functions in the firmware, and to trace their arguments and return values.
First, we’ll need to write a “patcher”, which will allow us to insert hooks on given RAM-resident functions. It’s important to note that both the malloc and free functions are both present in RAM (they are among the first functions in the RAM’s code chunk). This allows us to freely re-write their prologues in order to introduce a branch to our own code. I’ve written a patcher which performs insertion of such hooks, allowing execution of small assembly stubs before and after the invocation of the hooked function.
In short, the patcher is fairly standard - it writes the patch’s code to an unused region in RAM (the head of the largest free chunk in the heap), and then inserts a Thumb-2 wide branch (which is, coincidentally, perhaps the ugliest encoding for an opcode I’ve ever seen - see 4.6.12 T4) from the prologue of the hooked function to the hook itself.
![](https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhGVBIu0V92LnkDaaJNQ5mL_gRsj5PfCvabLsaIKEis2VeuzX_id3fJsM9WyY_u8uId_ZOT6lFu3Zc_fxUAOd9eSDD3tby_XngPmgw2iguWK44aE2Dji42y5fPKE-mA7dD6ISnu3DGxeeglf7eo3oRy2LSmPn3kQLeT_9owPzrAJ1m2NxcqjBlFnDgL/s600/yTM_5n1RHaiIgjzheF44py3pPgTAWPn-u9aUFwq7LdcxkrcNZr2RQMQT34mbRSHybYt59jsKN41HKoKRO23FlBCu8ZkktaK4j_-pEW3g0L_pySsbj31ZIzR_nY02KMJrVs9HM8Ef.png)
Using our new patcher, we can now instrument the malloc and free functions in order to add traces allowing us to follow every operation occurring on the heap. These traces can then be read from the firmware’s console buffer, by issuing dhdutil’s “consoledump” command. Note that on some newer chips, like the BCM4358 on the Nexus 6P, this command fails. This is because Broadcom forgot to add the offset to the magic pointer in the firmware pointing to the console’s data structure. You can fix this either by adding the correct offset to the driver (see debug_info_ptrs), or by writing the magic value and pointer to one of the probed memory addresses in the list.
In any case, you can find both the malloc and free hooks, and the associated scripts needed to parse the traces from the firmware, here.
Using the newly acquired traces, we can write a better visualiser, allowing us to trace the state of the heap throughout the setup and teardown phases. This visualiser will have visibility into every operation occurring on the heap, offering far more granular data. I’ve written such a visualiser, which you can find here.
Without further ado, let’s take a look at heap activity while establishing a TDLS connection:
![](https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiGVJhp-sp08qasgGgKfgHG5fWAgEvifGSnr33ou8tTCCCNcz92FK-xXD8P0ywAxs0g_N8xs7-oamDiQtn-S0P1t4Qy8kPozvWuFXLYQ-swxxPZT42o1qicVdk6hMjD6HYNvJ2SFXDJicKSt31TyiFx58suDMYIDGGnV6YzFsDRjZAno_JlZMiuQPp6/s600/eg7DzhnDy2u8WLaLqI3D07X6RUCchz0l8bb4yrG_4wdPF61QkGfP5rt4NgwNJ7HuKc7c7YMryhflDKW7enEdmExIgUXWHYS60CcHTdDbM2rTpweNiFNAlT21_YBbCjQGZFDqydKR.png)
The vertical axis denotes time - each line is a new heap state after a malloc or free operation. The horizontal axis denotes space - lower addresses are on the left, while higher addresses are on the right. Red blocks indicate chunks that are in-use, grey blocks indicate free chunks.
As we can clearly see above, establishing a TDLS connection is a messy operation. There are many allocations and deallocations, for regions both large and small. This abundance of noise doesn’t bode well for us. Recall that the overflow during the setup stage is highly constrained, both in terms of the data being written, and in terms of the extent of the overflowing data. Moreover, the overflow occurs during one of the many allocations in the setup phase. This doesn’t allow us much control over the state of the heap prior to triggering the overflow.
Taking a step back, however, we can observe a fairly surprising fact. Apart from the heap activity during the TDLS connection establishment, it seems like there is little to no activity on the heap whatsoever. In fact, it turns out that transmitted and received frames are drawn from a shared pool, instead of the heap. Not only that, but their processing doesn’t incur a single heap operation - everything is done “in-place”. Even when trying to intentionally cause allocations by sending random frames containing exotic bit combinations, the firmware’s heap remains largely unaffected.
This is both a blessing and a curse. On the one hand, it means that the heap’s structure is highly consistent. In the seldom events that data structures are allocated, they are immediately freed thereafter, restoring the heap to its original state. On the other hand, it means that our degree of control over the heap’s structure is fairly limited. For the most part, whatever structure the heap has after the firmware’s initialisation, is what we’re going to have to work with (unless, of course, we find some primitive that will allow us to better shape the heap).
Perhaps we should take a look at the teardown stage instead? Indeed, activating the traces during the TDLS teardown stage reveals that there are very few allocations prior to triggering the overflow, so it seems like a much more convenient environment to explore.
![](https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgHz0boXHOIySdbLw2AwWfaVtA9jayye5GH5EuHhwJcNoGuP3qVGW0crchXrtF8Q9LuFvmpR8p9lBUgZ4yzS_6slAv-hDDMlkpJfkI98PenrVL3M4aWiWnlIgKxqqf_243DaYRqiqJHaLW8qHToULmC6Ce7A2xVq1XvwSaIr86dx5m3yGT6C5VE3tpP/s600/6bupfg8Vj2r6IiRPAVUUfjo0hCqsKlhmA2aXh1LZQyQIUn90ysw3dLCyVPIvkYv0k10bjKVrfJOJwJB2hrTP8iX6QIEP8YIl-mLFgEpRc8k0bIZKkPBYHTiafHpyJ_5H-w5xOaGk.png)
While these in-depth traces are useful for getting a high-level view of the heap’s state, they are rather difficult to decipher. In fact, in most cases it’s sufficient to take a single snapshot of the heap and just visualise it, as we did earlier with the graphviz visualiser. In that case, let’s improve our previous heap visualiser by allowing it to produce detailed graphical output, based on a single snapshot of the heap.
As we’ve seen earlier, we can “walk” over the freelist to extract the location and size of each free chunk. Moreover, we can deduce the location of in-use chunks by walking over the gaps between free chunks and reading the “size” field from each in-use chunk. I’ve written yet another visualiser that does just that - it simply produces a visualisation of the heap’s state from a series of “snapshot” images.
Using this visualiser, we can now take a look at the state of the heap after setting up a TDLS connection. This will be the state of the heap we need to work with when we trigger the overflow during the teardown stage.
(Upper Layer: initial heap state, Bottom Layer: heap state after creating a TDLS connection)
In the next blog post, we’ll see how we can use our assumed control of the Wi-Fi SoC in order to further escalate our privileges into the application processor, taking over the host’s operating system!
![](https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEh4Sk6XV9AxItH1tfXZeVOm2MaaEZ5t6w2oA_5Byydo6aqF6xYMOdQnOlkjij5Q1iIRZ0wFDBZVZ2iinLytXqipAqKZTXHj-9Nu0FUO3XVay22TJkggSzIYEu2RrqIfxrwh7NBVHMtBTU5Uki-rIvBZxWxCEynUWN2LkdZRGWlS4Kq0Iuwjrafhqzb2/s600/_1WqFb7VJbmEaV5v7OOTtqQZMt_L6vg3PpMSqw4_olfFfMCl3B-jkidkdCw1WXmxPWNrXYN5nYUawsM6acJ9tI6yRCNk3x_KwL-xG3jPsug9f1zr_jCLnpO3um00Thz2H0P45fy4.png)
We can see that after setting up the TDLS connection, most of the heap’s used chunks are consecutive, but also two holes are formed; one of size 0x11C, and another of size 0x124. Activating the traces for the teardown stage, we can see that the following allocations occur:
(29) malloc - size: 284, caller: 1828bb, res: 1f0404
(30) free - ptr: 1f0404
(31) malloc - size: 20, caller: 18c811, res: 1f1654
(32) malloc - size: 160, caller: 18c811, res: 1f0480
(33) malloc - size: 8, caller: 80eb, res: 1f2a44
(34) free - ptr: 1f2a44
(35) free - ptr: 1f1654
(36) free - ptr: 1f0480
(37) malloc - size: 256, caller: 7aa15, res: 1f0420
(38) malloc - size: 16, caller: 7aa23, res: 1f1658
The highlighted line denotes the allocation of the 256-byte buffer for the teardown frame’s MIC calculation, that same one we can overflow using our vulnerability. Moreover, it seems as though the heap activity is quite low prior to sending the overflow frame. Combining the heap snapshot above with the trace file, we can deduce that the best-fitting chunk for the 256-byte buffer is in the 0x11C-byte hole. This means that using our 25-byte overflow we’ll be able to overwrite:
- The header of the next in-use chunk
- A few bytes from the contents of the next in-use chunk
Let’s take a closer look at the next in-use chunk and see whether there’s any interesting information that we’d like to overwrite there:
![](https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiWm5yPiWjrfiCZNdnsJeWPTExZhy7m-5ktgCzWbKVimMCJ7zLJrhudmB797nDNSks2mrQrLFEY61hIY1l4GG5wpLeYVol_oeZS20pkHeS_4qqXzEOw2HzMyqbbaLClM17oVH4R5d0X3nbKGbZLFCDEHE5CGh0mizLa3AOmktwfy1KHA-gPVD82NPLm/s600/KVqmChVVa-PjdOB5-i5yyES2nFVPr1ZQu1ekhuyll5PsvVcwxg7PRcBlXd5p5G3IrGmDGnXGCNUVb4y1XcKb-8cf-jjg8dqTnSzhWI1YlPxqLEhIWjDLBYUpENGvBbdD9sxyNsb3.png)
Ah, so the next chunk is mostly empty, save for a couple of pointers near its head. Are these pointers of any use to us? Perhaps they are written to? Or freed at a later stage? We can find out by manually corrupting these pointers (pointing them at invalid memory addresses, such as 0xCDCDCDCD), and instrumenting the firmware’s exception vector to see whether it crashes. Unfortunately, after many such attempts, it seems as though none of these pointers are in fact used.
This leaves us, therefore, with a single possibility - corrupting the “size” field of the in-use chunk. Recall that once the TDLS connection is torn down, the data structures relating to it are freed. Freeing an in-use chunk whose size we’ve corrupted could have many interesting consequences. For starters, if we reduce the size of the chunk, we can intentionally “leak” the tail end of the buffer, causing it to remain forever un-allocatable. Much more interestingly, however, we could set the chunk’s size to a larger value, thereby causing the next free operation to create a free chunk whose tail end overlaps another heap chunk.
![](https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjwVTgyUCCApfO6_ksd5gKN5TLIUCPpIXwEQYeyHyHPFF6dHZX7-_ASe8rnG-YXLvmSqG_L3UV7o5rCoygBAveeWY2JL18nkxqKR9JFLtduKzY3D48H4dA-kqX_YKwArulc1eKCk1X50XkB0Mk0VuhT9Qw6pzwkErD69gvj1I6ZTHNMGU-9Whd8VtGE/s600/YDR4dBZmX0JFny3gnUrVJBsPmT-95wF68N4EEDfWI2lejYIRMF86-stVJ57GqOBf1PheT-ccr9tdbB-LWPydxscdXO5sc6rFFdLuRmMiu5yJSbukXuxsHclkxDGZl6DhEKNx3L9W.png)
Once a free chunk overlaps another heap chunk, subsequent allocations for which the overlapping free chunk is the best-fit will be carved from the end of the free chunk, thereby corrupting whatever fields reside at its tail. Before we start scheming, however, we need to confirm that we can create such a state (i.e., an overlapping chunk), after the teardown operation completes.
Creating an Overlapping Chunk
Recall that the MIC check is just one of many operations that take place when a TDLS connection is torn down. It may just so happen that by overwriting the next chunk’s size, once it is freed during the collection of the TDLS session’s data structures, it may become the best-fit for subsequent allocations during the teardown process. These allocations may then cause additional unintended corruptions, which will either leave the heap in a non-consistent state or even crash the firmware.
However, the search space for possible sizes isn’t that large - assuming we’re only interested in chunk sizes that are not larger than the RAM itself (for obvious reasons), we can simply enumerate each of the heap states produced by overwriting the “size” field of the next chunk with a given value and tearing down the connection. This can be automated by using a script on the sending (to perform the enumeration), while concurrently acquiring “snapshots” of RAM on the device, and observing their state (whether or not they are consistent, and whether the firmware managed to resume operation after the teardown).
Specifically, it would be highly advantageous if we were able to create a heap state whereby two free chunks overlap one another. In such a condition, allocations taken from one chunk, can be used to corrupt the “next” pointer of the other free chunk. This could be used, perhaps, to control the location of subsequent allocations - an interesting primitive in it’s own right.
In any case, after running through a few chunk sizes, tearing down the TDLS connection and observing the heap state, we come across quite an interesting resulting state! By overwriting the “size” field with the value 72 and tearing down the connection, we achieve the following heap state:
![](https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEii5MoKH8RuFYOar4v-lQywN1A-sPqwaHx0bRt0VufnRACnQxfw9K9p-ijpLHf8iY2yC5iY-qN4yTC9XfdZe4xrK4sCJpRNspz3Uc-80ZgAJ_lqZljwDz8B23sSDZ-_IFuglL2372PxNQFeqzDVslD6JJ7jT-HygXG76-DqdVfINuMN9drpO3rzzlNC/s600/pCBPThLDJsuThEzhg6oQnMRSrnnq2FYk7a62kF9wtwxiHZGiYi0POTHXPTHZX0Bwtu7DCYTUunYGN6qmP5PgU4a9cXbjtnzBismBbH4_PtOZ7PHpDAumj7imIE9nWuKDoZLzlmFf.png)
Great! So after tearing down the connection, we are left with a zero-sized free chunk, overlapping a different (larger) free chunk! This means that once an allocation is carved from the large chunk, it will corrupt the “size” and “next” fields of the smaller chunk. This could prove very useful - we could try and point the next free chunk at a memory address whose contents we’d like to modify. As long as the data in that address conforms with the format of a free chunk, we might be able to persuade the heap to overwrite the memory at that address with subsequent allocations.
Finding a Controlled Allocation
To start exploring these possibilities, we’ll first need to create a controlled allocation primitive, meaning we either control the size of the allocation, or it’s contents, or (ideally) both. Recall that, as we’ve seen previously, it is in fact very hard to trigger allocations during the normal processing of the firmware - nearly all the processing is done in-place. Moreover, even for cases where data is allocated, its lifespan is very short; memory is immediately reclaimed once it’s no longer used.
Be that as it may, we’ve already seen at least one set of data structures whose lifetime is controllable, and which contains multiple different pieces of information - the TDLS connection itself. The firmware must keep all the information pertaining to the TDLS connection as long as its active. Perhaps we could find some data structure relating to TDLS which could act as a good candidate for a controlled allocation?
To search for one, let’s start by looking at the function handling each of the TDLS action frames - wlc_tdls_rcv_action_frame. The function starts by reading out the TDLS category and action code. Then, it routes the frame to the appropriate handler function, according to the received action code:
![](https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjtTh4L114bCy_EjgCSgNn5ltuBBYyCAPmcLEXDMMAp2RSb_kWcQmQs3tZaTWvPFhAKRgOc55KE8WWY883BatmQcXroQ3Bcr6e5dN5xo3IxO29VzLVxFpNhj2UuPJHpBjSjdPs9qUc7ZfSoO852SBAq_GpsWmXAbcDXtALiVS3-AzYJUws1c5K2ZAMW/s559/0n0d5gtlNryrVDpLInpLUky3KwYhQ7TTSj7iRwT7fuBSbmBigiGlQk8EaKuYuSob78vXIT-QPjHpcLW4mJnKbTfz6LHt-r3m7o24XnA0MghcbQQcQxy2iaERqJuVpD-8-HjdDcys.png)
We can see that apart from the regular, specification-defined action codes, the firmware also supports an out-of-spec frame with an action code of 127. Anything out-of-spec is automatically suspect, so that might be as good a place as any to look for our primitive.
Indeed, digging into this function, we find out that it performs a rather curious task. First, it verifies that the first 3 bytes in the frame’s contents match the Wi-Fi alliance OUI (50:6F:9A). Then, it retrieves the fourth byte of the frame, and uses it as a “command code”. Currently, only two vendor-specific commands are implemented, commands #4 and #5. On a high-level; command #4 is used to send a tunneled probe request over the TDLS connection, and command #5 is used to send an “event” notification to the host, signalling that a “special” frame has arrived.
However, much more interestingly, we see that the implementation for command #4 seems relevant to our current pursuit. First, it does not require the existence of a TDLS connection in order to be processed! This allows us to send the frame even after tearing down the connection. Second, by activating heap traces during this function’s execution and reverse-engineering its logic, we find that the function triggers the following high-level sequence of events:
1. if (A) { free(A); }
2. A = malloc(received_frame_size);
3. memcpy(A, received_frame, received_frame_size);
4. B = malloc(788);
5. free(B)
6. C = malloc(284);
7. free(C);
Great! So we get an allocation (A) with a controlled lifetime, a controlled size and controlled contents! What more could we possibly ask for?
There is one tiny snag, however. Modifying wpa_supplicant to send this crafted TDLS frame results in a resounding failure. While wpa_supplicant allows us to fully control many of the fields in the TDLS frames, it is only a supplicant, not an MLME implementation. This means that the corresponding MLME layer is responsible for composing and sending the actual TDLS frames.
On the setup I’m using for the attack platform, I have a laptop running Ubuntu 16.04, and a TP-Link TL-WN722N dongle. The dongle is a SoftMAC configuration, so the MLME layer in play is the one present in the Linux kernel, namely, the “cfg80211” configuration layer.
When wpa_supplicant wishes to create and send TDLS frames, it does so by sending special requests over Netlink, which are then handled by the cfg80211 framework, and subsequently passed to the SoftMAC layer, “mac80211”. Regrettably, however, mac80211 is unable to process the special vendor frames, and simply rejects them. Nonetheless, this is just a minor inconvenience - I’ve written a few patches to mac80211 which add support for these special vendor frames. After applying these patches, re-compiling and booting the kernel, we are now able to send our crafted frames.
![](https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhLjrNJBuzNQDCkFPAouNC1nI3Qn6bQ58ukX9HHChI1RwaAERGU2jO5Jv-xsann8v1aEb4FP3wicfIqiS3uEw145dRSFnLerRD1xtnceMSPIqFZkG1DSZDYW2PK7J4I4FHavXAYSxiZp9Yts8kNSlQnIdI6l-pbqWWWPZILAx2a4xi00-kKtNXqVwHi/s461/PD6pXRyzl_HIYV8BUN3DnlliwUhD6H8HMn4eJ1TuY3L4oWlJyXlnyArGkqJQvyfPmHAGYVGENMW-Isk3dVHzwd5MtkEJY4Ss0tSlDAQgPFbpzMnyhDf6rx7dnG6uGk23TJjKcBB0.png)
(schematic based on http://processors.wiki.ti.com/index.php/WL127x_WLAN_API_Information)
To allow for easier control over the vendor frames, I’ve also added support for a new command within wpa_supplicant’s CLI - “TDLS_VNDR”. This command allows us to send a crafted TDLS vendor frame with arbitrary data to any MAC address (regardless of whether a TDLS connection is established to that peer).
Putting It All Together
After creating two overlapping chunks, we can now use our controlled allocation primitive to allocate memory from the tail of the larger chunk, thereby pointing the smaller free chunk at a location of our choosing. Whichever location we choose, however, must have valid values for both the “size” and “next” fields, otherwise later calls to malloc and free may fail, possibly crashing the firmware. As a matter of fact, we’ve already seen perfect candidates to stand-in for free chunks - in-use chunks!
Recall that in-use chunks specify their size field at the same location free chunks do theirs. As for the “next” pointer, it is unused in free chunks, but is set to zero during the allocation of the chunk. This means that by corrupting the free list to point at an in-use chunk, we can trick the heap into thinking it’s just another free chunk, which is coincidentally also the last chunk in the freelist. That’s comfortable.
![](https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiDo8Z4cFD2nWoz8nZam9axDs2YIFGaN5gsXfbTsXVJ5hK5R43avIVc_-uv4i-VvxFeBQxrMQGRiyp5V59lL8-Al4i0Fmkct-sZi33nM8hH863Gt-6cReQfjHYNNHv8z9U2jhEAmXAbwUkOmyMtMWkOvMI1MO06KmqJK6ZkzrLTJVfXOf88c9TDKq9B/s541/0UW3ZMRQ0W-arCpUNZ_OJOmvc-hnaOtqvO3tnlA2bnb_rQeYbAhqGO-qEQqShi-S2NIaT0IOkvDzMNl7wvH0WuOZWyLosQf-g2sesJMhpMQEmxHlqQRMdtFwldoFj25WY1xNNdqD.png)
Now all we need to do is find an in-use chunk containing information that we’d like to overwrite. If we make that chunk the best-fitting chunk in the free list for a subsequent controlled allocation, we’ll get our own data to be allocated there instead of the in-use chunk’s data, effectively replacing the chunk’s contents. This means we’re able to arbitrarily replace the contents of any in-use chunk.
As we’re interested in achieving full code execution, it would be advantageous to locate and overwrite a function pointer in the heap. But… Where can we expect to find such values on the heap? Well, for starters, there are some events in the Wi-Fi standards that must be handled periodically, such as performing scans for adjacent networks. It would probably be a safe bet to assume that the firmware supports handling such periodic timers by using a common API.
Since timers may be created during the firmware’s operation, their data structures (e.g., which function to execute and when) must be stored on the heap. To locate these timers, we can reverse-engineer the IRQ vector table entry, and search for the logic corresponding to handling a timer interrupt. After doing so, we find a linked list of entries whose contents seem to conform to that of brcms_timer structure, used in the brcmsmac (SoftMAC) driver. After writing a short script, we can dump the list of timers given a RAM snapshot:
![](https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgAENnchgnmKeoCestup7alQiy9mLWP1ms27jNRvpcFY8iw5wSDn2ttddP6QaMyT2NlQfs0Hl450Jo_HgOwz1o_6oNRGumZTNecXiE4F4MlYCGqNyWU5sEmzd9nmFLu7ynE2OSSTGN7sAZRZxwkZBZ1kOcCwA8dC2p5Xyn9uVRcDQsAKAySM26p4JT9/s525/EohfSqY3K6WKRzY6vY8aawCKNyCbCYJ9oO3Nq5fR9lkiU8zgmanI-M9LwzTpwUqd--RUtrNZkIs04Yj1Jae6HxcUdWA3n8ipyD47YJF6srWw9QbkJLovL91iXIBXESA6cZNg_u_B.png)
We can see that the timer list is ordered by the timeout value, and most of the timers have a relatively short timeout. Moreover, all the timers are allocated during the firmware’s initialisation, and are therefore stored at constant addresses. This is important since, if we’d like to target our free chunk at a timer, we’d need to know it’s exact location in memory.
So all that’s left is to use our two primitives to replace the contents of one of the timers above with our own data, consequently pointing the timer’s function at an address of our choosing.
Here’s the game plan. First, we’ll use the techniques described above to create two overlapping free chunks. Now, we can use the controlled allocation primitive to point the smaller free chunk at one of the timers in the list above. Next, we create another controlled allocation (freeing the old one). This one will be of size 0x3C, for which the timer chunk is the best-fitting. Therefore, at this point, we’ll overwrite the timer’s contents.
![](https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjdLRwpO1W_W01SmPzELlZ--6zUiRbU7UIKHZQRxj9uLnJFY-XrIJ0koeMpq3uVcThuCZVc9iO0KXzOzujXM-v2AbtunQnRDj2SKpzgJsn8hKjeKRopnOnvi3_18FUaGU23dJVzPNNZLthptDwqT2D3O3FQ80tg1VTYOHhCKWq1xvPXHYs-gP1wM6PI/s600/3eYZSrFqsPHaADRu2lEYutXAati23OAMwZGi7qeqjH1idmnAYLdWAhPA1MA9a90BR44rGfsPuKmDWjSfgDBqqBZhV8dyA_dWxrIpgayb_LFKyITNcD2k7024_ECjrXPrv2J2OHa-.png)
But which function do we point our timer to? Well, we can use the same trick to commandeer another in-use chunk on the heap, and overwrite its contents with our own shellcode. After briefly searching the heap, we come across a large chunk which simply contains console data during the chip’s boot sequence, and is then left allocated but unused. Not only is the allocation is fairly large (0x400 bytes), but it is also placed at a constant address (since it is allocated during the firmware’s initialisation sequence) - perfect for our exploit.
Lastly, how can we be sure that the contents of the heap is even executable? After all, the ARM Cortex R4 has a Memory Protection Unit (MPU). Unlike an MMU, it does not allow for the facilitation of a virtual address space, but it does allow control over the access permissions of different memory ranges in RAM. Using the MPU, the heap could (and should) be marked as RW and non-executable.
By reversing the firmware’s initialisation routines in the binary, we can see that the MPU is indeed being activated during boot. But what are the contents with which it’s configured? We can find out by writing a small assembly stub to dump out the contents of the MPU:
0x00000000 - 0x10000000
AP: 3 - Full access
XN: 0
0x10000000 - 0x20000000
AP: 3 - Full access
XN: 0
0x20000000 - 0x40000000
AP: 3 - Full access
XN: 0
0x40000000 - 0x80000000
AP: 3 - Full access
XN: 0
0x80000000 - 0x100000000
AP: 3 - Full access
XN: 0
Ah-ha - while the MPU is initialised, it is effectively set to mark all of memory as RWX, making it useless. This saves us some hassle… We can conveniently execute our code directly from the heap.
So, at long last, we have an exploit ready! Putting it all together we can now hijack a code chunk to store our shellcode, then hijack a timer to point it at our stored shellcode. Once the timer expires, our code will be executed on the firmware!
![](https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhR_YcyP40168XU5epNJYbE3dRajQ9G1Slgck7tARKR_IH1OJDXHjG_RN_0WPcUGu28-_Aft7llJ_Ak3yy7f0ScP0DaXA9A7pUoUIjKtEPgFfkj00xFlgqEhLw3A9pvwbFJpPHFUfEVRBxtqDKONzaC5s5gkdi9UYjL8YA1pECJO7ivLZ0sOywM_Ye1/s600/mpmsF1QB0M7_k7rVsrHSj5YG2czTCUBVcOEzAI-ifYHRg8BMO_1hSqhZG06IBZY259013hEzcr5GEZKnYTh9nskSntDRFdNjeI4JzusaAxWJXEULEHqYz8s9LohGbWI4MkDWOcTy.png)
At long last, we’ve gone through the entire process of researching the platform, discovering a vulnerability and writing a full-fledged exploit. Although this post is relatively long, there are many smaller details that I left out in favour of brevity. If you have any specific questions, please let me know. You can find the full exploit, including instructions, here. The exploit includes a relatively benign shellcode, which simply writes a magic value to address 0x200000 in the firmware’s RAM, signalling successful execution.
Wrapping Up
We’ve seen that while the firmware implementation on the Wi-Fi SoC is incredibly complex, it still lags behind in terms of security. Specifically, it lacks all basic exploit mitigations - including stack cookies, safe unlinking and access permission protection (by means of an MPU).
Broadcom have informed me that newer versions of the SoC utilise the MPU, along with several additional hardware security mechanisms. This is an interesting development and a step in the right direction. They are also considering implementing exploit mitigations in future firmware versions.
In the next blog post, we’ll see how we can use our assumed control of the Wi-Fi SoC in order to further escalate our privileges into the application processor, taking over the host’s operating system!
Great Article
ReplyDeleteCould such an exploit allow the use of the FM band on iPhones that use broadcom chips for close stations even if there is no rx antenna ?
ReplyDeleteYou guys are ****ing amazing.
ReplyDeleteOver The Air: Exploiting Broadcom’s Wi-Fi Stack (Part 1)
Exploiting Broadcom’s Wi-Fi Stack (Part 1)
Wi-Fi Stack (Part 1)
(Part 1)
Man that must have been fun.
ReplyDeleteMan that must have been fun.
ReplyDeleteGreat piece! thanks...
ReplyDeleteJust a note: When you cast something from a phone via a Chromecast, the stream does not go through the phone/casting device. The phone only tells the Chromecast what to cast, and the chromecast itself streams the data directly from the source. So your example isn't very relevant. :)
ReplyDeleteNot necessarily, you can cast a chrome tab or your Nexus phone's full screen
DeleteIf you cast your desktop then it behaves as he said. But you are correct in that most commonly people cast streamed data, which chrome cast is intelligent enough to get straight from the source (aka. youtube or netflix).
DeleteI was referring to the "screen casting" feature, where the phone streams the content to the Chromecast. This, AFAIK, uses TDLS to establish the connection in order to avoid congestion on the AP.
DeleteWhile you are right about that regarding applications like Youtube or Netflix, other applications do make use of this, such as Chrome's tab casting feature and I believe Android also has such a feature for display mirroring. In this case, the phone or computer simply is the source and would therefore benefit from a direct connection as described.
DeleteBy "casting a video from your mobile device", he means the video file is on the phone, so the phone is the source.
DeleteOut of curiosity, even if you are casting from netflix, the phone still has to communicate with the Chromecast to keep track of time so you can pause, few, rewind and other commands. At this point, would this traffic go over the AP or direct over TDLS?
DeleteAwesome research and great article ;)
ReplyDeleteI love to read such articles and getting myself more into this subject. I'm still struggling to find my path though.
Wow, what an amazing post. Great job, and thanks for taking the time to document it in such detail!
ReplyDeleteAn awesome and detailed article! it's great!
ReplyDeleteBut I have a simple question, how do you know which subject or project you should work on?
I mean, why did you decided to research on these Broadcom chips instead of for example an application's vulnerability?
I was wondering the same thing
DeleteI would also be highly interested how one decides what he wants to research. Hopefully Gal Beniamini will comment on this question ;)
DeleteWe have the freedom to pick our research subjects, so long as they're relevant. At the beginning of each quarter we think of research topics for that quarter, and set some estimated research goals. Anecdotally, both myself and halvarflake thought of this same research subject at the same time, independently; I guess this means its not that unique a subject.
DeleteExcellent research
ReplyDeleteThis is huge...
ReplyDeleteIf I read this correctly, the vulnerable code is in the Broadcom SoftMAC layer that is integrated into the FullMAC SoC ROM. Do these vulnerabilities also affect devices using the brcmsmac driver? I would expect at least a DoS via kernel panic.
ReplyDeleteTDLS seems to be handled by on upper layer generic SoftMAC implementation
Deletehttps://github.com/torvalds/linux/blob/master/net/mac80211/tdls.c
which is different.
Broadcom's SoftMAC driver does not include an implementation of TDLS (not all of the MLME is included in the SoftMAC driver - in fact, most isn't). Instead, when brcmsmac is used, Linux's mac80211 provides the TDLS implementation.
DeleteThanks for your wonderful work.
ReplyDeleteGreat Post
ReplyDeletePresumably laptops with brcmfmac wifi (e.g. Dell XPS 13 BCM4350) are vulnerable too?
ReplyDeleteAny idea if wifi routers with Broadcom chipsets are also vulnerable? Or maybe some router firmware supports the server side fast roaming features mentioned and is similarly exploitable. If so, that opens up the possibility of a worm that can spread across both routers and phones.
I think laptops which support the relevant feature sets (e.g., TDLS) are vulnerable as well. I just ran a short experiment by loading a laptop's firmware file on a mobile phone, and I could indeed reproduce the TDLS crash. Unfortunately, it doesn't seem to me like the firmware images are updated... See: https://git.kernel.org/pub/scm/linux/kernel/git/firmware/linux-firmware.git/tree/brcm
DeleteAs for routers - the vulnerabilities discussed here are in client-related code flows, so I don't believe they would affect routers.
Given the right publicity, this research will sell the most recent Pixel phones rather well. Nicely played, Google.
ReplyDelete10 years ago, I ran a small managed service provider business. My business partner and I frequently joked that we should write a virus and send it to our clients if the percentage of virus jobs ever decreased below a certain threshold. Tail wagging the dog. It could happen one day.
fwiw, on your rainbow stack - physical generates traffic far faster than application, is higher frequency, so application is red, physical is blue...
ReplyDeletei'm using archos video player on my android device to stream content that is saved on my pc's hard disk.. it's pretty cool when i tell this to my friends! but now that you've covered this phenomenon in such a great detail.. i feel like a caveman again lol
ReplyDeleteWhen exits the Part 2 of this fantastic article? Great job boys!
ReplyDeleteIt's out :) Here: https://googleprojectzero.blogspot.com/2017/04/over-air-exploiting-broadcoms-wi-fi_11.html
DeleteAwesome. Great piece of work.
ReplyDeleteAwesome. Great piece of work.
ReplyDeleteHow much time did you approx. spend to get to this point?
ReplyDeleteThe entire research in these two blog posts took around 2.5 months.
DeleteIs TDLS transparent to user land applications, or do they need to explicitly request a tunneled link and use a separate socket?
ReplyDeleteTransparent.
DeleteThis is amazing. Earlier today I happened to read about PartitionAlloc in Chrome, and how it keeps allocator metadata from living next to the data, and allows some stuff like sticking guard pages past the end of a region so that linear overwrites can only muck things up within their region.
ReplyDeleteDo you think allocator changes are interesting as a mitigation here? Or less useful than it might seem? (Maybe there were a bunch of other routes to an exploit if allocator metadata weren't located in a handy place.) Or is it unrealistic for size/performance reasons in a limited environment like this? (Chrome is certainly not trying to run on an ARM R4 and 768KB RAM.)
Thank you. It'd probably be unrealistic; the MPU supports at-most 12 protection regions, so that's the upper bound of guard pages, for example. That said, the allocator can still be hardened quite a bit. One example being not having free-chunks strewn all over RAM where they can possibly overflow into important data (that'd also make enforcing MPU protection easier because there would be less segmentation).
ReplyDeleteAh, interesting. Different world from the application programming I'm used to. Thanks for replying!
DeleteMy pleasure!
DeleteGreat article! i can only imagine the happiness after all breadcrumbs have been put together. Well done!
ReplyDeleteHow to dump ROM and RAM with dhdutil, when i execute the cmd: dhdutil -i wlan0 membytes -r 0x180000 0xc0000 > /sdcard/ram.bin, it always output "__dhd_dervier_io: Invalid argument"
ReplyDeleteThe command you posted works on my Nexus 6P. I would check dmesg for anything more descriptive, and make sure you're running this command from a sufficiently privileged context.
DeleteHi! I wanted to write a version of this exploit for a local iPhone 4s, however, I was curious about something. In a separate, jailbroken 4s, I found the expected BCM firmware version string in /usr/share/firmware/wifi/4330b2/uno3.trx, however it did not have TDLS support listed in its version string, nor did it even have 802.11r FT support or CCKM support listed in it. On a jailbroken 6s, I noticed the same phenomenon in the expected BCM firmware version string in /usr/share/firmware/wifi/C-4345__s-B1/barbera.trx: No TDLS, no 802.11r FT, no CCKM. Would this inherently mean that their BCM chips do not have TDLS support? Could I be looking in the wrong directory? Initially I would worry that is the case, but considering that there was an iOS 10.3.1 update for this very reason, I'm really confused. Would you know much about iOS's specific handling of the BCM firmware? I can post the version strings or send the files if it would help.
ReplyDeleteThanks!
The BCM firmware files on iPhones unfortunately don't contain the tagged list of supported features, which makes it harder to find out which features are actually supported. Of the features mentioned above, iPhones only support 802.11r FT.
ReplyDeleteVery nice work! Is there any chance that you will publish your symbols/IDA files or push them to the nexmon guys?
ReplyDeleteAnd where is the update for older iPhones?
ReplyDeleteThis comment has been removed by the author.
ReplyDeleteSolid works!
ReplyDeleteI have a question: why timer slab's size is zero when we have overwrited it's contents?
This comment has been removed by the author.
ReplyDelete