Message ID | 20220602055027.849014-1-dzm91@hust.edu.cn (mailing list archive) |
---|---|
State | Accepted |
Headers |
Received: from vger.kernel.org ([23.128.96.18]) by www.linuxtv.org with esmtp (Exim 4.92) (envelope-from <linux-media-owner@vger.kernel.org>) id 1nwdjo-0035fb-EQ; Thu, 02 Jun 2022 05:51:17 +0000 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230183AbiFBFvN (ORCPT <rfc822;mkrufky@linuxtv.org> + 1 other); Thu, 2 Jun 2022 01:51:13 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37844 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230048AbiFBFvN (ORCPT <rfc822;linux-media@vger.kernel.org>); Thu, 2 Jun 2022 01:51:13 -0400 Received: from hust.edu.cn (mail.hust.edu.cn [202.114.0.240]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7E4FF2AA019; Wed, 1 Jun 2022 22:51:10 -0700 (PDT) Received: from localhost.localdomain ([172.16.0.254]) (user=dzm91@hust.edu.cn mech=LOGIN bits=0) by mx1.hust.edu.cn with ESMTP id 2525oSaA027428-2525oSaD027428 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128 verify=NO); Thu, 2 Jun 2022 13:50:32 +0800 From: Dongliang Mu <dzm91@hust.edu.cn> To: Mauro Carvalho Chehab <mchehab@kernel.org>, gushengxian <gushengxian@yulong.com>, Hans Verkuil <hverkuil-cisco@xs4all.nl>, Johan Hovold <johan@kernel.org>, Oliver Neukum <oneukum@suse.com>, Sean Young <sean@mess.org> Cc: Dongliang Mu <mudongliangabcd@gmail.com>, Mauro Carvalho Chehab <mchehab+huawei@kernel.org>, linux-media@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH] media: flexcop-usb: fix sanity check of bNumEndpoints Date: Thu, 2 Jun 2022 13:50:24 +0800 Message-Id: <20220602055027.849014-1-dzm91@hust.edu.cn> X-Mailer: git-send-email 2.25.1 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-FEAS-AUTH-USER: dzm91@hust.edu.cn X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,SPF_HELO_PASS, SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: <linux-media.vger.kernel.org> X-Mailing-List: linux-media@vger.kernel.org X-LSpam-Score: -2.4 (--) X-LSpam-Report: No, score=-2.4 required=5.0 tests=BAYES_00=-1.9,HEADER_FROM_DIFFERENT_DOMAINS=0.5,MAILING_LIST_MULTI=-1 autolearn=ham autolearn_force=no |
Series |
media: flexcop-usb: fix sanity check of bNumEndpoints
|
|
Commit Message
Dongliang Mu
June 2, 2022, 5:50 a.m. UTC
From: Dongliang Mu <mudongliangabcd@gmail.com> Commit d725d20e81c2 ("media: flexcop-usb: sanity checking of endpoint type ") adds a sanity check for endpoint[1], but fails to modify the sanity check of bNumEndpoints. Fix this by modifying the sanity check of bNumEndpoints to 2. Fixes: d725d20e81c2 ("media: flexcop-usb: sanity checking of endpoint type") Signed-off-by: Dongliang Mu <mudongliangabcd@gmail.com> --- drivers/media/usb/b2c2/flexcop-usb.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
Comments
On Thu, Jun 02, 2022 at 01:50:24PM +0800, Dongliang Mu wrote: > From: Dongliang Mu <mudongliangabcd@gmail.com> > > Commit d725d20e81c2 ("media: flexcop-usb: sanity checking of endpoint type > ") adds a sanity check for endpoint[1], but fails to modify the sanity > check of bNumEndpoints. > > Fix this by modifying the sanity check of bNumEndpoints to 2. Are you sure that d725d20e81c2 ("media: flexcop-usb: sanity checking of endpoint type) was correct? > Fixes: d725d20e81c2 ("media: flexcop-usb: sanity checking of endpoint type") > Signed-off-by: Dongliang Mu <mudongliangabcd@gmail.com> > --- > drivers/media/usb/b2c2/flexcop-usb.c | 2 +- > 1 file changed, 1 insertion(+), 1 deletion(-) > > diff --git a/drivers/media/usb/b2c2/flexcop-usb.c b/drivers/media/usb/b2c2/flexcop-usb.c > index 7835bb0f32fc..eb54bfdda01f 100644 > --- a/drivers/media/usb/b2c2/flexcop-usb.c > +++ b/drivers/media/usb/b2c2/flexcop-usb.c > @@ -509,7 +509,7 @@ static int flexcop_usb_init(struct flexcop_usb *fc_usb) > return ret; > } > > - if (fc_usb->uintf->cur_altsetting->desc.bNumEndpoints < 1) > + if (fc_usb->uintf->cur_altsetting->desc.bNumEndpoints < 2) > return -ENODEV; > if (!usb_endpoint_is_isoc_in(&fc_usb->uintf->cur_altsetting->endpoint[1].desc)) > return -ENODEV; It looks like it should have verified the type of endpoint[0] here instead. Oliver? Johan
On Thu, Jun 2, 2022 at 2:45 PM Johan Hovold <johan@kernel.org> wrote: > > On Thu, Jun 02, 2022 at 01:50:24PM +0800, Dongliang Mu wrote: > > From: Dongliang Mu <mudongliangabcd@gmail.com> > > > > Commit d725d20e81c2 ("media: flexcop-usb: sanity checking of endpoint type > > ") adds a sanity check for endpoint[1], but fails to modify the sanity > > check of bNumEndpoints. > > > > Fix this by modifying the sanity check of bNumEndpoints to 2. > > Are you sure that d725d20e81c2 ("media: flexcop-usb: sanity checking of > endpoint type) was correct? I am not sure if fc_usb->uintf->cur_altsetting->endpoint[1] is right or not. But the sanity check of bNumEndpoints does not match the following dereference. > > > Fixes: d725d20e81c2 ("media: flexcop-usb: sanity checking of endpoint type") > > Signed-off-by: Dongliang Mu <mudongliangabcd@gmail.com> > > --- > > drivers/media/usb/b2c2/flexcop-usb.c | 2 +- > > 1 file changed, 1 insertion(+), 1 deletion(-) > > > > diff --git a/drivers/media/usb/b2c2/flexcop-usb.c b/drivers/media/usb/b2c2/flexcop-usb.c > > index 7835bb0f32fc..eb54bfdda01f 100644 > > --- a/drivers/media/usb/b2c2/flexcop-usb.c > > +++ b/drivers/media/usb/b2c2/flexcop-usb.c > > @@ -509,7 +509,7 @@ static int flexcop_usb_init(struct flexcop_usb *fc_usb) > > return ret; > > } > > > > - if (fc_usb->uintf->cur_altsetting->desc.bNumEndpoints < 1) > > + if (fc_usb->uintf->cur_altsetting->desc.bNumEndpoints < 2) > > return -ENODEV; > > if (!usb_endpoint_is_isoc_in(&fc_usb->uintf->cur_altsetting->endpoint[1].desc)) > > return -ENODEV; > > It looks like it should have verified the type of endpoint[0] here > instead. This sanity check originally makes sure the fc_usb->uintf->cur_altsetting->endpoint[0] in flexcop_usb_transfer_init. > > Oliver? > > Johan
On Thu, Jun 09, 2022 at 09:42:15AM +0800, Dongliang Mu wrote: > On Thu, Jun 2, 2022 at 2:45 PM Johan Hovold <johan@kernel.org> wrote: > > > > On Thu, Jun 02, 2022 at 01:50:24PM +0800, Dongliang Mu wrote: > > > From: Dongliang Mu <mudongliangabcd@gmail.com> > > > > > > Commit d725d20e81c2 ("media: flexcop-usb: sanity checking of endpoint type > > > ") adds a sanity check for endpoint[1], but fails to modify the sanity > > > check of bNumEndpoints. > > > > > > Fix this by modifying the sanity check of bNumEndpoints to 2. > > > > Are you sure that d725d20e81c2 ("media: flexcop-usb: sanity checking of > > endpoint type) was correct? > > I am not sure if fc_usb->uintf->cur_altsetting->endpoint[1] is right or not. > > But the sanity check of bNumEndpoints does not match the following dereference. I should know better than try to be subtle on the internet: Your fix is wrong. You need to try to understand the code you're changing. Not just do pattern matching. > > > Fixes: d725d20e81c2 ("media: flexcop-usb: sanity checking of endpoint type") > > > Signed-off-by: Dongliang Mu <mudongliangabcd@gmail.com> > > > --- > > > drivers/media/usb/b2c2/flexcop-usb.c | 2 +- > > > 1 file changed, 1 insertion(+), 1 deletion(-) > > > > > > diff --git a/drivers/media/usb/b2c2/flexcop-usb.c b/drivers/media/usb/b2c2/flexcop-usb.c > > > index 7835bb0f32fc..eb54bfdda01f 100644 > > > --- a/drivers/media/usb/b2c2/flexcop-usb.c > > > +++ b/drivers/media/usb/b2c2/flexcop-usb.c > > > @@ -509,7 +509,7 @@ static int flexcop_usb_init(struct flexcop_usb *fc_usb) > > > return ret; > > > } > > > > > > - if (fc_usb->uintf->cur_altsetting->desc.bNumEndpoints < 1) > > > + if (fc_usb->uintf->cur_altsetting->desc.bNumEndpoints < 2) > > > return -ENODEV; > > > if (!usb_endpoint_is_isoc_in(&fc_usb->uintf->cur_altsetting->endpoint[1].desc)) > > > return -ENODEV; > > > > It looks like it should have verified the type of endpoint[0] here > > instead. > > This sanity check originally makes sure the > fc_usb->uintf->cur_altsetting->endpoint[0] in > flexcop_usb_transfer_init. Yes, and that is the only endpoint that this driver uses. I've posted a fix here: https://lore.kernel.org/r/20220609135341.19941-1-johan@kernel.org Johan
On Thu, Jun 9, 2022 at 10:00 PM Johan Hovold <johan@kernel.org> wrote: > > On Thu, Jun 09, 2022 at 09:42:15AM +0800, Dongliang Mu wrote: > > On Thu, Jun 2, 2022 at 2:45 PM Johan Hovold <johan@kernel.org> wrote: > > > > > > On Thu, Jun 02, 2022 at 01:50:24PM +0800, Dongliang Mu wrote: > > > > From: Dongliang Mu <mudongliangabcd@gmail.com> > > > > > > > > Commit d725d20e81c2 ("media: flexcop-usb: sanity checking of endpoint type > > > > ") adds a sanity check for endpoint[1], but fails to modify the sanity > > > > check of bNumEndpoints. > > > > > > > > Fix this by modifying the sanity check of bNumEndpoints to 2. > > > > > > Are you sure that d725d20e81c2 ("media: flexcop-usb: sanity checking of > > > endpoint type) was correct? > > > > I am not sure if fc_usb->uintf->cur_altsetting->endpoint[1] is right or not. > > > > But the sanity check of bNumEndpoints does not match the following dereference. > > I should know better than try to be subtle on the internet: Your fix is > wrong. > > You need to try to understand the code you're changing. Not just do > pattern matching. I see. Yeah, I have such an incorrect assumption - previous commits should be somehow correct since maintainers already review them. Next time, I will dig more about the code logic and try to post a more comprehensive patch. > > > > > Fixes: d725d20e81c2 ("media: flexcop-usb: sanity checking of endpoint type") > > > > Signed-off-by: Dongliang Mu <mudongliangabcd@gmail.com> > > > > --- > > > > drivers/media/usb/b2c2/flexcop-usb.c | 2 +- > > > > 1 file changed, 1 insertion(+), 1 deletion(-) > > > > > > > > diff --git a/drivers/media/usb/b2c2/flexcop-usb.c b/drivers/media/usb/b2c2/flexcop-usb.c > > > > index 7835bb0f32fc..eb54bfdda01f 100644 > > > > --- a/drivers/media/usb/b2c2/flexcop-usb.c > > > > +++ b/drivers/media/usb/b2c2/flexcop-usb.c > > > > @@ -509,7 +509,7 @@ static int flexcop_usb_init(struct flexcop_usb *fc_usb) > > > > return ret; > > > > } > > > > > > > > - if (fc_usb->uintf->cur_altsetting->desc.bNumEndpoints < 1) > > > > + if (fc_usb->uintf->cur_altsetting->desc.bNumEndpoints < 2) > > > > return -ENODEV; > > > > if (!usb_endpoint_is_isoc_in(&fc_usb->uintf->cur_altsetting->endpoint[1].desc)) > > > > return -ENODEV; > > > > > > It looks like it should have verified the type of endpoint[0] here > > > instead. > > > > This sanity check originally makes sure the > > fc_usb->uintf->cur_altsetting->endpoint[0] in > > flexcop_usb_transfer_init. > > Yes, and that is the only endpoint that this driver uses. This needs an understanding of the working mechanism of this hardware. > > I've posted a fix here: > > https://lore.kernel.org/r/20220609135341.19941-1-johan@kernel.org > > Johan
On Fri, Jun 10, 2022 at 09:27:27AM +0800, Dongliang Mu wrote: > On Thu, Jun 9, 2022 at 10:00 PM Johan Hovold <johan@kernel.org> wrote: > > > > On Thu, Jun 09, 2022 at 09:42:15AM +0800, Dongliang Mu wrote: > > > On Thu, Jun 2, 2022 at 2:45 PM Johan Hovold <johan@kernel.org> wrote: > > > > Are you sure that d725d20e81c2 ("media: flexcop-usb: sanity checking of > > > > endpoint type) was correct? > > > > > > I am not sure if fc_usb->uintf->cur_altsetting->endpoint[1] is right or not. > > > > > > But the sanity check of bNumEndpoints does not match the following dereference. > > > > I should know better than try to be subtle on the internet: Your fix is > > wrong. > > > > You need to try to understand the code you're changing. Not just do > > pattern matching. > > I see. Yeah, I have such an incorrect assumption - previous commits > should be somehow correct since maintainers already review them. Everyone makes mistakes and our review process isn't perfect. And if your assumption was correct we wouldn't have any bugs at all. > Next time, I will dig more about the code logic and try to post a more > comprehensive patch. Sounds good. > > > > > Fixes: d725d20e81c2 ("media: flexcop-usb: sanity checking of endpoint type") > > > > > Signed-off-by: Dongliang Mu <mudongliangabcd@gmail.com> > > > > > --- > > > > > drivers/media/usb/b2c2/flexcop-usb.c | 2 +- > > > > > 1 file changed, 1 insertion(+), 1 deletion(-) > > > > > > > > > > diff --git a/drivers/media/usb/b2c2/flexcop-usb.c b/drivers/media/usb/b2c2/flexcop-usb.c > > > > > index 7835bb0f32fc..eb54bfdda01f 100644 > > > > > --- a/drivers/media/usb/b2c2/flexcop-usb.c > > > > > +++ b/drivers/media/usb/b2c2/flexcop-usb.c > > > > > @@ -509,7 +509,7 @@ static int flexcop_usb_init(struct flexcop_usb *fc_usb) > > > > > return ret; > > > > > } > > > > > > > > > > - if (fc_usb->uintf->cur_altsetting->desc.bNumEndpoints < 1) > > > > > + if (fc_usb->uintf->cur_altsetting->desc.bNumEndpoints < 2) > > > > > return -ENODEV; > > > > > if (!usb_endpoint_is_isoc_in(&fc_usb->uintf->cur_altsetting->endpoint[1].desc)) > > > > > return -ENODEV; > > > > > > > > It looks like it should have verified the type of endpoint[0] here > > > > instead. > > > > > > This sanity check originally makes sure the > > > fc_usb->uintf->cur_altsetting->endpoint[0] in > > > flexcop_usb_transfer_init. > > > > Yes, and that is the only endpoint that this driver uses. > > This needs an understanding of the working mechanism of this hardware. Not really, you only need to look at the driver in this case. But sure, you need some familiarity with USB to understand what is going on. Johan
diff --git a/drivers/media/usb/b2c2/flexcop-usb.c b/drivers/media/usb/b2c2/flexcop-usb.c index 7835bb0f32fc..eb54bfdda01f 100644 --- a/drivers/media/usb/b2c2/flexcop-usb.c +++ b/drivers/media/usb/b2c2/flexcop-usb.c @@ -509,7 +509,7 @@ static int flexcop_usb_init(struct flexcop_usb *fc_usb) return ret; } - if (fc_usb->uintf->cur_altsetting->desc.bNumEndpoints < 1) + if (fc_usb->uintf->cur_altsetting->desc.bNumEndpoints < 2) return -ENODEV; if (!usb_endpoint_is_isoc_in(&fc_usb->uintf->cur_altsetting->endpoint[1].desc)) return -ENODEV;