HIGH
media/mtk-jpeg Context UAF
CVE-2026-46011
CVSS:3.1/AV:L/AC:L/PR:L/UI:N/S:U/C:H/I:H/A:H
KernelScan AI7.0HIGH
01Description
In the Linux kernel, the following vulnerability has been resolved: media: mtk-jpeg: fix use-after-free in release path due to uncancelled work The mtk_jpeg_release() function frees the context structure (ctx) without first cancelling any pending or running work in ctx->jpeg_work. This creates a race window where the workqueue callback may still be accessing the context memory after it has been freed. Race condition: CPU 0 (release) CPU 1 (workqueue) ---------------- ------------------ close() mtk_jpeg_release() mtk_jpegenc_worker() ctx = work->data // accessing ctx kfree(ctx) // freed! access ctx // UAF! The work is queued via queue_work() during JPEG encode/decode operations (via mtk_jpeg_device_run). If the device is closed while work is pending or running, the work handler will access freed memory. Fix this by calling cancel_work_sync() BEFORE acquiring the mutex. This ordering is critical: if cancel_work_sync() is called after mutex_lock(), and the work handler also tries to acquire the same mutex, it would cause a deadlock. Note: The open error path does NOT need cancel_work_sync() because INIT_WORK() only initializes the work structure - it does not schedule it. Work is only scheduled later during ioctl operations.
02KernelScan AI Analysis
Risk summary
Local users with access to MediaTek JPEG hardware can trigger a use-after-free vulnerability by closing the device while JPEG encode/decode operations are in progress. This can lead to kernel memory corruption, privilege escalation, or system crashes on affected MediaTek platforms.
Vulnerability analysis
The root cause is a classic use-after-free race condition in the mtk_jpeg_release() function. When a user closes the JPEG device file descriptor, the release function immediately frees the context structure without canceling pending workqueue operations. If a JPEG encode/decode operation is still running on another CPU core, the worker thread (mtk_jpegenc_worker) will continue accessing the freed context memory, leading to use-after-free. The fix adds cancel_work_sync() before acquiring the mutex to ensure all pending work completes before freeing the context. The ordering is critical to avoid deadlock since the worker also acquires the same mutex. This vulnerability requires local access to the MediaTek JPEG device node and the ability to trigger concurrent operations.
03Fix Versions
| Branch | Fixed in | Patch commit |
|---|---|---|
| 6.12 | 6.12.86 | 0498b27a1542 |
| 6.18 | 6.18.27 | 26506a30e0e2 |
| 6.6 | 6.6.140 | 2209fdae5c2f |
| 7.0 | 7.0.4 | e78c39f72067 |
| mainline | 7.1-rc1 | 34c519feef3e |