* [PATCH] staging: media: atomisp: add missing mutex lock in atomisp_s_fmt_cap
@ 2025-07-16 1:42 Abdelrahman Fekry
2025-07-16 8:10 ` Andy Shevchenko
0 siblings, 1 reply; 3+ messages in thread
From: Abdelrahman Fekry @ 2025-07-16 1:42 UTC (permalink / raw)
To: hansg, mchehab, sakari.ailus, andy, gregkh
Cc: linux-media, linux-kernel, linux-staging, linux-kernel-mentees,
skhan, dan.carpenter, Abdelrahman Fekry
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().
Signed-off-by: Abdelrahman Fekry <abdelrahmanfekry375@gmail.com>
---
drivers/staging/media/atomisp/pci/atomisp_ioctl.c | 9 ++++++++-
1 file changed, 8 insertions(+), 1 deletion(-)
diff --git a/drivers/staging/media/atomisp/pci/atomisp_ioctl.c b/drivers/staging/media/atomisp/pci/atomisp_ioctl.c
index bb8b2f2213b0..9bf0be00657c 100644
--- a/drivers/staging/media/atomisp/pci/atomisp_ioctl.c
+++ b/drivers/staging/media/atomisp/pci/atomisp_ioctl.c
@@ -416,8 +416,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);
+ mutex_lock(&isp->mutex);
+ ret = atomisp_set_fmt(vdev, f);
+ mutex_unlock(&isp->mutex);
+
+ return ret;
}
/*
--
2.25.1
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH] staging: media: atomisp: add missing mutex lock in atomisp_s_fmt_cap
2025-07-16 1:42 [PATCH] staging: media: atomisp: add missing mutex lock in atomisp_s_fmt_cap Abdelrahman Fekry
@ 2025-07-16 8:10 ` Andy Shevchenko
2025-07-16 17:27 ` Abdelrahman Fekry
0 siblings, 1 reply; 3+ messages in thread
From: Andy Shevchenko @ 2025-07-16 8:10 UTC (permalink / raw)
To: Abdelrahman Fekry
Cc: hansg, mchehab, sakari.ailus, andy, gregkh, linux-media,
linux-kernel, linux-staging, linux-kernel-mentees, skhan,
dan.carpenter
On Wed, Jul 16, 2025 at 4:42 AM Abdelrahman Fekry
<abdelrahmanfekry375@gmail.com> wrote:
>
> 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().
If it's a fix, please add the Fixes tag.
...
> - return atomisp_set_fmt(vdev, f);
> + mutex_lock(&isp->mutex);
> + ret = atomisp_set_fmt(vdev, f);
> + mutex_unlock(&isp->mutex);
Side note: Can you consider switching the driver to use cleanup.h
(guard()(), scoped_guard(), __free(), etc)?
--
With Best Regards,
Andy Shevchenko
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH] staging: media: atomisp: add missing mutex lock in atomisp_s_fmt_cap
2025-07-16 8:10 ` Andy Shevchenko
@ 2025-07-16 17:27 ` Abdelrahman Fekry
0 siblings, 0 replies; 3+ messages in thread
From: Abdelrahman Fekry @ 2025-07-16 17:27 UTC (permalink / raw)
To: Andy Shevchenko
Cc: hansg, mchehab, sakari.ailus, andy, gregkh, linux-media,
linux-kernel, linux-staging, linux-kernel-mentees, skhan,
dan.carpenter
Hi Andy,
On Wed, Jul 16, 2025 at 11:11 AM Andy Shevchenko
<andy.shevchenko@gmail.com> wrote:
>
> On Wed, Jul 16, 2025 at 4:42 AM Abdelrahman Fekry
> <abdelrahmanfekry375@gmail.com> wrote:
> >
> > 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().
>
> If it's a fix, please add the Fixes tag.
>
will do , thanks.
> ...
>
> > - return atomisp_set_fmt(vdev, f);
> > + mutex_lock(&isp->mutex);
> > + ret = atomisp_set_fmt(vdev, f);
> > + mutex_unlock(&isp->mutex);
>
> Side note: Can you consider switching the driver to use cleanup.h
> (guard()(), scoped_guard(), __free(), etc)?
will look at it .
Would you please look at this patch series [1] , it hasn't got any feedback
and i have more work that builds on it.
> --
> With Best Regards,
> Andy Shevchenko
Link: https://lore.kernel.org/all/20250712191325.132666-1-abdelrahmanfekry375@gmail.com/
[1]
Best Regards,
Abdelrahman Fekry
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2025-07-16 17:27 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-07-16 1:42 [PATCH] staging: media: atomisp: add missing mutex lock in atomisp_s_fmt_cap Abdelrahman Fekry
2025-07-16 8:10 ` Andy Shevchenko
2025-07-16 17:27 ` Abdelrahman Fekry
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).