Message ID | 20180208083655.32248-12-hverkuil@xs4all.nl (mailing list archive) |
---|---|
State | Superseded, archived |
Delegated to: | Hans Verkuil |
Headers |
Received: from vger.kernel.org ([209.132.180.67]) by www.linuxtv.org with esmtp (Exim 4.84_2) (envelope-from <linux-media-owner@vger.kernel.org>) id 1ejhhh-0002tI-Bl; Thu, 08 Feb 2018 08:37:13 +0000 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752100AbeBHIhF (ORCPT <rfc822;mkrufky@linuxtv.org> + 1 other); Thu, 8 Feb 2018 03:37:05 -0500 Received: from lb1-smtp-cloud9.xs4all.net ([194.109.24.22]:50078 "EHLO lb1-smtp-cloud9.xs4all.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750954AbeBHIhC (ORCPT <rfc822;linux-media@vger.kernel.org>); Thu, 8 Feb 2018 03:37:02 -0500 Received: from tschai.fritz.box ([212.251.195.8]) by smtp-cloud9.xs4all.net with ESMTPA id jhhQefdbboWCOjhhVe2xeL; Thu, 08 Feb 2018 09:37:01 +0100 From: Hans Verkuil <hverkuil@xs4all.nl> To: linux-media@vger.kernel.org Cc: Hans Verkuil <hans.verkuil@cisco.com> Subject: [PATCHv2 11/15] media-device.c: zero reserved field Date: Thu, 8 Feb 2018 09:36:51 +0100 Message-Id: <20180208083655.32248-12-hverkuil@xs4all.nl> X-Mailer: git-send-email 2.15.1 In-Reply-To: <20180208083655.32248-1-hverkuil@xs4all.nl> References: <20180208083655.32248-1-hverkuil@xs4all.nl> X-CMAE-Envelope: MS4wfC5J03/GRVuqLwm7me//PbbW2XvvME+yWo/OZ1V9kdbmFNYpq3DX+GMf8dESvbvzJY4f2N/n9JNd1LA17LtWwkxYvpr47BZwSzt0LUdukef3IgKtFB8W s+wbiElz0YBwWktfh2pwm/6P/VEYDhaaetXP172sR4NDocFweSLiFx7O7tSCSt+T/ia2qx8GFYfjSzj6p2K8J+ApUv56Vd1Kzu8= Sender: linux-media-owner@vger.kernel.org Precedence: bulk List-ID: <linux-media.vger.kernel.org> X-Mailing-List: linux-media@vger.kernel.org |
Commit Message
Hans Verkuil
Feb. 8, 2018, 8:36 a.m. UTC
MEDIA_IOC_SETUP_LINK didn't zero the reserved field of the media_link_desc
struct. Do so in media_device_setup_link().
Signed-off-by: Hans Verkuil <hans.verkuil@cisco.com>
---
drivers/media/media-device.c | 2 ++
1 file changed, 2 insertions(+)
Comments
On Thu, Feb 08, 2018 at 09:36:51AM +0100, Hans Verkuil wrote: > MEDIA_IOC_SETUP_LINK didn't zero the reserved field of the media_link_desc > struct. Do so in media_device_setup_link(). > > Signed-off-by: Hans Verkuil <hans.verkuil@cisco.com> > --- > drivers/media/media-device.c | 2 ++ > 1 file changed, 2 insertions(+) > > diff --git a/drivers/media/media-device.c b/drivers/media/media-device.c > index e79f72b8b858..afbf23a19e16 100644 > --- a/drivers/media/media-device.c > +++ b/drivers/media/media-device.c > @@ -218,6 +218,8 @@ static long media_device_setup_link(struct media_device *mdev, > if (link == NULL) > return -EINVAL; > > + memset(linkd->reserved, 0, sizeof(linkd->reserved)); > + Doesn't media_device_enum_links() need the same for its reserved field? > /* Setup the link on both entities. */ > return __media_entity_setup_link(link, linkd->flags); > } > -- > 2.15.1 >
On 02/09/18 13:17, Sakari Ailus wrote: > On Thu, Feb 08, 2018 at 09:36:51AM +0100, Hans Verkuil wrote: >> MEDIA_IOC_SETUP_LINK didn't zero the reserved field of the media_link_desc >> struct. Do so in media_device_setup_link(). >> >> Signed-off-by: Hans Verkuil <hans.verkuil@cisco.com> >> --- >> drivers/media/media-device.c | 2 ++ >> 1 file changed, 2 insertions(+) >> >> diff --git a/drivers/media/media-device.c b/drivers/media/media-device.c >> index e79f72b8b858..afbf23a19e16 100644 >> --- a/drivers/media/media-device.c >> +++ b/drivers/media/media-device.c >> @@ -218,6 +218,8 @@ static long media_device_setup_link(struct media_device *mdev, >> if (link == NULL) >> return -EINVAL; >> >> + memset(linkd->reserved, 0, sizeof(linkd->reserved)); >> + > > Doesn't media_device_enum_links() need the same for its reserved field? enum_links() already zeroes this (actually the whole media_link_desc struct is zeroed). Regards, Hans > >> /* Setup the link on both entities. */ >> return __media_entity_setup_link(link, linkd->flags); >> } >> -- >> 2.15.1 >> >
On Fri, Feb 09, 2018 at 01:20:41PM +0100, Hans Verkuil wrote: > On 02/09/18 13:17, Sakari Ailus wrote: > > On Thu, Feb 08, 2018 at 09:36:51AM +0100, Hans Verkuil wrote: > >> MEDIA_IOC_SETUP_LINK didn't zero the reserved field of the media_link_desc > >> struct. Do so in media_device_setup_link(). > >> > >> Signed-off-by: Hans Verkuil <hans.verkuil@cisco.com> > >> --- > >> drivers/media/media-device.c | 2 ++ > >> 1 file changed, 2 insertions(+) > >> > >> diff --git a/drivers/media/media-device.c b/drivers/media/media-device.c > >> index e79f72b8b858..afbf23a19e16 100644 > >> --- a/drivers/media/media-device.c > >> +++ b/drivers/media/media-device.c > >> @@ -218,6 +218,8 @@ static long media_device_setup_link(struct media_device *mdev, > >> if (link == NULL) > >> return -EINVAL; > >> > >> + memset(linkd->reserved, 0, sizeof(linkd->reserved)); > >> + > > > > Doesn't media_device_enum_links() need the same for its reserved field? > > enum_links() already zeroes this (actually the whole media_link_desc struct is zeroed). I can't see that being done in here and I also don't mean the compat variant. Can you point me to it?
On 02/09/18 13:46, Sakari Ailus wrote: > On Fri, Feb 09, 2018 at 01:20:41PM +0100, Hans Verkuil wrote: >> On 02/09/18 13:17, Sakari Ailus wrote: >>> On Thu, Feb 08, 2018 at 09:36:51AM +0100, Hans Verkuil wrote: >>>> MEDIA_IOC_SETUP_LINK didn't zero the reserved field of the media_link_desc >>>> struct. Do so in media_device_setup_link(). >>>> >>>> Signed-off-by: Hans Verkuil <hans.verkuil@cisco.com> >>>> --- >>>> drivers/media/media-device.c | 2 ++ >>>> 1 file changed, 2 insertions(+) >>>> >>>> diff --git a/drivers/media/media-device.c b/drivers/media/media-device.c >>>> index e79f72b8b858..afbf23a19e16 100644 >>>> --- a/drivers/media/media-device.c >>>> +++ b/drivers/media/media-device.c >>>> @@ -218,6 +218,8 @@ static long media_device_setup_link(struct media_device *mdev, >>>> if (link == NULL) >>>> return -EINVAL; >>>> >>>> + memset(linkd->reserved, 0, sizeof(linkd->reserved)); >>>> + >>> >>> Doesn't media_device_enum_links() need the same for its reserved field? >> >> enum_links() already zeroes this (actually the whole media_link_desc struct is zeroed). > > I can't see that being done in here and I also don't mean the compat > variant. Can you point me to it? > static long media_device_enum_links(struct media_device *mdev, struct media_links_enum *links) { struct media_entity *entity; entity = find_entity(mdev, links->entity); if (entity == NULL) return -EINVAL; if (links->pads) { ... } if (links->links) { struct media_link *link; struct media_link_desc __user *ulink_desc = links->links; list_for_each_entry(link, &entity->links, list) { struct media_link_desc klink_desc; /* Ignore backlinks. */ if (link->source->entity != entity) continue; memset(&klink_desc, 0, sizeof(klink_desc)); // ^^^^^^^^^^^ zeroed here media_device_kpad_to_upad(link->source, &klink_desc.source); media_device_kpad_to_upad(link->sink, &klink_desc.sink); klink_desc.flags = link->flags; if (copy_to_user(ulink_desc, &klink_desc, sizeof(*ulink_desc))) // ^^^^^^^ copied back to userspace (including zeroed reserved array) here return -EFAULT; ulink_desc++; } } return 0; } Regards, Hans
Hi Hans, On Fri, Feb 09, 2018 at 01:52:50PM +0100, Hans Verkuil wrote: > On 02/09/18 13:46, Sakari Ailus wrote: > > On Fri, Feb 09, 2018 at 01:20:41PM +0100, Hans Verkuil wrote: > >> On 02/09/18 13:17, Sakari Ailus wrote: > >>> On Thu, Feb 08, 2018 at 09:36:51AM +0100, Hans Verkuil wrote: > >>>> MEDIA_IOC_SETUP_LINK didn't zero the reserved field of the media_link_desc > >>>> struct. Do so in media_device_setup_link(). > >>>> > >>>> Signed-off-by: Hans Verkuil <hans.verkuil@cisco.com> > >>>> --- > >>>> drivers/media/media-device.c | 2 ++ > >>>> 1 file changed, 2 insertions(+) > >>>> > >>>> diff --git a/drivers/media/media-device.c b/drivers/media/media-device.c > >>>> index e79f72b8b858..afbf23a19e16 100644 > >>>> --- a/drivers/media/media-device.c > >>>> +++ b/drivers/media/media-device.c > >>>> @@ -218,6 +218,8 @@ static long media_device_setup_link(struct media_device *mdev, > >>>> if (link == NULL) > >>>> return -EINVAL; > >>>> > >>>> + memset(linkd->reserved, 0, sizeof(linkd->reserved)); > >>>> + > >>> > >>> Doesn't media_device_enum_links() need the same for its reserved field? > >> > >> enum_links() already zeroes this (actually the whole media_link_desc struct is zeroed). > > > > I can't see that being done in here and I also don't mean the compat > > variant. Can you point me to it? > > > > static long media_device_enum_links(struct media_device *mdev, > struct media_links_enum *links) > { > struct media_entity *entity; > > entity = find_entity(mdev, links->entity); > if (entity == NULL) > return -EINVAL; > > if (links->pads) { > ... > } > > if (links->links) { > struct media_link *link; > struct media_link_desc __user *ulink_desc = links->links; > > list_for_each_entry(link, &entity->links, list) { > struct media_link_desc klink_desc; > > /* Ignore backlinks. */ > if (link->source->entity != entity) > continue; > memset(&klink_desc, 0, sizeof(klink_desc)); > // ^^^^^^^^^^^ zeroed here > > media_device_kpad_to_upad(link->source, > &klink_desc.source); > media_device_kpad_to_upad(link->sink, > &klink_desc.sink); > klink_desc.flags = link->flags; > if (copy_to_user(ulink_desc, &klink_desc, > sizeof(*ulink_desc))) > // ^^^^^^^ copied back to userspace (including zeroed reserved array) here We are indeed talking about a different reserved field. I mean the one in struct media_links_enum . > return -EFAULT; > ulink_desc++; > } > } > > return 0; > } > > Regards, > > Hans
On 02/09/18 14:04, Sakari Ailus wrote: > Hi Hans, > > On Fri, Feb 09, 2018 at 01:52:50PM +0100, Hans Verkuil wrote: >> On 02/09/18 13:46, Sakari Ailus wrote: >>> On Fri, Feb 09, 2018 at 01:20:41PM +0100, Hans Verkuil wrote: >>>> On 02/09/18 13:17, Sakari Ailus wrote: >>>>> On Thu, Feb 08, 2018 at 09:36:51AM +0100, Hans Verkuil wrote: >>>>>> MEDIA_IOC_SETUP_LINK didn't zero the reserved field of the media_link_desc >>>>>> struct. Do so in media_device_setup_link(). >>>>>> >>>>>> Signed-off-by: Hans Verkuil <hans.verkuil@cisco.com> >>>>>> --- >>>>>> drivers/media/media-device.c | 2 ++ >>>>>> 1 file changed, 2 insertions(+) >>>>>> >>>>>> diff --git a/drivers/media/media-device.c b/drivers/media/media-device.c >>>>>> index e79f72b8b858..afbf23a19e16 100644 >>>>>> --- a/drivers/media/media-device.c >>>>>> +++ b/drivers/media/media-device.c >>>>>> @@ -218,6 +218,8 @@ static long media_device_setup_link(struct media_device *mdev, >>>>>> if (link == NULL) >>>>>> return -EINVAL; >>>>>> >>>>>> + memset(linkd->reserved, 0, sizeof(linkd->reserved)); >>>>>> + >>>>> >>>>> Doesn't media_device_enum_links() need the same for its reserved field? >>>> >>>> enum_links() already zeroes this (actually the whole media_link_desc struct is zeroed). >>> >>> I can't see that being done in here and I also don't mean the compat >>> variant. Can you point me to it? >>> >> >> static long media_device_enum_links(struct media_device *mdev, >> struct media_links_enum *links) >> { >> struct media_entity *entity; >> >> entity = find_entity(mdev, links->entity); >> if (entity == NULL) >> return -EINVAL; >> >> if (links->pads) { >> ... >> } >> >> if (links->links) { >> struct media_link *link; >> struct media_link_desc __user *ulink_desc = links->links; >> >> list_for_each_entry(link, &entity->links, list) { >> struct media_link_desc klink_desc; >> >> /* Ignore backlinks. */ >> if (link->source->entity != entity) >> continue; >> memset(&klink_desc, 0, sizeof(klink_desc)); >> // ^^^^^^^^^^^ zeroed here >> >> media_device_kpad_to_upad(link->source, >> &klink_desc.source); >> media_device_kpad_to_upad(link->sink, >> &klink_desc.sink); >> klink_desc.flags = link->flags; >> if (copy_to_user(ulink_desc, &klink_desc, >> sizeof(*ulink_desc))) >> // ^^^^^^^ copied back to userspace (including zeroed reserved array) here > > We are indeed talking about a different reserved field. I mean the one in > struct media_links_enum . Ah! I missed that one. I added a check to v4l2-compliance and posted a patch fixing this. I thought you meant the reserved field in the media_link_desc structs. That was very confusing :-) Regards, Hans
diff --git a/drivers/media/media-device.c b/drivers/media/media-device.c index e79f72b8b858..afbf23a19e16 100644 --- a/drivers/media/media-device.c +++ b/drivers/media/media-device.c @@ -218,6 +218,8 @@ static long media_device_setup_link(struct media_device *mdev, if (link == NULL) return -EINVAL; + memset(linkd->reserved, 0, sizeof(linkd->reserved)); + /* Setup the link on both entities. */ return __media_entity_setup_link(link, linkd->flags); }