Android Upgrades, Custom ROMs (LineageOS), & Kernels

RE Lab: Unpacking an Android Security Patch – Identifying Fixed Vulnerabilities & Their Code Changes

Google AdSense Native Placement - Horizontal Top-Post banner

Introduction: The Unseen Changes in Your Android Device

Every month, Google releases an Android Security Bulletin detailing vulnerabilities patched in the Android operating system. While end-users simply receive an update notification, security researchers, custom ROM developers, and exploit developers delve much deeper, reverse engineering these patches to understand the underlying vulnerabilities and their fixes. This process, often referred to as patch diffing, is crucial for tracking exploit trends, developing custom mitigations, or even crafting zero-day exploits if a fix is incomplete. This article will guide you through an expert-level methodology for unpacking an Android security patch, focusing on identifying fixed vulnerabilities and analyzing the specific code changes.

Understanding Android Security Patch Levels (SPLs)

Android Security Patch Levels (SPLs) are dates in a YYYY-MM-DD format that indicate the most recent security patches applied to a device. For instance, an SPL of “2023-01-05” means the device includes all patches up to and including those released on January 5, 2023. These patches are a culmination of fixes for vulnerabilities discovered in AOSP components, Linux kernel, vendor components, and open-source libraries. Google’s Android Security Bulletins provide a high-level overview, categorizing vulnerabilities by severity and type (e.g., remote code execution, elevation of privilege). Our goal is to bridge the gap between these high-level descriptions and the actual bytes changed on a device.

The Role of AOSP and Vendor Patches

Android’s ecosystem involves AOSP (Android Open Source Project) and various vendors (Qualcomm, Samsung, MediaTek, etc.). AOSP provides the core OS, while vendors contribute device-specific hardware abstraction layers (HALs), drivers, and firmware. Security patches often involve components from both. Google publishes AOSP patches, but vendors are responsible for integrating these and developing their own fixes for proprietary components. This means analyzing a device-specific OTA (Over-The-Air) update is often more complex than just checking AOSP commits.

Methodology: A Step-by-Step Approach to Patch Analysis

Step 1: Obtain System Images and OTA Updates

The first step is acquiring the necessary system images or OTA update packages. Ideally, you need two versions: a base version (e.g., January 2023 security patch) and a patched version (e.g., February 2023 security patch). For Pixel devices, factory images are publicly available from Google. For other devices, you might need to extract images from OTA updates or even pull partitions directly from a rooted device.

# Example: Download Pixel factory images for a specific device (e.g., 'oriole' for Pixel 6) # You'd download two versions, e.g., '13.0.0 (TQ1A.230105.002, Jan 2023)' and '13.0.0 (TQ1A.230205.003, Feb 2023)' # from developers.google.com/android/images  # Extract the images unzip oriole-tq1a.230105.002-factory-03f47e30.zip unzip oriole-tq1a.230205.003-factory-ea9c678a.zip  # Navigate into the extracted directories and extract the system.img/vendor.img/boot.img # For Android 10+, images are sparse and need conversion: simg2img January_image/system.img January_image/system.ext4 simg2img February_image/system.img February_image/system.ext4  # Mount the images to a directory mkdir -p jan_system feb_system sudo mount -t ext4 January_image/system.ext4 jan_system sudo mount -t ext4 February_image/system.ext4 feb_system

Step 2: Identifying Changed Components

Once you have the file systems extracted and mounted, you can use `diff` to quickly identify changed files. This gives you a starting point for further analysis.

# Recursively compare directories and list differences diff -qr jan_system feb_system > system_diff.txt diff -qr jan_vendor feb_vendor > vendor_diff.txt diff -qr jan_boot feb_boot > boot_diff.txt  # Filter for common executable paths grep 'Only in feb_system/bin' system_diff.txt grep 'Files feb_system/bin/some_binary and jan_system/bin/some_binary differ' system_diff.txt

Pay close attention to changes in `/system/bin`, `/system/lib`, `/vendor/bin`, `/vendor/lib`, and especially the `boot.img` for kernel-level changes.

Step 3: Pinpointing Vulnerabilities with AOSP Bulletins

Cross-reference your `diff` output with the official Android Security Bulletin for the corresponding patch level. If the bulletin mentions a fix for CVE-XXXX-XXXX affecting, for example, `system/core/libutils`, and your `diff` shows changes in files within that path, you’ve likely found the relevant binary or library.

For kernel vulnerabilities, the bulletin will often specify affected kernel versions or drivers. You’d then look for changes in the `boot.img` (specifically the kernel image and modules) or vendor-specific kernel modules.

Step 4: Deep Dive into Code Changes with Disassemblers

Once you’ve identified specific binaries or kernel modules that have changed, it’s time for reverse engineering. Tools like IDA Pro, Ghidra, or Binary Ninja are indispensable here. Load both the old and new versions of the changed binary into your disassembler. Many of these tools offer binary diffing capabilities (e.g., IDA’s BinDiff plugin, Ghidra’s Diaphora script).

# Example steps using Ghidra (manual process) 1.  Load 'old_binary' into Ghidra. Analyze it. 2.  Load 'new_binary' into Ghidra. Analyze it. 3.  Use Ghidra's 'Compare' feature (File -> Compare With...) or a plugin like Diaphora. 4.  Focus on functions with significant changes in basic block structure or added/removed instructions.

Example: Analyzing a Hypothetical Heap Overflow Fix

Consider a hypothetical vulnerability (CVE-XXXX-XXXX) related to a heap overflow in a networking daemon (`/system/bin/netd`). The security bulletin states it’s an RCE due to improper input validation. After diffing, you find `netd` has changed. Using a disassembler, you might identify a function handling incoming packet data that previously used `memcpy` without proper size checks. The patch introduces a bounds check:

Vulnerable Code (Simplified Pseudocode):
// Old version of netd_handle_packet() void netd_handle_packet(char* packet_data, size_t data_len) {     char buffer[256];     // ... other operations     memcpy(buffer, packet_data, data_len); // data_len could be > 256!     // ... further processing }
Patched Code (Simplified Pseudocode):
// New version of netd_handle_packet() void netd_handle_packet(char* packet_data, size_t data_len) {     char buffer[256];     // ... other operations     if (data_len > sizeof(buffer)) {         // Handle error, drop packet, or truncate         LOGE(

Android Mobile Specs & Compare Directory

Are you researching mobile hardware properties, processor SoCs, GPU chipsets, or RAM configurations? Access our complete specs catalog to compare up to 5 devices side-by-side!

Compare Devices Specs →
Google AdSense Inline Placement - Content Footer banner