* [PATCH v2] media: videobuf2: forbid remove_bufs when legacy fileio is active [not found] <CGME20251020160135eucas1p29eb8517e240f188f102e77713f85e29d@eucas1p2.samsung.com> @ 2025-10-20 16:01 ` Marek Szyprowski 2025-10-20 16:03 ` Benjamin Gaignard 2025-10-21 9:56 ` Hans Verkuil 0 siblings, 2 replies; 5+ messages in thread From: Marek Szyprowski @ 2025-10-20 16:01 UTC (permalink / raw) To: linux-media, linux-kernel Cc: Marek Szyprowski, Tomasz Figa, Mauro Carvalho Chehab, Guennadi Liakhovetski, Benjamin Gaignard, Hans Verkuil, stable, Shuangpeng Bai vb2_ioctl_remove_bufs() call manipulates queue internal buffer list, potentially overwriting some pointers used by the legacy fileio access mode. Add a vb2_verify_memory_type() check symmetrical to vb2_ioctl_create_bufs() to forbid that ioctl when fileio is active to protect internal queue state between subsequent read/write calls. CC: stable@vger.kernel.org Fixes: a3293a85381e ("media: v4l2: Add REMOVE_BUFS ioctl") Reported-by: Shuangpeng Bai<SJB7183@psu.edu> Suggested-by: Benjamin Gaignard <benjamin.gaignard@collabora.com> Signed-off-by: Marek Szyprowski <m.szyprowski@samsung.com> --- v2: - dropped a change to vb2_ioctl_create_bufs(), as it is already handled by the vb2_verify_memory_type() call - replaced queue->type check in vb2_ioctl_remove_bufs() by a call to vb2_verify_memory_type() which covers all cases v1: https://lore.kernel.org/all/20251016111154.993949-1-m.szyprowski@samsung.com/ --- drivers/media/common/videobuf2/videobuf2-v4l2.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/drivers/media/common/videobuf2/videobuf2-v4l2.c b/drivers/media/common/videobuf2/videobuf2-v4l2.c index d911021c1bb0..0de7490292fe 100644 --- a/drivers/media/common/videobuf2/videobuf2-v4l2.c +++ b/drivers/media/common/videobuf2/videobuf2-v4l2.c @@ -1000,9 +1000,11 @@ int vb2_ioctl_remove_bufs(struct file *file, void *priv, struct v4l2_remove_buffers *d) { struct video_device *vdev = video_devdata(file); + int res; - if (vdev->queue->type != d->type) - return -EINVAL; + res = vb2_verify_memory_type(vdev->queue, vdev->queue->memory, d->type); + if (res) + return res; if (d->count == 0) return 0; -- 2.34.1 ^ permalink raw reply related [flat|nested] 5+ messages in thread
* Re: [PATCH v2] media: videobuf2: forbid remove_bufs when legacy fileio is active 2025-10-20 16:01 ` [PATCH v2] media: videobuf2: forbid remove_bufs when legacy fileio is active Marek Szyprowski @ 2025-10-20 16:03 ` Benjamin Gaignard 2025-10-21 9:56 ` Hans Verkuil 1 sibling, 0 replies; 5+ messages in thread From: Benjamin Gaignard @ 2025-10-20 16:03 UTC (permalink / raw) To: Marek Szyprowski, linux-media, linux-kernel Cc: Tomasz Figa, Mauro Carvalho Chehab, Guennadi Liakhovetski, Hans Verkuil, stable, Shuangpeng Bai Le 20/10/2025 à 18:01, Marek Szyprowski a écrit : > vb2_ioctl_remove_bufs() call manipulates queue internal buffer list, > potentially overwriting some pointers used by the legacy fileio access > mode. Add a vb2_verify_memory_type() check symmetrical to > vb2_ioctl_create_bufs() to forbid that ioctl when fileio is active to > protect internal queue state between subsequent read/write calls. > > CC: stable@vger.kernel.org > Fixes: a3293a85381e ("media: v4l2: Add REMOVE_BUFS ioctl") > Reported-by: Shuangpeng Bai<SJB7183@psu.edu> > Suggested-by: Benjamin Gaignard <benjamin.gaignard@collabora.com> > Signed-off-by: Marek Szyprowski <m.szyprowski@samsung.com> Thanks for the patch. Reviewed-by: Benjamin Gaignard <benjamin.gaignard@collabora.com> > --- > v2: > - dropped a change to vb2_ioctl_create_bufs(), as it is already handled > by the vb2_verify_memory_type() call > - replaced queue->type check in vb2_ioctl_remove_bufs() by a call to > vb2_verify_memory_type() which covers all cases > > v1: https://lore.kernel.org/all/20251016111154.993949-1-m.szyprowski@samsung.com/ > --- > drivers/media/common/videobuf2/videobuf2-v4l2.c | 6 ++++-- > 1 file changed, 4 insertions(+), 2 deletions(-) > > diff --git a/drivers/media/common/videobuf2/videobuf2-v4l2.c b/drivers/media/common/videobuf2/videobuf2-v4l2.c > index d911021c1bb0..0de7490292fe 100644 > --- a/drivers/media/common/videobuf2/videobuf2-v4l2.c > +++ b/drivers/media/common/videobuf2/videobuf2-v4l2.c > @@ -1000,9 +1000,11 @@ int vb2_ioctl_remove_bufs(struct file *file, void *priv, > struct v4l2_remove_buffers *d) > { > struct video_device *vdev = video_devdata(file); > + int res; > > - if (vdev->queue->type != d->type) > - return -EINVAL; > + res = vb2_verify_memory_type(vdev->queue, vdev->queue->memory, d->type); > + if (res) > + return res; > > if (d->count == 0) > return 0; ^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH v2] media: videobuf2: forbid remove_bufs when legacy fileio is active 2025-10-20 16:01 ` [PATCH v2] media: videobuf2: forbid remove_bufs when legacy fileio is active Marek Szyprowski 2025-10-20 16:03 ` Benjamin Gaignard @ 2025-10-21 9:56 ` Hans Verkuil 2025-10-23 9:01 ` Hans Verkuil 1 sibling, 1 reply; 5+ messages in thread From: Hans Verkuil @ 2025-10-21 9:56 UTC (permalink / raw) To: Marek Szyprowski, linux-media, linux-kernel Cc: Tomasz Figa, Mauro Carvalho Chehab, Guennadi Liakhovetski, Benjamin Gaignard, Hans Verkuil, stable, Shuangpeng Bai Hi Marek, On 20/10/2025 18:01, Marek Szyprowski wrote: > vb2_ioctl_remove_bufs() call manipulates queue internal buffer list, > potentially overwriting some pointers used by the legacy fileio access > mode. Add a vb2_verify_memory_type() check symmetrical to > vb2_ioctl_create_bufs() to forbid that ioctl when fileio is active to > protect internal queue state between subsequent read/write calls. > > CC: stable@vger.kernel.org > Fixes: a3293a85381e ("media: v4l2: Add REMOVE_BUFS ioctl") > Reported-by: Shuangpeng Bai<SJB7183@psu.edu> > Suggested-by: Benjamin Gaignard <benjamin.gaignard@collabora.com> > Signed-off-by: Marek Szyprowski <m.szyprowski@samsung.com> I'll pick this up as a fix for v6.18. I think this is important enough to not wait for v6.19. Regards, Hans > --- > v2: > - dropped a change to vb2_ioctl_create_bufs(), as it is already handled > by the vb2_verify_memory_type() call > - replaced queue->type check in vb2_ioctl_remove_bufs() by a call to > vb2_verify_memory_type() which covers all cases > > v1: https://lore.kernel.org/all/20251016111154.993949-1-m.szyprowski@samsung.com/ > --- > drivers/media/common/videobuf2/videobuf2-v4l2.c | 6 ++++-- > 1 file changed, 4 insertions(+), 2 deletions(-) > > diff --git a/drivers/media/common/videobuf2/videobuf2-v4l2.c b/drivers/media/common/videobuf2/videobuf2-v4l2.c > index d911021c1bb0..0de7490292fe 100644 > --- a/drivers/media/common/videobuf2/videobuf2-v4l2.c > +++ b/drivers/media/common/videobuf2/videobuf2-v4l2.c > @@ -1000,9 +1000,11 @@ int vb2_ioctl_remove_bufs(struct file *file, void *priv, > struct v4l2_remove_buffers *d) > { > struct video_device *vdev = video_devdata(file); > + int res; > > - if (vdev->queue->type != d->type) > - return -EINVAL; > + res = vb2_verify_memory_type(vdev->queue, vdev->queue->memory, d->type); > + if (res) > + return res; > > if (d->count == 0) > return 0; ^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH v2] media: videobuf2: forbid remove_bufs when legacy fileio is active 2025-10-21 9:56 ` Hans Verkuil @ 2025-10-23 9:01 ` Hans Verkuil 2025-10-23 10:54 ` Hans Verkuil 0 siblings, 1 reply; 5+ messages in thread From: Hans Verkuil @ 2025-10-23 9:01 UTC (permalink / raw) To: Marek Szyprowski, linux-media, linux-kernel Cc: Tomasz Figa, Mauro Carvalho Chehab, Guennadi Liakhovetski, Benjamin Gaignard, Hans Verkuil, stable, Shuangpeng Bai On 21/10/2025 11:56, Hans Verkuil wrote: > Hi Marek, > > On 20/10/2025 18:01, Marek Szyprowski wrote: >> vb2_ioctl_remove_bufs() call manipulates queue internal buffer list, >> potentially overwriting some pointers used by the legacy fileio access >> mode. Add a vb2_verify_memory_type() check symmetrical to >> vb2_ioctl_create_bufs() to forbid that ioctl when fileio is active to >> protect internal queue state between subsequent read/write calls. >> >> CC: stable@vger.kernel.org >> Fixes: a3293a85381e ("media: v4l2: Add REMOVE_BUFS ioctl") >> Reported-by: Shuangpeng Bai<SJB7183@psu.edu> >> Suggested-by: Benjamin Gaignard <benjamin.gaignard@collabora.com> >> Signed-off-by: Marek Szyprowski <m.szyprowski@samsung.com> > > I'll pick this up as a fix for v6.18. I think this is important enough to > not wait for v6.19. Hmm, it's failing on v4l2-compliance. I'm debugging to see whether it is a kernel or v4l2-compliance problem. Regards, Hans > > Regards, > > Hans > >> --- >> v2: >> - dropped a change to vb2_ioctl_create_bufs(), as it is already handled >> by the vb2_verify_memory_type() call >> - replaced queue->type check in vb2_ioctl_remove_bufs() by a call to >> vb2_verify_memory_type() which covers all cases >> >> v1: https://lore.kernel.org/all/20251016111154.993949-1-m.szyprowski@samsung.com/ >> --- >> drivers/media/common/videobuf2/videobuf2-v4l2.c | 6 ++++-- >> 1 file changed, 4 insertions(+), 2 deletions(-) >> >> diff --git a/drivers/media/common/videobuf2/videobuf2-v4l2.c b/drivers/media/common/videobuf2/videobuf2-v4l2.c >> index d911021c1bb0..0de7490292fe 100644 >> --- a/drivers/media/common/videobuf2/videobuf2-v4l2.c >> +++ b/drivers/media/common/videobuf2/videobuf2-v4l2.c >> @@ -1000,9 +1000,11 @@ int vb2_ioctl_remove_bufs(struct file *file, void *priv, >> struct v4l2_remove_buffers *d) >> { >> struct video_device *vdev = video_devdata(file); >> + int res; >> >> - if (vdev->queue->type != d->type) >> - return -EINVAL; >> + res = vb2_verify_memory_type(vdev->queue, vdev->queue->memory, d->type); >> + if (res) >> + return res; >> >> if (d->count == 0) >> return 0; > > ^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH v2] media: videobuf2: forbid remove_bufs when legacy fileio is active 2025-10-23 9:01 ` Hans Verkuil @ 2025-10-23 10:54 ` Hans Verkuil 0 siblings, 0 replies; 5+ messages in thread From: Hans Verkuil @ 2025-10-23 10:54 UTC (permalink / raw) To: Marek Szyprowski, linux-media, linux-kernel Cc: Tomasz Figa, Mauro Carvalho Chehab, Guennadi Liakhovetski, Benjamin Gaignard, Hans Verkuil, stable, Shuangpeng Bai On 23/10/2025 11:01, Hans Verkuil wrote: > On 21/10/2025 11:56, Hans Verkuil wrote: >> Hi Marek, >> >> On 20/10/2025 18:01, Marek Szyprowski wrote: >>> vb2_ioctl_remove_bufs() call manipulates queue internal buffer list, >>> potentially overwriting some pointers used by the legacy fileio access >>> mode. Add a vb2_verify_memory_type() check symmetrical to >>> vb2_ioctl_create_bufs() to forbid that ioctl when fileio is active to >>> protect internal queue state between subsequent read/write calls. >>> >>> CC: stable@vger.kernel.org >>> Fixes: a3293a85381e ("media: v4l2: Add REMOVE_BUFS ioctl") >>> Reported-by: Shuangpeng Bai<SJB7183@psu.edu> >>> Suggested-by: Benjamin Gaignard <benjamin.gaignard@collabora.com> >>> Signed-off-by: Marek Szyprowski <m.szyprowski@samsung.com> >> >> I'll pick this up as a fix for v6.18. I think this is important enough to >> not wait for v6.19. > > Hmm, it's failing on v4l2-compliance. I'm debugging to see whether it is a > kernel or v4l2-compliance problem. > > Regards, > > Hans > >> >> Regards, >> >> Hans >> >>> --- >>> v2: >>> - dropped a change to vb2_ioctl_create_bufs(), as it is already handled >>> by the vb2_verify_memory_type() call >>> - replaced queue->type check in vb2_ioctl_remove_bufs() by a call to >>> vb2_verify_memory_type() which covers all cases >>> >>> v1: https://lore.kernel.org/all/20251016111154.993949-1-m.szyprowski@samsung.com/ >>> --- >>> drivers/media/common/videobuf2/videobuf2-v4l2.c | 6 ++++-- >>> 1 file changed, 4 insertions(+), 2 deletions(-) >>> >>> diff --git a/drivers/media/common/videobuf2/videobuf2-v4l2.c b/drivers/media/common/videobuf2/videobuf2-v4l2.c >>> index d911021c1bb0..0de7490292fe 100644 >>> --- a/drivers/media/common/videobuf2/videobuf2-v4l2.c >>> +++ b/drivers/media/common/videobuf2/videobuf2-v4l2.c >>> @@ -1000,9 +1000,11 @@ int vb2_ioctl_remove_bufs(struct file *file, void *priv, >>> struct v4l2_remove_buffers *d) >>> { >>> struct video_device *vdev = video_devdata(file); >>> + int res; >>> >>> - if (vdev->queue->type != d->type) >>> - return -EINVAL; >>> + res = vb2_verify_memory_type(vdev->queue, vdev->queue->memory, d->type); >>> + if (res) >>> + return res; >>> >>> if (d->count == 0) >>> return 0; This is the problem. For the corner case where d->count == 0 it can be that vdev->queue->memory is VB2_MEMORY_UNKNOWN (that happens if no buffers were ever queued). But it should still return 0 in that case. Also the fileio test doesn't apply in that case, but that's not tested in v4l2-compliance. I suggest this: if (d->count == 0) return d->type == vdev->queue->type ? 0 : -EINVAL; res = vb2_verify_memory_type(vdev->queue, vdev->queue->memory, d->type); if (res) return res; I tested this and it passes v4l2-compliance. Marek, can you post a v3? Thank you, Hans >> >> > > ^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2025-10-23 10:54 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
[not found] <CGME20251020160135eucas1p29eb8517e240f188f102e77713f85e29d@eucas1p2.samsung.com>
2025-10-20 16:01 ` [PATCH v2] media: videobuf2: forbid remove_bufs when legacy fileio is active Marek Szyprowski
2025-10-20 16:03 ` Benjamin Gaignard
2025-10-21 9:56 ` Hans Verkuil
2025-10-23 9:01 ` Hans Verkuil
2025-10-23 10:54 ` Hans Verkuil
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox