public inbox for stable@vger.kernel.org
 help / color / mirror / Atom feed
From: Johan Hovold <johan@kernel.org>
To: Ian Abbott <abbotti@mev.co.uk>
Cc: H Hartley Sweeten <hsweeten@visionengravers.com>,
	Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
	linux-usb@vger.kernel.org, linux-kernel@vger.kernel.org,
	stable@vger.kernel.org,
	Luca Ellero <luca.ellero@brickedbrain.com>
Subject: Re: [PATCH 1/5] comedi: ni_usb6501: fix NULL-deref in command paths
Date: Wed, 27 Oct 2021 10:54:51 +0200	[thread overview]
Message-ID: <YXkT24DuZHehBO/b@hovoldconsulting.com> (raw)
In-Reply-To: <be9dcb4f-3594-e756-78e3-74750a49fe91@mev.co.uk>

On Tue, Oct 26, 2021 at 03:12:28PM +0100, Ian Abbott wrote:
> On 25/10/2021 12:45, Johan Hovold wrote:
> > The driver uses endpoint-sized USB transfer buffers but had no sanity
> > checks on the sizes. This can lead to zero-size-pointer dereferences or
> > overflowed transfer buffers in ni6501_port_command() and
> > ni6501_counter_command() if a (malicious) device has smaller max-packet
> > sizes than expected (or when doing descriptor fuzz testing).
> > 
> > Add the missing sanity checks to probe().
> > 
> > Fixes: a03bb00e50ab ("staging: comedi: add NI USB-6501 support")
> > Cc: stable@vger.kernel.org      # 3.18
> > Cc: Luca Ellero <luca.ellero@brickedbrain.com>
> > Signed-off-by: Johan Hovold <johan@kernel.org>
> > ---
> >   drivers/comedi/drivers/ni_usb6501.c | 8 ++++++++
> >   1 file changed, 8 insertions(+)
> > 
> > diff --git a/drivers/comedi/drivers/ni_usb6501.c b/drivers/comedi/drivers/ni_usb6501.c
> > index 5b6d9d783b2f..eb2e5c23f25d 100644
> > --- a/drivers/comedi/drivers/ni_usb6501.c
> > +++ b/drivers/comedi/drivers/ni_usb6501.c
> > @@ -144,6 +144,10 @@ static const u8 READ_COUNTER_RESPONSE[]	= {0x00, 0x01, 0x00, 0x10,
> >   					   0x00, 0x00, 0x00, 0x02,
> >   					   0x00, 0x00, 0x00, 0x00};
> >   
> > +/* Largest supported packets */
> > +static const size_t TX_MAX_SIZE	= sizeof(SET_PORT_DIR_REQUEST);
> > +static const size_t RX_MAX_SIZE	= sizeof(READ_PORT_RESPONSE);
> > +
> >   enum commands {
> >   	READ_PORT,
> >   	WRITE_PORT,
> > @@ -486,12 +490,16 @@ static int ni6501_find_endpoints(struct comedi_device *dev)
> >   		ep_desc = &iface_desc->endpoint[i].desc;
> >   
> >   		if (usb_endpoint_is_bulk_in(ep_desc)) {
> > +			if (usb_endpoint_maxp(ep_desc) < RX_MAX_SIZE)
> > +				continue;
> >   			if (!devpriv->ep_rx)
> >   				devpriv->ep_rx = ep_desc;
> >   			continue;
> >   		}
> >   
> >   		if (usb_endpoint_is_bulk_out(ep_desc)) {
> > +			if (usb_endpoint_maxp(ep_desc) < TX_MAX_SIZE)
> > +				continue;
> >   			if (!devpriv->ep_tx)
> >   				devpriv->ep_tx = ep_desc;
> >   			continue;
> > 
> 
> Perhaps it should return an error if the first encountered bulk-in 
> endpoint has the wrong size or the first encountered bulk-out endpoint 
> has the wrong size. Something like:
> 
> 		if (usb_endpoint_is_bulk_in(ep_desc)) {
> 			if (!devpriv->ep_rx) {
> 				if (usb_endpoint_maxp(ep_desc) < RX_MAX_SIZE)
> 					break;
> 			}
> 			continue;

This is too convoluted, but I can move the max-packet sanity checks
after the endpoint look-ups instead.

It doesn't really matter in the end as the real devices presumably only
have two bulk endpoints.

Johan

  reply	other threads:[~2021-10-27  8:55 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <20211025114532.4599-1-johan@kernel.org>
2021-10-25 11:45 ` [PATCH 1/5] comedi: ni_usb6501: fix NULL-deref in command paths Johan Hovold
2021-10-26 14:12   ` Ian Abbott
2021-10-27  8:54     ` Johan Hovold [this message]
2021-10-25 11:45 ` [PATCH 2/5] comedi: dt9812: fix DMA buffers on stack Johan Hovold
2021-10-26 14:27   ` Ian Abbott
2021-10-27  9:05     ` Johan Hovold
2021-10-25 11:45 ` [PATCH 3/5] comedi: vmk80xx: fix transfer-buffer overflows Johan Hovold
2021-10-26 14:32   ` Ian Abbott
2021-10-25 11:45 ` [PATCH 4/5] comedi: vmk80xx: fix bulk-buffer overflow Johan Hovold
2021-10-26 14:34   ` Ian Abbott
2021-10-25 11:45 ` [PATCH 5/5] comedi: vmk80xx: fix bulk and interrupt message timeouts Johan Hovold
2021-10-26 14:35   ` Ian Abbott

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=YXkT24DuZHehBO/b@hovoldconsulting.com \
    --to=johan@kernel.org \
    --cc=abbotti@mev.co.uk \
    --cc=gregkh@linuxfoundation.org \
    --cc=hsweeten@visionengravers.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-usb@vger.kernel.org \
    --cc=luca.ellero@brickedbrain.com \
    --cc=stable@vger.kernel.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