Asynchronous Flaws: Exploiting and Detecting Dispatch Queue Misuse on macOS

Olivia Gallucci

CypherCon 9.0 (2026)

Overview

In her CypherCon talk, Olivia Gallucci of Datadog delved into the often-overlooked security implications of Grand Central Dispatch (GCD) misuse on macOS. The presentation, titled "Asynchronous Flaws: Exploiting and Detecting Dispatch Queue Misuse on macOS," illuminated how seemingly benign programming errors related to concurrency can escalate into critical security vulnerabilities, particularly in privileged system services. Gallucci emphasized that these are not merely reliability bugs but direct pathways to privilege escalation and sandbox escapes.

Watch on YouTube

Visual summary for Asynchronous Flaws: Exploiting and Detecting Dispatch Queue Misuse on macOS by Olivia Gallucci
Visual summary for Asynchronous Flaws: Exploiting and Detecting Dispatch Queue Misuse on macOS by Olivia Gallucci

Key moments

  1. 4:00 Understanding Grand Central Dispatch (GCD) and QoS
  2. 7:50 Priority inversion: dangers of spin locks and semaphores
  3. 11:45 Dispatch Sync Deadlocks: avoiding common pitfalls
  4. 17:40 GSS Cred CVE: exploiting a race condition in a root service
  5. 23:45 Static review and telemetry for detecting concurrency flaws
  6. 30:20 Q&A: Understanding OS unfair lock and system priority

Asynchronous Flaws: Exploiting and Detecting Dispatch Queue Misuse on macOS

Speakers: Olivia Gallucci, Datadog

Conference: CypherCon

YouTube: https://www.youtube.com/watch?v=ag56d1IbDVA

Overview

In her CypherCon talk, Olivia Gallucci of Datadog delved into the often-overlooked security implications of Grand Central Dispatch (GCD) misuse on macOS. The presentation, titled "Asynchronous Flaws: Exploiting and Detecting Dispatch Queue Misuse on macOS," illuminated how seemingly benign programming errors related to concurrency can escalate into critical security vulnerabilities, particularly in privileged system services. Gallucci emphasized that these are not merely reliability bugs but direct pathways to privilege escalation and sandbox escapes.

The core of the talk centered on how incorrect configuration or understanding of GCD's dispatch queues and Quality of Service (QoS) levels can lead to exploitable race conditions, deadlocks, and resource starvation. By dissecting fundamental concepts like processes, threads, concurrency, and parallelism, Gallucci laid a robust foundation for understanding the mechanics of these asynchronous flaws. The discussion culminated in actionable insights for both developers and security practitioners, detailing static review patterns, telemetry signals, and behavioral detections crucial for identifying and mitigating these sophisticated vulnerabilities in macOS environments.

This talk is particularly relevant for anyone involved in macOS application development, system security, or vulnerability research. It highlights that even well-established system frameworks, when misunderstood or misimplemented, can introduce significant attack surfaces. The detailed exploration of past CVEs and practical detection strategies makes this a vital resource for enhancing the security posture of macOS applications and services.

Background

▶ Watch: Understanding Grand Central Dispatch (GCD) and QoS (4:00)

To appreciate the nuances of asynchronous flaws, it's essential to first grasp the foundational concepts of modern operating systems. As Gallucci highlighted, drawing from Jonathan Levin, a process is a container for resources like virtual memory and descriptors, but it is not the runnable entity. The actual executing code resides within threads. A process, therefore, is a container for one or more threads, sharing resources among them.

Concurrency refers to a system's ability to make progress on multiple tasks by overlapping or interleaving their execution, even on a single core. This improves responsiveness and resource utilization. Interleaving describes the different possible execution orders when multiple threads access shared resources, often leading to non-deterministic behavior. In contrast, parallelism involves the simultaneous execution of multiple tasks on multiple cores. This talk addresses both: concurrency reveals the logic and timing bugs, while parallelism explains how GCD scales execution and where that scaling can introduce vulnerabilities.

Grand Central Dispatch (GCD) is Apple's fundamental concurrency framework and system library on macOS. It manages task queues and execution, abstracting away explicit thread management from developers. Developers submit blocks of work to dispatch queues, which then schedule these tasks to be executed by system-managed threads. GCD employs Quality of Service (QoS) classes—such as User Interactive, User Initiated, Utility, and Background—to prioritize tasks. The kernel uses these QoS levels to allocate CPU resources, ensuring that high-priority operations are not unduly delayed.

GCD offers two primary types of dispatch queues:

  1. Serial queues: These ensure tasks run one at a time, in the order they are received, guaranteeing sequential execution.
  2. Concurrent queues: These allow multiple tasks to execute simultaneously, managed by the system scheduler.

The choice and configuration of these queues, especially in conjunction with QoS levels, become critically security-relevant. Misconfigured QoS can allow lower-priority tasks to delay higher-priority ones, creating exploitable timing windows. This can lead to classic concurrency issues like race conditions, deadlocks, and priority inversions, which GCD does not automatically prevent; correct usage and explicit serialization are required.

Key Findings

▶ Watch: Dispatch Sync Deadlocks: avoiding common pitfalls (11:45)

Olivia Gallucci's talk unveiled several critical findings regarding GCD misuse on macOS, emphasizing that these asynchronous flaws transcend mere stability issues and pose significant security risks:

  1. GCD Misuse as a Security Vulnerability: The primary finding is that incorrect usage of GCD, particularly around dispatch queue configuration and synchronization, can lead directly to exploitable security vulnerabilities like privilege escalation and sandbox escapes, rather than just application crashes or performance degradation.
  2. Specific Vulnerability Classes: The talk detailed three major categories of asynchronous flaws:
  • Priority Inversion: A high-priority task gets indefinitely blocked waiting for a lower-priority task to release a resource. This is exacerbated by Darwin's aggressive scheduler and the misuse of synchronization primitives that don't support priority inheritance.
  • Dispatch Sync Deadlocks: Occur when dispatch_sync is used to submit a block to the same serial queue that the calling thread is already executing on, leading to an immediate and unrecoverable deadlock.
  • Resource Starvation / Thread Pool Exhaustion: Excessive dispatch operations, especially blocking ones, can saturate GCD's underlying thread pool. This leads to thread explosion (where the system spawns many threads to break stalemates) and significant CPU thrashing, starving other system components.
  1. The "Semaphore Anti-Pattern": A common and dangerous pattern where developers use dispatch_semaphore or plain spin locks to bridge asynchronous work into synchronous control flows. This pattern breaks Apple's scheduling guarantees because semaphores don't carry ownership information, preventing the kernel from applying priority boosting mechanisms and leading to priority inversions and deadlocks.
  2. Implicit vs. Explicit Serialization: Privileged services often implicitly assume serial execution, but if GCD queues are not explicitly configured with targetQueue for serialization, message handlers can run concurrently. This violation of serialization assumptions creates critical race windows, as demonstrated by the GSSCred CVE.
  3. Actionable Detection Strategies: Beyond identifying the flaws, the talk provided concrete methodologies for detection, including specific static code review patterns, telemetry signals (e.g., crash patterns, thread churn spikes, queue backlogs), and behavioral detections (e.g., unusual thread creation, high XPC invocation rates, queue drain anomalies).

These findings collectively underscore the importance of treating concurrency design, queue choices, and synchronization mechanisms as security-critical aspects of macOS development, particularly for privileged system services and XPC interfaces.

Technical Deep Dive

▶ Watch: GSS Cred CVE: exploiting a race condition in a root service (17:40)

Grand Central Dispatch (GCD) is designed to abstract away thread management, allowing developers to focus on tasks. However, its sophisticated mechanisms, if misunderstood, can introduce complex vulnerabilities. GCD manages dispatch queues, which are objects that organize blocks of work. These blocks are then executed by a pool of system-managed threads.

Quality of Service (QoS) is a critical component of GCD, influencing how the kernel prioritizes CPU allocation. There are several QoS classes: userInteractive, userInitiated, utility, and background. Correct QoS assignment is crucial; a high-priority operation delayed by a lower-priority task due to incorrect QoS can open exploitable timing windows. These QoS classes are implemented end-to-end across libdispatch, pthreads, and the kernel scheduler.

One of the most insidious flaws is Priority Inversion. This occurs when a high-priority task is blocked, waiting for a resource held by a lower-priority task. On Darwin, the scheduler can indefinitely preempt (end) low-QoS threads in favor of higher-QoS ones. If a low-priority thread holds a lock that a high-priority thread needs, the low-priority thread might never get scheduled to release it, leading to a deadlock. This is particularly acute with spin locks, where a blocked thread repeatedly checks for the lock's release, busy-waiting and consuming CPU cycles.

Apple's kernel combats priority inversion through priority inheritance, but only for specific synchronization primitives. For instance, pthread_mutex and OS_unfair_lock support this. If a high-QoS thread waits on a lock held by a low-QoS thread, and that lock is a mutex or unfair lock, the kernel will temporarily boost the low-QoS thread's priority to match the high-QoS thread until the lock is released. This mechanism ensures the low-priority task can complete and release the resource promptly.

Conversely, developers must avoid synchronization mechanisms that do not support priority inheritance. Examples include reader/writer locks, semaphores, and custom lock implementations. A dispatch_semaphore, for instance, is a counter-based primitive that allows a thread to wait until another signals it. However, it doesn't carry ownership information. A high-priority thread waiting on a semaphore held by a low-priority task will simply wait indefinitely, without any priority boost to the low-priority task. This is so common that it's termed the "semaphore anti-pattern"—a seemingly convenient way to bridge async work into sync control flow, but one that breaks scheduling guarantees and often leads to priority inversion and deadlocks.

Another common pitfall is Dispatch Sync Deadlocks. dispatch_sync synchronously executes a block on a target queue, blocking the calling thread until the block completes. A deadlock occurs when dispatch_sync targets the same serial queue that the caller is already running on, or a queue directly dependent on it (e.g., calling dispatch_sync on the main queue from the main thread). The calling thread waits for the block to finish, but the block cannot start because the queue is blocked by the calling thread itself, creating a circular wait. This can freeze an application instantly, as Apple's documentation explicitly warns.

Finally, Resource Starvation via Worker Thread Busyness arises from excessive or blocking dispatch operations within concurrent queues. GCD uses a thread pool to run concurrent tasks. If too many tasks are dispatched, or if tasks block without completing (e.g., waiting on locks or synchronous calls), the thread pool can become saturated. Early GCD documentation suggested the system would smartly limit thread creation, but in practice, thread explosion can occur. If existing threads are blocked, libdispatch may spawn additional threads to try and break the stalemate, leading to dozens or even hundreds of threads thrashing the CPU. This not only degrades performance but can also starve other system components of CPU time, as the scheduler struggles to manage the overwhelming number of tasks. A historical example cited was the now-abandoned security transforms API in macOS 10.17, which inadvertently created a new queue and thread per task, causing severe thread proliferation. This led to many macOS daemons in iOS 12 being rewritten to be single-threaded, reflecting a hard-learned lesson about constrained concurrency.

These technical details highlight that GCD, while powerful, requires careful consideration of queue types, QoS, synchronization primitives, and synchronous call patterns to prevent serious stability and security vulnerabilities.

Demo / Proof of Concept

▶ Watch: Static review and telemetry for detecting concurrency flaws (23:45)

While the talk did not feature a live coding demo, Olivia Gallucci effectively demonstrated the concepts through practical tools and a highly impactful real-world CVE (CVE-2018-4286).

For observing priority inversion, Gallucci recommended using Xcode's Thread Performance Checker. This is a runtime tool that developers can enable in their scheme settings. When an application is run with this checker enabled, Xcode automatically logs warnings if it detects a high-QoS thread waiting on a lower-QoS thread, or if non-UI work is running on the main thread. This provides an immediate, visual indicator of potential priority inversion issues, making it accessible even for those new to macOS vulnerability research. The checker flags these QoS mismatches, which are red flags for potential priority inversions, even if the kernel temporarily boosts priorities.

The most compelling proof of concept discussed was the 2018 GSSCred vulnerability (CVE-2018-4286). This incident served as a stark example of how GCD misuse can lead to arbitrary code execution in a root context. The com.apple.GSSCred service, responsible for managing credentials like Kerberos and enterprise SSO tickets, exposed an XPC service. A security researcher, Brandon Azad, discovered a high-impact race condition within this service.

The root cause was a subtle but critical misconfiguration: the GSSCred service created a serial dispatch queue for handling events, but it failed to set this queue as the target queue for client XPC connections. This omission meant that instead of executing on the intended serial queue, message handlers ran on a default concurrent queue. Consequently, the service's implicit assumptions about serialization were violated, allowing multiple client requests to be processed concurrently.

The exploit mechanism leveraged this concurrency. An unprivileged process could send two carefully timed requests that would interleave: one handler would free a credential while another was still processing it. This created a memory corruption condition within a privileged root service, ultimately leading to arbitrary code execution. The business impact was profound, demonstrating that misconfigured queue targets can break serialization assumptions in critical XPC services, enabling unprivileged clients to exploit race windows for privilege escalation, even without kernel compromise.

This CVE powerfully illustrates the broader problem: a single GCD queue targeting mistake transformed a supposedly serialized, privileged service into one with concurrent handlers, opening a race window that an unprivileged client could reliably hit. The lessons from GSSCred framed the talk's focus on identifying privileged XPC services at sandbox boundaries, scrutinizing their handler-level race conditions, and challenging trust assumptions that can turn normal IPC into a sandbox escape vector.

Defensive Implications

▶ Watch: Q&A: Understanding OS unfair lock and system priority (30:20)

Understanding asynchronous flaws is the first step; the next is implementing robust defensive strategies. Olivia Gallucci outlined a comprehensive approach combining static code review, telemetry, and behavioral detection.

Static Review Patterns

Static code analysis is crucial for identifying potential weaknesses before deployment.

  1. XPC Connection Queuing: When a daemon accepts a new XPC connection, it's vital to verify that setTargetQueue: is explicitly called on the NSXPCConnection object. If this API is omitted or incorrectly configured, message handlers may execute on an unintended concurrent queue, exposing the service to race conditions. This is a strong, easily codifiable signal directly linked to race exposure in privileged services.
  2. Serial vs. Concurrent Execution Assumptions: Developers often write code assuming requests arrive one at a time. However, XPC clients can easily generate parallel pressure. Code reviews should actively look for logic that implicitly depends on serial handling, especially concerning authorization state, object lifecycle management, or access to shared caches. If the implementation relies on ordering guarantees that are not explicitly enforced by a serial queue or appropriate locks, it's a high-value finding.
  3. Synchronous Calls (dispatch_sync): Any use of dispatch_sync, particularly within a privileged daemon, should be treated as suspicious and require explicit justification. While not inherently wrong in every context, it often indicates blocking behavior, carries a high risk of lock inversion, and can easily lead to deadlocks under load or adversarial conditions, even if it performs fine during "happy path" testing.
  4. Shared Mutable State without Synchronization: This is one of the most common root causes of timing-dependent flaws. Identify any global variables or shared objects accessed from multiple handlers without proper synchronization mechanisms like locks (OS_unfair_lock, pthread_mutex), atomics, or a dedicated serial queue funneling all access. Secure coding guidance in this area can yield significant returns by preventing both reliability defects and exploit primitives.

Telemetry Signals

Runtime telemetry provides visibility into when these weaknesses are being stressed or actively exploited.

  1. Crash Patterns: Repeated crashes, assertions, or guard failures within a privileged daemon, especially in timing-sensitive code paths (e.g., state transitions, cleanup, request handling boundaries), are major indicators. A single crash might be a stability bug, but repeated crashes suggest a race window is being intentionally or accidentally hit or probed, signaling potential exploitation attempts.
  2. Thread Churn Spikes: If a daemon suddenly starts creating an unusual number of threads, or its queue drain behavior changes unexpectedly, it indicates concurrency stress. Attackers probing for race conditions often generate similar pressure. This signal points to code paths with weak concurrency controls, even if not malicious.
  3. Queue Backlogs: Long wait times on dispatch queues, heavy synchronous waits, or evidence of work piling up faster than it drains are all useful indicators. These conditions often precede visible crashes and can suggest deadlocks, priority inversions, or lock contention. Detecting these earlier in the failure chain can help identify exploitation attempts or unsafe code paths.

Behavioral Detection

Analyzing process behavior over time can detect anomalous activity indicative of attacks.

  1. Frequent Thread Creation Spikes: Flag any process that shows frequent spikes in thread creation relative to its established baseline. The focus should be on relative deviation from normal profiles, not absolute volume, to reduce false positives.
  2. Rate Limiting XPC Invocations: If a client is issuing many parallel requests into a privileged service, it might be probing for race windows. This is particularly interesting when request volume and concurrency are high, and the target daemon normally expects low to moderate parallelism. Such activity should be logged, scored, and correlated with crashes or queue delays.
  3. Queue Drain Time Anomalies: Elevated synchronization wait times are a strong signal of deadlocks, lock contention, or scheduling inversion. This demonstrates how performance telemetry can become security telemetry, helping threat detection engineers identify adversarial timing behavior.

In essence, static review identifies where race conditions might exist, telemetry indicates where those weak points are being stressed, and behavioral detections pinpoint where that stress looks abnormal or adversarial. By integrating these layers, security organizations can significantly reduce exploit opportunities in privileged macOS services.

Key Takeaways

  • Asynchronous flaws are security vulnerabilities: Misusing GCD on macOS can lead to exploitable race conditions, deadlocks, and resource starvation, enabling privilege escalation and sandbox escapes, not just reliability issues.
  • Understand GCD fundamentals: Grasping serial vs. concurrent queues, Quality of Service (QoS), and the distinction between concurrency and parallelism is crucial for secure design.
  • Avoid the "semaphore anti-pattern": Do not use dispatch_semaphore or plain spin locks for synchronization across different QoS levels, as they prevent priority inheritance and often lead to priority inversions and deadlocks. Prefer OS_unfair_lock or pthread_mutex which support priority boosting.
  • Beware of dispatch_sync: Never call dispatch_sync on a serial queue from within that same queue, or on the main queue from the main thread, as this will inevitably cause a deadlock.
  • Explicitly enforce serialization: For privileged XPC services, always explicitly set the targetQueue for client connections to a serial queue if single-threaded state assumptions are made. Implicit serialization can be easily broken.
  • Implement multi-layered detection: Combine static code reviews (e.g., checking XPC connection queuing, dispatch_sync usage, shared mutable state), runtime telemetry (e.g., crash patterns, thread churn, queue backlogs), and behavioral detection (e.g., unusual thread creation spikes, XPC invocation rates) to identify and mitigate these flaws proactively.

About the Speaker(s)

Olivia Gallucci is a security researcher working at Datadog. A recent graduate, she has a keen interest in macOS vulnerability research, particularly focusing on concurrency and timing-related flaws. Olivia has a strong background in communicating complex security topics, having published a blog on tactile attacks and co-hosted a podcast on the same subject with "Hacker on the Rocks." She also maintains an Apple security newsletter called "Retreat to Read," where she regularly shares her research findings and insights into macOS security.

Reviews

Dr. Zero (Offensive Security Researcher) — STRONG ACCEPT

Gallucci takes a sledgehammer to macOS Grand Central Dispatch misuse, showing exactly how concurrency 'reliability bugs' escalate into privilege escalation. It's a tight, no-bullshit breakdown of XPC serialization failures and priority inversions that will actually help you hunt. Strong accept for anyone touching macOS daemon security.

Heather Calloway (CISO) — SOLID

Gallucci outlines how macOS concurrency misconfigurations turn stability bugs into privilege escalation vectors. This is highly technical work, but it hands defenders a clear playbook for telemetry and static analysis. It is worth your AppSec and detection engineering teams' time, especially if you develop native macOS apps or deploy privileged third-party agents.

→ Top-rated talks at CypherCon 9.0 (2026)

All talks from CypherCon 9.0 (2026)