public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH v1 0/1] [RESEND] uvc: Handle cames with invalid descriptors
@ 2022-09-20 14:04 Ricardo Ribalda
  2022-09-20 14:04 ` [PATCH v1 1/1] media: uvc: Handle cameras " Ricardo Ribalda
  0 siblings, 1 reply; 9+ messages in thread
From: Ricardo Ribalda @ 2022-09-20 14:04 UTC (permalink / raw)
  To: Mauro Carvalho Chehab, Laurent Pinchart
  Cc: linux-media, linux-kernel, syzbot, Ricardo Ribalda

Just a resend of the patch.

To: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
To: Mauro Carvalho Chehab <mchehab@kernel.org>
Cc: linux-media@vger.kernel.org
Cc: linux-kernel@vger.kernel.org
Signed-off-by: Ricardo Ribalda <ribalda@chromium.org>

---
Ricardo Ribalda (1):
      media: uvc: Handle cameras with invalid descriptors

 drivers/media/usb/uvc/uvc_entity.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
---
base-commit: 521a547ced6477c54b4b0cc206000406c221b4d6
change-id: 20220920-invalid-desc-80bcc8082ce3

Best regards,
-- 
Ricardo Ribalda <ribalda@chromium.org>

^ permalink raw reply	[flat|nested] 9+ messages in thread

* [PATCH v1 1/1] media: uvc: Handle cameras with invalid descriptors
  2022-09-20 14:04 [PATCH v1 0/1] [RESEND] uvc: Handle cames with invalid descriptors Ricardo Ribalda
@ 2022-09-20 14:04 ` Ricardo Ribalda
  2022-09-21  0:53   ` Laurent Pinchart
  0 siblings, 1 reply; 9+ messages in thread
From: Ricardo Ribalda @ 2022-09-20 14:04 UTC (permalink / raw)
  To: Mauro Carvalho Chehab, Laurent Pinchart
  Cc: linux-media, linux-kernel, syzbot, Ricardo Ribalda

If the source entity does not contain any pads, do not create a link.

Reported-by: syzbot <syzkaller@googlegroups.com>
Signed-off-by: Ricardo Ribalda <ribalda@chromium.org>

diff --git a/drivers/media/usb/uvc/uvc_entity.c b/drivers/media/usb/uvc/uvc_entity.c
index 7c4d2f93d351..1f730cb72e58 100644
--- a/drivers/media/usb/uvc/uvc_entity.c
+++ b/drivers/media/usb/uvc/uvc_entity.c
@@ -43,7 +43,7 @@ static int uvc_mc_create_links(struct uvc_video_chain *chain,
 		source = (UVC_ENTITY_TYPE(remote) == UVC_TT_STREAMING)
 		       ? (remote->vdev ? &remote->vdev->entity : NULL)
 		       : &remote->subdev.entity;
-		if (source == NULL)
+		if (source == NULL || source->num_pads == 0)
 			continue;
 
 		remote_pad = remote->num_pads - 1;

-- 
b4 0.11.0-dev-d93f8

^ permalink raw reply related	[flat|nested] 9+ messages in thread

* Re: [PATCH v1 1/1] media: uvc: Handle cameras with invalid descriptors
  2022-09-20 14:04 ` [PATCH v1 1/1] media: uvc: Handle cameras " Ricardo Ribalda
@ 2022-09-21  0:53   ` Laurent Pinchart
  2022-09-21  7:51     ` Ricardo Ribalda
  0 siblings, 1 reply; 9+ messages in thread
From: Laurent Pinchart @ 2022-09-21  0:53 UTC (permalink / raw)
  To: Ricardo Ribalda; +Cc: Mauro Carvalho Chehab, linux-media, linux-kernel, syzbot

Hi Ricardo,

Thank you for the patch.

On Tue, Sep 20, 2022 at 04:04:55PM +0200, Ricardo Ribalda wrote:
> If the source entity does not contain any pads, do not create a link.
> 
> Reported-by: syzbot <syzkaller@googlegroups.com>
> Signed-off-by: Ricardo Ribalda <ribalda@chromium.org>
> 
> diff --git a/drivers/media/usb/uvc/uvc_entity.c b/drivers/media/usb/uvc/uvc_entity.c
> index 7c4d2f93d351..1f730cb72e58 100644
> --- a/drivers/media/usb/uvc/uvc_entity.c
> +++ b/drivers/media/usb/uvc/uvc_entity.c
> @@ -43,7 +43,7 @@ static int uvc_mc_create_links(struct uvc_video_chain *chain,
>  		source = (UVC_ENTITY_TYPE(remote) == UVC_TT_STREAMING)
>  		       ? (remote->vdev ? &remote->vdev->entity : NULL)
>  		       : &remote->subdev.entity;
> -		if (source == NULL)
> +		if (source == NULL || source->num_pads == 0)

source->num_pads and remote->num_pads should always be identical, but as
the next line uses remote->num_pads, wouldn't it be better to test that
variable ? If so, I'd move the test a file lines earlier, with the
remote == NULL test.

What do you think ? If you agree I can make that change when applying,
there's no need for a new version. Otherwise I'll keep the patch as-is.

>  			continue;
>  
>  		remote_pad = remote->num_pads - 1;
> 

-- 
Regards,

Laurent Pinchart

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [PATCH v1 1/1] media: uvc: Handle cameras with invalid descriptors
  2022-09-21  0:53   ` Laurent Pinchart
@ 2022-09-21  7:51     ` Ricardo Ribalda
  2022-09-21 21:16       ` Laurent Pinchart
  0 siblings, 1 reply; 9+ messages in thread
From: Ricardo Ribalda @ 2022-09-21  7:51 UTC (permalink / raw)
  To: Laurent Pinchart; +Cc: Mauro Carvalho Chehab, linux-media, linux-kernel, syzbot

Do you mean something like this?

diff --git a/drivers/media/usb/uvc/uvc_entity.c
b/drivers/media/usb/uvc/uvc_entity.c
index 7c4d2f93d351..66d1f5da4ec7 100644
--- a/drivers/media/usb/uvc/uvc_entity.c
+++ b/drivers/media/usb/uvc/uvc_entity.c
@@ -37,7 +37,7 @@ static int uvc_mc_create_links(struct uvc_video_chain *chain,
                        continue;

                remote = uvc_entity_by_id(chain->dev, entity->baSourceID[i]);
-               if (remote == NULL)
+               if (remote == NULL || remote->num_pads == 0)
                        return -EINVAL;

                source = (UVC_ENTITY_TYPE(remote) == UVC_TT_STREAMING)
@@ -46,6 +46,9 @@ static int uvc_mc_create_links(struct uvc_video_chain *chain,
                if (source == NULL)
                        continue;

+               if (source->num_pads != remote->num_pads)
+                       return -EINVAL;
+
                remote_pad = remote->num_pads - 1;
                ret = media_create_pad_link(source, remote_pad,
                                               sink, i, flags);

regarding making a new patch, whatever is easier for you ;)


On Wed, 21 Sept 2022 at 02:53, Laurent Pinchart
<laurent.pinchart@ideasonboard.com> wrote:
>
> Hi Ricardo,
>
> Thank you for the patch.
>
> On Tue, Sep 20, 2022 at 04:04:55PM +0200, Ricardo Ribalda wrote:
> > If the source entity does not contain any pads, do not create a link.
> >
> > Reported-by: syzbot <syzkaller@googlegroups.com>
> > Signed-off-by: Ricardo Ribalda <ribalda@chromium.org>
> >
> > diff --git a/drivers/media/usb/uvc/uvc_entity.c b/drivers/media/usb/uvc/uvc_entity.c
> > index 7c4d2f93d351..1f730cb72e58 100644
> > --- a/drivers/media/usb/uvc/uvc_entity.c
> > +++ b/drivers/media/usb/uvc/uvc_entity.c
> > @@ -43,7 +43,7 @@ static int uvc_mc_create_links(struct uvc_video_chain *chain,
> >               source = (UVC_ENTITY_TYPE(remote) == UVC_TT_STREAMING)
> >                      ? (remote->vdev ? &remote->vdev->entity : NULL)
> >                      : &remote->subdev.entity;
> > -             if (source == NULL)
> > +             if (source == NULL || source->num_pads == 0)
>
> source->num_pads and remote->num_pads should always be identical, but as
> the next line uses remote->num_pads, wouldn't it be better to test that
> variable ? If so, I'd move the test a file lines earlier, with the
> remote == NULL test.
>
> What do you think ? If you agree I can make that change when applying,
> there's no need for a new version. Otherwise I'll keep the patch as-is.
>
> >                       continue;
> >
> >               remote_pad = remote->num_pads - 1;
> >
>
> --
> Regards,
>
> Laurent Pinchart



-- 
Ricardo Ribalda

^ permalink raw reply related	[flat|nested] 9+ messages in thread

* Re: [PATCH v1 1/1] media: uvc: Handle cameras with invalid descriptors
  2022-09-21  7:51     ` Ricardo Ribalda
@ 2022-09-21 21:16       ` Laurent Pinchart
  2022-09-21 21:52         ` Ricardo Ribalda
  0 siblings, 1 reply; 9+ messages in thread
From: Laurent Pinchart @ 2022-09-21 21:16 UTC (permalink / raw)
  To: Ricardo Ribalda; +Cc: Mauro Carvalho Chehab, linux-media, linux-kernel, syzbot

Hi Ricardo,

On Wed, Sep 21, 2022 at 09:51:44AM +0200, Ricardo Ribalda wrote:
> Do you mean something like this?
> 
> diff --git a/drivers/media/usb/uvc/uvc_entity.c
> b/drivers/media/usb/uvc/uvc_entity.c
> index 7c4d2f93d351..66d1f5da4ec7 100644
> --- a/drivers/media/usb/uvc/uvc_entity.c
> +++ b/drivers/media/usb/uvc/uvc_entity.c
> @@ -37,7 +37,7 @@ static int uvc_mc_create_links(struct uvc_video_chain *chain,
>                         continue;
> 
>                 remote = uvc_entity_by_id(chain->dev, entity->baSourceID[i]);
> -               if (remote == NULL)
> +               if (remote == NULL || remote->num_pads == 0)
>                         return -EINVAL;

Yes.

> 
>                 source = (UVC_ENTITY_TYPE(remote) == UVC_TT_STREAMING)
> @@ -46,6 +46,9 @@ static int uvc_mc_create_links(struct uvc_video_chain *chain,
>                 if (source == NULL)
>                         continue;
> 
> +               if (source->num_pads != remote->num_pads)
> +                       return -EINVAL;
> +

But this I would have dropped, as the media_entity num_pads is
initialized from uvc_entity num_pads and neither are changed after.

>                 remote_pad = remote->num_pads - 1;
>                 ret = media_create_pad_link(source, remote_pad,
>                                                sink, i, flags);
> 
> regarding making a new patch, whatever is easier for you ;)
> 
> 
> On Wed, 21 Sept 2022 at 02:53, Laurent Pinchart wrote:
> >
> > Hi Ricardo,
> >
> > Thank you for the patch.
> >
> > On Tue, Sep 20, 2022 at 04:04:55PM +0200, Ricardo Ribalda wrote:
> > > If the source entity does not contain any pads, do not create a link.
> > >
> > > Reported-by: syzbot <syzkaller@googlegroups.com>
> > > Signed-off-by: Ricardo Ribalda <ribalda@chromium.org>
> > >
> > > diff --git a/drivers/media/usb/uvc/uvc_entity.c b/drivers/media/usb/uvc/uvc_entity.c
> > > index 7c4d2f93d351..1f730cb72e58 100644
> > > --- a/drivers/media/usb/uvc/uvc_entity.c
> > > +++ b/drivers/media/usb/uvc/uvc_entity.c
> > > @@ -43,7 +43,7 @@ static int uvc_mc_create_links(struct uvc_video_chain *chain,
> > >               source = (UVC_ENTITY_TYPE(remote) == UVC_TT_STREAMING)
> > >                      ? (remote->vdev ? &remote->vdev->entity : NULL)
> > >                      : &remote->subdev.entity;
> > > -             if (source == NULL)
> > > +             if (source == NULL || source->num_pads == 0)
> >
> > source->num_pads and remote->num_pads should always be identical, but as
> > the next line uses remote->num_pads, wouldn't it be better to test that
> > variable ? If so, I'd move the test a file lines earlier, with the
> > remote == NULL test.
> >
> > What do you think ? If you agree I can make that change when applying,
> > there's no need for a new version. Otherwise I'll keep the patch as-is.
> >
> > >                       continue;
> > >
> > >               remote_pad = remote->num_pads - 1;
> > >

-- 
Regards,

Laurent Pinchart

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [PATCH v1 1/1] media: uvc: Handle cameras with invalid descriptors
  2022-09-21 21:16       ` Laurent Pinchart
@ 2022-09-21 21:52         ` Ricardo Ribalda
  2022-10-24 18:18           ` Laurent Pinchart
  0 siblings, 1 reply; 9+ messages in thread
From: Ricardo Ribalda @ 2022-09-21 21:52 UTC (permalink / raw)
  To: Laurent Pinchart; +Cc: Mauro Carvalho Chehab, linux-media, linux-kernel, syzbot

Hi Laurent

On Wed, 21 Sept 2022 at 23:16, Laurent Pinchart
<laurent.pinchart@ideasonboard.com> wrote:
>
> Hi Ricardo,
>
> On Wed, Sep 21, 2022 at 09:51:44AM +0200, Ricardo Ribalda wrote:
> > Do you mean something like this?
> >
> > diff --git a/drivers/media/usb/uvc/uvc_entity.c
> > b/drivers/media/usb/uvc/uvc_entity.c
> > index 7c4d2f93d351..66d1f5da4ec7 100644
> > --- a/drivers/media/usb/uvc/uvc_entity.c
> > +++ b/drivers/media/usb/uvc/uvc_entity.c
> > @@ -37,7 +37,7 @@ static int uvc_mc_create_links(struct uvc_video_chain *chain,
> >                         continue;
> >
> >                 remote = uvc_entity_by_id(chain->dev, entity->baSourceID[i]);
> > -               if (remote == NULL)
> > +               if (remote == NULL || remote->num_pads == 0)
> >                         return -EINVAL;
>
> Yes.
>
> >
> >                 source = (UVC_ENTITY_TYPE(remote) == UVC_TT_STREAMING)
> > @@ -46,6 +46,9 @@ static int uvc_mc_create_links(struct uvc_video_chain *chain,
> >                 if (source == NULL)
> >                         continue;
> >
> > +               if (source->num_pads != remote->num_pads)
> > +                       return -EINVAL;
> > +
>
> But this I would have dropped, as the media_entity num_pads is
> initialized from uvc_entity num_pads and neither are changed after.

Works for me. Shall I send a v2 or you can take it?

Thanks!
>
> >                 remote_pad = remote->num_pads - 1;
> >                 ret = media_create_pad_link(source, remote_pad,
> >                                                sink, i, flags);
> >
> > regarding making a new patch, whatever is easier for you ;)
> >
> >
> > On Wed, 21 Sept 2022 at 02:53, Laurent Pinchart wrote:
> > >
> > > Hi Ricardo,
> > >
> > > Thank you for the patch.
> > >
> > > On Tue, Sep 20, 2022 at 04:04:55PM +0200, Ricardo Ribalda wrote:
> > > > If the source entity does not contain any pads, do not create a link.
> > > >
> > > > Reported-by: syzbot <syzkaller@googlegroups.com>
> > > > Signed-off-by: Ricardo Ribalda <ribalda@chromium.org>
> > > >
> > > > diff --git a/drivers/media/usb/uvc/uvc_entity.c b/drivers/media/usb/uvc/uvc_entity.c
> > > > index 7c4d2f93d351..1f730cb72e58 100644
> > > > --- a/drivers/media/usb/uvc/uvc_entity.c
> > > > +++ b/drivers/media/usb/uvc/uvc_entity.c
> > > > @@ -43,7 +43,7 @@ static int uvc_mc_create_links(struct uvc_video_chain *chain,
> > > >               source = (UVC_ENTITY_TYPE(remote) == UVC_TT_STREAMING)
> > > >                      ? (remote->vdev ? &remote->vdev->entity : NULL)
> > > >                      : &remote->subdev.entity;
> > > > -             if (source == NULL)
> > > > +             if (source == NULL || source->num_pads == 0)
> > >
> > > source->num_pads and remote->num_pads should always be identical, but as
> > > the next line uses remote->num_pads, wouldn't it be better to test that
> > > variable ? If so, I'd move the test a file lines earlier, with the
> > > remote == NULL test.
> > >
> > > What do you think ? If you agree I can make that change when applying,
> > > there's no need for a new version. Otherwise I'll keep the patch as-is.
> > >
> > > >                       continue;
> > > >
> > > >               remote_pad = remote->num_pads - 1;
> > > >
>
> --
> Regards,
>
> Laurent Pinchart



-- 
Ricardo Ribalda

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [PATCH v1 1/1] media: uvc: Handle cameras with invalid descriptors
  2022-09-21 21:52         ` Ricardo Ribalda
@ 2022-10-24 18:18           ` Laurent Pinchart
  2023-01-03 14:55             ` Ricardo Ribalda
  0 siblings, 1 reply; 9+ messages in thread
From: Laurent Pinchart @ 2022-10-24 18:18 UTC (permalink / raw)
  To: Ricardo Ribalda; +Cc: Mauro Carvalho Chehab, linux-media, linux-kernel, syzbot

Hi Ricardo,

On Wed, Sep 21, 2022 at 11:52:29PM +0200, Ricardo Ribalda wrote:
> On Wed, 21 Sept 2022 at 23:16, Laurent Pinchart wrote:
> > On Wed, Sep 21, 2022 at 09:51:44AM +0200, Ricardo Ribalda wrote:
> > > Do you mean something like this?
> > >
> > > diff --git a/drivers/media/usb/uvc/uvc_entity.c
> > > b/drivers/media/usb/uvc/uvc_entity.c
> > > index 7c4d2f93d351..66d1f5da4ec7 100644
> > > --- a/drivers/media/usb/uvc/uvc_entity.c
> > > +++ b/drivers/media/usb/uvc/uvc_entity.c
> > > @@ -37,7 +37,7 @@ static int uvc_mc_create_links(struct uvc_video_chain *chain,
> > >                         continue;
> > >
> > >                 remote = uvc_entity_by_id(chain->dev, entity->baSourceID[i]);
> > > -               if (remote == NULL)
> > > +               if (remote == NULL || remote->num_pads == 0)
> > >                         return -EINVAL;
> >
> > Yes.
> >
> > >
> > >                 source = (UVC_ENTITY_TYPE(remote) == UVC_TT_STREAMING)
> > > @@ -46,6 +46,9 @@ static int uvc_mc_create_links(struct uvc_video_chain *chain,
> > >                 if (source == NULL)
> > >                         continue;
> > >
> > > +               if (source->num_pads != remote->num_pads)
> > > +                       return -EINVAL;
> > > +
> >
> > But this I would have dropped, as the media_entity num_pads is
> > initialized from uvc_entity num_pads and neither are changed after.
> 
> Works for me. Shall I send a v2 or you can take it?

I'm handling it locally, will be in the next pull request.

> > >                 remote_pad = remote->num_pads - 1;
> > >                 ret = media_create_pad_link(source, remote_pad,
> > >                                                sink, i, flags);
> > >
> > > regarding making a new patch, whatever is easier for you ;)
> > >
> > >
> > > On Wed, 21 Sept 2022 at 02:53, Laurent Pinchart wrote:
> > > >
> > > > Hi Ricardo,
> > > >
> > > > Thank you for the patch.
> > > >
> > > > On Tue, Sep 20, 2022 at 04:04:55PM +0200, Ricardo Ribalda wrote:
> > > > > If the source entity does not contain any pads, do not create a link.
> > > > >
> > > > > Reported-by: syzbot <syzkaller@googlegroups.com>
> > > > > Signed-off-by: Ricardo Ribalda <ribalda@chromium.org>
> > > > >
> > > > > diff --git a/drivers/media/usb/uvc/uvc_entity.c b/drivers/media/usb/uvc/uvc_entity.c
> > > > > index 7c4d2f93d351..1f730cb72e58 100644
> > > > > --- a/drivers/media/usb/uvc/uvc_entity.c
> > > > > +++ b/drivers/media/usb/uvc/uvc_entity.c
> > > > > @@ -43,7 +43,7 @@ static int uvc_mc_create_links(struct uvc_video_chain *chain,
> > > > >               source = (UVC_ENTITY_TYPE(remote) == UVC_TT_STREAMING)
> > > > >                      ? (remote->vdev ? &remote->vdev->entity : NULL)
> > > > >                      : &remote->subdev.entity;
> > > > > -             if (source == NULL)
> > > > > +             if (source == NULL || source->num_pads == 0)
> > > >
> > > > source->num_pads and remote->num_pads should always be identical, but as
> > > > the next line uses remote->num_pads, wouldn't it be better to test that
> > > > variable ? If so, I'd move the test a file lines earlier, with the
> > > > remote == NULL test.
> > > >
> > > > What do you think ? If you agree I can make that change when applying,
> > > > there's no need for a new version. Otherwise I'll keep the patch as-is.
> > > >
> > > > >                       continue;
> > > > >
> > > > >               remote_pad = remote->num_pads - 1;

-- 
Regards,

Laurent Pinchart

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [PATCH v1 1/1] media: uvc: Handle cameras with invalid descriptors
  2022-10-24 18:18           ` Laurent Pinchart
@ 2023-01-03 14:55             ` Ricardo Ribalda
  2023-01-03 20:54               ` Laurent Pinchart
  0 siblings, 1 reply; 9+ messages in thread
From: Ricardo Ribalda @ 2023-01-03 14:55 UTC (permalink / raw)
  To: Laurent Pinchart; +Cc: Mauro Carvalho Chehab, linux-media, linux-kernel, syzbot

Hi Laurent

I think we have missed this patch.

Regards!

On Mon, 24 Oct 2022 at 20:19, Laurent Pinchart
<laurent.pinchart@ideasonboard.com> wrote:
>
> Hi Ricardo,
>
> On Wed, Sep 21, 2022 at 11:52:29PM +0200, Ricardo Ribalda wrote:
> > On Wed, 21 Sept 2022 at 23:16, Laurent Pinchart wrote:
> > > On Wed, Sep 21, 2022 at 09:51:44AM +0200, Ricardo Ribalda wrote:
> > > > Do you mean something like this?
> > > >
> > > > diff --git a/drivers/media/usb/uvc/uvc_entity.c
> > > > b/drivers/media/usb/uvc/uvc_entity.c
> > > > index 7c4d2f93d351..66d1f5da4ec7 100644
> > > > --- a/drivers/media/usb/uvc/uvc_entity.c
> > > > +++ b/drivers/media/usb/uvc/uvc_entity.c
> > > > @@ -37,7 +37,7 @@ static int uvc_mc_create_links(struct uvc_video_chain *chain,
> > > >                         continue;
> > > >
> > > >                 remote = uvc_entity_by_id(chain->dev, entity->baSourceID[i]);
> > > > -               if (remote == NULL)
> > > > +               if (remote == NULL || remote->num_pads == 0)
> > > >                         return -EINVAL;
> > >
> > > Yes.
> > >
> > > >
> > > >                 source = (UVC_ENTITY_TYPE(remote) == UVC_TT_STREAMING)
> > > > @@ -46,6 +46,9 @@ static int uvc_mc_create_links(struct uvc_video_chain *chain,
> > > >                 if (source == NULL)
> > > >                         continue;
> > > >
> > > > +               if (source->num_pads != remote->num_pads)
> > > > +                       return -EINVAL;
> > > > +
> > >
> > > But this I would have dropped, as the media_entity num_pads is
> > > initialized from uvc_entity num_pads and neither are changed after.
> >
> > Works for me. Shall I send a v2 or you can take it?
>
> I'm handling it locally, will be in the next pull request.
>
> > > >                 remote_pad = remote->num_pads - 1;
> > > >                 ret = media_create_pad_link(source, remote_pad,
> > > >                                                sink, i, flags);
> > > >
> > > > regarding making a new patch, whatever is easier for you ;)
> > > >
> > > >
> > > > On Wed, 21 Sept 2022 at 02:53, Laurent Pinchart wrote:
> > > > >
> > > > > Hi Ricardo,
> > > > >
> > > > > Thank you for the patch.
> > > > >
> > > > > On Tue, Sep 20, 2022 at 04:04:55PM +0200, Ricardo Ribalda wrote:
> > > > > > If the source entity does not contain any pads, do not create a link.
> > > > > >
> > > > > > Reported-by: syzbot <syzkaller@googlegroups.com>
> > > > > > Signed-off-by: Ricardo Ribalda <ribalda@chromium.org>
> > > > > >
> > > > > > diff --git a/drivers/media/usb/uvc/uvc_entity.c b/drivers/media/usb/uvc/uvc_entity.c
> > > > > > index 7c4d2f93d351..1f730cb72e58 100644
> > > > > > --- a/drivers/media/usb/uvc/uvc_entity.c
> > > > > > +++ b/drivers/media/usb/uvc/uvc_entity.c
> > > > > > @@ -43,7 +43,7 @@ static int uvc_mc_create_links(struct uvc_video_chain *chain,
> > > > > >               source = (UVC_ENTITY_TYPE(remote) == UVC_TT_STREAMING)
> > > > > >                      ? (remote->vdev ? &remote->vdev->entity : NULL)
> > > > > >                      : &remote->subdev.entity;
> > > > > > -             if (source == NULL)
> > > > > > +             if (source == NULL || source->num_pads == 0)
> > > > >
> > > > > source->num_pads and remote->num_pads should always be identical, but as
> > > > > the next line uses remote->num_pads, wouldn't it be better to test that
> > > > > variable ? If so, I'd move the test a file lines earlier, with the
> > > > > remote == NULL test.
> > > > >
> > > > > What do you think ? If you agree I can make that change when applying,
> > > > > there's no need for a new version. Otherwise I'll keep the patch as-is.
> > > > >
> > > > > >                       continue;
> > > > > >
> > > > > >               remote_pad = remote->num_pads - 1;
>
> --
> Regards,
>
> Laurent Pinchart



-- 
Ricardo Ribalda

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [PATCH v1 1/1] media: uvc: Handle cameras with invalid descriptors
  2023-01-03 14:55             ` Ricardo Ribalda
@ 2023-01-03 20:54               ` Laurent Pinchart
  0 siblings, 0 replies; 9+ messages in thread
From: Laurent Pinchart @ 2023-01-03 20:54 UTC (permalink / raw)
  To: Ricardo Ribalda; +Cc: Mauro Carvalho Chehab, linux-media, linux-kernel, syzbot

On Tue, Jan 03, 2023 at 03:55:54PM +0100, Ricardo Ribalda wrote:
> Hi Laurent
> 
> I think we have missed this patch.

Pushed to
https://git.kernel.org/pub/scm/linux/kernel/git/pinchartl/linux.git/log/?h=next/uvc,
I'll send a pull request next week when Mauro comes back from vacation.

> On Mon, 24 Oct 2022 at 20:19, Laurent Pinchart wrote:
> > On Wed, Sep 21, 2022 at 11:52:29PM +0200, Ricardo Ribalda wrote:
> > > On Wed, 21 Sept 2022 at 23:16, Laurent Pinchart wrote:
> > > > On Wed, Sep 21, 2022 at 09:51:44AM +0200, Ricardo Ribalda wrote:
> > > > > Do you mean something like this?
> > > > >
> > > > > diff --git a/drivers/media/usb/uvc/uvc_entity.c
> > > > > b/drivers/media/usb/uvc/uvc_entity.c
> > > > > index 7c4d2f93d351..66d1f5da4ec7 100644
> > > > > --- a/drivers/media/usb/uvc/uvc_entity.c
> > > > > +++ b/drivers/media/usb/uvc/uvc_entity.c
> > > > > @@ -37,7 +37,7 @@ static int uvc_mc_create_links(struct uvc_video_chain *chain,
> > > > >                         continue;
> > > > >
> > > > >                 remote = uvc_entity_by_id(chain->dev, entity->baSourceID[i]);
> > > > > -               if (remote == NULL)
> > > > > +               if (remote == NULL || remote->num_pads == 0)
> > > > >                         return -EINVAL;
> > > >
> > > > Yes.
> > > >
> > > > >
> > > > >                 source = (UVC_ENTITY_TYPE(remote) == UVC_TT_STREAMING)
> > > > > @@ -46,6 +46,9 @@ static int uvc_mc_create_links(struct uvc_video_chain *chain,
> > > > >                 if (source == NULL)
> > > > >                         continue;
> > > > >
> > > > > +               if (source->num_pads != remote->num_pads)
> > > > > +                       return -EINVAL;
> > > > > +
> > > >
> > > > But this I would have dropped, as the media_entity num_pads is
> > > > initialized from uvc_entity num_pads and neither are changed after.
> > >
> > > Works for me. Shall I send a v2 or you can take it?
> >
> > I'm handling it locally, will be in the next pull request.
> >
> > > > >                 remote_pad = remote->num_pads - 1;
> > > > >                 ret = media_create_pad_link(source, remote_pad,
> > > > >                                                sink, i, flags);
> > > > >
> > > > > regarding making a new patch, whatever is easier for you ;)
> > > > >
> > > > >
> > > > > On Wed, 21 Sept 2022 at 02:53, Laurent Pinchart wrote:
> > > > > >
> > > > > > Hi Ricardo,
> > > > > >
> > > > > > Thank you for the patch.
> > > > > >
> > > > > > On Tue, Sep 20, 2022 at 04:04:55PM +0200, Ricardo Ribalda wrote:
> > > > > > > If the source entity does not contain any pads, do not create a link.
> > > > > > >
> > > > > > > Reported-by: syzbot <syzkaller@googlegroups.com>
> > > > > > > Signed-off-by: Ricardo Ribalda <ribalda@chromium.org>
> > > > > > >
> > > > > > > diff --git a/drivers/media/usb/uvc/uvc_entity.c b/drivers/media/usb/uvc/uvc_entity.c
> > > > > > > index 7c4d2f93d351..1f730cb72e58 100644
> > > > > > > --- a/drivers/media/usb/uvc/uvc_entity.c
> > > > > > > +++ b/drivers/media/usb/uvc/uvc_entity.c
> > > > > > > @@ -43,7 +43,7 @@ static int uvc_mc_create_links(struct uvc_video_chain *chain,
> > > > > > >               source = (UVC_ENTITY_TYPE(remote) == UVC_TT_STREAMING)
> > > > > > >                      ? (remote->vdev ? &remote->vdev->entity : NULL)
> > > > > > >                      : &remote->subdev.entity;
> > > > > > > -             if (source == NULL)
> > > > > > > +             if (source == NULL || source->num_pads == 0)
> > > > > >
> > > > > > source->num_pads and remote->num_pads should always be identical, but as
> > > > > > the next line uses remote->num_pads, wouldn't it be better to test that
> > > > > > variable ? If so, I'd move the test a file lines earlier, with the
> > > > > > remote == NULL test.
> > > > > >
> > > > > > What do you think ? If you agree I can make that change when applying,
> > > > > > there's no need for a new version. Otherwise I'll keep the patch as-is.
> > > > > >
> > > > > > >                       continue;
> > > > > > >
> > > > > > >               remote_pad = remote->num_pads - 1;

-- 
Regards,

Laurent Pinchart

^ permalink raw reply	[flat|nested] 9+ messages in thread

end of thread, other threads:[~2023-01-03 20:54 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2022-09-20 14:04 [PATCH v1 0/1] [RESEND] uvc: Handle cames with invalid descriptors Ricardo Ribalda
2022-09-20 14:04 ` [PATCH v1 1/1] media: uvc: Handle cameras " Ricardo Ribalda
2022-09-21  0:53   ` Laurent Pinchart
2022-09-21  7:51     ` Ricardo Ribalda
2022-09-21 21:16       ` Laurent Pinchart
2022-09-21 21:52         ` Ricardo Ribalda
2022-10-24 18:18           ` Laurent Pinchart
2023-01-03 14:55             ` Ricardo Ribalda
2023-01-03 20:54               ` Laurent Pinchart

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox