[PATCH] media: meson: vdec: avoid double free on video register failure

sashiko-bot at kernel.org sashiko-bot at kernel.org
Sun May 17 23:10:04 PDT 2026


Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [Critical] Bypassing kobject lifetime management via a dummy release function creates a Use-After-Free (UAF) vulnerability.
--

commit c9bf433f66378b70af4be79f5c3eedbee4a4582b
Author: Guangshuo Li <lgs201920130244 at gmail.com>

media: meson: vdec: avoid double free on video register failure

This commit temporarily sets the video device release function to
video_device_release_empty before calling video_register_device() to prevent
a double-free on failure. It restores the original release function upon
success.

> diff --git a/drivers/staging/media/meson/vdec/vdec.c b/drivers/staging/media/meson/vdec/vdec.c
> index 4b77ec1af5a76..2994e46cbc259 100644
> --- a/drivers/staging/media/meson/vdec/vdec.c
> +++ b/drivers/staging/media/meson/vdec/vdec.c
> @@ -1074,7 +1074,7 @@ static int vdec_probe(struct platform_device *pdev)
>  	mutex_init(&core->lock);
>  
>  	strscpy(vdev->name, "meson-video-decoder", sizeof(vdev->name));
> -	vdev->release = video_device_release;
> +	vdev->release = video_device_release_empty;
>  	vdev->fops = &vdec_fops;
>  	vdev->ioctl_ops = &vdec_ioctl_ops;
>  	vdev->vfl_dir = VFL_DIR_M2M;
> @@ -1089,6 +1089,7 @@ static int vdec_probe(struct platform_device *pdev)
>  		dev_err(dev, "Failed registering video device\n");
>  		goto err_vdev_release;

When video_register_device() invokes device_register(), the embedded struct
device is initialized and can potentially be exposed to the system via
sysfs.

If registration fails, put_device() is called to drop the reference, but
this does not guarantee immediate synchronous destruction. Concurrent
subsystems might temporarily hold references, or if
CONFIG_DEBUG_KOBJECT_RELEASE is enabled, the kobject release is scheduled
on a workqueue.

Will bypassing the kobject lifetime management here by setting a dummy
release function and synchronously freeing the device in err_vdev_release
lead to a use-after-free?

Once the delayed kobject cleanup runs or concurrent holders drop their
references, the kernel could access the already-freed struct device within
the freed vdev to perform internal kobject teardown.

>  	}
> +	vdev->release = video_device_release;
>  
>  	return 0;

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20260518054318.979147-1-lgs201920130244@gmail.com?part=1



More information about the linux-amlogic mailing list