PageJack: A Powerful Exploit Technique With Page-Level UAF

Unknown

Black Hat USA 2024 · Day 1 · Briefing

Overview

This talk introduces PageJack, a sophisticated exploit technique designed to achieve privilege escalation within operating system kernels, particularly focusing on Linux and Android. Presented by Chen, a professor from the University of California Riverside, on behalf of a collaborative academic research team, PageJack addresses a critical challenge in modern kernel exploitation: reliably targeting sensitive kernel data structures across different memory caches. As Control Flow Integrity (CFI) mitigations increasingly harden systems against traditional control flow hijack attacks, the focus for attackers is shifting towards data-only attacks. PageJack provides a novel and more reliable methodology for executing such attacks by leveraging a page-level Use-After-Free (UAF) primitive.

Watch on YouTube

Visual summary for PageJack: A Powerful Exploit Technique With Page-Level UAF by Unknown
Visual summary for PageJack: A Powerful Exploit Technique With Page-Level UAF by Unknown

Key moments

  1. 0:00 Introduction and the rise of data-only attacks
  2. 4:00 Heap variables are prime targets for data-only attacks
  3. 4:30 The significant cross-cache challenge in data-only attacks
  4. 6:50 Pivoting Out-of-Bounds writes into Use-After-Free
  5. 8:40 Achieving privilege escalation by reusing freed cache pages

PageJack: A Powerful Exploit Technique With Page-Level UAF

Speakers: Chen, Professor, University of California Riverside

Conference: Black Hat USA

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

Overview

This talk introduces PageJack, a sophisticated exploit technique designed to achieve privilege escalation within operating system kernels, particularly focusing on Linux and Android. Presented by Chen, a professor from the University of California Riverside, on behalf of a collaborative academic research team, PageJack addresses a critical challenge in modern kernel exploitation: reliably targeting sensitive kernel data structures across different memory caches. As Control Flow Integrity (CFI) mitigations increasingly harden systems against traditional control flow hijack attacks, the focus for attackers is shifting towards data-only attacks. PageJack provides a novel and more reliable methodology for executing such attacks by leveraging a page-level Use-After-Free (UAF) primitive.

The research presented is highly pertinent to the evolving landscape of OS kernel security. By offering a robust mechanism to overcome the cross-cache challenge—a significant hurdle for data-only attacks—PageJack demonstrates a new frontier in kernel exploitation. This technique allows attackers to manipulate core operating system data, such as user IDs or file permissions, even when these critical objects are isolated in dedicated memory caches. The implications are substantial, compelling security researchers and defenders to reassess current mitigation strategies and develop new defenses against these advanced memory management exploits.

Background

▶ Watch: Introduction and the rise of data-only attacks (0:00)

The evolution of kernel exploitation has seen a significant shift in recent years. Historically, control flow hijack attacks were prevalent, where attackers would manipulate control data like function pointers to redirect execution to attacker-controlled code, often facilitating Return-Oriented Programming (ROP). However, the widespread adoption of Control Flow Integrity (CFI) has made these techniques increasingly difficult to execute reliably. Consequently, the security community has observed a clear trend towards data-only attacks, which instead corrupt data pointers or critical data fields, leading to arbitrary read/write capabilities that can ultimately alter key OS data such as credentials (cred) or user IDs (UID). A survey of publicly available kernel exploits against CVEs in Linux and Android confirms this rise in data-only attacks.

Data-only attacks typically target two types of critical OS data: global variables and heap variables. Global variables, such as modprobe_path, store system-wide configuration or paths. Overwriting modprobe_path, which holds the file path to the modprobe binary executed with root privileges, can lead to privilege escalation by running an attacker-controlled binary. However, targeting global variables presents several challenges: bypassing Kernel Address Space Layout Randomization (KASLR), requiring an arbitrary address write primitive, and overcoming kernel options that protect popular targets like modprobe_path by making their file paths static.

In contrast, heap variables like cred objects (containing UID) or file objects (with F_MODE for permissions) are often more desirable targets for data-only attacks. Corrupting fields like UID to zero (root) or changing F_MODE to enable writes on a read-only file can directly lead to privilege escalation. The key advantage of heap variables is that an attacker can spray numerous such objects onto the heap and utilize relative rights, such as out-of-bounds (OOB) writes, instead of needing an arbitrary absolute address write. This theoretically negates the need for KASLR bypass for the write operation itself, as the target address is relative to a known, controlled object.

Despite the advantages of heap variables, a significant hurdle remains: the cross-cache challenge. Most vulnerabilities in the Linux kernel occur in generic heap caches, while many critical heap objects (like cred structures) reside in dedicated caches. This separation prevents direct corruption of critical objects using relative writes within a generic cache. Previous attempts to overcome this challenge, while sometimes successful, have proven unreliable or not future-proof.

Existing cross-cache attack techniques include:

  1. Page Adjacent Attacks for OOB Writes: This involves arranging memory layout such that two different caches become adjacent in memory, allowing an OOB write from one cache to spill into an adjacent, different cache. However, this method relies heavily on luck, as the exact location and distance between objects are uncertain, especially with modern kernel mitigations.
  2. Pivoting OOB Writes to Double Free or Use-After-Free (UAF): This more sophisticated technique involves using an OOB write to corrupt the lower bits of a heap data pointer found in many heap objects, such as the list_head field (containing next and previous pointers) in message_message objects. As demonstrated by prior exploits, an OOB write corrupting the lower bytes of a next pointer within an array of message_message objects has a high probability of making it point to an object that is already referenced by another pointer. This creates a scenario where two pointers point to the same object. An attacker can then free the object using one of these pointers, automatically transforming the other into a dangling pointer. This dangling pointer provides a UAF primitive, allowing the attacker to free the object again (double free) or use the freed memory for subsequent malicious allocations. While better than direct OOB cross-cache attacks, even with a UAF primitive, the cross-cache challenge for reliably landing a victim object in the freed memory persists, demanding more robust solutions.

Key Findings

▶ Watch: Heap variables are prime targets for data-only attacks (4:00)

The central contribution of the PageJack research is the identification and development of a novel exploit technique that reliably overcomes the persistent cross-cache challenge in kernel exploitation. The key finding is that by leveraging a page-level Use-After-Free (UAF) primitive, attackers can achieve precise heap grooming across distinct memory cache boundaries, enabling the consistent targeting of critical kernel objects.

Specifically, the core discovery lies in the realization that while individual object UAFs might struggle with cache isolation, the liberation of an entire cache and its underlying memory pages provides a powerful mechanism for control. This allows for a strategic reuse of these freed pages by subsequent allocations, irrespective of the original cache type. The research demonstrates that:

  1. Page-Level UAF for Cross-Cache Targeting: Instead of merely freeing a single vulnerable object, the technique focuses on freeing the vulnerable object and enough surrounding padding objects to cause the entire memory page(s) associated with that generic cache to be returned to the kernel's page allocator.
  2. Reliable Victim Object Placement: Once these pages are freed, they can then be re-allocated by a different kernel subsystem or cache that manages sensitive victim objects (e.g., cred structures). This effectively bridges the gap between generic vulnerable caches and dedicated critical object caches.
  3. Consistent Privilege Escalation: By strategically triggering the page-level UAF and then forcing the allocation of victim objects into these newly available pages, the original dangling pointer (from the initial UAF) now points to a critical, attacker-controlled object. This provides a robust primitive for modifying sensitive data fields, such as setting UID to zero for root privileges, thereby enabling consistent privilege escalation.

This finding fundamentally changes how attackers can approach data-only attacks against isolated heap objects, making kernel UAF vulnerabilities significantly more potent and reliable for achieving high-privilege access.

Technical Deep Dive

▶ Watch: The significant cross-cache challenge in data-only attacks (4:30)

The PageJack technique hinges on a sophisticated manipulation of the kernel's memory management, specifically targeting the page allocation mechanism underlying heap caches. It transforms a standard Use-After-Free (UAF) primitive, often limited by cache isolation, into a page-level UAF capable of bridging the cross-cache challenge. The process involves several critical steps of heap grooming:

  1. Initial Heap Spray and Vulnerable Object Allocation:

The attacker first needs to trigger the allocation of a vulnerable object within a generic kernel slab cache. To facilitate the page-level UAF, this allocation is surrounded by numerous padding objects of the same size. The goal is to fill an entire or significant portion of a memory page with objects belonging to this generic cache. For instance, if a cache allocates objects of size X, the attacker would allocate N objects such that N * X approximates the size of a memory page (e.g., 4KB or 8KB). This ensures that when these objects are freed, the underlying physical page is more likely to be returned to the kernel's page allocator.

  1. Triggering the Use-After-Free (UAF):

A kernel vulnerability, typically a UAF, is then exploited to free the targeted vulnerable object. This leaves a dangling pointer—a pointer that still references the memory location but the memory has been marked as free. At this stage, a traditional UAF might struggle to re-allocate a critical victim object into this specific freed slot if the victim object belongs to a different, dedicated cache.

  1. Page-Level Deallocation:

This is the crucial distinction of PageJack. Instead of merely relying on the single freed slot, the attacker proceeds to free other padding objects that reside within the same memory page as the vulnerable object. The strategic allocation in step 1 ensures that when a sufficient number of objects within that page are freed, the kernel's slab allocator determines that the entire underlying physical memory page is now largely or completely empty. Consequently, the slab allocator returns this page to the kernel's higher-level page allocator. This means the physical memory page itself is now available for any subsequent page-level allocation request, effectively breaking the cache boundary.

  1. Victim Object Reallocation:

With the physical page now freed and available, the attacker then triggers the allocation of the desired victim object. This victim object, such as a cred structure (which typically resides in a dedicated cred_jar cache), can now be allocated directly into the previously freed page. Because the entire page is available, the kernel's page allocator can fulfill the cred allocation request by using this page.

  1. Exploiting the Dangling Pointer:

At this point, the original dangling pointer, which previously pointed to the vulnerable object, now points to the newly allocated cred structure. The attacker can then use this dangling pointer to perform an arbitrary read/write operation on the cred object. For example, by writing a 0 to the UID field within the cred structure, the attacker can elevate the privileges of the current process to root. Similarly, other critical fields like F_MODE in a file object could be modified to change file permissions.

This method bypasses the limitations of traditional UAF exploitation where re-allocating a single object slot within a specific cache might not allow for cross-cache object placement. By freeing an entire page, PageJack effectively "resets" the memory region, making it available for any subsequent page-aligned allocation, regardless of the original slab cache type. This makes the technique highly reliable for achieving precise heap grooming and targeting isolated critical kernel data structures.

Demo / Proof of Concept

▶ Watch: Pivoting Out-of-Bounds writes into Use-After-Free (6:50)

While the provided transcript snippet details the technical underpinnings of PageJack and the theoretical steps required to achieve privilege escalation via a page-level Use-After-Free (UAF), it concludes just as the speaker is about to delve into the full demonstration or proof-of-concept. Therefore, specific details about a live demonstration, the exact tools used, or the precise steps of a proof-of-concept are not available within this segment of the talk.

However, the theoretical explanation clearly outlines how a successful Page-Level UAF could be leveraged. A full demonstration would likely involve:

  1. Identifying a specific UAF vulnerability in a generic kernel object.
  2. Crafting an exploit that performs the initial heap spray with padding objects.
  3. Triggering the UAF and the subsequent page-level deallocation.
  4. Forcing the allocation of a cred object into the freed page.
  5. Using the dangling pointer to modify the UID field of the cred object to 0.
  6. Demonstrating the elevated privileges (e.g., by executing a root-only command).

Such a demonstration would visually confirm the ability of PageJack to bypass cross-cache isolation and achieve reliable privilege escalation, validating the theoretical framework presented.

Defensive Implications

▶ Watch: Achieving privilege escalation by reusing freed cache pages (8:40)

The PageJack technique represents a significant advancement in kernel exploitation, particularly for data-only attacks, and carries several critical defensive implications for operating system developers and security practitioners.

  1. Heightened Scrutiny for UAF Vulnerabilities: The primary implication is that all Use-After-Free (UAF) vulnerabilities, regardless of how seemingly minor or isolated they appear within a specific slab cache, must be treated as critical. PageJack demonstrates that even a UAF in a generic object can be escalated into a powerful cross-cache primitive by manipulating page-level allocations. Kernel developers must prioritize eliminating UAFs and implementing robust memory safety measures.
  1. Advanced Heap Sanitization and Poisoning: Current heap sanitization techniques might need to be re-evaluated. If a freed page can be re-allocated by a different cache, simply zeroing out freed objects might not be sufficient if the new object type has different sensitive fields or if the attacker can control the re-allocation timing. More aggressive heap poisoning strategies that make freed pages unusable or detectable across different cache types could be beneficial.
  1. Mitigations for Page-Level Reallocation: New mitigations might be required to detect or prevent the rapid freeing and reallocation of entire memory pages across disparate kernel caches. Monitoring for unusual patterns of page deallocation followed by allocations from unrelated caches could be a detection strategy. However, implementing this without impacting performance would be challenging.
  1. Strengthening Critical Data Structures: While cred structures are already considered highly sensitive, PageJack highlights the need for even more robust protections. This could involve more complex integrity checks on UID and GID fields before privilege operations, or making cred objects immutable after initial setup, requiring a more controlled and audited mechanism for privilege changes.
  1. Beyond Control Flow Integrity (CFI): PageJack underscores the limitations of CFI as a standalone mitigation. While CFI effectively thwarts control flow hijacks, it offers no protection against data-only attacks that manipulate memory contents directly to achieve privilege escalation. Defenders must invest in a layered security approach that includes strong memory safety, data integrity checks, and effective UAF prevention.
  1. Kernel Memory Allocator Hardening: The underlying kernel memory allocators (like SLAB, SLUB, or SLAB_RCU) are central to this attack. Hardening these allocators to make page-level reuse less predictable or more difficult to control by an attacker could be a long-term defensive strategy. This might involve increasing randomization in page allocation, implementing stricter checks on page ownership before reuse, or introducing delays in page recycling.

In essence, PageJack forces defenders to think beyond individual object-level vulnerabilities and consider the broader implications of memory page lifecycle management within the kernel.

Key Takeaways

  • Shift to Data-Only Attacks: Due to the increasing effectiveness of Control Flow Integrity (CFI), the landscape of OS kernel exploitation is shifting towards data-only attacks that manipulate critical data fields rather than hijacking control flow.
  • Persistent Cross-Cache Challenge: A major hurdle for data-only attacks is the cross-cache challenge, where critical victim objects (e.g., cred) reside in dedicated memory caches, isolated from generic caches where most vulnerabilities occur.
  • Page-Level UAF as a Solution: PageJack introduces a novel page-level Use-After-Free (UAF) technique that reliably overcomes the cross-cache challenge by strategically freeing an entire memory page, not just a single object.
  • Reliable Victim Object Grooming: This technique allows attackers to free a page associated with a generic cache and then force the allocation of a desired victim object (like cred) into that same freed page, effectively bridging cache boundaries.
  • Consistent Privilege Escalation: By gaining control over a critical object through a dangling pointer, PageJack enables consistent and reliable privilege escalation (e.g., setting UID=0) within the kernel.
  • Defensive Focus on UAF and Memory Management: Defenders must prioritize preventing all UAF vulnerabilities, enhance heap sanitization, and develop new mitigations that address page-level memory allocation and reuse across different kernel caches.

About the Speaker(s)

The talk was presented by Chen, a professor from the University of California Riverside. He delivered the presentation on behalf of a collaborative academic research group comprising experts from several institutions, including the University of California Riverside. The team's collective passion and focus lie in OS kernel security, with the core research and development work being primarily performed by the students within the group.

All talks from Black Hat USA 2024