CVE-2023-52491 media: mtk-jpeg: Fix use after free bug due to error path handling in mtk_jpeg_dec_device_run

High 7.8 Published Updated

A use-after-free vulnerability in the Linux kernel's MediaTek JPEG decoder driver allows local attackers to execute arbitrary code or escalate privileges via race conditions.

Exploited in the wild
Not known
Login needed
Any signed-in user
Attackable
Local or same network only
Victim action needed
Not needed
Fix
Available

What is CVE-2023-52491?

CVE-2023-52491 is a high-severity use after free vulnerability in Linux kernel, published on 29 Feb 2024. It can only be exploited from the same machine or local network, with no action from the victim.

Official description

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

media: mtk-jpeg: Fix use after free bug due to error path handling in mtk_jpeg_dec_device_run

In mtk_jpeg_probe, &jpeg->job_timeout_work is bound with mtk_jpeg_job_timeout_work.

In mtk_jpeg_dec_device_run, if error happens in mtk_jpeg_set_dec_dst, it will finally start the worker while mark the job as finished by invoking v4l2_m2m_job_finish.

There are two methods to trigger the bug. If we remove the module, it which will call mtk_jpeg_remove to make cleanup. The possible sequence is as follows, which will cause a use-after-free bug.

CPU0 CPU1 mtk_jpeg_dec_... | start worker | |mtk_jpeg_job_timeout_work mtk_jpeg_remove | v4l2_m2m_release | kfree(m2m_dev); | | | v4l2_m2m_get_curr_priv | m2m_dev->curr_ctx //use

If we close the file descriptor, which will call mtk_jpeg_release, it will have a similar sequence.

Fix this bug by starting timeout worker only if started jpegdec worker successfully. Then v4l2_m2m_job_finish will only be called in either mtk_jpeg_job_timeout_work or mtk_jpeg_dec_device_run.

Weakness: CWE-416

Which versions are affected by CVE-2023-52491?

It affects 1 product.

Products include Linux kernel.

How do I fix CVE-2023-52491?

Apply the vendor's patch.

Upgrade to the fixed version. These bugs are found with fuzzing and sanitisers and avoided by memory-safe languages. More about Use after free.

Is CVE-2023-52491 being exploited?

There is no known exploitation of CVE-2023-52491 in the wild and no public exploit code.

All Linux kernel vulnerabilities

Sources

Also known as BELL-CVE-2023-52491, DEBIAN-CVE-2023-52491, GHSA-2vrm-jm55-jg94, UBUNTU-CVE-2023-52491.

Is CVE-2023-52491 in your software?

Upload an SBOM and sbomify checks it against every vulnerability here, every day.

Check your SBOMs for free