mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Marek Szyprowski <m.szyprowski@samsung.com>
To: Hans Verkuil <hverkuil+cisco@kernel.org>,
	linux-media@vger.kernel.org, linux-kernel@vger.kernel.org
Cc: Tomasz Figa <tfiga@chromium.org>,
	Mauro Carvalho Chehab <mchehab@kernel.org>,
	Guennadi Liakhovetski <g.liakhovetski@gmx.de>,
	Benjamin Gaignard <benjamin.gaignard@collabora.com>,
	Hans Verkuil <hverkuil@kernel.org>,
	stable@vger.kernel.org, Shuangpeng Bai <SJB7183@psu.edu>
Subject: Re: [PATCH v3] media: videobuf2: forbid remove_bufs when legacy fileio is active
Date: Thu, 23 Oct 2025 13:55:42 +0200	[thread overview]
Message-ID: <85aa56ff-098b-4db1-9de5-05b0f306623f@samsung.com> (raw)
In-Reply-To: <81a46647-c666-4475-893b-d4af043c90ea@kernel.org>

On 23.10.2025 13:36, Hans Verkuil wrote:
> On 23/10/2025 13:30, 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>
>> ---
>>   drivers/media/common/videobuf2/videobuf2-v4l2.c | 8 +++++---
>>   1 file changed, 5 insertions(+), 3 deletions(-)
>>
>> diff --git a/drivers/media/common/videobuf2/videobuf2-v4l2.c b/drivers/media/common/videobuf2/videobuf2-v4l2.c
>> index d911021c1bb0..a8a5b42a42d0 100644
>> --- a/drivers/media/common/videobuf2/videobuf2-v4l2.c
>> +++ b/drivers/media/common/videobuf2/videobuf2-v4l2.c
>> @@ -1000,13 +1000,15 @@ int vb2_ioctl_remove_bufs(struct file *file, void *priv,
>>   			  struct v4l2_remove_buffers *d)
>>   {
>>   	struct video_device *vdev = video_devdata(file);
>> -
>> -	if (vdev->queue->type != d->type)
>> -		return -EINVAL;
>> +	int res;
>>   
>>   	if (d->count == 0)
>>   		return 0;
> Ah, no. This should still check d->type. So:
>
> 	if (d->count == 0)
> 		return d->type == vdev->queue->type ? 0 : -EINVAL;

Then frankly speaking lets get back to v1 limited to 
vb2_ioctl_remove_bufs(), as using vb2_verify_memory_type() in this 
context only makes things harder to understand:

diff --git a/drivers/media/common/videobuf2/videobuf2-v4l2.c 
b/drivers/media/common/videobuf2/videobuf2-v4l2.c index 
d911021c1bb0..f4104d5971dd 100644 --- 
a/drivers/media/common/videobuf2/videobuf2-v4l2.c +++ 
b/drivers/media/common/videobuf2/videobuf2-v4l2.c

@@ -1010,6 +1015,11 @@ int vb2_ioctl_remove_bufs(struct file *file, void 
*priv, if (vb2_queue_is_busy(vdev->queue, file)) return -EBUSY; + if 
(vb2_fileio_is_active(vdev->queue)) { + dprintk(vdev->queue, 1, "file io 
in progress\n"); + return -EBUSY; + } + return 
vb2_core_remove_bufs(vdev->queue, d->index, d->count); } 
EXPORT_SYMBOL_GPL(vb2_ioctl_remove_bufs);


> Regards,
>
> 	Hans
>
>>   
>> +	res = vb2_verify_memory_type(vdev->queue, vdev->queue->memory, d->type);
>> +	if (res)
>> +		return res;
>> +
>>   	if (vb2_queue_is_busy(vdev->queue, file))
>>   		return -EBUSY;
>>
Best regards
-- 
Marek Szyprowski, PhD
Samsung R&D Institute Poland


  reply	other threads:[~2025-10-23 11:55 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <CGME20251023113101eucas1p2c227985b0198d888564cab00aeb94f01@eucas1p2.samsung.com>
2025-10-23 11:30 ` Marek Szyprowski
2025-10-23 11:36   ` Hans Verkuil
2025-10-23 11:55     ` Marek Szyprowski [this message]
2025-10-23 12:25       ` Hans Verkuil
2025-10-23 11:44   ` Marek Szyprowski

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=85aa56ff-098b-4db1-9de5-05b0f306623f@samsung.com \
    --to=m.szyprowski@samsung.com \
    --cc=SJB7183@psu.edu \
    --cc=benjamin.gaignard@collabora.com \
    --cc=g.liakhovetski@gmx.de \
    --cc=hverkuil+cisco@kernel.org \
    --cc=hverkuil@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-media@vger.kernel.org \
    --cc=mchehab@kernel.org \
    --cc=stable@vger.kernel.org \
    --cc=tfiga@chromium.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®