staging: media: atomisp: add missing mutex lock in atomisp_s_fmt_cap
Subsystems (4)
PATCH v2 1/1 staging: media: atomisp: add missing mutex lock in atomisp_s_fmt_cap
The function atomisp_set_fmt() modifies shared device state and expects callers to hold the isp->mutex for synchronization. While most internal callers correctly lock the mutex before invoking atomisp_set_fmt(), the V4L2 ioctl handler atomisp_s_fmt_cap() does not.
This results in an unsafe execution path for VIDIOC_S_FMT ioctls (e.g. via v4l2-ctl), where shared structures such as pipe->pix and pipe->frame_info may be modified concurrently without proper protection.
- Fix this by explicitly locking isp->mutex in atomisp_s_fmt_cap().
---
v2:
- Add Fixes tag
- use cleanup.h micros instead of explicitly calling mutex_lock/unlock
v1: https://lore.kernel.org/all/[email protected]/
drivers/staging/media/atomisp/pci/atomisp_ioctl.c | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-)
drivers/staging/media/atomisp/pci/atomisp_ioctl.c +9 -1
@@ -9,6 +9,7 @@#include <linux/delay.h> #include <linux/pci.h> +#include <linux/cleanup.h> #include <media/v4l2-ioctl.h> #include <media/v4l2-event.h>
@@ -416,8 +417,15 @@ static int atomisp_s_fmt_cap(struct file *file, void *fh, struct v4l2_format *f) {struct video_device *vdev =video_devdata (file); +struct atomisp_device *isp =video_get_drvdata (vdev); + +int ret; -return atomisp_set_fmt (vdev, f); + scoped_guard(mutex, &isp->mutex) + { + ret =atomisp_set_fmt (vdev, f); + } +return ret; }/*
Signature · 1 line
2.25.1
Quoted 13 lines · Abdelrahman Fekry
drivers/staging/media/atomisp/pci/atomisp_ioctl.c +1
-0@@ -9,6 +9,7 @@#include <linux/delay.h> #include <linux/pci.h> +#include <linux/cleanup.h> #include <media/v4l2-ioctl.h> #include <media/v4l2-event.h>
drivers/staging/media/atomisp/pci/atomisp_ioctl.c static int atomisp_s_fmt_cap(struct file *file, void *fh, · line 421
Quoted 5 lines
drivers/staging/media/atomisp/pci/atomisp_ioctl.c +2
-0@@ -416,8 +417,15 @@ static int atomisp_s_fmt_cap(struct file *file, void *fh, struct v4l2_format *f) {struct video_device *vdev =video_devdata (file); +struct atomisp_device *isp =video_get_drvdata (vdev); +
Delete this blank line.
drivers/staging/media/atomisp/pci/atomisp_ioctl.c static int atomisp_s_fmt_cap(struct file *file, void *fh, · line 425
Quoted 5 lines
drivers/staging/media/atomisp/pci/atomisp_ioctl.c +3
-1+int ret; -return atomisp_set_fmt (vdev, f); + scoped_guard(mutex, &isp->mutex) + {
This open curly brace should have gone on the line before:
scoped_guard(mutex, &isp->mutex) {But actually just use:
guard(mutex)(&isp->mutex);
It will hold the lock until the end of the function.
regards,
dan carpenter
Quoted 4 lines
drivers/staging/media/atomisp/pci/atomisp_ioctl.c +3
-0+ ret =atomisp_set_fmt (vdev, f); + } +return ret; }
Quoted 11 lines · Abdelrahman Fekry
The function
atomisp_set_fmt()modifies shared device state and expects callers to hold theisp->mutexfor synchronization. While most internal callers correctly lock the mutex before invokingatomisp_set_fmt(), the V4L2 ioctl handleratomisp_s_fmt_cap()does not.This results in an unsafe execution path for
VIDIOC_S_FMTioctls (e.g. via v4l2-ctl), where shared structures such aspipe->pixandpipe->frame_infomay be modified concurrently without proper protection.- Fix this by explicitly locking
isp->mutexinatomisp_s_fmt_cap().
...
Quoted 3 lines
#include <
linux/delay.h>
#include <linux/pci.h>
+#include <linux/cleanup.h>
Keep it ordered.
...
drivers/staging/media/atomisp/pci/atomisp_ioctl.c static int atomisp_s_fmt_cap(struct file *file, void *fh, · line 428
Quoted 8 lines
drivers/staging/media/atomisp/pci/atomisp_ioctl.c +6
-1+int ret; -return atomisp_set_fmt (vdev, f); + scoped_guard(mutex, &isp->mutex) + { + ret =atomisp_set_fmt (vdev, f); + } +return ret;
As Dan said, this should just add a (one line) guard()() and no other lines being touched.
Quoted 1 line
}
Signature · 2 lines
With Best Regards, Andy Shevchenko