Dirty Ptrace: Exploiting Undocumented Behaviors in Kernel mmap Handlers

Xingyu Jin (Security Researcher · Google), Martijn Bogaard (Security Engineer · Google)

POC2025 (Power of Community) · Main Stage

Overview

This talk, "Dirty Ptrace: Exploiting Undocumented Behaviors in Kernel mmap Handlers," delivered by Xingyu Jin and Martijn Bogaard from the Android team at Google, unveils a novel class of vulnerabilities that leverages overlooked interactions between the Linux kernel's ptrace syscall and device driver memory mapping. The researchers demonstrate how seemingly read-only memory regions, particularly those managed by graphics processing unit (GPU) drivers, can be unexpectedly modified by an unprivileged debugger due to a subtle misattribution of security responsibility between the kernel and driver developers. This "Dirty Ptrace" primitive allows for powerful privilege escalation and sandbox escape on modern Android devices, including a live demonstration of rooting a Pixel 10.

Watch on YouTube · Slides

Visual summary for Dirty Ptrace: Exploiting Undocumented Behaviors in Kernel mmap Handlers by Xingyu Jin, Martijn Bogaard
Visual summary for Dirty Ptrace: Exploiting Undocumented Behaviors in Kernel mmap Handlers by Xingyu Jin, Martijn Bogaard

Key moments

  1. 0:00 Introduction to Dirty Ptrace and talk agenda
  2. 2:00 History and persistence of mmap vulnerabilities
  3. 6:00 Deep dive: Samsung Exynos in-the-wild zero-day
  4. 14:40 Introducing Dirty Ptrace: writing to read-only memory
  5. 18:00 Kernel vs. driver 'blame game' on ptrace security
  6. 24:00 Dirty Ptrace impact on ImageTec GPUs (Pixel 10)
  7. 32:00 Pixel 10 rooting: Detailed exploit methodology and demo
  8. 44:30 Q&A: Android module signatures and patch status

Dirty Ptrace: Exploiting Undocumented Behaviors in Kernel mmap Handlers

Speakers: Xingyu Jin (Security Researcher, Google); Martijn Bogaard (Security Engineer, Google)

Conference: POC

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

Overview

This talk, "Dirty Ptrace: Exploiting Undocumented Behaviors in Kernel mmap Handlers," delivered by Xingyu Jin and Martijn Bogaard from the Android team at Google, unveils a novel class of vulnerabilities that leverages overlooked interactions between the Linux kernel's ptrace syscall and device driver memory mapping. The researchers demonstrate how seemingly read-only memory regions, particularly those managed by graphics processing unit (GPU) drivers, can be unexpectedly modified by an unprivileged debugger due to a subtle misattribution of security responsibility between the kernel and driver developers. This "Dirty Ptrace" primitive allows for powerful privilege escalation and sandbox escape on modern Android devices, including a live demonstration of rooting a Pixel 10.

The core of the issue lies in how the kernel handles ptrace requests to write to memory pages marked with the PFN_MAP flag, which are typically managed directly by device drivers. While the kernel usually enforces strict read-only protections for shared memory, it bypasses these checks for PFN_MAP pages if the driver has registered an access callback function without adequately validating write permissions. This oversight creates a critical security gap, transforming what should be immutable memory into a writable target for attackers. The implications are significant, as it challenges long-held assumptions about memory protection boundaries and highlights the persistent difficulties in securing complex kernel-driver interfaces against sophisticated attacks.

Background

▶ Watch: Introduction to Dirty Ptrace and talk agenda (0:00)

The history of Android rooting, particularly between 2011 and 2015, is often referred to as its "golden age," characterized by the prevalence of straightforward driver mmap vulnerabilities. These bugs frequently allowed applications to read or write arbitrary physical memory, leading to easy device rooting. Early Android systems, lacking robust security mechanisms like SELinux, often exposed device drivers directly to unprivileged users, enabling direct memory manipulation. Even when direct access was curtailed, mmap issues could lead to information leaks if kernel and user space shared pages, allowing for the exposure of kernel objects and addresses. Exploiting these flaws was relatively simple, often involving patching kernel symbols or functions to gain control.

Over the past decade, significant efforts have been made to curb these types of vulnerabilities. SELinux was introduced and progressively enforced, restricting user access to sensitive drivers. OEMs also began sanitizing user input for mmap arguments, such as memory size and offset. However, these sanitization efforts often introduced new vulnerabilities, such as integer overflows when developers simply added page offset and size without proper bounds checking, leading to bypasses of security checks. Despite these advancements, the Linux kernel is far from immune to memory corruption issues. The speakers cite recent examples from 2023, including an off-by-one error discovered by BFS lab in a Linux machine driver and another in the CMA heap buffer used by Android devices. These straightforward off-by-one issues could allow an attacker to map an extra page with read/write permissions, enabling easy overwriting of adjacent memory.

Beyond simple memory corruptions, the management of memory pages, especially those mapped by drivers with the PFN_MAP flag, presents persistent challenges. This flag signals that the kernel will not manage these pages' reference counts, shifting that responsibility entirely to the driver—a common source of errors. A prominent example is the Samsung Exynos zero-day discovered in 2023 by Google's Threat Analysis Group. This in-the-wild exploit targeted Samsung Exynos drivers for JPEG image decoding and scaling, leveraging a reference count issue related to PFN_MAP memory. The vulnerability stemmed from the Axelos_MMU function failing to increment reference counts for PFN_MAP pages when importing them from ion drivers. This allowed the exploit to unmap pages that were still mapped by the IOMMU, leading to a use-after-free (UAF) condition. The exploit writers used the mincore syscall on neighboring normal memory to precisely time the freeing of PFN_MAP pages, ensuring the IOMMU mapped freed physical memory for a controlled UAF write primitive. This primitive was then used to craft malicious page tables, ultimately granting arbitrary kernel read/write capabilities. This case underscores the complexity and high stakes involved in managing driver-mapped memory and the subtle ways in which seemingly minor oversights can be weaponized.

The speakers also highlighted other persistent challenges in writing secure mmap driver code, including race conditions in kernel VMA freeing (especially after kernel 4.20's change from writer to reader locks), misuse of the VM_IO flag leading to undefined behaviors via madvise syscalls, and GPU page use-after-free vulnerabilities. Furthermore, they pointed out that even "read-only" pages mapped by drivers might not truly be read-only if the kernel's VM_READ flag isn't properly cleared, potentially allowing mprotect to make them writable. These historical and ongoing issues provide the critical context for understanding the "Dirty Ptrace" vulnerability, which exploits another nuanced aspect of kernel-driver memory interactions.

Key Findings

▶ Watch: Deep dive: Samsung Exynos in-the-wild zero-day (6:00)

The central discovery presented in this talk is the "Dirty Ptrace" vulnerability, which exploits an undocumented kernel behavior concerning ptrace operations on read-only memory mapped by device drivers. The researchers identified a critical bypass in the Linux kernel's security checks that allows an unprivileged debugger (ptrace) to write to memory regions that should be immutable, specifically those marked with the PFN_MAP flag and managed by drivers.

Normally, ptrace behaves predictably: it can write to read-only memory mapped with MAP_PRIVATE by triggering a copy-on-write mechanism, but it cannot write to MAP_SHARED read-only memory, as this would allow unprivileged modification of shared libraries or other critical system components. However, the "Dirty Ptrace" vulnerability reveals an exception to this rule. When ptrace attempts to write to PFN_MAP pages (which are directly managed by drivers and not by the kernel's standard page table mechanisms), the kernel's access_remote_vm function, responsible for security checks, bypasses these checks. If the memory is mapped by a driver, this function returns an error to the caller without performing any validation. Crucially, the kernel then provides a "second chance" by invoking an access callback function if the driver has registered one.

The vulnerability arises because many driver developers, assuming the kernel would have already performed necessary security checks, implement these access callbacks without validating the write argument. They simply perform the requested write operation, inadvertently allowing ptrace to overwrite read-only memory. This creates a "blame game" scenario: kernel developers believe driver developers should sanitize input and check page writability, while driver developers expect the kernel to enforce memory protections. This lack of clear responsibility, combined with the undocumented ptrace behavior, forms the basis of "Dirty Ptrace."

The researchers found that this vulnerability impacts critical components, particularly Nvidia GPUs and ImageTech (PowerVR DXT) GPUs found in devices like the Pixel 10. For Nvidia GPUs, it allows an unprivileged user to write to read-only PCIe BAR memory, which can affect MMO registers, VRAM, or the Nvidia DMU engine. On the Pixel 10's ImageTech GPU, it enables writing to shared read-only driver information pages and shared shader memory pages. Since these shader memories are trusted by all Android graphic processes, corrupting them can lead to out-of-bounds access and crashes across the Android UI. Furthermore, the ImageTech GPU's ability to import user memory means attackers can import any read-only file and then use ptrace to write to it, effectively achieving arbitrary file overwrites.

Technical Deep Dive

▶ Watch: Kernel vs. driver 'blame game' on ptrace security (18:00)

The "Dirty Ptrace" vulnerability hinges on a nuanced interaction between the ptrace syscall and how the Linux kernel handles memory regions mapped by device drivers, specifically those flagged with PFN_MAP. To understand this, we first need to review ptrace's typical behavior. An unprivileged debugger using ptrace can write to read-only memory segments that are MAP_PRIVATE. In such cases, the kernel triggers a copy-on-write mechanism, creating a private, writable copy of the page for the ptrace's target process, thus preserving the original read-only memory. However, ptrace is strictly prevented from writing to MAP_SHARED read-only memory, as this would allow unprivileged modification of shared libraries (like libc) or other critical system resources.

The critical exception to this rule arises when memory is mapped by device drivers using the PFN_MAP flag. This flag indicates that the memory pages are managed directly by the driver rather than through the kernel's standard page table mechanisms. By default, ptrace is not intended to access these PFN_MAP pages directly. However, the kernel's internal functions for handling ptrace write requests, specifically access_remote_vm, exhibit an undocumented behavior. When access_remote_vm encounters memory mapped by a driver, it skips its usual security checks for writability and ownership. Instead, it returns an error to the caller.

Crucially, the Linux kernel provides a "second chance" mechanism. If the driver that mapped the PFN_MAP region has registered an access callback function, the kernel will invoke this callback. This access callback is intended for special debugging scenarios, allowing drivers to define how external tools (like ptrace) interact with their mapped memory. The problem is that driver developers often implement these access callbacks without explicitly checking the write argument passed to them. They assume that the kernel would have already performed the necessary security checks to ensure the memory is writable. As a result, if the write argument is 1 (indicating a write request), the driver's callback proceeds to write to the memory, effectively bypassing the read-only protection that the kernel itself failed to enforce.

This creates a significant security disconnect. The kernel developers, when confronted with this issue, argue that access callbacks are the driver's responsibility, and drivers should sanitize their input and check memory permissions. Conversely, driver developers argue that the kernel's mainstream code should handle fundamental memory protection checks. This "blame game" highlights a systemic issue in securing complex kernel-driver interfaces.

The researchers demonstrated the practical impact of this vulnerability on two major GPU architectures:

  1. Nvidia GPUs: Nvidia drivers implement access callbacks without checking writability. An unprivileged user can map PCIe BAR memory (Base Address Register memory) with read-only permissions. Using "Dirty Ptrace," the attacker can then write to this read-only BAR memory. PCIe BAR memory often contains MMO registers (Memory-Mapped I/O registers), VRAM (Video RAM), and can impact the Nvidia DMU engine. Arbitrary writes to these privileged memory regions can lead to serious system compromise. The proposed patch for Nvidia involves a simple check for page writability within the driver's access callback.
  1. ImageTech (PowerVR DXT) GPUs (on Pixel 10): Unlike AMD and Intel GPUs (which either implement access callbacks correctly or have memory mapping policies that prevent the attack), the ImageTech GPU on the Pixel 10 is vulnerable. It maps several read-only privileged memory regions back to user space, similar to Nvidia. These include a shared read-only driver information page and shared shader memory pages. The shader memory, originating from GPU firmware, is read-only but accessible by all Android graphic processes. By using "Dirty Ptrace" to overwrite these shared shader memories, an attacker can cause memory corruptions that lead to out-of-bounds access in various Android processes, including the UI, as these processes implicitly trust the integrity of this memory. Furthermore, the ImageTech GPU allows importing user memory. This means an attacker can import any read-only file into the GPU's context, then use ptrace to write to it, effectively gaining an arbitrary read-only file write primitive.

The proposed kernel patch to address this issue involves adding a check within the kernel's ptrace handling to verify the writability of PFN_MAP pages, even if an access callback is present. However, this patch has faced resistance from the Linux community, with questions raised about the scenario's uncommon nature, the assumption that only root users call ptrace, and whether it's the kernel's responsibility to check debugging feature inputs. This ongoing debate underscores the difficulty in achieving consensus on security fixes in a distributed open-source project.

Demo / Proof of Concept

▶ Watch: Dirty Ptrace impact on ImageTec GPUs (Pixel 10) (24:00)

The live demonstration showcased the exploitation of "Dirty Ptrace" on a Google Pixel 10 running an unpatched PowerVR DXT GPU driver, culminating in rooting the device. The exploit leveraged the ImageTech GPU's specific vulnerabilities to achieve arbitrary file overwrites and subsequent privilege escalation.

PowerVR DXT GPU Architecture and Interaction

The PowerVR DXT GPU on the Pixel 10 has a multi-layered driver stack:

  • Android Application: Initiates rendering jobs.
  • User Mode Driver Stack: Implements OpenGL, OpenCL, and Vulkan APIs.
  • Kernel Driver: A substantial component featuring a Bridge Server, which exposes 100-150 ioctl commands organized into various "bridges" (e.g., server core for version info, memory management, cache management, 3D rendering, compute workloads, hardware synchronization).
  • GPU Hardware: Executes the submitted work.

Key steps for interacting with the GPU involve:

  1. Creating a device memory context: Attaches memory to the GPU, including device memory heaps (pools of GPU addresses).
  2. Allocating or mapping memory:
  • physical_me_new_rambacked_PMR: Allocates new memory.
  • fism_wrap_external_memory: Crucially, this command allows mapping existing memory from the application's virtual address space into the GPU. While it provides flags for CPU/GPU read/write permissions, current policy only allows importing existing memory as read-only to prevent overwriting issues.
  1. Connecting memory: def_map_internal_reserve_range_and_map_PMR maps allocated/imported memory to GPU virtual addresses.
  2. Creating a rendering context: Prepares data structures (e.g., free list, HWRT2 dataset).
  3. Submitting work: kick command sends the rendering job to the GPU.
  4. Cleanup: Releases allocated resources.

The fism_wrap_external_memory function is the linchpin for the exploit. It takes a virtual address, size, and flags, returning a PMR handle. This handle can then be used to map the GPU memory back into the application's address space using mmap.

Exploit Chain for Rooting Pixel 10

The exploit proceeds in several stages:

  1. Arbitrary Read-Only File Overwrite (using Dirty Ptrace):
  • An unprivileged Android application forks into a parent and child process. The parent waits.
  • The child process opens a target read-only file (e.g., a system library), then mmaps it into its address space as MAP_SHARED | PROT_READ.
  • The child then calls fism_wrap_external_memory to map this read-only file into the GPU's context, also as read-only.
  • Using the PMR handle returned by the GPU driver, the child creates a second mmap of the same underlying memory pages into its address space, again as MAP_SHARED | PROT_READ.
  • The child then signals the parent and ptraces itself.
  • The parent process uses PTRACE_POKEDATA with the virtual address of the second mapping. Due to the "Dirty Ptrace" vulnerability, this allows the parent to write to the underlying read-only file.
  1. Privilege Escalation via init Process:
  • The target for the arbitrary file overwrite is the init binary's linked libbase.so shared object, specifically the should_lock function. This is a highly privileged target, as init runs as root.
  • Stage 1 Payload (injected into libbase.so):
  • Checks if it's running within the init process. If not, it returns normally.
  • If it is init, it clones/forks itself. The original init parent process continues normally.
  • The child process (forked from init) resolves dlopen and dlsym symbols.
  • It then overwrites a randomly chosen, seldom-used font file (or any other file readable by applications and accessible by init) with the Stage 2 Payload (a shared object).
  • It loads this font file as a shared object, looks up its entry point, and jumps to the Stage 2 payload.
  • Stage 2 Payload (injected into the font file):
  • Creates a mount point for a disk image within the /data partition.
  • Writes a bundled disk image (containing the privilege escalation kernel module and modprobe prerequisites) to /data, ensuring correct SELinux labels.
  • Mounts the disk image using the loop device driver.
  • Forks again to switch to the modprobe SELinux context.
  • Modprobes the privilege escalation driver.
  • Privilege Escalation Driver: This is a simple peek-poke driver that exposes a /dev node allowing arbitrary physical kernel memory read/write, along with functions to look up required kernel symbols.
  • Final Steps: The driver then performs standard privilege escalation: disabling SELinux, walking the task list, setting the current process as root, and granting all capabilities.
  1. Triggering the Exploit:
  • The init process's property service thread periodically checks for system property changes. To reliably trigger the should_lock function (and thus the Stage 1 payload), the exploit starts the camera application, which is guaranteed to change a system property.

Demo Execution

The demonstration showed an ADB shell on a Pixel 10 (with the vulnerability unpatched and SELinux set to permissive for visualization). A basic Android application was launched, which included sleeps to make the process visible. The camera app briefly popped up and disappeared, signaling the trigger. Immediately after, the ADB shell was shown to have gained root privileges, confirming the successful exploit. The speakers noted that Pixel devices do not enforce kernel module signatures, simplifying the loading of the custom peek_poke driver.

Defensive Implications

▶ Watch: Q&A: Android module signatures and patch status (44:30)

The "Dirty Ptrace" vulnerability and the broader context of mmap driver issues highlight several critical areas for defensive action across kernel development, driver development, and system deployment.

  1. Driver Developer Responsibility:
  • Explicit Writability Checks: The most immediate and crucial implication for driver developers is to always explicitly check the write argument and the memory region's permissions within their access callbacks for PFN_MAP pages. They should not assume the kernel has already performed these checks. If a memory region is intended to be read-only, the callback must refuse write requests, even from ptrace.
  • Input Sanitization: Continue to rigorously sanitize all user-supplied arguments for mmap and ioctl calls, paying close attention to potential integer overflows in size and offset calculations.
  • Reference Counting: Implement robust reference counting mechanisms for PFN_MAP pages, ensuring that memory is not freed while still in use by the IOMMU or other kernel components, as demonstrated by the Samsung Exynos zero-day.
  • Secure Memory Mapping Policies: As seen with AMD's GPU drivers, implementing policies that disallow remapping user-provided memory back to the CPU if it was originally from user space can prevent entire classes of attacks. Drivers should carefully evaluate the necessity and security implications of such re-mappings.
  1. Linux Kernel Developer Responsibility:
  • Strengthened ptrace Checks: The debate surrounding the proposed kernel patch indicates a need for clearer guidelines or even direct implementation of stronger security checks within the kernel's ptrace handling, particularly for PFN_MAP pages. While access callbacks offer flexibility, a baseline level of kernel-enforced protection for critical memory attributes like writability should be considered.
  • Clearer Documentation: The "undocumented behavior" aspect suggests a need for more explicit documentation regarding the expected security responsibilities of both kernel and driver components when interacting with PFN_MAP and ptrace.
  • Consistent VMA Management: Address race conditions and other subtle bugs in VMA (Virtual Memory Area) management, especially concerning freeing operations and the interaction with VM_IO flags, to prevent UAF and undefined behaviors.
  1. OEMs and Android Platform:
  • Vulnerable Driver Patching: OEMs and Android platform maintainers must prioritize patching vulnerable GPU drivers (like Nvidia and ImageTech) to mitigate "Dirty Ptrace" and similar issues.
  • Runtime Monitoring: Implement or enhance runtime monitoring capabilities to detect unusual ptrace activity or attempts to modify read-only system components.
  • Kernel Module Signature Enforcement: The fact that Pixel devices do not enforce kernel module signatures (as revealed in the Q&A) is a significant defensive gap. Enforcing module signatures would make it harder for attackers to load arbitrary kernel modules for privilege escalation.
  • SELinux Policy Refinement: While SELinux is a strong defense, continuous refinement of policies is necessary to ensure that even if code execution is achieved in a privileged process like init, its actions remain constrained and cannot easily load arbitrary kernel modules or perform other unauthorized operations.

In essence, defending against "Dirty Ptrace" requires a multi-layered approach, emphasizing shared responsibility, explicit security checks at all interfaces, and a continuous review of assumptions about memory protection boundaries in complex hardware-software interactions.

Key Takeaways

  • "Dirty Ptrace" is a novel vulnerability class exploiting undocumented kernel behavior where ptrace can write to read-only PFN_MAP memory pages if the driver's access callback fails to validate write permissions.
  • The vulnerability stems from a "blame game" between kernel and driver developers regarding responsibility for enforcing memory writability checks for driver-mapped memory accessed via ptrace.
  • Impacted hardware includes Nvidia and ImageTech (PowerVR DXT) GPUs, allowing unprivileged users to overwrite critical read-only memory like PCIe BARs, MMO registers, VRAM, and shared shader memory, leading to privilege escalation and system instability.
  • Exploitation on Pixel 10 involves a multi-stage attack: using "Dirty Ptrace" to overwrite libbase.so within the init process, loading a custom kernel module via a disk image and modprobe, and ultimately gaining arbitrary kernel read/write for full root access.
  • Defenders must implement explicit writability checks in driver access callbacks for PFN_MAP memory, and kernel developers should consider stronger default protections or clearer guidelines for these interfaces.
  • The case highlights persistent challenges in securing complex kernel-driver interfaces, including issues with mmap input sanitization, reference counting, race conditions, and inconsistent memory protection assumptions.

About the Speaker(s)

Xingyu Jin is a Security Researcher at Google, and Martijn Bogaard is a Security Engineer at Google. Both are part of the Android team, where their mission involves protecting the Android ecosystem through offensive security efforts. Their work focuses on vulnerability research and exploit development, actively engaging in finding and addressing security issues across the platform. Their expertise is evident in their detailed analysis of kernel-driver interactions and the sophisticated exploit chain developed for the "Dirty Ptrace" vulnerability.

Reviews

Dr. Zero (Offensive Security Researcher) — MUST SEE

This is the real deal — a novel vulnerability class with a working Pixel 10 root, built on a genuinely subtle kernel/driver interface gap that's been sitting in plain sight. The 'blame game' framing isn't just narrative dressing; it's the actual security failure mode, and they prove it with code.

Heather Calloway (CISO) — STRONG ACCEPT

A serious exploit primitive affecting mobile devices in enterprise fleets, demonstrated with a full chain rooting Pixel 10. The kernel-driver responsibility gap they expose is systemic. Every CISO with Android in their environment should understand this exists.

→ Top-rated talks at POC2025 (Power of Community)

All talks from POC2025 (Power of Community)