Message ID | 20211026095511.26673-1-johan@kernel.org (mailing list archive) |
---|---|
State | New |
Delegated to: | Laurent Pinchart |
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 1mfJBh-000jSF-Um; Tue, 26 Oct 2021 09:56:10 +0000 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233663AbhJZJ6a (ORCPT <rfc822;mkrufky@linuxtv.org> + 1 other); Tue, 26 Oct 2021 05:58:30 -0400 Received: from mail.kernel.org ([198.145.29.99]:59768 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233386AbhJZJ63 (ORCPT <rfc822;linux-media@vger.kernel.org>); Tue, 26 Oct 2021 05:58:29 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 49B976108D; Tue, 26 Oct 2021 09:56:06 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1635242166; bh=/ilLyt2le3FT2bWtymL6pE9ixHdnwtGauLPFZAdNzf4=; h=From:To:Cc:Subject:Date:From; b=fBk/gxjYOid3GvSxoecTMfLLCt1WQli0HRS1Fac9hQeLiLZWqQKykXPfUwz30bjdY 59WnlWjjGj9a5W0GAV0J7D3ZloCxAdToqvmgD2WDSMWl/n4xUbuPmxXa+LjuUYBVuN 315yyA69g8ZQGrgd0naEksXw9x4EIxmVgg2/Cugmz7Tu2k8zvGQ7hD3CRQbrVkoO1n gFzQhC7XpGGJQtZW3jEr4Jz+Uk8jK53gxO1N/rdTi7w4un1YcG/Pk23NDUIEqKJfLL U6Fz3fYubJvieAhvW32rbMdqCEZni73LdKoB8ZzDDMWzeJmRSB41721c0OkONH1TwZ yLUfexoktL8yg== Received: from johan by xi.lan with local (Exim 4.94.2) (envelope-from <johan@kernel.org>) id 1mfJBN-0006x9-Vy; Tue, 26 Oct 2021 11:55:50 +0200 From: Johan Hovold <johan@kernel.org> To: Laurent Pinchart <laurent.pinchart@ideasonboard.com> Cc: Mauro Carvalho Chehab <mchehab@kernel.org>, linux-media@vger.kernel.org, linux-usb@vger.kernel.org, linux-kernel@vger.kernel.org, Johan Hovold <johan@kernel.org>, stable@vger.kernel.org Subject: [PATCH] media: uvcvideo: fix division by zero at stream start Date: Tue, 26 Oct 2021 11:55:11 +0200 Message-Id: <20211026095511.26673-1-johan@kernel.org> X-Mailer: git-send-email 2.32.0 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: <linux-media.vger.kernel.org> X-Mailing-List: linux-media@vger.kernel.org X-LSpam-Score: -3.1 (---) X-LSpam-Report: No, score=-3.1 required=5.0 tests=BAYES_00=-1.9,DKIMWL_WL_HIGH=0.001,DKIM_SIGNED=0.1,DKIM_VALID=-0.1,DKIM_VALID_AU=-0.1,DKIM_VALID_EF=-0.1,MAILING_LIST_MULTI=-1,RCVD_IN_DNSWL_NONE=-0.0001 autolearn=ham autolearn_force=no |
Series |
media: uvcvideo: fix division by zero at stream start
|
|
Commit Message
Johan Hovold
Oct. 26, 2021, 9:55 a.m. UTC
Add the missing bulk-endpoint max-packet sanity check to probe() to
avoid division by zero in uvc_alloc_urb_buffers() in case a malicious
device has broken descriptors (or when doing descriptor fuzz testing).
Note that USB core will reject URBs submitted for endpoints with zero
wMaxPacketSize but that drivers doing packet-size calculations still
need to handle this (cf. commit 2548288b4fb0 ("USB: Fix: Don't skip
endpoint descriptors with maxpacket=0")).
Fixes: c0efd232929c ("V4L/DVB (8145a): USB Video Class driver")
Cc: stable@vger.kernel.org # 2.6.26
Signed-off-by: Johan Hovold <johan@kernel.org>
---
drivers/media/usb/uvc/uvc_video.c | 4 ++++
1 file changed, 4 insertions(+)
Comments
Quoting Johan Hovold (2021-10-26 10:55:11) > Add the missing bulk-endpoint max-packet sanity check to probe() to > avoid division by zero in uvc_alloc_urb_buffers() in case a malicious > device has broken descriptors (or when doing descriptor fuzz testing). > > Note that USB core will reject URBs submitted for endpoints with zero > wMaxPacketSize but that drivers doing packet-size calculations still > need to handle this (cf. commit 2548288b4fb0 ("USB: Fix: Don't skip > endpoint descriptors with maxpacket=0")). > > Fixes: c0efd232929c ("V4L/DVB (8145a): USB Video Class driver") > Cc: stable@vger.kernel.org # 2.6.26 > Signed-off-by: Johan Hovold <johan@kernel.org> > --- > drivers/media/usb/uvc/uvc_video.c | 4 ++++ > 1 file changed, 4 insertions(+) > > diff --git a/drivers/media/usb/uvc/uvc_video.c b/drivers/media/usb/uvc/uvc_video.c > index e16464606b14..85ac5c1081b6 100644 > --- a/drivers/media/usb/uvc/uvc_video.c > +++ b/drivers/media/usb/uvc/uvc_video.c > @@ -1958,6 +1958,10 @@ static int uvc_video_start_transfer(struct uvc_streaming *stream, > if (ep == NULL) > return -EIO; > > + /* Reject broken descriptors. */ > + if (usb_endpoint_maxp(&ep->desc) == 0) > + return -EIO; Is there any value in identifying this with a specific return code like -ENODATA? But either way, this seems sane. Reviewed-by: Kieran Bingham <kieran.bingham+renesas@ideasonboard.com> > + > ret = uvc_init_video_bulk(stream, ep, gfp_flags); > } > > -- > 2.32.0 >
On Tue, Oct 26, 2021 at 11:55:05AM +0100, Kieran Bingham wrote: > Quoting Johan Hovold (2021-10-26 10:55:11) > > Add the missing bulk-endpoint max-packet sanity check to probe() to > > avoid division by zero in uvc_alloc_urb_buffers() in case a malicious > > device has broken descriptors (or when doing descriptor fuzz testing). > > > > Note that USB core will reject URBs submitted for endpoints with zero > > wMaxPacketSize but that drivers doing packet-size calculations still > > need to handle this (cf. commit 2548288b4fb0 ("USB: Fix: Don't skip > > endpoint descriptors with maxpacket=0")). > > > > Fixes: c0efd232929c ("V4L/DVB (8145a): USB Video Class driver") > > Cc: stable@vger.kernel.org # 2.6.26 > > Signed-off-by: Johan Hovold <johan@kernel.org> > > --- > > drivers/media/usb/uvc/uvc_video.c | 4 ++++ > > 1 file changed, 4 insertions(+) > > > > diff --git a/drivers/media/usb/uvc/uvc_video.c b/drivers/media/usb/uvc/uvc_video.c > > index e16464606b14..85ac5c1081b6 100644 > > --- a/drivers/media/usb/uvc/uvc_video.c > > +++ b/drivers/media/usb/uvc/uvc_video.c > > @@ -1958,6 +1958,10 @@ static int uvc_video_start_transfer(struct uvc_streaming *stream, > > if (ep == NULL) > > return -EIO; > > > > + /* Reject broken descriptors. */ > > + if (usb_endpoint_maxp(&ep->desc) == 0) > > + return -EIO; > > Is there any value in identifying this with a specific return code like > -ENODATA? Going one step further, wouldn't it be better to fail probe() for those devices ? > But either way, this seems sane. > > Reviewed-by: Kieran Bingham <kieran.bingham+renesas@ideasonboard.com> > > > + > > ret = uvc_init_video_bulk(stream, ep, gfp_flags); > > } > >
On Tue, Oct 26, 2021 at 02:15:20PM +0300, Laurent Pinchart wrote: > On Tue, Oct 26, 2021 at 11:55:05AM +0100, Kieran Bingham wrote: > > Quoting Johan Hovold (2021-10-26 10:55:11) > > > Add the missing bulk-endpoint max-packet sanity check to probe() to > > > avoid division by zero in uvc_alloc_urb_buffers() in case a malicious > > > device has broken descriptors (or when doing descriptor fuzz testing). > > > > > > Note that USB core will reject URBs submitted for endpoints with zero > > > wMaxPacketSize but that drivers doing packet-size calculations still > > > need to handle this (cf. commit 2548288b4fb0 ("USB: Fix: Don't skip > > > endpoint descriptors with maxpacket=0")). > > > > > > Fixes: c0efd232929c ("V4L/DVB (8145a): USB Video Class driver") > > > Cc: stable@vger.kernel.org # 2.6.26 > > > Signed-off-by: Johan Hovold <johan@kernel.org> > > > --- > > > drivers/media/usb/uvc/uvc_video.c | 4 ++++ > > > 1 file changed, 4 insertions(+) > > > > > > diff --git a/drivers/media/usb/uvc/uvc_video.c b/drivers/media/usb/uvc/uvc_video.c > > > index e16464606b14..85ac5c1081b6 100644 > > > --- a/drivers/media/usb/uvc/uvc_video.c > > > +++ b/drivers/media/usb/uvc/uvc_video.c > > > @@ -1958,6 +1958,10 @@ static int uvc_video_start_transfer(struct uvc_streaming *stream, > > > if (ep == NULL) > > > return -EIO; > > > > > > + /* Reject broken descriptors. */ > > > + if (usb_endpoint_maxp(&ep->desc) == 0) > > > + return -EIO; > > > > Is there any value in identifying this with a specific return code like > > -ENODATA? > > Going one step further, wouldn't it be better to fail probe() for those > devices ? This is not how the driver works today. Look at the "return -EIO" just above in case the expected endpoint is missing. And similarly for the isochronous case for which zero wMaxPacket isn't handled until uvc_video_start_transfer() either (a few lines further up still). Note however the copy-paste error in the commit message mentioning probe(), which is indeed where this would typically be handled. Do you want me to resend or can you change s/probe()/uvc_video_start_transfer()/ in the commit message when applying if you think this is acceptable as is? Johan
Hi Johan, On Tue, Oct 26, 2021 at 02:06:55PM +0200, Johan Hovold wrote: > On Tue, Oct 26, 2021 at 02:15:20PM +0300, Laurent Pinchart wrote: > > On Tue, Oct 26, 2021 at 11:55:05AM +0100, Kieran Bingham wrote: > > > Quoting Johan Hovold (2021-10-26 10:55:11) > > > > Add the missing bulk-endpoint max-packet sanity check to probe() to > > > > avoid division by zero in uvc_alloc_urb_buffers() in case a malicious > > > > device has broken descriptors (or when doing descriptor fuzz testing). > > > > > > > > Note that USB core will reject URBs submitted for endpoints with zero > > > > wMaxPacketSize but that drivers doing packet-size calculations still > > > > need to handle this (cf. commit 2548288b4fb0 ("USB: Fix: Don't skip > > > > endpoint descriptors with maxpacket=0")). > > > > > > > > Fixes: c0efd232929c ("V4L/DVB (8145a): USB Video Class driver") > > > > Cc: stable@vger.kernel.org # 2.6.26 > > > > Signed-off-by: Johan Hovold <johan@kernel.org> > > > > --- > > > > drivers/media/usb/uvc/uvc_video.c | 4 ++++ > > > > 1 file changed, 4 insertions(+) > > > > > > > > diff --git a/drivers/media/usb/uvc/uvc_video.c b/drivers/media/usb/uvc/uvc_video.c > > > > index e16464606b14..85ac5c1081b6 100644 > > > > --- a/drivers/media/usb/uvc/uvc_video.c > > > > +++ b/drivers/media/usb/uvc/uvc_video.c > > > > @@ -1958,6 +1958,10 @@ static int uvc_video_start_transfer(struct uvc_streaming *stream, > > > > if (ep == NULL) > > > > return -EIO; > > > > > > > > + /* Reject broken descriptors. */ > > > > + if (usb_endpoint_maxp(&ep->desc) == 0) > > > > + return -EIO; > > > > > > Is there any value in identifying this with a specific return code like > > > -ENODATA? > > > > Going one step further, wouldn't it be better to fail probe() for those > > devices ? > > This is not how the driver works today. Look at the "return -EIO" just > above in case the expected endpoint is missing. And similarly for the > isochronous case for which zero wMaxPacket isn't handled until > uvc_video_start_transfer() either (a few lines further up still). That's a good point, it wouldn't be reasonable to ask you to fix all that :-) > Note however the copy-paste error in the commit message mentioning > probe(), which is indeed where this would typically be handled. > > Do you want me to resend or can you change > > s/probe()/uvc_video_start_transfer()/ > > in the commit message when applying if you think this is acceptable as > is? I can fix this when applying. Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
On Wed, Oct 27, 2021 at 12:50:46AM +0300, Laurent Pinchart wrote: > Hi Johan, > > On Tue, Oct 26, 2021 at 02:06:55PM +0200, Johan Hovold wrote: > > Do you want me to resend or can you change > > > > s/probe()/uvc_video_start_transfer()/ > > > > in the commit message when applying if you think this is acceptable as > > is? > > I can fix this when applying. Perfect, thanks. > Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com> Johan
Hi Laurent, On Wed, Oct 27, 2021 at 12:50:46AM +0300, Laurent Pinchart wrote: > Hi Johan, > > On Tue, Oct 26, 2021 at 02:06:55PM +0200, Johan Hovold wrote: > > On Tue, Oct 26, 2021 at 02:15:20PM +0300, Laurent Pinchart wrote: > > > On Tue, Oct 26, 2021 at 11:55:05AM +0100, Kieran Bingham wrote: > > > > Quoting Johan Hovold (2021-10-26 10:55:11) > > > > > Add the missing bulk-endpoint max-packet sanity check to probe() to > > > > > avoid division by zero in uvc_alloc_urb_buffers() in case a malicious > > > > > device has broken descriptors (or when doing descriptor fuzz testing). > > > > > > > > > > Note that USB core will reject URBs submitted for endpoints with zero > > > > > wMaxPacketSize but that drivers doing packet-size calculations still > > > > > need to handle this (cf. commit 2548288b4fb0 ("USB: Fix: Don't skip > > > > > endpoint descriptors with maxpacket=0")). > > > > > > > > > > Fixes: c0efd232929c ("V4L/DVB (8145a): USB Video Class driver") > > > > > Cc: stable@vger.kernel.org # 2.6.26 > > > > > Signed-off-by: Johan Hovold <johan@kernel.org> > > Note however the copy-paste error in the commit message mentioning > > probe(), which is indeed where this would typically be handled. > > > > Do you want me to resend or can you change > > > > s/probe()/uvc_video_start_transfer()/ > > > > in the commit message when applying if you think this is acceptable as > > is? > > I can fix this when applying. > > Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com> I noticed that this one hasn't showed up in linux-next yet. Do you still have it in your queue or do you want me to resend? Johan
Hi Johan, On Fri, Dec 03, 2021 at 11:29:07AM +0100, Johan Hovold wrote: > On Wed, Oct 27, 2021 at 12:50:46AM +0300, Laurent Pinchart wrote: > > On Tue, Oct 26, 2021 at 02:06:55PM +0200, Johan Hovold wrote: > > > On Tue, Oct 26, 2021 at 02:15:20PM +0300, Laurent Pinchart wrote: > > > > On Tue, Oct 26, 2021 at 11:55:05AM +0100, Kieran Bingham wrote: > > > > > Quoting Johan Hovold (2021-10-26 10:55:11) > > > > > > Add the missing bulk-endpoint max-packet sanity check to probe() to > > > > > > avoid division by zero in uvc_alloc_urb_buffers() in case a malicious > > > > > > device has broken descriptors (or when doing descriptor fuzz testing). > > > > > > > > > > > > Note that USB core will reject URBs submitted for endpoints with zero > > > > > > wMaxPacketSize but that drivers doing packet-size calculations still > > > > > > need to handle this (cf. commit 2548288b4fb0 ("USB: Fix: Don't skip > > > > > > endpoint descriptors with maxpacket=0")). > > > > > > > > > > > > Fixes: c0efd232929c ("V4L/DVB (8145a): USB Video Class driver") > > > > > > Cc: stable@vger.kernel.org # 2.6.26 > > > > > > Signed-off-by: Johan Hovold <johan@kernel.org> > > > > > > Note however the copy-paste error in the commit message mentioning > > > probe(), which is indeed where this would typically be handled. > > > > > > Do you want me to resend or can you change > > > > > > s/probe()/uvc_video_start_transfer()/ > > > > > > in the commit message when applying if you think this is acceptable as > > > is? > > > > I can fix this when applying. > > > > Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com> > > I noticed that this one hasn't showed up in linux-next yet. Do you still > have it in your queue or do you want me to resend? It should be in Mauro's queue now: https://lore.kernel.org/all/YacOun3Diggsi05V@pendragon.ideasonboard.com/
On Fri, Dec 03, 2021 at 12:52:19PM +0200, Laurent Pinchart wrote: > > I noticed that this one hasn't showed up in linux-next yet. Do you still > > have it in your queue or do you want me to resend? > > It should be in Mauro's queue now: > > https://lore.kernel.org/all/YacOun3Diggsi05V@pendragon.ideasonboard.com/ Perfect, thanks! Johan
diff --git a/drivers/media/usb/uvc/uvc_video.c b/drivers/media/usb/uvc/uvc_video.c index e16464606b14..85ac5c1081b6 100644 --- a/drivers/media/usb/uvc/uvc_video.c +++ b/drivers/media/usb/uvc/uvc_video.c @@ -1958,6 +1958,10 @@ static int uvc_video_start_transfer(struct uvc_streaming *stream, if (ep == NULL) return -EIO; + /* Reject broken descriptors. */ + if (usb_endpoint_maxp(&ep->desc) == 0) + return -EIO; + ret = uvc_init_video_bulk(stream, ep, gfp_flags); }