# CVE-2026-31584: media: mediatek: vcodec: fix use-after-free in encoder release path

> Archived entry. Full-text search covers entries since 2026-11-10; exact IDs work for all years.

- **Severity:** HIGH 7.8
- **CVSS:** 7.8 (v3.1, CNA) `CVSS:3.1/AV:L/AC:L/PR:L/UI:N/S:U/C:H/I:H/A:H`
- **CVSS metrics:** Attack vector: Local; Attack complexity: Low; Privileges required: Low; User interaction: None; Scope: Unchanged; Confidentiality impact: High; Integrity impact: High; Availability impact: High
- **Exploited in the wild:** Not in CISA KEV
- **Public exploit / PoC:** None known
- **Remote exploitation:** Not remotely exploitable (local or adjacent access needed)
- **EPSS:** 0.18% (percentile 4, 2026-11-26)
- **CWE:** CWE-416
- **Published:** 2026-04-24T14:42:13.586Z
- **Modified:** 2026-11-11T23:10:00.263Z

## Who should check

- Anyone running Linux \>= 0934d37596151edce115c6d0843a9ad7d5e5d232, \< 9a9bdaf9dc42ccca50e53f82165292f74a365c11; \>= 0934d37596151edce115c6d0843a9ad7d5e5d232, \< a8a55913552aed45108525d1851c65e1db0cc25b; \>= 0934d37596151edce115c6d0843a9ad7d5e5d232, \< f99353cd0e9f58bf17889049137b8d65fb44ebf1; \>= 0934d37596151edce115c6d0843a9ad7d5e5d232, \< 93d9a58961a9e09306857e999b3ee76aa4be67f0; \>= 0934d37596151edce115c6d0843a9ad7d5e5d232, \< f1692337c6fa26e04f89b22a4d84bf5b7ada50d1; \>= 0934d37596151edce115c6d0843a9ad7d5e5d232, \< 76e35091ffc722ba39b303e48bc5d08abb59dd56
- Anyone running Linux 6.6

## Description

In the Linux kernel, the following vulnerability has been resolved:

media: mediatek: vcodec: fix use-after-free in encoder release path

The fops\_vcodec\_release() function frees the context structure (ctx)
without first cancelling any pending or running work in ctx-\>encode\_work.
This creates a race window where the workqueue handler (mtk\_venc\_worker)
may still be accessing the context memory after it has been freed.

Race condition:

    CPU 0 (release path)               CPU 1 (workqueue)
    ---------------------               ------------------
    fops\_vcodec\_release()
      v4l2\_m2m\_ctx\_release()
        v4l2\_m2m\_cancel\_job()
        // waits for m2m job "done"
                                        mtk\_venc\_worker()
                                          v4l2\_m2m\_job\_finish()
                                          // m2m job "done"
                                          // BUT worker still running!
                                          // post-job\_finish access:
                                        other ctx dereferences
                                          // UAF if ctx already freed
        // returns (job "done")
      kfree(ctx)  // ctx freed

Root cause: The v4l2\_m2m\_ctx\_release() only waits for the m2m job
lifecycle (via TRANS\_RUNNING flag), not the workqueue lifecycle.
After v4l2\_m2m\_job\_finish() is called, the m2m framework considers
the job complete and v4l2\_m2m\_ctx\_release() returns, but the worker
function continues executing and may still access ctx.

The work is queued during encode operations via:
  queue\_work(ctx-\>dev-\>encode\_workqueue, &ctx-\>encode\_work)
The worker function accesses ctx-\>m2m\_ctx, ctx-\>dev, and other ctx
fields even after calling v4l2\_m2m\_job\_finish().

This vulnerability was confirmed with KASAN by running an instrumented
test module that widens the post-job\_finish race window. KASAN detected:

  BUG: KASAN: slab-use-after-free in mtk\_venc\_worker+0x159/0x180
  Read of size 4 at addr ffff88800326e000 by task kworker/u8:0/12

  Workqueue: mtk\_vcodec\_enc\_wq mtk\_venc\_worker

  Allocated by task 47:
    \_\_kasan\_kmalloc+0x7f/0x90
    fops\_vcodec\_open+0x85/0x1a0

  Freed by task 47:
    \_\_kasan\_slab\_free+0x43/0x70
    kfree+0xee/0x3a0
    fops\_vcodec\_release+0xb7/0x190

Fix this by calling cancel\_work\_sync(&ctx-\>encode\_work) before kfree(ctx).
This ensures the workqueue handler is both cancelled (if pending) and
synchronized (waits for any running handler to complete) before the
context is freed.

Placement rationale: The fix is placed after v4l2\_ctrl\_handler\_free()
and before list\_del\_init(&ctx-\>list). At this point, all m2m operations
are done (v4l2\_m2m\_ctx\_release() has returned), and we need to ensure
the workqueue is synchronized before removing ctx from the list and
freeing it.

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 device\_run() operations.

## Affected and fixed versions

- Linux: \>= 0934d37596151edce115c6d0843a9ad7d5e5d232, \< 9a9bdaf9dc42ccca50e53f82165292f74a365c11; \>= 0934d37596151edce115c6d0843a9ad7d5e5d232, \< a8a55913552aed45108525d1851c65e1db0cc25b; \>= 0934d37596151edce115c6d0843a9ad7d5e5d232, \< f99353cd0e9f58bf17889049137b8d65fb44ebf1; \>= 0934d37596151edce115c6d0843a9ad7d5e5d232, \< 93d9a58961a9e09306857e999b3ee76aa4be67f0; \>= 0934d37596151edce115c6d0843a9ad7d5e5d232, \< f1692337c6fa26e04f89b22a4d84bf5b7ada50d1; \>= 0934d37596151edce115c6d0843a9ad7d5e5d232, \< 76e35091ffc722ba39b303e48bc5d08abb59dd56 (cvelist)
- Linux: 6.6 (cvelist)

## Mitigation

- Upgrade Linux to 76e35091ffc722ba39b303e48bc5d08abb59dd56 or later.

## Check your systems with an agent

Paste this into a coding agent:

```text
Check whether anything I run is affected by CVE-2026-31584. Work read-only: do not install, upgrade, delete or change anything.

Details: https://flawdb.com/CVE-2026-31584.md
Affected: Linux >= 0934d37596151edce115c6d0843a9ad7d5e5d232, < 9a9bdaf9dc42ccca50e53f82165292f74a365c11; >= 0934d37596151edce115c6d0843a9ad7d5e5d232, < a8a55913552aed45108525d1851c65e1db0cc25b; >= 0934d37596151edce115c6d0843a9ad7d5e5d232, < f99353cd0e9f58bf17889049137b8d65fb44ebf1; >= 0934d37596151edce115c6d…
Fixed in: Linux 9a9bdaf9dc42ccca50e53f82165292f74a365c11, Linux 93d9a58961a9e09306857e999b3ee76aa4be67f0, Linux 76e35091ffc722ba39b303e48bc5d08abb59dd56

Steps:
1. Search this machine and project for Linux: dependency manifests and lockfiles, installed packages, container images and running services.
2. For each match, note the installed version and whether it is inside the affected range.
3. Report a table: location, installed version, affected (yes / no / unsure), evidence. If affected, say which fixed version or mitigation from the details link applies, but don't apply it.
```

## FAQ

### Is CVE-2026-31584 being exploited?

There is no confirmed exploitation: CVE-2026-31584 is not in the CISA Known Exploited Vulnerabilities catalog. No public exploit code is known. EPSS estimates a 0.18% chance of exploitation in the next 30 days (as of 2026-11-26).

### How serious is CVE-2026-31584?

High: CVSS 7.8 (v3.1, scored by CNA). Not remotely exploitable (local or adjacent access needed).

### Which versions are affected by CVE-2026-31584?

Linux \>= 0934d37596151edce115c6d0843a9ad7d5e5d232, \< 9a9bdaf9dc42ccca50e53f82165292f74a365c11; \>= 0934d37596151edce115c6d0843a9ad7d5e5d232, \< a8a55913552aed45108525d1851c65e1db0cc25b; \>= 0934d37596151edce115c6d0843a9ad7d5e5d232, \< f99353cd0e9f58bf17889049137b8d65fb44ebf1; \>= 0934d37596151edce115c6d0843a9ad7d5e5d232, \< 93d9a58961a9e09306857e999b3ee76aa4be67f0; \>= 0934d37596151edce115c6d0843a9ad7d5e5d232, \< f1692337c6fa26e04f89b22a4d84bf5b7ada50d1; \>= 0934d37596151edce115c6d0843a9ad7d5e5d232, \< 76e35091ffc722ba39b303e48bc5d08abb59dd56; Linux 6.6.

### Is there a fix for CVE-2026-31584?

Yes. Fixed in Linux 9a9bdaf9dc42ccca50e53f82165292f74a365c11, Linux 93d9a58961a9e09306857e999b3ee76aa4be67f0, Linux 76e35091ffc722ba39b303e48bc5d08abb59dd56. Upgrade Linux to 76e35091ffc722ba39b303e48bc5d08abb59dd56 or later.

### How do I check if I'm affected by CVE-2026-31584?

Find where you use the affected software (dependency lockfiles, installed packages, container images, servers) and compare the installed version with the affected range above. The agent prompt on this page does this read-only.

## References

- patch: <https://git.kernel.org/stable/c/9a9bdaf9dc42ccca50e53f82165292f74a365c11>
- patch: <https://git.kernel.org/stable/c/a8a55913552aed45108525d1851c65e1db0cc25b>
- patch: <https://git.kernel.org/stable/c/f99353cd0e9f58bf17889049137b8d65fb44ebf1>
- patch: <https://git.kernel.org/stable/c/93d9a58961a9e09306857e999b3ee76aa4be67f0>
- patch: <https://git.kernel.org/stable/c/f1692337c6fa26e04f89b22a4d84bf5b7ada50d1>
- patch: <https://git.kernel.org/stable/c/76e35091ffc722ba39b303e48bc5d08abb59dd56>

## Attribution

- CVE Program: CVE® is a registered trademark of The MITRE Corporation. CVE records © 1999–2026 The MITRE Corporation. <https://www.cve.org/Legal/TermsOfUse>
- NVD: This product uses data from the NVD API but is not endorsed or certified by the NVD. <https://nvd.nist.gov/vuln/detail/CVE-2026-31584>

HTML: <https://flawdb.com/CVE-2026-31584> · JSON: <https://flawdb.com/api/v1/entries/CVE-2026-31584>
